Skip to content

Commit 87b1880

Browse files
committed
rpc: clarify ALREADY_IN_CHAIN rpc errors
When using `sendrawtransaction` the ALREADY_IN_CHAIN error help string may be confusing. Rename TransactionError::ALREADY_IN_CHAIN to TransactionError::ALREADY_IN_UTXO_SET and update the rpc help string. Remove backwards compatibility alias as no longer required.
1 parent f0d0855 commit 87b1880

File tree

8 files changed

+11
-12
lines changed

8 files changed

+11
-12
lines changed

src/common/messages.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ bilingual_str TransactionErrorString(const TransactionError err)
100100
return Untranslated("No error");
101101
case TransactionError::MISSING_INPUTS:
102102
return Untranslated("Inputs missing or spent");
103-
case TransactionError::ALREADY_IN_CHAIN:
104-
return Untranslated("Transaction already in block chain");
103+
case TransactionError::ALREADY_IN_UTXO_SET:
104+
return Untranslated("Transaction outputs already in utxo set");
105105
case TransactionError::MEMPOOL_REJECTED:
106106
return Untranslated("Transaction rejected by mempool");
107107
case TransactionError::MEMPOOL_ERROR:

src/node/transaction.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef t
5555
const Coin& existingCoin = view.AccessCoin(COutPoint(txid, o));
5656
// IsSpent doesn't mean the coin is spent, it means the output doesn't exist.
5757
// So if the output does exist, then this transaction exists in the chain.
58-
if (!existingCoin.IsSpent()) return TransactionError::ALREADY_IN_CHAIN;
58+
if (!existingCoin.IsSpent()) return TransactionError::ALREADY_IN_UTXO_SET;
5959
}
6060

6161
if (auto mempool_tx = node.mempool->get(txid); mempool_tx) {

src/node/types.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace node {
1919
enum class TransactionError {
2020
OK, //!< No error
2121
MISSING_INPUTS,
22-
ALREADY_IN_CHAIN,
22+
ALREADY_IN_UTXO_SET,
2323
MEMPOOL_REJECTED,
2424
MEMPOOL_ERROR,
2525
MAX_FEE_EXCEEDED,

src/rpc/mempool.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ static RPCHelpMan sendrawtransaction()
4343
"\nThe transaction will be sent unconditionally to all peers, so using sendrawtransaction\n"
4444
"for manual rebroadcast may degrade privacy by leaking the transaction's origin, as\n"
4545
"nodes will normally not rebroadcast non-wallet transactions already in their mempool.\n"
46-
"\nA specific exception, RPC_TRANSACTION_ALREADY_IN_CHAIN, may throw if the transaction cannot be added to the mempool.\n"
46+
"\nA specific exception, RPC_TRANSACTION_ALREADY_IN_UTXO_SET, may throw if the transaction cannot be added to the mempool.\n"
4747
"\nRelated RPCs: createrawtransaction, signrawtransactionwithkey\n",
4848
{
4949
{"hexstring", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The hex string of the raw transaction"},

src/rpc/protocol.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,13 @@ enum RPCErrorCode
4646
RPC_DESERIALIZATION_ERROR = -22, //!< Error parsing or validating structure in raw format
4747
RPC_VERIFY_ERROR = -25, //!< General error during transaction or block submission
4848
RPC_VERIFY_REJECTED = -26, //!< Transaction or block was rejected by network rules
49-
RPC_VERIFY_ALREADY_IN_CHAIN = -27, //!< Transaction already in chain
49+
RPC_VERIFY_ALREADY_IN_UTXO_SET = -27, //!< Transaction already in utxo set
5050
RPC_IN_WARMUP = -28, //!< Client still warming up
5151
RPC_METHOD_DEPRECATED = -32, //!< RPC method is deprecated
5252

5353
//! Aliases for backward compatibility
5454
RPC_TRANSACTION_ERROR = RPC_VERIFY_ERROR,
5555
RPC_TRANSACTION_REJECTED = RPC_VERIFY_REJECTED,
56-
RPC_TRANSACTION_ALREADY_IN_CHAIN= RPC_VERIFY_ALREADY_IN_CHAIN,
5756

5857
//! P2P client errors
5958
RPC_CLIENT_NOT_CONNECTED = -9, //!< Bitcoin is not connected

src/rpc/util.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,8 @@ RPCErrorCode RPCErrorFromTransactionError(TransactionError terr)
399399
switch (terr) {
400400
case TransactionError::MEMPOOL_REJECTED:
401401
return RPC_TRANSACTION_REJECTED;
402-
case TransactionError::ALREADY_IN_CHAIN:
403-
return RPC_TRANSACTION_ALREADY_IN_CHAIN;
402+
case TransactionError::ALREADY_IN_UTXO_SET:
403+
return RPC_VERIFY_ALREADY_IN_UTXO_SET;
404404
default: break;
405405
}
406406
return RPC_TRANSACTION_ERROR;

src/test/fuzz/kitchen_sink.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ using node::TransactionError;
2323
namespace {
2424
constexpr TransactionError ALL_TRANSACTION_ERROR[] = {
2525
TransactionError::MISSING_INPUTS,
26-
TransactionError::ALREADY_IN_CHAIN,
26+
TransactionError::ALREADY_IN_UTXO_SET,
2727
TransactionError::MEMPOOL_REJECTED,
2828
TransactionError::MEMPOOL_ERROR,
2929
TransactionError::MAX_FEE_EXCEEDED,

test/functional/rpc_rawtransaction.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -430,13 +430,13 @@ def sendrawtransaction_testmempoolaccept_tests(self):
430430
assert_equal(testres['allowed'], True)
431431
self.nodes[2].sendrawtransaction(hexstring=tx['hex'], maxfeerate='0.20000000')
432432

433-
self.log.info("Test sendrawtransaction/testmempoolaccept with tx already in the chain")
433+
self.log.info("Test sendrawtransaction/testmempoolaccept with tx outputs already in the utxo set")
434434
self.generate(self.nodes[2], 1)
435435
for node in self.nodes:
436436
testres = node.testmempoolaccept([tx['hex']])[0]
437437
assert_equal(testres['allowed'], False)
438438
assert_equal(testres['reject-reason'], 'txn-already-known')
439-
assert_raises_rpc_error(-27, 'Transaction already in block chain', node.sendrawtransaction, tx['hex'])
439+
assert_raises_rpc_error(-27, 'Transaction outputs already in utxo set', node.sendrawtransaction, tx['hex'])
440440

441441
def decoderawtransaction_tests(self):
442442
self.log.info("Test decoderawtransaction")

0 commit comments

Comments
 (0)