From ec1a6692d9f74e4f7c6e83d1b4adc330bfc3c5b3 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Fri, 27 Aug 2021 10:15:30 -0500 Subject: [PATCH] mempool: Remove unneeded max tx ver std checks. This removes the handling for a configurable maximum allowed transaction version via the standardness policy since it is now enforced via consensus rules instead. The following is an overview of the changes: - Remove the MaxTxVersion field from the Policy struct - Remove the max tx version checking logic from checkTransactionStandard - Remove the max tx version param from checkTransactionStandard - Update the transaction standardness tests accordingly - Update all callers accordingly --- internal/mempool/mempool.go | 8 +------- internal/mempool/mempool_test.go | 1 - internal/mempool/policy.go | 12 ++++-------- internal/mempool/policy_test.go | 19 +------------------ server.go | 1 - 5 files changed, 6 insertions(+), 35 deletions(-) diff --git a/internal/mempool/mempool.go b/internal/mempool/mempool.go index ff885ee78e..e0c03015bb 100644 --- a/internal/mempool/mempool.go +++ b/internal/mempool/mempool.go @@ -162,11 +162,6 @@ type Config struct { // Policy houses the policy (configuration parameters) which is used to // control the mempool. type Policy struct { - // MaxTxVersion is the max transaction version that the mempool should - // accept. All transactions above this version are rejected as - // non-standard. - MaxTxVersion uint16 - // DisableRelayPriority defines whether to relay free or low-fee // transactions that do not have enough priority to be relayed. DisableRelayPriority bool @@ -1311,8 +1306,7 @@ func (mp *TxPool) maybeAcceptTransaction(tx *dcrutil.Tx, isNew, rateLimit, medianTime := mp.cfg.PastMedianTime() if !mp.cfg.Policy.AcceptNonStd { err := checkTransactionStandard(tx, txType, nextBlockHeight, - medianTime, mp.cfg.Policy.MinRelayTxFee, - mp.cfg.Policy.MaxTxVersion, isTreasuryEnabled) + medianTime, mp.cfg.Policy.MinRelayTxFee, isTreasuryEnabled) if err != nil { str := fmt.Sprintf("transaction %v is not standard: %v", txHash, err) diff --git a/internal/mempool/mempool_test.go b/internal/mempool/mempool_test.go index 15b0d9057b..2ed42649bd 100644 --- a/internal/mempool/mempool_test.go +++ b/internal/mempool/mempool_test.go @@ -790,7 +790,6 @@ func newPoolHarness(chainParams *chaincfg.Params) (*poolHarness, []spendableOutp txPool: New(&Config{ Policy: Policy{ EnableAncestorTracking: true, - MaxTxVersion: wire.TxVersionTreasury, DisableRelayPriority: true, FreeTxRelayLimit: 15.0, MaxOrphanTxs: 5, diff --git a/internal/mempool/policy.go b/internal/mempool/policy.go index 3d5879f7ed..1530316482 100644 --- a/internal/mempool/policy.go +++ b/internal/mempool/policy.go @@ -296,21 +296,17 @@ func isDust(txOut *wire.TxOut, minRelayTxFee dcrutil.Amount) bool { // // Note: all non-nil errors MUST be RuleError with an underlying TxRuleError // instance. -func checkTransactionStandard(tx *dcrutil.Tx, txType stake.TxType, height int64, medianTime time.Time, minRelayTxFee dcrutil.Amount, maxTxVersion uint16, isTreasuryEnabled bool) error { +func checkTransactionStandard(tx *dcrutil.Tx, txType stake.TxType, height int64, + medianTime time.Time, minRelayTxFee dcrutil.Amount, + isTreasuryEnabled bool) error { - // The transaction must be a currently supported version and serialize - // type. + // The transaction must be a currently supported serialize type. msgTx := tx.MsgTx() if msgTx.SerType != wire.TxSerializeFull { str := fmt.Sprintf("transaction is not serialized with all "+ "required data -- type %v", msgTx.SerType) return txRuleError(ErrNonStandard, str) } - if msgTx.Version > maxTxVersion || msgTx.Version < 1 { - str := fmt.Sprintf("transaction version %d is not in the "+ - "valid range of %d-%d", msgTx.Version, 1, maxTxVersion) - return txRuleError(ErrNonStandard, str) - } // The transaction must be finalized to be standard and therefore // considered for inclusion in a block. diff --git a/internal/mempool/policy_test.go b/internal/mempool/policy_test.go index 25393355f1..6de820c3c6 100644 --- a/internal/mempool/policy_test.go +++ b/internal/mempool/policy_test.go @@ -306,10 +306,6 @@ func TestDust(t *testing.T) { // TestCheckTransactionStandard tests the checkTransactionStandard API. func TestCheckTransactionStandard(t *testing.T) { - // maxTxVersion is used as the maximum support transaction version for - // the policy in these tests. - const maxTxVersion = 1 - // Create some dummy, but otherwise standard, data for transactions. prevOutHash, err := chainhash.NewHashFromStr("01") if err != nil { @@ -370,19 +366,6 @@ func TestCheckTransactionStandard(t *testing.T) { isStandard: false, err: ErrNonStandard, }, - { - name: "Transaction version too high", - tx: wire.MsgTx{ - SerType: wire.TxSerializeFull, - Version: maxTxVersion + 1, - TxIn: []*wire.TxIn{&dummyTxIn}, - TxOut: []*wire.TxOut{&dummyTxOut}, - LockTime: 0, - }, - height: 300000, - isStandard: false, - err: ErrNonStandard, - }, { name: "Transaction is not finalized", tx: wire.MsgTx{ @@ -536,7 +519,7 @@ func TestCheckTransactionStandard(t *testing.T) { txType := stake.DetermineTxType(&test.tx, noTreasury) tx := dcrutil.NewTx(&test.tx) err := checkTransactionStandard(tx, txType, test.height, medianTime, - DefaultMinRelayTxFee, maxTxVersion, noTreasury) + DefaultMinRelayTxFee, noTreasury) if err == nil && test.isStandard { // Test passes since function returned standard for a // transaction which is intended to be standard. diff --git a/server.go b/server.go index 5f10aa2e1d..973d374b9c 100644 --- a/server.go +++ b/server.go @@ -3433,7 +3433,6 @@ func newServer(ctx context.Context, listenAddrs []string, db database.DB, txC := mempool.Config{ Policy: mempool.Policy{ EnableAncestorTracking: len(cfg.miningAddrs) > 0, - MaxTxVersion: wire.TxVersionTreasury, DisableRelayPriority: cfg.NoRelayPriority, AcceptNonStd: cfg.AcceptNonStd, FreeTxRelayLimit: cfg.FreeTxRelayLimit,