diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2015-08-15 12:37:23 +0100 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2015-08-15 12:37:23 +0100 |
commit | 769d5ef0e6213e55bf8940a03e2de8c8070a8f54 (patch) | |
tree | a5ddd57133708f69d7e9c671e51a92bf2d1823d0 | |
parent | Merge pull request #376 (diff) | |
download | monero-769d5ef0e6213e55bf8940a03e2de8c8070a8f54.tar.xz |
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.
-rw-r--r-- | src/cryptonote_core/blockchain.cpp | 6 |
1 files 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)); |