mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 23:09:44 -04:00
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.
This commit is contained in:
parent
f0d08550a0
commit
87b1880525
8 changed files with 11 additions and 12 deletions
|
@ -100,8 +100,8 @@ bilingual_str TransactionErrorString(const TransactionError err)
|
||||||
return Untranslated("No error");
|
return Untranslated("No error");
|
||||||
case TransactionError::MISSING_INPUTS:
|
case TransactionError::MISSING_INPUTS:
|
||||||
return Untranslated("Inputs missing or spent");
|
return Untranslated("Inputs missing or spent");
|
||||||
case TransactionError::ALREADY_IN_CHAIN:
|
case TransactionError::ALREADY_IN_UTXO_SET:
|
||||||
return Untranslated("Transaction already in block chain");
|
return Untranslated("Transaction outputs already in utxo set");
|
||||||
case TransactionError::MEMPOOL_REJECTED:
|
case TransactionError::MEMPOOL_REJECTED:
|
||||||
return Untranslated("Transaction rejected by mempool");
|
return Untranslated("Transaction rejected by mempool");
|
||||||
case TransactionError::MEMPOOL_ERROR:
|
case TransactionError::MEMPOOL_ERROR:
|
||||||
|
|
|
@ -55,7 +55,7 @@ TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef t
|
||||||
const Coin& existingCoin = view.AccessCoin(COutPoint(txid, o));
|
const Coin& existingCoin = view.AccessCoin(COutPoint(txid, o));
|
||||||
// IsSpent doesn't mean the coin is spent, it means the output doesn't exist.
|
// IsSpent doesn't mean the coin is spent, it means the output doesn't exist.
|
||||||
// So if the output does exist, then this transaction exists in the chain.
|
// So if the output does exist, then this transaction exists in the chain.
|
||||||
if (!existingCoin.IsSpent()) return TransactionError::ALREADY_IN_CHAIN;
|
if (!existingCoin.IsSpent()) return TransactionError::ALREADY_IN_UTXO_SET;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auto mempool_tx = node.mempool->get(txid); mempool_tx) {
|
if (auto mempool_tx = node.mempool->get(txid); mempool_tx) {
|
||||||
|
|
|
@ -19,7 +19,7 @@ namespace node {
|
||||||
enum class TransactionError {
|
enum class TransactionError {
|
||||||
OK, //!< No error
|
OK, //!< No error
|
||||||
MISSING_INPUTS,
|
MISSING_INPUTS,
|
||||||
ALREADY_IN_CHAIN,
|
ALREADY_IN_UTXO_SET,
|
||||||
MEMPOOL_REJECTED,
|
MEMPOOL_REJECTED,
|
||||||
MEMPOOL_ERROR,
|
MEMPOOL_ERROR,
|
||||||
MAX_FEE_EXCEEDED,
|
MAX_FEE_EXCEEDED,
|
||||||
|
|
|
@ -43,7 +43,7 @@ static RPCHelpMan sendrawtransaction()
|
||||||
"\nThe transaction will be sent unconditionally to all peers, so using sendrawtransaction\n"
|
"\nThe transaction will be sent unconditionally to all peers, so using sendrawtransaction\n"
|
||||||
"for manual rebroadcast may degrade privacy by leaking the transaction's origin, as\n"
|
"for manual rebroadcast may degrade privacy by leaking the transaction's origin, as\n"
|
||||||
"nodes will normally not rebroadcast non-wallet transactions already in their mempool.\n"
|
"nodes will normally not rebroadcast non-wallet transactions already in their mempool.\n"
|
||||||
"\nA specific exception, RPC_TRANSACTION_ALREADY_IN_CHAIN, may throw if the transaction cannot be added to the mempool.\n"
|
"\nA specific exception, RPC_TRANSACTION_ALREADY_IN_UTXO_SET, may throw if the transaction cannot be added to the mempool.\n"
|
||||||
"\nRelated RPCs: createrawtransaction, signrawtransactionwithkey\n",
|
"\nRelated RPCs: createrawtransaction, signrawtransactionwithkey\n",
|
||||||
{
|
{
|
||||||
{"hexstring", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The hex string of the raw transaction"},
|
{"hexstring", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The hex string of the raw transaction"},
|
||||||
|
|
|
@ -46,14 +46,13 @@ enum RPCErrorCode
|
||||||
RPC_DESERIALIZATION_ERROR = -22, //!< Error parsing or validating structure in raw format
|
RPC_DESERIALIZATION_ERROR = -22, //!< Error parsing or validating structure in raw format
|
||||||
RPC_VERIFY_ERROR = -25, //!< General error during transaction or block submission
|
RPC_VERIFY_ERROR = -25, //!< General error during transaction or block submission
|
||||||
RPC_VERIFY_REJECTED = -26, //!< Transaction or block was rejected by network rules
|
RPC_VERIFY_REJECTED = -26, //!< Transaction or block was rejected by network rules
|
||||||
RPC_VERIFY_ALREADY_IN_CHAIN = -27, //!< Transaction already in chain
|
RPC_VERIFY_ALREADY_IN_UTXO_SET = -27, //!< Transaction already in utxo set
|
||||||
RPC_IN_WARMUP = -28, //!< Client still warming up
|
RPC_IN_WARMUP = -28, //!< Client still warming up
|
||||||
RPC_METHOD_DEPRECATED = -32, //!< RPC method is deprecated
|
RPC_METHOD_DEPRECATED = -32, //!< RPC method is deprecated
|
||||||
|
|
||||||
//! Aliases for backward compatibility
|
//! Aliases for backward compatibility
|
||||||
RPC_TRANSACTION_ERROR = RPC_VERIFY_ERROR,
|
RPC_TRANSACTION_ERROR = RPC_VERIFY_ERROR,
|
||||||
RPC_TRANSACTION_REJECTED = RPC_VERIFY_REJECTED,
|
RPC_TRANSACTION_REJECTED = RPC_VERIFY_REJECTED,
|
||||||
RPC_TRANSACTION_ALREADY_IN_CHAIN= RPC_VERIFY_ALREADY_IN_CHAIN,
|
|
||||||
|
|
||||||
//! P2P client errors
|
//! P2P client errors
|
||||||
RPC_CLIENT_NOT_CONNECTED = -9, //!< Bitcoin is not connected
|
RPC_CLIENT_NOT_CONNECTED = -9, //!< Bitcoin is not connected
|
||||||
|
|
|
@ -399,8 +399,8 @@ RPCErrorCode RPCErrorFromTransactionError(TransactionError terr)
|
||||||
switch (terr) {
|
switch (terr) {
|
||||||
case TransactionError::MEMPOOL_REJECTED:
|
case TransactionError::MEMPOOL_REJECTED:
|
||||||
return RPC_TRANSACTION_REJECTED;
|
return RPC_TRANSACTION_REJECTED;
|
||||||
case TransactionError::ALREADY_IN_CHAIN:
|
case TransactionError::ALREADY_IN_UTXO_SET:
|
||||||
return RPC_TRANSACTION_ALREADY_IN_CHAIN;
|
return RPC_VERIFY_ALREADY_IN_UTXO_SET;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
return RPC_TRANSACTION_ERROR;
|
return RPC_TRANSACTION_ERROR;
|
||||||
|
|
|
@ -23,7 +23,7 @@ using node::TransactionError;
|
||||||
namespace {
|
namespace {
|
||||||
constexpr TransactionError ALL_TRANSACTION_ERROR[] = {
|
constexpr TransactionError ALL_TRANSACTION_ERROR[] = {
|
||||||
TransactionError::MISSING_INPUTS,
|
TransactionError::MISSING_INPUTS,
|
||||||
TransactionError::ALREADY_IN_CHAIN,
|
TransactionError::ALREADY_IN_UTXO_SET,
|
||||||
TransactionError::MEMPOOL_REJECTED,
|
TransactionError::MEMPOOL_REJECTED,
|
||||||
TransactionError::MEMPOOL_ERROR,
|
TransactionError::MEMPOOL_ERROR,
|
||||||
TransactionError::MAX_FEE_EXCEEDED,
|
TransactionError::MAX_FEE_EXCEEDED,
|
||||||
|
|
|
@ -430,13 +430,13 @@ class RawTransactionsTest(BitcoinTestFramework):
|
||||||
assert_equal(testres['allowed'], True)
|
assert_equal(testres['allowed'], True)
|
||||||
self.nodes[2].sendrawtransaction(hexstring=tx['hex'], maxfeerate='0.20000000')
|
self.nodes[2].sendrawtransaction(hexstring=tx['hex'], maxfeerate='0.20000000')
|
||||||
|
|
||||||
self.log.info("Test sendrawtransaction/testmempoolaccept with tx already in the chain")
|
self.log.info("Test sendrawtransaction/testmempoolaccept with tx outputs already in the utxo set")
|
||||||
self.generate(self.nodes[2], 1)
|
self.generate(self.nodes[2], 1)
|
||||||
for node in self.nodes:
|
for node in self.nodes:
|
||||||
testres = node.testmempoolaccept([tx['hex']])[0]
|
testres = node.testmempoolaccept([tx['hex']])[0]
|
||||||
assert_equal(testres['allowed'], False)
|
assert_equal(testres['allowed'], False)
|
||||||
assert_equal(testres['reject-reason'], 'txn-already-known')
|
assert_equal(testres['reject-reason'], 'txn-already-known')
|
||||||
assert_raises_rpc_error(-27, 'Transaction already in block chain', node.sendrawtransaction, tx['hex'])
|
assert_raises_rpc_error(-27, 'Transaction outputs already in utxo set', node.sendrawtransaction, tx['hex'])
|
||||||
|
|
||||||
def decoderawtransaction_tests(self):
|
def decoderawtransaction_tests(self):
|
||||||
self.log.info("Test decoderawtransaction")
|
self.log.info("Test decoderawtransaction")
|
||||||
|
|
Loading…
Add table
Reference in a new issue