Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 2,240 Lines • ▼ Show 20 Lines | bool CWalletTx::IsEquivalentTo(const CWalletTx &_tx) const { | ||||
for (auto &txin : tx2.vin) { | for (auto &txin : tx2.vin) { | ||||
txin.scriptSig = CScript(); | txin.scriptSig = CScript(); | ||||
} | } | ||||
return CTransaction(tx1) == CTransaction(tx2); | return CTransaction(tx1) == CTransaction(tx2); | ||||
} | } | ||||
std::vector<uint256> | |||||
CWallet::ResendWalletTransactionsBefore(interfaces::Chain::Lock &locked_chain, | |||||
int64_t nTime) { | |||||
std::vector<uint256> result; | |||||
LOCK(cs_wallet); | |||||
// Sort them in chronological order | |||||
std::multimap<unsigned int, CWalletTx *> mapSorted; | |||||
for (std::pair<const TxId, CWalletTx> &item : mapWallet) { | |||||
CWalletTx &wtx = item.second; | |||||
// Don't rebroadcast if newer than nTime: | |||||
if (wtx.nTimeReceived > nTime) { | |||||
continue; | |||||
} | |||||
mapSorted.insert(std::make_pair(wtx.nTimeReceived, &wtx)); | |||||
} | |||||
for (const std::pair<const unsigned int, CWalletTx *> &item : mapSorted) { | |||||
CWalletTx &wtx = *item.second; | |||||
if (wtx.RelayWalletTransaction(locked_chain)) { | |||||
result.push_back(wtx.GetId()); | |||||
} | |||||
} | |||||
return result; | |||||
} | |||||
void CWallet::ResendWalletTransactions(interfaces::Chain::Lock &locked_chain) { | void CWallet::ResendWalletTransactions(interfaces::Chain::Lock &locked_chain) { | ||||
// 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. | ||||
if (GetTime() < nNextResend || !fBroadcastTransactions) { | if (GetTime() < nNextResend || !fBroadcastTransactions) { | ||||
return; | return; | ||||
} | } | ||||
bool fFirst = (nNextResend == 0); | bool fFirst = (nNextResend == 0); | ||||
nNextResend = GetTime() + GetRand(30 * 60); | nNextResend = GetTime() + GetRand(30 * 60); | ||||
if (fFirst) { | if (fFirst) { | ||||
return; | return; | ||||
} | } | ||||
// Only do it if there's been a new block since last time | // Only do it if there's been a new block since last time | ||||
if (m_best_block_time < nLastResend) { | if (m_best_block_time < nLastResend) { | ||||
return; | return; | ||||
} | } | ||||
nLastResend = GetTime(); | nLastResend = GetTime(); | ||||
// Rebroadcast unconfirmed txes older than 5 minutes before the last block | int relayed_tx_count = 0; | ||||
// was found: | |||||
std::vector<uint256> relayed = ResendWalletTransactionsBefore( | { // cs_wallet scope | ||||
locked_chain, m_best_block_time - 5 * 60); | LOCK(cs_wallet); | ||||
if (!relayed.empty()) { | |||||
// Relay transactions | |||||
for (std::pair<const TxId, CWalletTx> &item : mapWallet) { | |||||
CWalletTx &wtx = item.second; | |||||
// only rebroadcast unconfirmed txes older than 5 minutes before the | |||||
// last block was found | |||||
if (wtx.nTimeReceived > m_best_block_time - 5 * 60) { | |||||
continue; | |||||
} | |||||
relayed_tx_count += | |||||
wtx.RelayWalletTransaction(locked_chain) ? 1 : 0; | |||||
} | |||||
} // cs_wallet | |||||
if (relayed_tx_count > 0) { | |||||
WalletLogPrintf("%s: rebroadcast %u unconfirmed transactions\n", | WalletLogPrintf("%s: rebroadcast %u unconfirmed transactions\n", | ||||
__func__, relayed.size()); | __func__, relayed_tx_count); | ||||
} | } | ||||
} | } | ||||
/** @} */ // end of mapWallet | /** @} */ // end of mapWallet | ||||
/** | /** | ||||
* @defgroup Actions | * @defgroup Actions | ||||
* | * | ||||
▲ Show 20 Lines • Show All 2,644 Lines • Show Last 20 Lines |