mirror of
https://github.com/btcsuite/btcd.git
synced 2025-01-19 05:33:36 +01:00
mempool: export check Standardness func
This commit is contained in:
parent
074266215c
commit
511b464878
@ -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 (
|
||||
@ -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 {
|
||||
|
@ -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 (
|
||||
@ -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 {
|
||||
|
||||
|
@ -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.
|
||||
@ -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")
|
||||
@ -469,7 +469,7 @@ 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
|
||||
@ -477,12 +477,12 @@ func TestCheckTransactionStandard(t *testing.T) {
|
||||
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
|
||||
}
|
||||
@ -490,20 +490,20 @@ func TestCheckTransactionStandard(t *testing.T) {
|
||||
// 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
|
||||
|
Loading…
Reference in New Issue
Block a user