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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions mempool/mempool.go
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
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
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