There is a function here, named ResendWalletTransactions
in the Bitcoin Core:
// Rebroadcast transactions from the wallet. We do this on a random timer
// to slightly obfuscate which transactions come from our wallet.
//
// 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
// blockweight of transactions in the mempool shouldn't have been mined,
// and so is probably just sitting in the mempool waiting to be confirmed.
// Rebroadcasting does nothing to speed up confirmation and only damages
// privacy.
void CWallet::ResendWalletTransactions()
{
// During reindex, importing and IBD, old wallet transactions become
// unconfirmed. Don't resend them as that would spam other nodes.
if (!chain().isReadyToBroadcast()) return;
// Do this infrequently and randomly to avoid giving away
// that these are our transactions.
if (GetTime() < nNextResend || !fBroadcastTransactions) return;
bool fFirst = (nNextResend == 0);
// resend 12-36 hours from now, ~1 day on average.
nNextResend = GetTime() + (12 * 60 * 60) + GetRand(24 * 60 * 60);
if (fFirst) return;
int submitted_tx_count = 0;
{ // cs_wallet scope
LOCK(cs_wallet);
// Try to add wallet transactions to memory pool
for (auto wtx : GetSortedTxs()) {
// Attempt to rebroadcast all txes more than 5 minutes older than
// the last block. SubmitTxMemoryPoolAndRelay() will not rebroadcast
// any confirmed or conflicting txs.
if (wtx->nTimeReceived > m_best_block_time - 5 * 60) continue;
std::string unused_err_string;
if (SubmitTxMemoryPoolAndRelay(*wtx, unused_err_string, true)) ++submitted_tx_count;
}
} // cs_wallet
if (submitted_tx_count > 0) {
WalletLogPrintf("%s: resubmit %u unconfirmed transactions\n", __func__, submitted_tx_count);
}
}
I'm not sure I correctly understand the usage of the
CWallet
class. By reading the comments and code, I think this class manages the transactions of the Bitcoin Core's node itself and it plays as a role of regular wallet (beside the fact that it is running on a node). It creates transactions and manages UTXOs. Is this correct?I tried to figure out the reason behind rebroadcasting from comments above, but couldn't understand anything useful. What is the need to rebroadcast a transaction? As its name suggest, it is broadcasting a previously broadcasted transaction. So why should we want such a thing? Isn't broadcasting once sufficient?
Even if the flag
fBroadcastTransactions
is set totrue
, the function waits untilGetTime()
is greater that thenNextResend
, and this variable is set to at least 12 hours later fromGetTime()
. So this means that someone who uses the Bitcoin Core's wallet, should wait at least 12 hour for the transaction to be broadcasted? I'm pretty sure that I'm wrong but can't figure out where.
Thanks for any help.