mempool: transaction finality checks now use median-time-past
This coincides with the mempool only, policy change which enforces transaction finality according to the median-time-past rather than blockheader timestamps. The behavior is pre-cursor to full blown BIP 113 consensus deployment, and subsequent activation. As a result, the TimeSource field in the mempoolConfig is no longer needed so it has been removed. Additionally, checkTransactionStandard has been modified to instead take a time.Time as the mempool is no longer explicitly dependant on a Chain instance.
This commit is contained in:
parent
a82f67b538
commit
e7caccc866
3 changed files with 11 additions and 11 deletions
|
@ -67,9 +67,6 @@ type Config struct {
|
|||
// SigCache defines a signature cache to use.
|
||||
SigCache *txscript.SigCache
|
||||
|
||||
// TimeSource defines the timesource to use.
|
||||
TimeSource blockchain.MedianTimeSource
|
||||
|
||||
// AddrIndex defines the optional address index instance to use for
|
||||
// indexing the unconfirmed transactions in the memory pool.
|
||||
// This can be nil if the address index is not enabled.
|
||||
|
@ -551,8 +548,9 @@ func (mp *TxPool) maybeAcceptTransaction(tx *btcutil.Tx, isNew, rateLimit bool)
|
|||
// Don't allow non-standard transactions if the network parameters
|
||||
// forbid their relaying.
|
||||
if !mp.cfg.Policy.RelayNonStd {
|
||||
err := checkTransactionStandard(tx, nextBlockHeight,
|
||||
mp.cfg.TimeSource, mp.cfg.Policy.MinRelayTxFee)
|
||||
medianTimePast := mp.cfg.MedianTimePast()
|
||||
err = checkTransactionStandard(tx, nextBlockHeight,
|
||||
medianTimePast, mp.cfg.Policy.MinRelayTxFee)
|
||||
if err != nil {
|
||||
// Attempt to extract a reject code from the error so
|
||||
// it can be retained. When not possible, fall back to
|
||||
|
|
|
@ -6,6 +6,7 @@ package mempool
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/blockchain"
|
||||
"github.com/btcsuite/btcd/txscript"
|
||||
|
@ -326,7 +327,9 @@ func isDust(txOut *wire.TxOut, minRelayTxFee btcutil.Amount) bool {
|
|||
// finalized, conforming to more stringent size constraints, having scripts
|
||||
// of recognized forms, and not containing "dust" outputs (those that are
|
||||
// so small it costs more to process them than they are worth).
|
||||
func checkTransactionStandard(tx *btcutil.Tx, height int32, timeSource blockchain.MedianTimeSource, minRelayTxFee btcutil.Amount) error {
|
||||
func checkTransactionStandard(tx *btcutil.Tx, height int32,
|
||||
medianTimePast time.Time, minRelayTxFee btcutil.Amount) error {
|
||||
|
||||
// The transaction must be a currently supported version.
|
||||
msgTx := tx.MsgTx()
|
||||
if msgTx.Version > wire.TxVersion || msgTx.Version < 1 {
|
||||
|
@ -338,8 +341,7 @@ func checkTransactionStandard(tx *btcutil.Tx, height int32, timeSource blockchai
|
|||
|
||||
// The transaction must be finalized to be standard and therefore
|
||||
// considered for inclusion in a block.
|
||||
adjustedTime := timeSource.AdjustedTime()
|
||||
if !blockchain.IsFinalizedTransaction(tx, height, adjustedTime) {
|
||||
if !blockchain.IsFinalizedTransaction(tx, height, medianTimePast) {
|
||||
return txRuleError(wire.RejectNonstandard,
|
||||
"transaction is not finalized")
|
||||
}
|
||||
|
|
|
@ -7,8 +7,8 @@ package mempool
|
|||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/blockchain"
|
||||
"github.com/btcsuite/btcd/btcec"
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
|
@ -466,11 +466,11 @@ func TestCheckTransactionStandard(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
timeSource := blockchain.NewMedianTime()
|
||||
pastMedianTime := time.Now()
|
||||
for _, test := range tests {
|
||||
// Ensure standardness is as expected.
|
||||
err := checkTransactionStandard(btcutil.NewTx(&test.tx),
|
||||
test.height, timeSource, DefaultMinRelayTxFee)
|
||||
test.height, pastMedianTime, DefaultMinRelayTxFee)
|
||||
if err == nil && test.isStandard {
|
||||
// Test passes since function returned standard for a
|
||||
// transaction which is intended to be standard.
|
||||
|
|
Loading…
Reference in a new issue