Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 2,251 Lines • ▼ Show 20 Lines | |||||
// to slightly obfuscate which transactions come from our wallet. | // to slightly obfuscate which transactions come from our wallet. | ||||
// | // | ||||
// Ideally, we'd only resend transactions that we think should have been | // Ideally, we'd only resend transactions that we think should have been | ||||
// mined in the most recent block. Any transaction that wasn't in the top | // mined in the most recent block. Any transaction that wasn't in the top | ||||
// blockweight of transactions in the mempool shouldn't have been mined, | // blockweight of transactions in the mempool shouldn't have been mined, | ||||
// and so is probably just sitting in the mempool waiting to be confirmed. | // and so is probably just sitting in the mempool waiting to be confirmed. | ||||
// Rebroadcasting does nothing to speed up confirmation and only damages | // Rebroadcasting does nothing to speed up confirmation and only damages | ||||
// privacy. | // privacy. | ||||
void CWallet::ResendWalletTransactions(interfaces::Chain::Lock &locked_chain) { | void CWallet::ResendWalletTransactions() { | ||||
// During reindex, importing and IBD, old wallet transactions become | // During reindex, importing and IBD, old wallet transactions become | ||||
// unconfirmed. Don't resend them as that would spam other nodes. | // unconfirmed. Don't resend them as that would spam other nodes. | ||||
if (!chain().isReadyToBroadcast()) { | if (!chain().isReadyToBroadcast()) { | ||||
return; | return; | ||||
} | } | ||||
// Do this infrequently and randomly to avoid giving away that these are our | // Do this infrequently and randomly to avoid giving away that these are our | ||||
// transactions. | // transactions. | ||||
Show All 11 Lines | void CWallet::ResendWalletTransactions() { | ||||
if (m_best_block_time < nLastResend) { | if (m_best_block_time < nLastResend) { | ||||
return; | return; | ||||
} | } | ||||
nLastResend = GetTime(); | nLastResend = GetTime(); | ||||
int relayed_tx_count = 0; | int relayed_tx_count = 0; | ||||
{ // cs_wallet scope | { // locked_chain and cs_wallet scope | ||||
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 | // only rebroadcast unconfirmed txes older than 5 minutes before the | ||||
// last block was found | // last block was found | ||||
if (wtx.nTimeReceived > m_best_block_time - 5 * 60) { | if (wtx.nTimeReceived > m_best_block_time - 5 * 60) { | ||||
continue; | continue; | ||||
} | } | ||||
relayed_tx_count += | if (wtx.RelayWalletTransaction(*locked_chain)) { | ||||
wtx.RelayWalletTransaction(locked_chain) ? 1 : 0; | ++relayed_tx_count; | ||||
} | |||||
} | } | ||||
} // cs_wallet | } // locked_chain and cs_wallet | ||||
if (relayed_tx_count > 0) { | if (relayed_tx_count > 0) { | ||||
WalletLogPrintf("%s: rebroadcast %u unconfirmed transactions\n", | WalletLogPrintf("%s: rebroadcast %u unconfirmed transactions\n", | ||||
__func__, relayed_tx_count); | __func__, relayed_tx_count); | ||||
} | } | ||||
} | } | ||||
/** @} */ // end of mapWallet | /** @} */ // end of mapWallet | ||||
void MaybeResendWalletTxs() { | void MaybeResendWalletTxs() { | ||||
for (const std::shared_ptr<CWallet> &pwallet : GetWallets()) { | for (const std::shared_ptr<CWallet> &pwallet : GetWallets()) { | ||||
auto locked_chain = pwallet->chain().lock(); | pwallet->ResendWalletTransactions(); | ||||
pwallet->ResendWalletTransactions(*locked_chain); | |||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* @defgroup Actions | * @defgroup Actions | ||||
* | * | ||||
* @{ | * @{ | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 2,642 Lines • Show Last 20 Lines |