mempool: add function to config for computing sequence locks

This commit is contained in:
Olaoluwa Osuntokun 2016-08-26 17:24:39 -07:00
parent ecdaf9726c
commit 7eb0ab5f8d
No known key found for this signature in database
GPG key ID: 9CC5B105D03521A2
3 changed files with 29 additions and 8 deletions

View file

@ -67,6 +67,11 @@ type Config struct {
// chain tip within the best chain. // chain tip within the best chain.
MedianTimePast func() time.Time 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 defines a signature cache to use.
SigCache *txscript.SigCache SigCache *txscript.SigCache

View file

@ -92,6 +92,17 @@ func (s *fakeChain) SetMedianTimePast(mtp time.Time) {
s.Unlock() 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 // spendableOutput is a convenience type that houses a particular utxo and the
// amount associated with it. // amount associated with it.
type spendableOutput struct { type spendableOutput struct {
@ -302,12 +313,13 @@ func newPoolHarness(chainParams *chaincfg.Params) (*poolHarness, []spendableOutp
MaxSigOpsPerTx: blockchain.MaxSigOpsPerBlock / 5, MaxSigOpsPerTx: blockchain.MaxSigOpsPerBlock / 5,
MinRelayTxFee: 1000, // 1 Satoshi per byte MinRelayTxFee: 1000, // 1 Satoshi per byte
}, },
ChainParams: chainParams, ChainParams: chainParams,
FetchUtxoView: chain.FetchUtxoView, FetchUtxoView: chain.FetchUtxoView,
BestHeight: chain.BestHeight, BestHeight: chain.BestHeight,
MedianTimePast: chain.MedianTimePast, MedianTimePast: chain.MedianTimePast,
SigCache: nil, CalcSequenceLock: chain.CalcSequenceLock,
AddrIndex: nil, SigCache: nil,
AddrIndex: nil,
}), }),
} }
@ -328,6 +340,7 @@ func newPoolHarness(chainParams *chaincfg.Params) (*poolHarness, []spendableOutp
outputs = append(outputs, txOutToSpendableOut(coinbase, i)) outputs = append(outputs, txOutToSpendableOut(coinbase, i))
} }
harness.chain.SetHeight(int32(chainParams.CoinbaseMaturity) + curHeight) harness.chain.SetHeight(int32(chainParams.CoinbaseMaturity) + curHeight)
harness.chain.SetMedianTimePast(time.Now())
return &harness, outputs, nil return &harness, outputs, nil
} }

View file

@ -2360,8 +2360,11 @@ func newServer(listenAddrs []string, db database.DB, chainParams *chaincfg.Param
FetchUtxoView: s.blockManager.chain.FetchUtxoView, FetchUtxoView: s.blockManager.chain.FetchUtxoView,
BestHeight: func() int32 { return bm.chain.BestSnapshot().Height }, BestHeight: func() int32 { return bm.chain.BestSnapshot().Height },
MedianTimePast: func() time.Time { return bm.chain.BestSnapshot().MedianTime }, MedianTimePast: func() time.Time { return bm.chain.BestSnapshot().MedianTime },
SigCache: s.sigCache, CalcSequenceLock: func(tx *btcutil.Tx, view *blockchain.UtxoViewpoint) (*blockchain.SequenceLock, error) {
AddrIndex: s.addrIndex, return bm.chain.CalcSequenceLock(tx, view, true)
},
SigCache: s.sigCache,
AddrIndex: s.addrIndex,
} }
s.txMemPool = mempool.New(&txC) s.txMemPool = mempool.New(&txC)