Skip to content

Commit 76ebabb

Browse files
committed
mempool+server: wire StandardPackageAnalyzer into TxMempoolV2
This commit integrates the StandardPackageAnalyzer into the v2 mempool initialization flow, enabling TRUC validation for all transactions processed through TxMempoolV2. The analyzer is constructed during server initialization and passed to the transaction graph through GraphConfig. When the --usetxmempoolv2 flag is enabled, the server now creates a StandardPackageAnalyzer instance and configures it in the graph. This enables automatic enforcement of BIP 431 rules during transaction acceptance without requiring explicit validation calls in the mempool logic, as the graph handles package identification and validation internally. Convenience wrapper functions NewStandardPackageAnalyzer and DefaultGraphConfig in the mempool package simplify server initialization while keeping the txgraph package focused on graph operations. This layering prevents circular dependencies and maintains clean separation between graph logic and higher-level mempool policy.
1 parent e5063b0 commit 76ebabb

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

mempool/mempool_v2.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,5 +902,17 @@ func (mp *TxMempoolV2) CheckMempoolAcceptance(tx *btcutil.Tx) (*MempoolAcceptRes
902902
return mp.checkMempoolAcceptance(tx, true, false, true)
903903
}
904904

905+
// NewStandardPackageAnalyzer creates a new standard package analyzer for TRUC
906+
// (BIP 431) validation. This is a convenience wrapper for the txgraph package.
907+
func NewStandardPackageAnalyzer() *txgraph.StandardPackageAnalyzer {
908+
return txgraph.NewStandardPackageAnalyzer()
909+
}
910+
911+
// DefaultGraphConfig returns the default txgraph configuration. This is a
912+
// convenience wrapper for the txgraph package.
913+
func DefaultGraphConfig() *txgraph.Config {
914+
return txgraph.DefaultConfig()
915+
}
916+
905917
// Ensure TxMempoolV2 implements the TxMempool interface.
906918
var _ TxMempool = (*TxMempoolV2)(nil)

server.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3214,6 +3214,13 @@ func (s *server) initTxMempoolV2(cfg *config, chainParams *chaincfg.Params) (mem
32143214
}
32153215
orphanManager := mempool.NewOrphanManager(orphanCfg)
32163216

3217+
// Create PackageAnalyzer for TRUC (BIP 431) validation.
3218+
packageAnalyzer := mempool.NewStandardPackageAnalyzer()
3219+
3220+
// Create GraphConfig with package analyzer.
3221+
graphCfg := mempool.DefaultGraphConfig()
3222+
graphCfg.PackageAnalyzer = packageAnalyzer
3223+
32173224
// Create MempoolConfig with all dependencies.
32183225
mempoolCfg := &mempool.MempoolConfig{
32193226
FetchUtxoView: s.chain.FetchUtxoView,
@@ -3224,7 +3231,7 @@ func (s *server) initTxMempoolV2(cfg *config, chainParams *chaincfg.Params) (mem
32243231
OrphanManager: orphanManager,
32253232
AddrIndex: s.addrIndex,
32263233
FeeEstimator: s.feeEstimator,
3227-
GraphConfig: nil, // Use defaults.
3234+
GraphConfig: graphCfg,
32283235
}
32293236

32303237
return mempool.NewTxMempoolV2(mempoolCfg)

0 commit comments

Comments
 (0)