Merge 79cabe3a5b into merged_master (Bitcoin PR bitcoin/bitcoin#25239)

This commit is contained in:
James Dorfman 2024-09-09 19:39:28 +00:00
commit aaf41fec40

View file

@ -2300,7 +2300,7 @@ void CWallet::CommitTransaction(CTransactionRef tx, mapValue_t mapValue, std::ve
// Add tx to wallet, because if it has change it's also ours,
// otherwise just for transaction history.
AddToWallet(tx, TxStateInactive{}, [&](CWalletTx& wtx, bool new_tx) {
CWalletTx* wtx = AddToWallet(tx, TxStateInactive{}, [&](CWalletTx& wtx, bool new_tx) {
CHECK_NONFATAL(wtx.mapValue.empty());
CHECK_NONFATAL(wtx.vOrderForm.empty());
wtx.mapValue = std::move(mapValue);
@ -2319,6 +2319,11 @@ void CWallet::CommitTransaction(CTransactionRef tx, mapValue_t mapValue, std::ve
return true;
});
// wtx can only be null if the db write failed.
if (!wtx) {
throw std::runtime_error(std::string(__func__) + ": Wallet db error, transaction commit failed");
}
// Notify that old coins are spent
for (const CTxIn& txin : tx->vin) {
// ELEMENTS: Pegins are not in our UTXO set.
@ -2330,17 +2335,13 @@ void CWallet::CommitTransaction(CTransactionRef tx, mapValue_t mapValue, std::ve
NotifyTransactionChanged(coin.GetHash(), CT_UPDATED);
}
// Get the inserted-CWalletTx from mapWallet so that the
// wtx cached mempool state is updated correctly
CWalletTx& wtx = mapWallet.at(tx->GetHash());
if (!fBroadcastTransactions) {
// Don't submit tx to the mempool
return;
}
std::string err_string;
if (!SubmitTxMemoryPoolAndRelay(wtx, err_string, true)) {
if (!SubmitTxMemoryPoolAndRelay(*wtx, err_string, true)) {
WalletLogPrintf("CommitTransaction(): Transaction cannot be broadcast immediately, %s\n", err_string);
// TODO: if we expect the failure to be long term or permanent, instead delete wtx from the wallet and return failure.
}