mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-10 09:06:15 +01:00
refactor: rename BlockKey to BlockRef
This commit is contained in:
parent
9f1aa88d4d
commit
89a8f74bbb
8 changed files with 33 additions and 18 deletions
|
@ -113,7 +113,7 @@ bool BaseIndex::Init()
|
||||||
|
|
||||||
// Child init
|
// Child init
|
||||||
const CBlockIndex* start_block = m_best_block_index.load();
|
const CBlockIndex* start_block = m_best_block_index.load();
|
||||||
if (!CustomInit(start_block ? std::make_optional(interfaces::BlockKey{start_block->GetBlockHash(), start_block->nHeight}) : std::nullopt)) {
|
if (!CustomInit(start_block ? std::make_optional(interfaces::BlockRef{start_block->GetBlockHash(), start_block->nHeight}) : std::nullopt)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#include <dbwrapper.h>
|
#include <dbwrapper.h>
|
||||||
#include <interfaces/chain.h>
|
#include <interfaces/chain.h>
|
||||||
|
#include <interfaces/types.h>
|
||||||
#include <util/string.h>
|
#include <util/string.h>
|
||||||
#include <util/threadinterrupt.h>
|
#include <util/threadinterrupt.h>
|
||||||
#include <validationinterface.h>
|
#include <validationinterface.h>
|
||||||
|
@ -107,7 +108,7 @@ protected:
|
||||||
void ChainStateFlushed(ChainstateRole role, const CBlockLocator& locator) override;
|
void ChainStateFlushed(ChainstateRole role, const CBlockLocator& locator) override;
|
||||||
|
|
||||||
/// Initialize internal state from the database and block index.
|
/// Initialize internal state from the database and block index.
|
||||||
[[nodiscard]] virtual bool CustomInit(const std::optional<interfaces::BlockKey>& block) { return true; }
|
[[nodiscard]] virtual bool CustomInit(const std::optional<interfaces::BlockRef>& block) { return true; }
|
||||||
|
|
||||||
/// Write update index entries for a newly connected block.
|
/// Write update index entries for a newly connected block.
|
||||||
[[nodiscard]] virtual bool CustomAppend(const interfaces::BlockInfo& block) { return true; }
|
[[nodiscard]] virtual bool CustomAppend(const interfaces::BlockInfo& block) { return true; }
|
||||||
|
@ -118,7 +119,7 @@ protected:
|
||||||
|
|
||||||
/// Rewind index to an earlier chain tip during a chain reorg. The tip must
|
/// Rewind index to an earlier chain tip during a chain reorg. The tip must
|
||||||
/// be an ancestor of the current best block.
|
/// be an ancestor of the current best block.
|
||||||
[[nodiscard]] virtual bool CustomRewind(const interfaces::BlockKey& current_tip, const interfaces::BlockKey& new_tip) { return true; }
|
[[nodiscard]] virtual bool CustomRewind(const interfaces::BlockRef& current_tip, const interfaces::BlockRef& new_tip) { return true; }
|
||||||
|
|
||||||
virtual DB& GetDB() const = 0;
|
virtual DB& GetDB() const = 0;
|
||||||
|
|
||||||
|
|
|
@ -112,7 +112,7 @@ BlockFilterIndex::BlockFilterIndex(std::unique_ptr<interfaces::Chain> chain, Blo
|
||||||
m_filter_fileseq = std::make_unique<FlatFileSeq>(std::move(path), "fltr", FLTR_FILE_CHUNK_SIZE);
|
m_filter_fileseq = std::make_unique<FlatFileSeq>(std::move(path), "fltr", FLTR_FILE_CHUNK_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BlockFilterIndex::CustomInit(const std::optional<interfaces::BlockKey>& block)
|
bool BlockFilterIndex::CustomInit(const std::optional<interfaces::BlockRef>& block)
|
||||||
{
|
{
|
||||||
if (!m_db->Read(DB_FILTER_POS, m_next_filter_pos)) {
|
if (!m_db->Read(DB_FILTER_POS, m_next_filter_pos)) {
|
||||||
// Check that the cause of the read failure is that the key does not exist. Any other errors
|
// Check that the cause of the read failure is that the key does not exist. Any other errors
|
||||||
|
@ -316,7 +316,7 @@ bool BlockFilterIndex::Write(const BlockFilter& filter, uint32_t block_height, c
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BlockFilterIndex::CustomRewind(const interfaces::BlockKey& current_tip, const interfaces::BlockKey& new_tip)
|
bool BlockFilterIndex::CustomRewind(const interfaces::BlockRef& current_tip, const interfaces::BlockRef& new_tip)
|
||||||
{
|
{
|
||||||
CDBBatch batch(*m_db);
|
CDBBatch batch(*m_db);
|
||||||
std::unique_ptr<CDBIterator> db_it(m_db->NewIterator());
|
std::unique_ptr<CDBIterator> db_it(m_db->NewIterator());
|
||||||
|
|
|
@ -52,13 +52,13 @@ private:
|
||||||
std::optional<uint256> ReadFilterHeader(int height, const uint256& expected_block_hash);
|
std::optional<uint256> ReadFilterHeader(int height, const uint256& expected_block_hash);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool CustomInit(const std::optional<interfaces::BlockKey>& block) override;
|
bool CustomInit(const std::optional<interfaces::BlockRef>& block) override;
|
||||||
|
|
||||||
bool CustomCommit(CDBBatch& batch) override;
|
bool CustomCommit(CDBBatch& batch) override;
|
||||||
|
|
||||||
bool CustomAppend(const interfaces::BlockInfo& block) override;
|
bool CustomAppend(const interfaces::BlockInfo& block) override;
|
||||||
|
|
||||||
bool CustomRewind(const interfaces::BlockKey& current_tip, const interfaces::BlockKey& new_tip) override;
|
bool CustomRewind(const interfaces::BlockRef& current_tip, const interfaces::BlockRef& new_tip) override;
|
||||||
|
|
||||||
BaseIndex::DB& GetDB() const LIFETIMEBOUND override { return *m_db; }
|
BaseIndex::DB& GetDB() const LIFETIMEBOUND override { return *m_db; }
|
||||||
|
|
||||||
|
|
|
@ -265,7 +265,7 @@ bool CoinStatsIndex::CustomAppend(const interfaces::BlockInfo& block)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CoinStatsIndex::CustomRewind(const interfaces::BlockKey& current_tip, const interfaces::BlockKey& new_tip)
|
bool CoinStatsIndex::CustomRewind(const interfaces::BlockRef& current_tip, const interfaces::BlockRef& new_tip)
|
||||||
{
|
{
|
||||||
CDBBatch batch(*m_db);
|
CDBBatch batch(*m_db);
|
||||||
std::unique_ptr<CDBIterator> db_it(m_db->NewIterator());
|
std::unique_ptr<CDBIterator> db_it(m_db->NewIterator());
|
||||||
|
@ -304,7 +304,7 @@ bool CoinStatsIndex::CustomRewind(const interfaces::BlockKey& current_tip, const
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool LookUpOne(const CDBWrapper& db, const interfaces::BlockKey& block, DBVal& result)
|
static bool LookUpOne(const CDBWrapper& db, const interfaces::BlockRef& block, DBVal& result)
|
||||||
{
|
{
|
||||||
// First check if the result is stored under the height index and the value
|
// First check if the result is stored under the height index and the value
|
||||||
// there matches the block hash. This should be the case if the block is on
|
// there matches the block hash. This should be the case if the block is on
|
||||||
|
@ -350,7 +350,7 @@ std::optional<CCoinsStats> CoinStatsIndex::LookUpStats(const CBlockIndex& block_
|
||||||
return stats;
|
return stats;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CoinStatsIndex::CustomInit(const std::optional<interfaces::BlockKey>& block)
|
bool CoinStatsIndex::CustomInit(const std::optional<interfaces::BlockRef>& block)
|
||||||
{
|
{
|
||||||
if (!m_db->Read(DB_MUHASH, m_muhash)) {
|
if (!m_db->Read(DB_MUHASH, m_muhash)) {
|
||||||
// Check that the cause of the read failure is that the key does not
|
// Check that the cause of the read failure is that the key does not
|
||||||
|
|
|
@ -43,13 +43,13 @@ private:
|
||||||
bool AllowPrune() const override { return true; }
|
bool AllowPrune() const override { return true; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool CustomInit(const std::optional<interfaces::BlockKey>& block) override;
|
bool CustomInit(const std::optional<interfaces::BlockRef>& block) override;
|
||||||
|
|
||||||
bool CustomCommit(CDBBatch& batch) override;
|
bool CustomCommit(CDBBatch& batch) override;
|
||||||
|
|
||||||
bool CustomAppend(const interfaces::BlockInfo& block) override;
|
bool CustomAppend(const interfaces::BlockInfo& block) override;
|
||||||
|
|
||||||
bool CustomRewind(const interfaces::BlockKey& current_tip, const interfaces::BlockKey& new_tip) override;
|
bool CustomRewind(const interfaces::BlockRef& current_tip, const interfaces::BlockRef& new_tip) override;
|
||||||
|
|
||||||
BaseIndex::DB& GetDB() const override { return *m_db; }
|
BaseIndex::DB& GetDB() const override { return *m_db; }
|
||||||
|
|
||||||
|
|
|
@ -41,12 +41,6 @@ namespace interfaces {
|
||||||
class Handler;
|
class Handler;
|
||||||
class Wallet;
|
class Wallet;
|
||||||
|
|
||||||
//! Hash/height pair to help track and identify blocks.
|
|
||||||
struct BlockKey {
|
|
||||||
uint256 hash;
|
|
||||||
int height = -1;
|
|
||||||
};
|
|
||||||
|
|
||||||
//! Helper for findBlock to selectively return pieces of block data. If block is
|
//! Helper for findBlock to selectively return pieces of block data. If block is
|
||||||
//! found, data will be returned by setting specified output variables. If block
|
//! found, data will be returned by setting specified output variables. If block
|
||||||
//! is not found, output variables will keep their previous values.
|
//! is not found, output variables will keep their previous values.
|
||||||
|
|
20
src/interfaces/types.h
Normal file
20
src/interfaces/types.h
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
// Copyright (c) 2024 The Bitcoin Core developers
|
||||||
|
// Distributed under the MIT software license, see the accompanying
|
||||||
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
|
#ifndef BITCOIN_INTERFACES_TYPES_H
|
||||||
|
#define BITCOIN_INTERFACES_TYPES_H
|
||||||
|
|
||||||
|
#include <uint256.h>
|
||||||
|
|
||||||
|
namespace interfaces {
|
||||||
|
|
||||||
|
//! Hash/height pair to help track and identify blocks.
|
||||||
|
struct BlockRef {
|
||||||
|
uint256 hash;
|
||||||
|
int height = -1;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace interfaces
|
||||||
|
|
||||||
|
#endif // BITCOIN_INTERFACES_TYPES_H
|
Loading…
Add table
Reference in a new issue