mirror of
https://github.com/btcsuite/btcd.git
synced 2025-02-22 22:25:45 +01:00
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:
parent
6cd8955498
commit
e3eeb4a34a
5 changed files with 14 additions and 5 deletions
|
@ -84,6 +84,11 @@ type Config struct {
|
||||||
// Policy houses the policy (configuration parameters) which is used to
|
// Policy houses the policy (configuration parameters) which is used to
|
||||||
// control the mempool.
|
// control the mempool.
|
||||||
type Policy struct {
|
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
|
// DisableRelayPriority defines whether to relay free or low-fee
|
||||||
// transactions that do not have enough priority to be relayed.
|
// transactions that do not have enough priority to be relayed.
|
||||||
DisableRelayPriority bool
|
DisableRelayPriority bool
|
||||||
|
@ -625,7 +630,8 @@ func (mp *TxPool) maybeAcceptTransaction(tx *btcutil.Tx, isNew, rateLimit, rejec
|
||||||
// forbid their acceptance.
|
// forbid their acceptance.
|
||||||
if !mp.cfg.Policy.AcceptNonStd {
|
if !mp.cfg.Policy.AcceptNonStd {
|
||||||
err = checkTransactionStandard(tx, nextBlockHeight,
|
err = checkTransactionStandard(tx, nextBlockHeight,
|
||||||
medianTimePast, mp.cfg.Policy.MinRelayTxFee)
|
medianTimePast, mp.cfg.Policy.MinRelayTxFee,
|
||||||
|
mp.cfg.Policy.MaxTxVersion)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Attempt to extract a reject code from the error so
|
// Attempt to extract a reject code from the error so
|
||||||
// it can be retained. When not possible, fall back to
|
// it can be retained. When not possible, fall back to
|
||||||
|
|
|
@ -312,6 +312,7 @@ func newPoolHarness(chainParams *chaincfg.Params) (*poolHarness, []spendableOutp
|
||||||
MaxOrphanTxSize: 1000,
|
MaxOrphanTxSize: 1000,
|
||||||
MaxSigOpsPerTx: blockchain.MaxSigOpsPerBlock / 5,
|
MaxSigOpsPerTx: blockchain.MaxSigOpsPerBlock / 5,
|
||||||
MinRelayTxFee: 1000, // 1 Satoshi per byte
|
MinRelayTxFee: 1000, // 1 Satoshi per byte
|
||||||
|
MaxTxVersion: 1,
|
||||||
},
|
},
|
||||||
ChainParams: chainParams,
|
ChainParams: chainParams,
|
||||||
FetchUtxoView: chain.FetchUtxoView,
|
FetchUtxoView: chain.FetchUtxoView,
|
||||||
|
|
|
@ -252,14 +252,15 @@ func isDust(txOut *wire.TxOut, minRelayTxFee btcutil.Amount) bool {
|
||||||
// of recognized forms, and not containing "dust" outputs (those that are
|
// of recognized forms, and not containing "dust" outputs (those that are
|
||||||
// so small it costs more to process them than they are worth).
|
// so small it costs more to process them than they are worth).
|
||||||
func checkTransactionStandard(tx *btcutil.Tx, height int32,
|
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.
|
// The transaction must be a currently supported version.
|
||||||
msgTx := tx.MsgTx()
|
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 "+
|
str := fmt.Sprintf("transaction version %d is not in the "+
|
||||||
"valid range of %d-%d", msgTx.Version, 1,
|
"valid range of %d-%d", msgTx.Version, 1,
|
||||||
wire.TxVersion)
|
maxTxVersion)
|
||||||
return txRuleError(wire.RejectNonstandard, str)
|
return txRuleError(wire.RejectNonstandard, str)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -470,7 +470,7 @@ func TestCheckTransactionStandard(t *testing.T) {
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
// Ensure standardness is as expected.
|
// Ensure standardness is as expected.
|
||||||
err := checkTransactionStandard(btcutil.NewTx(&test.tx),
|
err := checkTransactionStandard(btcutil.NewTx(&test.tx),
|
||||||
test.height, pastMedianTime, DefaultMinRelayTxFee)
|
test.height, pastMedianTime, DefaultMinRelayTxFee, 1)
|
||||||
if err == nil && test.isStandard {
|
if err == nil && test.isStandard {
|
||||||
// Test passes since function returned standard for a
|
// Test passes since function returned standard for a
|
||||||
// transaction which is intended to be standard.
|
// transaction which is intended to be standard.
|
||||||
|
|
|
@ -2355,6 +2355,7 @@ func newServer(listenAddrs []string, db database.DB, chainParams *chaincfg.Param
|
||||||
MaxOrphanTxSize: defaultMaxOrphanTxSize,
|
MaxOrphanTxSize: defaultMaxOrphanTxSize,
|
||||||
MaxSigOpsPerTx: blockchain.MaxSigOpsPerBlock / 5,
|
MaxSigOpsPerTx: blockchain.MaxSigOpsPerBlock / 5,
|
||||||
MinRelayTxFee: cfg.minRelayTxFee,
|
MinRelayTxFee: cfg.minRelayTxFee,
|
||||||
|
MaxTxVersion: 2,
|
||||||
},
|
},
|
||||||
ChainParams: chainParams,
|
ChainParams: chainParams,
|
||||||
FetchUtxoView: s.blockManager.chain.FetchUtxoView,
|
FetchUtxoView: s.blockManager.chain.FetchUtxoView,
|
||||||
|
|
Loading…
Add table
Reference in a new issue