Skip to content

Commit

Permalink
mempool: Remove unneeded max tx ver std checks.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
davecgh committed Sep 1, 2021
1 parent 15f7a5b commit 5b48b20
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 35 deletions.
8 changes: 1 addition & 7 deletions internal/mempool/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion internal/mempool/mempool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 4 additions & 8 deletions internal/mempool/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 1 addition & 18 deletions internal/mempool/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 5b48b20

Please sign in to comment.