Skip to content

Commit afd7f84

Browse files
committed
perf: use GetAncestor() to jump blocks back for CreditPool
1 parent f7749db commit afd7f84

File tree

1 file changed

+1
-6
lines changed

1 file changed

+1
-6
lines changed

src/evo/creditpool.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include <deploymentstatus.h>
1616
#include <logging.h>
1717
#include <node/blockstorage.h>
18-
#include <util/irange.h>
1918
#include <validation.h>
2019

2120
#include <algorithm>
@@ -168,11 +167,7 @@ CCreditPool CCreditPoolManager::ConstructCreditPool(const gsl::not_null<const CB
168167
throw std::runtime_error(strprintf("%s: failed-getcreditpool-index-duplicated", __func__));
169168
}
170169

171-
const CBlockIndex* distant_block_index = block_index;
172-
for ([[maybe_unused]] auto _ : irange::range(Params().CreditPoolPeriodBlocks())) {
173-
distant_block_index = distant_block_index->pprev;
174-
if (distant_block_index == nullptr) break;
175-
}
170+
const CBlockIndex* distant_block_index{block_index->GetAncestor(block_index->nHeight - Params().CreditPoolPeriodBlocks())};
176171
CAmount distantUnlocked{0};
177172
if (distant_block_index) {
178173
if (std::optional<CBlock> distant_block = GetBlockForCreditPool(distant_block_index, consensusParams); distant_block) {

0 commit comments

Comments
 (0)