Skip to content

Commit

Permalink
Return txid even if ATMP fails for new transaction
Browse files Browse the repository at this point in the history
Github-Pull: bitcoin#9302
Rebased-From: b3a7410
  • Loading branch information
sipa authored and MarcoFalke committed Dec 14, 2016
1 parent 35174a0 commit f5d606e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
21 changes: 11 additions & 10 deletions src/wallet/wallet.cpp
Expand Up @@ -1442,7 +1442,8 @@ void CWallet::ReacceptWalletTransactions()
CWalletTx& wtx = *(item.second);

LOCK(mempool.cs);
wtx.AcceptToMemoryPool(false, maxTxFee);
CValidationState state;
wtx.AcceptToMemoryPool(false, maxTxFee, state);
}
}

Expand All @@ -1451,8 +1452,9 @@ bool CWalletTx::RelayWalletTransaction()
assert(pwallet->GetBroadcastTransactions());
if (!IsCoinBase() && !isAbandoned() && GetDepthInMainChain() == 0)
{
CValidationState state;
/* GetDepthInMainChain already catches known conflicts. */
if (InMempool() || AcceptToMemoryPool(false, maxTxFee)) {
if (InMempool() || AcceptToMemoryPool(false, maxTxFee, state)) {
LogPrintf("Relaying wtx %s\n", GetHash().ToString());
RelayTransaction((CTransaction)*this);
return true;
Expand Down Expand Up @@ -2482,14 +2484,14 @@ bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey)

if (fBroadcastTransactions)
{
CValidationState state;
// Broadcast
if (!wtxNew.AcceptToMemoryPool(false, maxTxFee))
{
// This must not fail. The transaction has already been signed and recorded.
LogPrintf("CommitTransaction(): Error: Transaction not valid\n");
return false;
if (!wtxNew.AcceptToMemoryPool(false, maxTxFee, state)) {
LogPrintf("CommitTransaction(): Transaction cannot be broadcast immediately, %s\n", state.GetRejectReason());
// TODO: if we expect the failure to be long term or permanent, instead delete wtx from the wallet and return failure.
} else {
wtxNew.RelayWalletTransaction();
}
wtxNew.RelayWalletTransaction();
}
}
return true;
Expand Down Expand Up @@ -3595,8 +3597,7 @@ int CMerkleTx::GetBlocksToMaturity() const
}


bool CMerkleTx::AcceptToMemoryPool(bool fLimitFree, CAmount nAbsurdFee)
bool CMerkleTx::AcceptToMemoryPool(bool fLimitFree, CAmount nAbsurdFee, CValidationState& state)
{
CValidationState state;
return ::AcceptToMemoryPool(mempool, state, *this, fLimitFree, NULL, false, nAbsurdFee);
}
2 changes: 1 addition & 1 deletion src/wallet/wallet.h
Expand Up @@ -213,7 +213,7 @@ class CMerkleTx : public CTransaction
bool IsInMainChain() const { const CBlockIndex *pindexRet; return GetDepthInMainChain(pindexRet) > 0; }
int GetBlocksToMaturity() const;
/** Pass this transaction to the mempool. Fails if absolute fee exceeds absurd fee. */
bool AcceptToMemoryPool(bool fLimitFree, const CAmount nAbsurdFee);
bool AcceptToMemoryPool(bool fLimitFree, const CAmount nAbsurdFee, CValidationState& state);
bool hashUnset() const { return (hashBlock.IsNull() || hashBlock == ABANDON_HASH); }
bool isAbandoned() const { return (hashBlock == ABANDON_HASH); }
void setAbandoned() { hashBlock = ABANDON_HASH; }
Expand Down

0 comments on commit f5d606e

Please sign in to comment.