refactor: add annotation gsl::not_null for ConstructCreditPool

This commit is contained in:
Konstantin Akimov 2024-12-10 15:41:30 +07:00
parent f1905ca950
commit 906c2d79ba
No known key found for this signature in database
GPG Key ID: 2176C4A5D01EA524
2 changed files with 8 additions and 4 deletions

View File

@ -112,7 +112,8 @@ void CCreditPoolManager::AddToCache(const uint256& block_hash, int height, const
} }
} }
static std::optional<CBlock> GetBlockForCreditPool(const CBlockIndex* const block_index, const Consensus::Params& consensusParams) static std::optional<CBlock> GetBlockForCreditPool(const gsl::not_null<const CBlockIndex*> block_index,
const Consensus::Params& consensusParams)
{ {
// There's no CbTx before DIP0003 activation // There's no CbTx before DIP0003 activation
if (!DeploymentActiveAt(*block_index, Params().GetConsensus(), Consensus::DEPLOYMENT_DIP0003)) { if (!DeploymentActiveAt(*block_index, Params().GetConsensus(), Consensus::DEPLOYMENT_DIP0003)) {
@ -132,7 +133,8 @@ static std::optional<CBlock> GetBlockForCreditPool(const CBlockIndex* const bloc
return block; return block;
} }
CCreditPool CCreditPoolManager::ConstructCreditPool(const CBlockIndex* const block_index, CCreditPool prev, const Consensus::Params& consensusParams) CCreditPool CCreditPoolManager::ConstructCreditPool(const gsl::not_null<const CBlockIndex*> block_index,
CCreditPool prev, const Consensus::Params& consensusParams)
{ {
std::optional<CBlock> block = GetBlockForCreditPool(block_index, consensusParams); std::optional<CBlock> block = GetBlockForCreditPool(block_index, consensusParams);
if (!block) { if (!block) {
@ -213,7 +215,7 @@ CCreditPool CCreditPoolManager::ConstructCreditPool(const CBlockIndex* const blo
CCreditPool CCreditPoolManager::GetCreditPool(const CBlockIndex* block_index, const Consensus::Params& consensusParams) CCreditPool CCreditPoolManager::GetCreditPool(const CBlockIndex* block_index, const Consensus::Params& consensusParams)
{ {
std::stack<const CBlockIndex *> to_calculate; std::stack<gsl::not_null<const CBlockIndex*>> to_calculate;
std::optional<CCreditPool> poolTmp; std::optional<CCreditPool> poolTmp;
while (block_index != nullptr && !(poolTmp = GetFromCache(*block_index)).has_value()) { while (block_index != nullptr && !(poolTmp = GetFromCache(*block_index)).has_value()) {

View File

@ -16,6 +16,7 @@
#include <evo/assetlocktx.h> #include <evo/assetlocktx.h>
#include <gsl/pointers.h>
#include <optional> #include <optional>
#include <unordered_set> #include <unordered_set>
@ -134,7 +135,8 @@ private:
std::optional<CCreditPool> GetFromCache(const CBlockIndex& block_index); std::optional<CCreditPool> GetFromCache(const CBlockIndex& block_index);
void AddToCache(const uint256& block_hash, int height, const CCreditPool& pool); void AddToCache(const uint256& block_hash, int height, const CCreditPool& pool);
CCreditPool ConstructCreditPool(const CBlockIndex* block_index, CCreditPool prev, const Consensus::Params& consensusParams); CCreditPool ConstructCreditPool(const gsl::not_null<const CBlockIndex*> block_index, CCreditPool prev,
const Consensus::Params& consensusParams);
}; };
std::optional<CCreditPoolDiff> GetCreditPoolDiffForBlock(CCreditPoolManager& cpoolman, const BlockManager& blockman, const llmq::CQuorumManager& qman, std::optional<CCreditPoolDiff> GetCreditPoolDiffForBlock(CCreditPoolManager& cpoolman, const BlockManager& blockman, const llmq::CQuorumManager& qman,