diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2019-02-21 00:13:21 +0000 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2019-03-08 12:04:14 +0000 |
commit | 4b21d38dfda29fe916700887c99d44edeb8fe06f (patch) | |
tree | 5d372ac8bdcff8d8d0ba043fc7dea0a20baad57d /tests | |
parent | Merge pull request #5232 (diff) | |
download | monero-4b21d38dfda29fe916700887c99d44edeb8fe06f.tar.xz |
blockchain: speed up getting N blocks weights/long term weights
Diffstat (limited to 'tests')
-rw-r--r-- | tests/block_weight/block_weight.cpp | 12 | ||||
-rw-r--r-- | tests/unit_tests/long_term_block_weight.cpp | 12 |
2 files changed, 24 insertions, 0 deletions
diff --git a/tests/block_weight/block_weight.cpp b/tests/block_weight/block_weight.cpp index 57fcb497e..1e8974b78 100644 --- a/tests/block_weight/block_weight.cpp +++ b/tests/block_weight/block_weight.cpp @@ -72,6 +72,18 @@ public: virtual uint64_t height() const override { return blocks.size(); } virtual size_t get_block_weight(const uint64_t &h) const override { return blocks[h].weight; } virtual uint64_t get_block_long_term_weight(const uint64_t &h) const override { return blocks[h].long_term_weight; } + virtual std::vector<uint64_t> get_block_weights(uint64_t start_height, size_t count) const override { + std::vector<uint64_t> ret; + ret.reserve(count); + while (count-- && start_height < blocks.size()) ret.push_back(blocks[start_height++].weight); + return ret; + } + virtual std::vector<uint64_t> get_long_term_block_weights(uint64_t start_height, size_t count) const override { + std::vector<uint64_t> ret; + ret.reserve(count); + while (count-- && start_height < blocks.size()) ret.push_back(blocks[start_height++].long_term_weight); + return ret; + } virtual crypto::hash top_block_hash(uint64_t *block_height = NULL) const override { uint64_t h = height(); crypto::hash top = crypto::null_hash; diff --git a/tests/unit_tests/long_term_block_weight.cpp b/tests/unit_tests/long_term_block_weight.cpp index f37b608b6..ce6ff3551 100644 --- a/tests/unit_tests/long_term_block_weight.cpp +++ b/tests/unit_tests/long_term_block_weight.cpp @@ -64,6 +64,18 @@ public: virtual uint64_t height() const override { return blocks.size(); } virtual size_t get_block_weight(const uint64_t &h) const override { return blocks[h].weight; } virtual uint64_t get_block_long_term_weight(const uint64_t &h) const override { return blocks[h].long_term_weight; } + virtual std::vector<uint64_t> get_block_weights(uint64_t start_height, size_t count) const override { + std::vector<uint64_t> ret; + ret.reserve(count); + while (count-- && start_height < blocks.size()) ret.push_back(blocks[start_height++].weight); + return ret; + } + virtual std::vector<uint64_t> get_long_term_block_weights(uint64_t start_height, size_t count) const override { + std::vector<uint64_t> ret; + ret.reserve(count); + while (count-- && start_height < blocks.size()) ret.push_back(blocks[start_height++].long_term_weight); + return ret; + } virtual crypto::hash top_block_hash(uint64_t *block_height = NULL) const override { uint64_t h = height(); crypto::hash top = crypto::null_hash; |