btcd/netsync/interface.go
Olaoluwa Osuntokun 0f61664ceb mempool+netsync: extend TxMempool interface for unified abstraction
This commit extends the TxMempool interface to support both the legacy
TxPool and new TxMempoolV2 implementations transparently. The interface
now includes all methods required by the server, netsync, and mining
subsystems, enabling a feature flag to toggle between implementations
at runtime.

The extended interface adds critical methods that were previously only
available on the concrete TxPool type: RemoveOrphansByTag for peer
cleanup, MiningDescs for block template generation, and several internal
methods (RemoveDoubleSpends, RemoveOrphan, ProcessOrphans,
MaybeAcceptTransaction) used by netsync for transaction relay.

By abstracting these operations, we enable the server to use either
implementation without subsystem-specific code changes. The netsync
package now accepts the TxMempool interface rather than requiring the
concrete TxPool type, allowing transparent switching.

The MockTxMempool test implementation is updated to provide all new
interface methods, ensuring tests continue to work with the expanded
interface contract.
2025-10-27 16:10:43 -07:00

41 lines
1.2 KiB
Go

// Copyright (c) 2017 The btcsuite developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package netsync
import (
"github.com/btcsuite/btcd/blockchain"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/mempool"
"github.com/btcsuite/btcd/peer"
"github.com/btcsuite/btcd/wire"
)
// PeerNotifier exposes methods to notify peers of status changes to
// transactions, blocks, etc. Currently server (in the main package) implements
// this interface.
type PeerNotifier interface {
AnnounceNewTransactions(newTxs []*mempool.TxDesc)
UpdatePeerHeights(latestBlkHash *chainhash.Hash, latestHeight int32, updateSource *peer.Peer)
RelayInventory(invVect *wire.InvVect, data interface{})
TransactionConfirmed(tx *btcutil.Tx)
}
// Config is a configuration struct used to initialize a new SyncManager.
type Config struct {
PeerNotifier PeerNotifier
Chain *blockchain.BlockChain
TxMemPool mempool.TxMempool
ChainParams *chaincfg.Params
DisableCheckpoints bool
MaxPeers int
FeeEstimator *mempool.FeeEstimator
}