[DEV-66] Make only transaction version 1 a standard transaction (#40)

* [DEV-66] Make only transaction version 1 a standard transaction

* [DEV-66] change checkTransactionStandard to get policy as argument
This commit is contained in:
Ori Newman 2018-08-06 16:59:33 +03:00 committed by Svarog
parent 904f2cf2e3
commit ed5df3bf7d
4 changed files with 8 additions and 10 deletions

View File

@ -677,8 +677,7 @@ 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)
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

View File

@ -251,15 +251,14 @@ 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, medianTimePast time.Time, policy *Policy) error {
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 > maxTxVersion || msgTx.Version < 1 { if msgTx.Version > policy.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,
maxTxVersion) policy.MaxTxVersion)
return txRuleError(wire.RejectNonstandard, str) return txRuleError(wire.RejectNonstandard, str)
} }
@ -326,7 +325,7 @@ func checkTransactionStandard(tx *btcutil.Tx, height int32,
// "dust". // "dust".
if scriptClass == txscript.NullDataTy { if scriptClass == txscript.NullDataTy {
numNullDataOutputs++ numNullDataOutputs++
} else if isDust(txOut, minRelayTxFee) { } else if isDust(txOut, policy.MinRelayTxFee) {
str := fmt.Sprintf("transaction output %d: payment "+ str := fmt.Sprintf("transaction output %d: payment "+
"of %d is dust", i, txOut.Value) "of %d is dust", i, txOut.Value)
return txRuleError(wire.RejectDust, str) return txRuleError(wire.RejectDust, str)

View File

@ -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, 1) test.height, pastMedianTime, &Policy{MinRelayTxFee: DefaultMinRelayTxFee, MaxTxVersion: 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.

View File

@ -25,9 +25,9 @@ import (
"github.com/daglabs/btcd/addrmgr" "github.com/daglabs/btcd/addrmgr"
"github.com/daglabs/btcd/blockdag" "github.com/daglabs/btcd/blockdag"
"github.com/daglabs/btcd/blockdag/indexers" "github.com/daglabs/btcd/blockdag/indexers"
"github.com/daglabs/btcd/connmgr"
"github.com/daglabs/btcd/dagconfig" "github.com/daglabs/btcd/dagconfig"
"github.com/daglabs/btcd/dagconfig/daghash" "github.com/daglabs/btcd/dagconfig/daghash"
"github.com/daglabs/btcd/connmgr"
"github.com/daglabs/btcd/database" "github.com/daglabs/btcd/database"
"github.com/daglabs/btcd/mempool" "github.com/daglabs/btcd/mempool"
"github.com/daglabs/btcd/mining" "github.com/daglabs/btcd/mining"
@ -2535,7 +2535,7 @@ func newServer(listenAddrs []string, db database.DB, chainParams *dagconfig.Para
MaxOrphanTxSize: defaultMaxOrphanTxSize, MaxOrphanTxSize: defaultMaxOrphanTxSize,
MaxSigOpsPerTx: blockdag.MaxSigOpsPerBlock / 5, MaxSigOpsPerTx: blockdag.MaxSigOpsPerBlock / 5,
MinRelayTxFee: cfg.minRelayTxFee, MinRelayTxFee: cfg.minRelayTxFee,
MaxTxVersion: 2, MaxTxVersion: 1,
}, },
ChainParams: chainParams, ChainParams: chainParams,
FetchUtxoView: s.dag.FetchUtxoView, FetchUtxoView: s.dag.FetchUtxoView,