refactor: Convert ChainstateRole enum to struct

Change ChainstateRole parameter passed to wallets and indexes. Wallets and
indexes need to know whether chainstate is historical and whether it is fully
validated. They should not be aware of the assumeutxo snapshot validation
process.
This commit is contained in:
Ryan Ofsky
2025-06-18 09:51:34 -04:00
parent 352ad27fc1
commit 4dfe383912
26 changed files with 130 additions and 79 deletions

View File

@@ -10,6 +10,7 @@
#include <interfaces/chain.h>
#include <interfaces/types.h>
#include <kernel/chain.h>
#include <kernel/types.h>
#include <logging.h>
#include <node/abort.h>
#include <node/blockstorage.h>
@@ -42,6 +43,8 @@
#include <utility>
#include <vector>
using kernel::ChainstateRole;
constexpr uint8_t DB_BEST_BLOCK{'B'};
constexpr auto SYNC_LOG_INTERVAL{30s};
@@ -323,15 +326,13 @@ bool BaseIndex::Rewind(const CBlockIndex* current_tip, const CBlockIndex* new_ti
return true;
}
void BaseIndex::BlockConnected(ChainstateRole role, const std::shared_ptr<const CBlock>& block, const CBlockIndex* pindex)
void BaseIndex::BlockConnected(const ChainstateRole& role, const std::shared_ptr<const CBlock>& block, const CBlockIndex* pindex)
{
// Ignore events from the assumed-valid chain; we will process its blocks
// (sequentially) after it is fully verified by the background chainstate. This
// is to avoid any out-of-order indexing.
// Ignore events from not fully validated chains to avoid out-of-order indexing.
//
// TODO at some point we could parameterize whether a particular index can be
// built out of order, but for now just do the conservative simple thing.
if (role == ChainstateRole::ASSUMEDVALID) {
if (!role.validated) {
return;
}
@@ -377,11 +378,10 @@ void BaseIndex::BlockConnected(ChainstateRole role, const std::shared_ptr<const
}
}
void BaseIndex::ChainStateFlushed(ChainstateRole role, const CBlockLocator& locator)
void BaseIndex::ChainStateFlushed(const ChainstateRole& role, const CBlockLocator& locator)
{
// Ignore events from the assumed-valid chain; we will process its blocks
// (sequentially) after it is fully verified by the background chainstate.
if (role == ChainstateRole::ASSUMEDVALID) {
// Ignore events from not fully validated chains to avoid out-of-order indexing.
if (!role.validated) {
return;
}