Skip to content

Commit

Permalink
ResendTX: forced rebroadcasting of unconfirmed transactions.
Browse files Browse the repository at this point in the history
  • Loading branch information
CryptoManiac committed Mar 8, 2016
1 parent 727ca3e commit d5c9639
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,10 @@ void static Inventory(const uint256& hash)
}

// ask wallets to resend their transactions
void ResendWalletTransactions()
void ResendWalletTransactions(bool fForceResend)
{
BOOST_FOREACH(CWallet* pwallet, setpwalletRegistered)
pwallet->ResendWalletTransactions();
pwallet->ResendWalletTransactions(fForceResend);
}


Expand Down
2 changes: 1 addition & 1 deletion src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ std::string GetWarnings(std::string strFor);
bool GetTransaction(const uint256 &hash, CTransaction &tx, uint256 &hashBlock);
uint256 WantedByOrphan(const CBlock* pblockOrphan);
const CBlockIndex* GetLastBlockIndex(const CBlockIndex* pindex, bool fProofOfStake);
void ResendWalletTransactions();
void ResendWalletTransactions(bool fForceResend=false);

bool VerifySignature(const CTransaction& txFrom, const CTransaction& txTo, unsigned int nIn, unsigned int flags, int nHashType);

Expand Down
2 changes: 1 addition & 1 deletion src/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1862,7 +1862,7 @@ Value resendtx(const Array& params, bool fHelp)
"Re-send unconfirmed transactions.\n"
);

ResendWalletTransactions();
ResendWalletTransactions(true);

return Value::null;
}
Expand Down
36 changes: 18 additions & 18 deletions src/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1152,23 +1152,25 @@ void CWalletTx::RelayWalletTransaction()
RelayWalletTransaction(txdb);
}

void CWallet::ResendWalletTransactions()
void CWallet::ResendWalletTransactions(bool fForceResend)
{
// Do this infrequently and randomly to avoid giving away
// that these are our transactions.
static int64_t nNextTime = GetRand(GetTime() + 30 * 60);
if (GetTime() < nNextTime)
return;
bool fFirst = (nNextTime == 0);
nNextTime = GetTime() + GetRand(30 * 60);
if (fFirst)
return;
if (!fForceResend) {
// Do this infrequently and randomly to avoid giving away
// that these are our transactions.
static int64_t nNextTime = GetRand(GetTime() + 30 * 60);
if (GetTime() < nNextTime)
return;
bool fFirst = (nNextTime == 0);
nNextTime = GetTime() + GetRand(30 * 60);
if (fFirst)
return;

// Only do it if there's been a new block since last time
static int64_t nLastTime = 0;
if (nTimeBestReceived < nLastTime)
return;
nLastTime = GetTime();
// Only do it if there's been a new block since last time
static int64_t nLastTime = 0;
if (nTimeBestReceived < nLastTime)
return;
nLastTime = GetTime();
}

// Rebroadcast any of our txes that aren't in a block yet
printf("ResendWalletTransactions()\n");
Expand All @@ -1182,7 +1184,7 @@ void CWallet::ResendWalletTransactions()
CWalletTx& wtx = item.second;
// Don't rebroadcast until it's had plenty of time that
// it should have gotten in already by now.
if (nTimeBestReceived - (int64_t)wtx.nTimeReceived > 5 * 60)
if (fForceResend || nTimeBestReceived - (int64_t)wtx.nTimeReceived > 5 * 60)
mapSorted.insert(make_pair(wtx.nTimeReceived, &wtx));
}
BOOST_FOREACH(PAIRTYPE(const unsigned int, CWalletTx*)& item, mapSorted)
Expand Down Expand Up @@ -2776,14 +2778,12 @@ void CWallet::GetAddresses(std::map<CBitcoinAddress, int64_t> &mapAddresses) con

for(std::vector<CKeyID>::const_iterator it3 = vAffected.begin(); it3 != vAffected.end(); it3++) {
CBitcoinAddress addrAffected(*it3);

if (mapAddresses.find(addrAffected) != mapAddresses.end() && (mapAddresses[addrAffected] == 0 || mapAddresses[addrAffected] > wtx.nTime))
mapAddresses[addrAffected] = wtx.nTime;
}
vAffected.clear();
}
}

}
}

Expand Down
2 changes: 1 addition & 1 deletion src/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class CWallet : public CCryptoKeyStore
int ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate = false);
int ScanForWalletTransaction(const uint256& hashTx);
void ReacceptWalletTransactions();
void ResendWalletTransactions();
void ResendWalletTransactions(bool fForceResend=false);
int64_t GetBalance() const;
int64_t GetWatchOnlyBalance() const;
int64_t GetUnconfirmedBalance() const;
Expand Down

0 comments on commit d5c9639

Please sign in to comment.