mempool: enforce relative lock-time semantics

This commit introduces behavior which enforces sequence num based
relative lock-time semantics when accepting transaction to the mempool.
This commit is contained in:
Olaoluwa Osuntokun 2016-06-21 22:09:11 -07:00
parent 7eb0ab5f8d
commit 6cd8955498
No known key found for this signature in database
GPG key ID: 9CC5B105D03521A2
2 changed files with 18 additions and 2 deletions

View file

@ -619,10 +619,11 @@ func (mp *TxPool) maybeAcceptTransaction(tx *btcutil.Tx, isNew, rateLimit, rejec
bestHeight := mp.cfg.BestHeight() bestHeight := mp.cfg.BestHeight()
nextBlockHeight := bestHeight + 1 nextBlockHeight := bestHeight + 1
medianTimePast := mp.cfg.MedianTimePast()
// Don't allow non-standard transactions if the network parameters // Don't allow non-standard transactions if the network parameters
// forbid their acceptance. // forbid their acceptance.
if !mp.cfg.Policy.AcceptNonStd { if !mp.cfg.Policy.AcceptNonStd {
medianTimePast := mp.cfg.MedianTimePast()
err = checkTransactionStandard(tx, nextBlockHeight, err = checkTransactionStandard(tx, nextBlockHeight,
medianTimePast, mp.cfg.Policy.MinRelayTxFee) medianTimePast, mp.cfg.Policy.MinRelayTxFee)
if err != nil { if err != nil {
@ -692,6 +693,22 @@ func (mp *TxPool) maybeAcceptTransaction(tx *btcutil.Tx, isNew, rateLimit, rejec
return missingParents, nil return missingParents, nil
} }
// Don't allow the transaction into the mempool unless its sequence
// lock is active, meaning that it'll be allowed into the next block
// with respect to its defined relative lock times.
sequenceLock, err := mp.cfg.CalcSequenceLock(tx, utxoView)
if err != nil {
if cerr, ok := err.(blockchain.RuleError); ok {
return nil, chainRuleError(cerr)
}
return nil, err
}
if !blockchain.SequenceLockActive(sequenceLock, nextBlockHeight,
medianTimePast) {
return nil, txRuleError(wire.RejectNonstandard,
"transaction's sequence locks on inputs not met")
}
// Perform several checks on the transaction inputs using the invariant // Perform several checks on the transaction inputs using the invariant
// rules in blockchain for what transactions are allowed into blocks. // rules in blockchain for what transactions are allowed into blocks.
// Also returns the fees associated with the transaction which will be // Also returns the fees associated with the transaction which will be

View file

@ -481,7 +481,6 @@ mempoolLoop:
} }
if !blockchain.IsFinalizedTransaction(tx, nextBlockHeight, if !blockchain.IsFinalizedTransaction(tx, nextBlockHeight,
timeSource.AdjustedTime()) { timeSource.AdjustedTime()) {
minrLog.Tracef("Skipping non-finalized tx %s", tx.Hash()) minrLog.Tracef("Skipping non-finalized tx %s", tx.Hash())
continue continue
} }