Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chain: Match for error code instead of text.
Browse files Browse the repository at this point in the history
ziggie1984 committed Oct 27, 2023

Verified

This commit was signed with the committer’s verified signature. The key has expired.
ziggie1984 ziggieXXX
1 parent e3ff374 commit 2bfdb87
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions chain/mempool.go
Original file line number Diff line number Diff line change
@@ -13,9 +13,10 @@ import (
)

const (
// txNotFoundErr is an error returned from bitcoind's
// errTxNotFoundCode is the error code returned from bitcoind's
// `getrawtransaction` RPC when the requested txid cannot be found.
txNotFoundErr = "-5: No such mempool or blockchain transaction"
// https://github.com/bitcoin/bitcoin/blob/fa05a726c225dc65dee79367bb67f099ae4f99e6/src/rpc/rawtransaction.cpp#L366
errTxNotFoundCode = "-5"

// DefaultGetRawTxBatchSize specifies the default number of requests to
// be batched before sending them to the bitcoind client.
@@ -583,8 +584,8 @@ func (m *mempool) batchGetRawTxes(txids []*chainhash.Hash,
//
// NOTE: if `txindex` is not enabled, `GetRawTransactionAsync` will only look
// for the txid in bitcoind's mempool. If the tx is replaced, confirmed, or not
// yet included in bitcoind's mempool, the error txNotFoundErr will be
// returned.
// yet included in bitcoind's mempool, the error code `errTxNotFoundCode` will
// be returned from bitcoind.
func getRawTxIgnoreErr(txid chainhash.Hash,
rawTx getRawTxReceiver) *btcutil.Tx {

@@ -596,9 +597,7 @@ func getRawTxIgnoreErr(txid chainhash.Hash,
}

// If this is the txNotFoundErr, we'll create a debug log.
errStr := strings.ToLower(err.Error())
errExp := strings.ToLower(txNotFoundErr)
if strings.Contains(errStr, errExp) {
if strings.Contains(err.Error(), errTxNotFoundCode) {
log.Debugf("unable to fetch transaction %s from mempool: %v",
txid, err)

0 comments on commit 2bfdb87

Please sign in to comment.