mempool: add policy config option for transaction version

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.
This commit is contained in:
Olaoluwa Osuntokun 2016-08-26 18:49:59 -07:00
parent 6cd8955498
commit e3eeb4a34a
No known key found for this signature in database
GPG key ID: 9CC5B105D03521A2
5 changed files with 14 additions and 5 deletions

View file

@ -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

View file

@ -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,

View file

@ -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)
}

View file

@ -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.

View file

@ -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,