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.
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

View file

@ -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
}

View file

@ -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)