Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mempool: export checkStandardness func #1840

Merged
merged 1 commit into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mempool/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import (
"github.com/btcsuite/btcd/blockchain"
"github.com/btcsuite/btcd/blockchain/indexers"
"github.com/btcsuite/btcd/btcjson"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/mining"
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcd/btcutil"
)

const (
Expand Down Expand Up @@ -989,7 +989,7 @@ func (mp *TxPool) maybeAcceptTransaction(tx *btcutil.Tx, isNew, rateLimit, rejec
// Don't allow non-standard transactions if the network parameters
// forbid their acceptance.
if !mp.cfg.Policy.AcceptNonStd {
err = checkTransactionStandard(tx, nextBlockHeight,
err = CheckTransactionStandard(tx, nextBlockHeight,
medianTimePast, mp.cfg.Policy.MinRelayTxFee,
mp.cfg.Policy.MaxTxVersion)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions mempool/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"time"

"github.com/btcsuite/btcd/blockchain"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcd/btcutil"
)

const (
Expand Down Expand Up @@ -275,14 +275,14 @@ func IsDust(txOut *wire.TxOut, minRelayTxFee btcutil.Amount) bool {
return txOut.Value*1000/GetDustThreshold(txOut) < int64(minRelayTxFee)
}

// checkTransactionStandard performs a series of checks on a transaction to
// CheckTransactionStandard performs a series of checks on a transaction to
// ensure it is a "standard" transaction. A standard transaction is one that
// conforms to several additional limiting cases over what is considered a
// "sane" transaction such as having a version in the supported range, being
// finalized, conforming to more stringent size constraints, having scripts
// 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,
func CheckTransactionStandard(tx *btcutil.Tx, height int32,
medianTimePast time.Time, minRelayTxFee btcutil.Amount,
maxTxVersion int32) error {

Expand Down
16 changes: 8 additions & 8 deletions mempool/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (
"time"

"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcd/btcutil"
)

// TestCalcMinRequiredTxRelayFee tests the calcMinRequiredTxRelayFee API.
Expand Down Expand Up @@ -277,7 +277,7 @@ func TestDust(t *testing.T) {
}
}

// TestCheckTransactionStandard tests the checkTransactionStandard API.
// TestCheckTransactionStandard tests the CheckTransactionStandard API.
func TestCheckTransactionStandard(t *testing.T) {
// Create some dummy, but otherwise standard, data for transactions.
prevOutHash, err := chainhash.NewHashFromStr("01")
Expand Down Expand Up @@ -469,41 +469,41 @@ func TestCheckTransactionStandard(t *testing.T) {
pastMedianTime := time.Now()
for _, test := range tests {
// Ensure standardness is as expected.
err := checkTransactionStandard(btcutil.NewTx(&test.tx),
err := CheckTransactionStandard(btcutil.NewTx(&test.tx),
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.
continue
}
if err == nil && !test.isStandard {
t.Errorf("checkTransactionStandard (%s): standard when "+
t.Errorf("CheckTransactionStandard (%s): standard when "+
"it should not be", test.name)
continue
}
if err != nil && test.isStandard {
t.Errorf("checkTransactionStandard (%s): nonstandard "+
t.Errorf("CheckTransactionStandard (%s): nonstandard "+
"when it should not be: %v", test.name, err)
continue
}

// Ensure error type is a TxRuleError inside of a RuleError.
rerr, ok := err.(RuleError)
if !ok {
t.Errorf("checkTransactionStandard (%s): unexpected "+
t.Errorf("CheckTransactionStandard (%s): unexpected "+
"error type - got %T", test.name, err)
continue
}
txrerr, ok := rerr.Err.(TxRuleError)
if !ok {
t.Errorf("checkTransactionStandard (%s): unexpected "+
t.Errorf("CheckTransactionStandard (%s): unexpected "+
"error type - got %T", test.name, rerr.Err)
continue
}

// Ensure the reject code is the expected one.
if txrerr.RejectCode != test.code {
t.Errorf("checkTransactionStandard (%s): unexpected "+
t.Errorf("CheckTransactionStandard (%s): unexpected "+
"error code - got %v, want %v", test.name,
txrerr.RejectCode, test.code)
continue
Expand Down