Skip to content

Commit

Permalink
Add right calc for height approximation
Browse files Browse the repository at this point in the history
  • Loading branch information
hayzamjs committed Aug 19, 2020
1 parent e6f9a3a commit bafcfd6
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions src/wallet/wallet2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4691,9 +4691,9 @@ crypto::secret_key wallet2::generate(const std::string& wallet_, const epee::wip
{
// -1 month for fluctuations in block time and machine date/time setup.
// avg seconds per block
const int seconds_per_block = DIFFICULTY_TARGET;
const int seconds_per_block = 120;
// ~num blocks per month
const uint64_t blocks_per_month = 60*60*24*30/seconds_per_block;
const uint64_t blocks_per_month = 21600; /* 720 * 30 */

// try asking the daemon first
std::string err;
Expand Down Expand Up @@ -11831,18 +11831,10 @@ 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;
// avg seconds per block
const int seconds_per_block = DIFFICULTY_TARGET;
// Calculated blockchain height
uint64_t approx_blockchain_height = fork_block + (time(NULL) - fork_time)/seconds_per_block;
// testnet got some huge rollbacks, so the estimation is way off
static const uint64_t approximate_testnet_rolled_back_blocks = 303967;
if (m_nettype == TESTNET && approx_blockchain_height > approximate_testnet_rolled_back_blocks)
approx_blockchain_height -= approximate_testnet_rolled_back_blocks;
const int seconds_per_block = DIFFICULTY_TARGET;
const time_t epochTimeMiningStarted = 1596258914;
const time_t currentTime = time(NULL);
uint64_t approx_blockchain_height = (currentTime < epochTimeMiningStarted) ? 0 : (currentTime - epochTimeMiningStarted)/seconds_per_block;
LOG_PRINT_L2("Calculated blockchain height: " << approx_blockchain_height);
return approx_blockchain_height;
}
Expand Down

0 comments on commit bafcfd6

Please sign in to comment.