use latest hard fork block for get_approximate_blockchain_height & update approximate_rolled_back_blocks
What changed, and why it matters
This commit updates the wallet's method for estimating the current blockchain height. Previously, the wallet used a fixed old hard-fork point and a fixed rollback adjustment. Now it uses the latest hard-fork data and updated rollback figures. The change is primarily about keeping the estimate accurate as the network evolves. It is not a direct fix for a code execution or theft vulnerability, but an inaccurate estimate could in theory affect wallet behavior such as when it considers itself synced or which outputs it scans.
Treat as a routine maintenance/accuracy improvement. Review whether any wallet logic relies on get_approximate_blockchain_height() for security-critical decisions (e.g., accepting unconfirmed transactions, determining spendability, or selecting outputs). If so, verify that the new estimates remain conservative and do not introduce edge cases around fork times or rollback values. No urgent security patch action is indicated by the diff alone.
Security signals we found
Logic change in blockchain height estimation used by wallet sync/scan heuristics
Removal of stale hard-coded fork constants in favor of dynamic latest-hard-fork lookup
Update to network-specific rollback adjustment values
No direct memory safety, cryptographic, or authorization changes visible
Evidence from the diff
The patch modifies wallet2::get_approximate_blockchain_height() in src/wallet/wallet2.cpp. It replaces hard-coded v2 fork time/block constants with the latest entry from the network-specific hardfork_t arrays, and updates approximate_rolled_back_blocks for mainnet, testnet, and stagenet. It also guards against negative time differences when the current time is not past the fork time. The function is used to estimate blockchain height when the daemon does not provide one, which can influence refresh/sync decisions and output scanning.
Changed components
src/wallet/wallet2.cppwallet2::get_approximate_blockchain_height()wallet synchronization and output scanning heuristicsInspect captured patch +16 / −7
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp
index b7ec6d2..4735a25 100644
--- a/src/wallet/wallet2.cpp
+++ b/src/wallet/wallet2.cpp
@@ -12870,17 +12870,26 @@ uint64_t wallet2::get_daemon_blockchain_target_height(string &err)
uint64_t wallet2::get_approximate_blockchain_height() const
{
- // time of v2 fork
- const time_t fork_time = m_nettype == TESTNET ? 1448285909 : m_nettype == STAGENET ? 1520937818 : 1458748658;
- // v2 fork block
- const uint64_t fork_block = m_nettype == TESTNET ? 624634 : m_nettype == STAGENET ? 32000 : 1009827;
+ const size_t wallet_num_hard_forks = m_nettype == TESTNET ? num_testnet_hard_forks
+ : m_nettype == STAGENET ? num_stagenet_hard_forks
+ : num_mainnet_hard_forks;
+ const hardfork_t *wallet_hard_forks = m_nettype == TESTNET ? testnet_hard_forks
+ : m_nettype == STAGENET ? stagenet_hard_forks
+ : mainnet_hard_forks;
+ // time of latest fork
+ const time_t fork_time = wallet_hard_forks[wallet_num_hard_forks-1].time;
+ // latest fork block
+ const uint64_t fork_block = wallet_hard_forks[wallet_num_hard_forks-1].height;
// avg seconds per block
const int seconds_per_block = DIFFICULTY_TARGET_V2;
// Calculated blockchain height
- uint64_t approx_blockchain_height = fork_block + (time(NULL) - fork_time)/seconds_per_block;
+ uint64_t approx_blockchain_height = fork_block;
+ const time_t now = time(NULL);
+ if (now > fork_time)
+ approx_blockchain_height += (now - fork_time) / seconds_per_block;
// testnet and stagenet got some huge rollbacks, so the estimation is way off
- static const uint64_t approximate_rolled_back_blocks = m_nettype == TESTNET ? 342100 : m_nettype == STAGENET ? 60000 : 30000;
- if ((m_nettype == TESTNET || m_nettype == STAGENET) && approx_blockchain_height > approximate_rolled_back_blocks)
+ const uint64_t approximate_rolled_back_blocks = m_nettype == TESTNET ? 26600 : m_nettype == STAGENET ? 48600 : 33600;
+ if (approx_blockchain_height > approximate_rolled_back_blocks)
approx_blockchain_height -= approximate_rolled_back_blocks;
LOG_PRINT_L2("Calculated blockchain height: " << approx_blockchain_height);
return approx_blockchain_height;
Why this scored 21/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.