Skip to content

Commit 797ec9d

Browse files
author
Antoine Riard
committed
[wallet] Add m_is_ibd in CWallet
1 parent 693bbc6 commit 797ec9d

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/wallet/wallet.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,6 +1180,8 @@ void CWallet::blockDisconnected(const CBlock& block, int height)
11801180
void CWallet::updatedBlockTip(bool is_ibd)
11811181
{
11821182
m_best_block_time = GetTime();
1183+
LOCK(cs_wallet);
1184+
m_is_ibd = is_ibd;
11831185
}
11841186

11851187

@@ -2014,6 +2016,8 @@ void CWallet::ResendWalletTransactions()
20142016
{ // cs_wallet scope
20152017
LOCK(cs_wallet);
20162018

2019+
if (m_is_ibd) return;
2020+
20172021
// Relay transactions
20182022
for (std::pair<const uint256, CWalletTx>& item : mapWallet) {
20192023
CWalletTx& wtx = item.second;
@@ -2587,9 +2591,9 @@ bool CWallet::FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, int& nC
25872591
return true;
25882592
}
25892593

2590-
static bool IsCurrentForAntiFeeSniping(interfaces::Chain& chain, const uint256& block_hash)
2594+
static bool IsCurrentForAntiFeeSniping(interfaces::Chain& chain, bool is_ibd, const uint256& block_hash)
25912595
{
2592-
if (chain.isInitialBlockDownload()) {
2596+
if (is_ibd) {
25932597
return false;
25942598
}
25952599
constexpr int64_t MAX_ANTI_FEE_SNIPING_TIP_AGE = 8 * 60 * 60; // in seconds
@@ -2605,7 +2609,7 @@ static bool IsCurrentForAntiFeeSniping(interfaces::Chain& chain, const uint256&
26052609
* Return a height-based locktime for new transactions (uses the height of the
26062610
* current chain tip unless we are not synced with the current chain
26072611
*/
2608-
static uint32_t GetLocktimeForNewTransaction(interfaces::Chain& chain, const uint256& block_hash, int block_height)
2612+
static uint32_t GetLocktimeForNewTransaction(interfaces::Chain& chain, bool is_ibd, const uint256& block_hash, int block_height)
26092613
{
26102614
uint32_t locktime;
26112615
// Discourage fee sniping.
@@ -2628,7 +2632,7 @@ static uint32_t GetLocktimeForNewTransaction(interfaces::Chain& chain, const uin
26282632
// enough, that fee sniping isn't a problem yet, but by implementing a fix
26292633
// now we ensure code won't be written that makes assumptions about
26302634
// nLockTime that preclude a fix later.
2631-
if (IsCurrentForAntiFeeSniping(chain, block_hash)) {
2635+
if (IsCurrentForAntiFeeSniping(chain, is_ibd, block_hash)) {
26322636
locktime = block_height;
26332637

26342638
// Secondly occasionally randomly pick a nLockTime even further back, so
@@ -2707,7 +2711,7 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CTransac
27072711
{
27082712
std::set<CInputCoin> setCoins;
27092713
LOCK(cs_wallet);
2710-
txNew.nLockTime = GetLocktimeForNewTransaction(chain(), GetLastBlockHash(), GetLastBlockHeight());
2714+
txNew.nLockTime = GetLocktimeForNewTransaction(chain(), m_is_ibd, GetLastBlockHash(), GetLastBlockHeight());
27112715
{
27122716
std::vector<COutput> vAvailableCoins;
27132717
AvailableCoins(vAvailableCoins, true, &coin_control, 1, MAX_MONEY, MAX_MONEY, 0);

src/wallet/wallet.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,12 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
723723
// ScriptPubKeyMan::GetID. In many cases it will be the hash of an internal structure
724724
std::map<uint256, std::unique_ptr<ScriptPubKeyMan>> m_spk_managers;
725725

726+
/* Flag to indicate chain is still in initial block download. Initialized to false,
727+
* latched to updateBlockTip if node evaluates being out of IBD. This method MUST be
728+
* called by rescanning code while boostraping the wallet.
729+
*/
730+
bool m_is_ibd GUARDED_BY(cs_wallet) = false;
731+
726732
public:
727733
/*
728734
* Main wallet lock.

0 commit comments

Comments
 (0)