From 2bfdb8775e4feaec03250245bc9876d1a2a788cc Mon Sep 17 00:00:00 2001 From: ziggie Date: Fri, 27 Oct 2023 10:27:49 +0200 Subject: [PATCH] chain: Match for error code instead of text. --- chain/mempool.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/chain/mempool.go b/chain/mempool.go index 0b2125e78d..a9bcddc89f 100644 --- a/chain/mempool.go +++ b/chain/mempool.go @@ -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)