From 769d5ef0e6213e55bf8940a03e2de8c8070a8f54 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sat, 15 Aug 2015 12:37:23 +0100 Subject: [PATCH] blockchain: fix off by 1 in timestamp median calculations The height function apparently used to return the index of the last block, rather than the height of the chain. This now seems to be incorrect, judging the the code, so we remove the now wrong comment, as well as a couple +/- 1 adjustments which now cause the median calculation to differ from the original blockchain_storage version. --- src/cryptonote_core/blockchain.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index efac2d3d9..acbd9f9a7 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -2218,7 +2218,7 @@ bool Blockchain::check_block_timestamp(const block& b) const } // if not enough blocks, no proper median yet, return true - if(m_db->height() < BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW + 1) + if(m_db->height() < BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW) { return true; } @@ -2227,9 +2227,7 @@ bool Blockchain::check_block_timestamp(const block& b) const auto h = m_db->height(); // need most recent 60 blocks, get index of first of those - // using +1 because BlockchainDB::height() returns the index of the top block, - // not the size of the blockchain (0-indexed) - size_t offset = h - BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW - 1; + size_t offset = h - BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW; for(;offset < h; ++offset) { timestamps.push_back(m_db->get_block_timestamp(offset));