From e3eeb4a34a04c8ec40298fee9f9d8fe2ce0c13ca Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Fri, 26 Aug 2016 18:49:59 -0700 Subject: [PATCH] mempool: add policy config option for transaction version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds a new option to the mempool’s policy configuration which determines which transaction versions should be accepted as standard. The default version set by the policy within the server is 2; this allows accepting transactions which have version 2 enabled in order to utilize the new sequence locks feature. --- mempool/mempool.go | 8 +++++++- mempool/mempool_test.go | 1 + mempool/policy.go | 7 ++++--- mempool/policy_test.go | 2 +- server.go | 1 + 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/mempool/mempool.go b/mempool/mempool.go index 9e8f9b63d..d3f8b75b1 100644 --- a/mempool/mempool.go +++ b/mempool/mempool.go @@ -84,6 +84,11 @@ type Config struct { // Policy houses the policy (configuration parameters) which is used to // control the mempool. type Policy struct { + // MaxTxVersion is the transaction version that the mempool should + // accept. All transactions above this version are rejected as + // non-standard. + MaxTxVersion int32 + // DisableRelayPriority defines whether to relay free or low-fee // transactions that do not have enough priority to be relayed. DisableRelayPriority bool @@ -625,7 +630,8 @@ func (mp *TxPool) maybeAcceptTransaction(tx *btcutil.Tx, isNew, rateLimit, rejec // forbid their acceptance. if !mp.cfg.Policy.AcceptNonStd { err = checkTransactionStandard(tx, nextBlockHeight, - medianTimePast, mp.cfg.Policy.MinRelayTxFee) + medianTimePast, mp.cfg.Policy.MinRelayTxFee, + mp.cfg.Policy.MaxTxVersion) if err != nil { // Attempt to extract a reject code from the error so // it can be retained. When not possible, fall back to diff --git a/mempool/mempool_test.go b/mempool/mempool_test.go index dd39f0ae8..e81ca0ec4 100644 --- a/mempool/mempool_test.go +++ b/mempool/mempool_test.go @@ -312,6 +312,7 @@ func newPoolHarness(chainParams *chaincfg.Params) (*poolHarness, []spendableOutp MaxOrphanTxSize: 1000, MaxSigOpsPerTx: blockchain.MaxSigOpsPerBlock / 5, MinRelayTxFee: 1000, // 1 Satoshi per byte + MaxTxVersion: 1, }, ChainParams: chainParams, FetchUtxoView: chain.FetchUtxoView, diff --git a/mempool/policy.go b/mempool/policy.go index fecf5952f..58482c99f 100644 --- a/mempool/policy.go +++ b/mempool/policy.go @@ -252,14 +252,15 @@ func isDust(txOut *wire.TxOut, minRelayTxFee btcutil.Amount) bool { // 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, - medianTimePast time.Time, minRelayTxFee btcutil.Amount) error { + medianTimePast time.Time, minRelayTxFee btcutil.Amount, + maxTxVersion int32) error { // The transaction must be a currently supported version. msgTx := tx.MsgTx() - if msgTx.Version > wire.TxVersion || msgTx.Version < 1 { + 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, - wire.TxVersion) + maxTxVersion) return txRuleError(wire.RejectNonstandard, str) } diff --git a/mempool/policy_test.go b/mempool/policy_test.go index 8637181eb..d616d6ed4 100644 --- a/mempool/policy_test.go +++ b/mempool/policy_test.go @@ -470,7 +470,7 @@ func TestCheckTransactionStandard(t *testing.T) { for _, test := range tests { // Ensure standardness is as expected. err := checkTransactionStandard(btcutil.NewTx(&test.tx), - test.height, pastMedianTime, DefaultMinRelayTxFee) + test.height, pastMedianTime, DefaultMinRelayTxFee, 1) 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 9ebc3b00f..2d938909f 100644 --- a/server.go +++ b/server.go @@ -2355,6 +2355,7 @@ func newServer(listenAddrs []string, db database.DB, chainParams *chaincfg.Param MaxOrphanTxSize: defaultMaxOrphanTxSize, MaxSigOpsPerTx: blockchain.MaxSigOpsPerBlock / 5, MinRelayTxFee: cfg.minRelayTxFee, + MaxTxVersion: 2, }, ChainParams: chainParams, FetchUtxoView: s.blockManager.chain.FetchUtxoView,