diff --git a/mempool/mempool.go b/mempool/mempool.go index c473bf38..8a528626 100644 --- a/mempool/mempool.go +++ b/mempool/mempool.go @@ -67,6 +67,11 @@ type Config struct { // chain tip within the best chain. MedianTimePast func() time.Time + // CalcSequenceLock defines the function to use in order to generate + // the current sequence lock for the given transaction using the passed + // utxo view. + CalcSequenceLock func(*btcutil.Tx, *blockchain.UtxoViewpoint) (*blockchain.SequenceLock, error) + // SigCache defines a signature cache to use. SigCache *txscript.SigCache diff --git a/mempool/mempool_test.go b/mempool/mempool_test.go index 29a0bf07..dd39f0ae 100644 --- a/mempool/mempool_test.go +++ b/mempool/mempool_test.go @@ -92,6 +92,17 @@ func (s *fakeChain) SetMedianTimePast(mtp time.Time) { s.Unlock() } +// CalcSequenceLock returns the current sequence lock for the passed +// transaction associated with the fake chain instance. +func (s *fakeChain) CalcSequenceLock(tx *btcutil.Tx, + view *blockchain.UtxoViewpoint) (*blockchain.SequenceLock, error) { + + return &blockchain.SequenceLock{ + Seconds: -1, + BlockHeight: -1, + }, nil +} + // spendableOutput is a convenience type that houses a particular utxo and the // amount associated with it. type spendableOutput struct { @@ -302,12 +313,13 @@ func newPoolHarness(chainParams *chaincfg.Params) (*poolHarness, []spendableOutp MaxSigOpsPerTx: blockchain.MaxSigOpsPerBlock / 5, MinRelayTxFee: 1000, // 1 Satoshi per byte }, - ChainParams: chainParams, - FetchUtxoView: chain.FetchUtxoView, - BestHeight: chain.BestHeight, - MedianTimePast: chain.MedianTimePast, - SigCache: nil, - AddrIndex: nil, + ChainParams: chainParams, + FetchUtxoView: chain.FetchUtxoView, + BestHeight: chain.BestHeight, + MedianTimePast: chain.MedianTimePast, + CalcSequenceLock: chain.CalcSequenceLock, + SigCache: nil, + AddrIndex: nil, }), } @@ -328,6 +340,7 @@ func newPoolHarness(chainParams *chaincfg.Params) (*poolHarness, []spendableOutp outputs = append(outputs, txOutToSpendableOut(coinbase, i)) } harness.chain.SetHeight(int32(chainParams.CoinbaseMaturity) + curHeight) + harness.chain.SetMedianTimePast(time.Now()) return &harness, outputs, nil } diff --git a/server.go b/server.go index df55b034..9ebc3b00 100644 --- a/server.go +++ b/server.go @@ -2360,8 +2360,11 @@ func newServer(listenAddrs []string, db database.DB, chainParams *chaincfg.Param FetchUtxoView: s.blockManager.chain.FetchUtxoView, BestHeight: func() int32 { return bm.chain.BestSnapshot().Height }, MedianTimePast: func() time.Time { return bm.chain.BestSnapshot().MedianTime }, - SigCache: s.sigCache, - AddrIndex: s.addrIndex, + CalcSequenceLock: func(tx *btcutil.Tx, view *blockchain.UtxoViewpoint) (*blockchain.SequenceLock, error) { + return bm.chain.CalcSequenceLock(tx, view, true) + }, + SigCache: s.sigCache, + AddrIndex: s.addrIndex, } s.txMemPool = mempool.New(&txC)