Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 2,311 Lines • ▼ Show 20 Lines | for (std::pair<const TxId, CWalletTx> &item : mapWallet) { | ||||
mapSorted.insert(std::make_pair(wtx.nOrderPos, &wtx)); | mapSorted.insert(std::make_pair(wtx.nOrderPos, &wtx)); | ||||
} | } | ||||
} | } | ||||
// Try to add wallet transactions to memory pool. | // Try to add wallet transactions to memory pool. | ||||
for (const std::pair<const int64_t, CWalletTx *> &item : mapSorted) { | for (const std::pair<const int64_t, CWalletTx *> &item : mapSorted) { | ||||
CWalletTx &wtx = *(item.second); | CWalletTx &wtx = *(item.second); | ||||
std::string unused_err_string; | std::string unused_err_string; | ||||
wtx.SubmitMemoryPoolAndRelay(unused_err_string, false); | wtx.SubmitMemoryPoolAndRelay(unused_err_string, false, locked_chain); | ||||
} | } | ||||
} | } | ||||
bool CWalletTx::SubmitMemoryPoolAndRelay(std::string &err_string, bool relay) { | bool CWalletTx::SubmitMemoryPoolAndRelay( | ||||
std::string &err_string, bool relay, | |||||
interfaces::Chain::Lock &locked_chain) { | |||||
// Can't relay if wallet is not broadcasting | // Can't relay if wallet is not broadcasting | ||||
if (!pwallet->GetBroadcastTransactions()) { | if (!pwallet->GetBroadcastTransactions()) { | ||||
return false; | return false; | ||||
} | } | ||||
// Don't relay abandoned transactions | // Don't relay abandoned transactions | ||||
if (isAbandoned()) { | if (isAbandoned()) { | ||||
return false; | return false; | ||||
} | } | ||||
// Don't try to submit coinbase transactions. These would fail anyway but | |||||
// would cause log spam. | |||||
if (IsCoinBase()) { | |||||
return false; | |||||
} | |||||
// Don't try to submit conflicted or confirmed transactions. | |||||
if (GetDepthInMainChain(locked_chain) != 0) { | |||||
return false; | |||||
} | |||||
// Submit transaction to mempool for relay | // Submit transaction to mempool for relay | ||||
pwallet->WalletLogPrintf("Submitting wtx %s to mempool for relay\n", | pwallet->WalletLogPrintf("Submitting wtx %s to mempool for relay\n", | ||||
GetId().ToString()); | GetId().ToString()); | ||||
// We must set fInMempool here - while it will be re-set to true by the | // We must set fInMempool here - while it will be re-set to true by the | ||||
// entered-mempool callback, if we did not there would be a race where a | // entered-mempool callback, if we did not there would be a race where a | ||||
// user could call sendmoney in a loop and hit spurious out of funds errors | // user could call sendmoney in a loop and hit spurious out of funds errors | ||||
// because we think that this newly generated transaction's change is | // because we think that this newly generated transaction's change is | ||||
▲ Show 20 Lines • Show All 245 Lines • ▼ Show 20 Lines | void CWallet::ResendWalletTransactions() { | ||||
{ // locked_chain and cs_wallet scope | { // locked_chain and cs_wallet scope | ||||
auto locked_chain = chain().lock(); | auto locked_chain = chain().lock(); | ||||
LOCK(cs_wallet); | LOCK(cs_wallet); | ||||
// Relay transactions | // Relay transactions | ||||
for (std::pair<const TxId, CWalletTx> &item : mapWallet) { | for (std::pair<const TxId, CWalletTx> &item : mapWallet) { | ||||
CWalletTx &wtx = item.second; | CWalletTx &wtx = item.second; | ||||
// only rebroadcast unconfirmed txes older than 5 minutes before the | // Attempt to rebroadcast all txes more than 5 minutes older than | ||||
// last block was found | // the last block. SubmitMemoryPoolAndRelay() will not rebroadcast | ||||
// any confirmed or conflicting txs. | |||||
if (wtx.nTimeReceived > m_best_block_time - 5 * 60) { | if (wtx.nTimeReceived > m_best_block_time - 5 * 60) { | ||||
continue; | continue; | ||||
} | } | ||||
std::string unused_err_string; | std::string unused_err_string; | ||||
if (wtx.SubmitMemoryPoolAndRelay(unused_err_string, true)) { | if (wtx.SubmitMemoryPoolAndRelay(unused_err_string, true, | ||||
*locked_chain)) { | |||||
++submitted_tx_count; | ++submitted_tx_count; | ||||
} | } | ||||
} | } | ||||
} // locked_chain and cs_wallet | } // locked_chain and cs_wallet | ||||
if (submitted_tx_count > 0) { | if (submitted_tx_count > 0) { | ||||
WalletLogPrintf("%s: resubmit %u unconfirmed transactions\n", __func__, | WalletLogPrintf("%s: resubmit %u unconfirmed transactions\n", __func__, | ||||
submitted_tx_count); | submitted_tx_count); | ||||
▲ Show 20 Lines • Show All 1,056 Lines • ▼ Show 20 Lines | bool CWallet::CommitTransaction( | ||||
} | } | ||||
// Get the inserted-CWalletTx from mapWallet so that the | // Get the inserted-CWalletTx from mapWallet so that the | ||||
// fInMempool flag is cached properly | // fInMempool flag is cached properly | ||||
CWalletTx &wtx = mapWallet.at(wtxNew.GetId()); | CWalletTx &wtx = mapWallet.at(wtxNew.GetId()); | ||||
if (fBroadcastTransactions) { | if (fBroadcastTransactions) { | ||||
std::string err_string; | std::string err_string; | ||||
if (!wtx.SubmitMemoryPoolAndRelay(err_string, true)) { | if (!wtx.SubmitMemoryPoolAndRelay(err_string, true, *locked_chain)) { | ||||
WalletLogPrintf("CommitTransaction(): Transaction cannot be " | WalletLogPrintf("CommitTransaction(): Transaction cannot be " | ||||
"broadcast immediately, %s\n", | "broadcast immediately, %s\n", | ||||
err_string); | err_string); | ||||
// TODO: if we expect the failure to be long term or permanent, | // TODO: if we expect the failure to be long term or permanent, | ||||
// instead delete wtx from the wallet and return failure. | // instead delete wtx from the wallet and return failure. | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,757 Lines • Show Last 20 Lines |