-
Notifications
You must be signed in to change notification settings - Fork 37.7k
wallet: add cached m_is_ibd to remove Chain::isInitialBlockDownload #17484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1177,9 +1177,11 @@ void CWallet::blockDisconnected(const CBlock& block, int height) | |
} | ||
} | ||
|
||
void CWallet::updatedBlockTip() | ||
void CWallet::updatedBlockTip(bool is_ibd) | ||
{ | ||
m_best_block_time = GetTime(); | ||
LOCK(cs_wallet); | ||
m_is_ibd = is_ibd; | ||
} | ||
|
||
|
||
|
@@ -2014,6 +2016,8 @@ void CWallet::ResendWalletTransactions() | |
{ // cs_wallet scope | ||
LOCK(cs_wallet); | ||
|
||
if (m_is_ibd) return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps make this change in the commit "Add m_is_ibd in CWallet` (or merge the two commits, IIUC) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. re: #17484 (comment) In commit "Remove Chain::isReadyToBroadcast method" (a5a6748)
Change does make sense (and is necessary) in this commit due to isReadyToBroadcast call a few lines up. But it would be good to add a comment here mentioning this is also needed to avoid spamming nodes with old transactions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In commit "[wallet] Add m_is_ibd in CWallet" (797ec9d) I do think it would be helpful to have comment here saying this is skipped during ibd to avoid spam. Also the comment above for isReadyToBroadcast() is incorrect after commit "[interfaces] Remove Chain::isReadyToBroadcast" (20eb0da), and should be updated to not mention IBD since the IBD check isn't there anymore |
||
|
||
// Relay transactions | ||
for (std::pair<const uint256, CWalletTx>& item : mapWallet) { | ||
CWalletTx& wtx = item.second; | ||
|
@@ -2587,9 +2591,9 @@ bool CWallet::FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, int& nC | |
return true; | ||
} | ||
|
||
static bool IsCurrentForAntiFeeSniping(interfaces::Chain& chain, const uint256& block_hash) | ||
static bool IsCurrentForAntiFeeSniping(interfaces::Chain& chain, bool is_ibd, const uint256& block_hash) | ||
{ | ||
if (chain.isInitialBlockDownload()) { | ||
if (is_ibd) { | ||
return false; | ||
} | ||
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& | |
* Return a height-based locktime for new transactions (uses the height of the | ||
* current chain tip unless we are not synced with the current chain | ||
*/ | ||
static uint32_t GetLocktimeForNewTransaction(interfaces::Chain& chain, const uint256& block_hash, int block_height) | ||
static uint32_t GetLocktimeForNewTransaction(interfaces::Chain& chain, bool is_ibd, const uint256& block_hash, int block_height) | ||
{ | ||
uint32_t locktime; | ||
// Discourage fee sniping. | ||
|
@@ -2628,7 +2632,7 @@ static uint32_t GetLocktimeForNewTransaction(interfaces::Chain& chain, const uin | |
// enough, that fee sniping isn't a problem yet, but by implementing a fix | ||
// now we ensure code won't be written that makes assumptions about | ||
// nLockTime that preclude a fix later. | ||
if (IsCurrentForAntiFeeSniping(chain, block_hash)) { | ||
if (IsCurrentForAntiFeeSniping(chain, is_ibd, block_hash)) { | ||
locktime = block_height; | ||
|
||
// Secondly occasionally randomly pick a nLockTime even further back, so | ||
|
@@ -2707,7 +2711,7 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CTransac | |
{ | ||
std::set<CInputCoin> setCoins; | ||
LOCK(cs_wallet); | ||
txNew.nLockTime = GetLocktimeForNewTransaction(chain(), GetLastBlockHash(), GetLastBlockHeight()); | ||
txNew.nLockTime = GetLocktimeForNewTransaction(chain(), m_is_ibd, GetLastBlockHash(), GetLastBlockHeight()); | ||
{ | ||
std::vector<COutput> vAvailableCoins; | ||
AvailableCoins(vAvailableCoins, true, &coin_control, 1, MAX_MONEY, MAX_MONEY, 0); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit "Remove Chain::isReadyToBroadcast method" (a5a6748)
Implementation and meaning of isReadyToBroadcast method is changing a lot, so I would rename it to something like "isInitializing" or "isLoading" and update the comment.
Also commit title could be changed to mention removing isInitialBlockDownload