Skip to content

Commit 89a8f74

Browse files
committed
refactor: rename BlockKey to BlockRef
1 parent 9f1aa88 commit 89a8f74

File tree

8 files changed

+33
-18
lines changed

8 files changed

+33
-18
lines changed

src/index/base.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ bool BaseIndex::Init()
113113

114114
// Child init
115115
const CBlockIndex* start_block = m_best_block_index.load();
116-
if (!CustomInit(start_block ? std::make_optional(interfaces::BlockKey{start_block->GetBlockHash(), start_block->nHeight}) : std::nullopt)) {
116+
if (!CustomInit(start_block ? std::make_optional(interfaces::BlockRef{start_block->GetBlockHash(), start_block->nHeight}) : std::nullopt)) {
117117
return false;
118118
}
119119

src/index/base.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <dbwrapper.h>
99
#include <interfaces/chain.h>
10+
#include <interfaces/types.h>
1011
#include <util/string.h>
1112
#include <util/threadinterrupt.h>
1213
#include <validationinterface.h>
@@ -107,7 +108,7 @@ class BaseIndex : public CValidationInterface
107108
void ChainStateFlushed(ChainstateRole role, const CBlockLocator& locator) override;
108109

109110
/// Initialize internal state from the database and block index.
110-
[[nodiscard]] virtual bool CustomInit(const std::optional<interfaces::BlockKey>& block) { return true; }
111+
[[nodiscard]] virtual bool CustomInit(const std::optional<interfaces::BlockRef>& block) { return true; }
111112

112113
/// Write update index entries for a newly connected block.
113114
[[nodiscard]] virtual bool CustomAppend(const interfaces::BlockInfo& block) { return true; }
@@ -118,7 +119,7 @@ class BaseIndex : public CValidationInterface
118119

119120
/// Rewind index to an earlier chain tip during a chain reorg. The tip must
120121
/// be an ancestor of the current best block.
121-
[[nodiscard]] virtual bool CustomRewind(const interfaces::BlockKey& current_tip, const interfaces::BlockKey& new_tip) { return true; }
122+
[[nodiscard]] virtual bool CustomRewind(const interfaces::BlockRef& current_tip, const interfaces::BlockRef& new_tip) { return true; }
122123

123124
virtual DB& GetDB() const = 0;
124125

src/index/blockfilterindex.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ BlockFilterIndex::BlockFilterIndex(std::unique_ptr<interfaces::Chain> chain, Blo
112112
m_filter_fileseq = std::make_unique<FlatFileSeq>(std::move(path), "fltr", FLTR_FILE_CHUNK_SIZE);
113113
}
114114

115-
bool BlockFilterIndex::CustomInit(const std::optional<interfaces::BlockKey>& block)
115+
bool BlockFilterIndex::CustomInit(const std::optional<interfaces::BlockRef>& block)
116116
{
117117
if (!m_db->Read(DB_FILTER_POS, m_next_filter_pos)) {
118118
// 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
316316
return true;
317317
}
318318

319-
bool BlockFilterIndex::CustomRewind(const interfaces::BlockKey& current_tip, const interfaces::BlockKey& new_tip)
319+
bool BlockFilterIndex::CustomRewind(const interfaces::BlockRef& current_tip, const interfaces::BlockRef& new_tip)
320320
{
321321
CDBBatch batch(*m_db);
322322
std::unique_ptr<CDBIterator> db_it(m_db->NewIterator());

src/index/blockfilterindex.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ class BlockFilterIndex final : public BaseIndex
5252
std::optional<uint256> ReadFilterHeader(int height, const uint256& expected_block_hash);
5353

5454
protected:
55-
bool CustomInit(const std::optional<interfaces::BlockKey>& block) override;
55+
bool CustomInit(const std::optional<interfaces::BlockRef>& block) override;
5656

5757
bool CustomCommit(CDBBatch& batch) override;
5858

5959
bool CustomAppend(const interfaces::BlockInfo& block) override;
6060

61-
bool CustomRewind(const interfaces::BlockKey& current_tip, const interfaces::BlockKey& new_tip) override;
61+
bool CustomRewind(const interfaces::BlockRef& current_tip, const interfaces::BlockRef& new_tip) override;
6262

6363
BaseIndex::DB& GetDB() const LIFETIMEBOUND override { return *m_db; }
6464

src/index/coinstatsindex.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ bool CoinStatsIndex::CustomAppend(const interfaces::BlockInfo& block)
265265
return true;
266266
}
267267

268-
bool CoinStatsIndex::CustomRewind(const interfaces::BlockKey& current_tip, const interfaces::BlockKey& new_tip)
268+
bool CoinStatsIndex::CustomRewind(const interfaces::BlockRef& current_tip, const interfaces::BlockRef& new_tip)
269269
{
270270
CDBBatch batch(*m_db);
271271
std::unique_ptr<CDBIterator> db_it(m_db->NewIterator());
@@ -304,7 +304,7 @@ bool CoinStatsIndex::CustomRewind(const interfaces::BlockKey& current_tip, const
304304
return true;
305305
}
306306

307-
static bool LookUpOne(const CDBWrapper& db, const interfaces::BlockKey& block, DBVal& result)
307+
static bool LookUpOne(const CDBWrapper& db, const interfaces::BlockRef& block, DBVal& result)
308308
{
309309
// First check if the result is stored under the height index and the value
310310
// 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_
350350
return stats;
351351
}
352352

353-
bool CoinStatsIndex::CustomInit(const std::optional<interfaces::BlockKey>& block)
353+
bool CoinStatsIndex::CustomInit(const std::optional<interfaces::BlockRef>& block)
354354
{
355355
if (!m_db->Read(DB_MUHASH, m_muhash)) {
356356
// Check that the cause of the read failure is that the key does not

src/index/coinstatsindex.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ class CoinStatsIndex final : public BaseIndex
4343
bool AllowPrune() const override { return true; }
4444

4545
protected:
46-
bool CustomInit(const std::optional<interfaces::BlockKey>& block) override;
46+
bool CustomInit(const std::optional<interfaces::BlockRef>& block) override;
4747

4848
bool CustomCommit(CDBBatch& batch) override;
4949

5050
bool CustomAppend(const interfaces::BlockInfo& block) override;
5151

52-
bool CustomRewind(const interfaces::BlockKey& current_tip, const interfaces::BlockKey& new_tip) override;
52+
bool CustomRewind(const interfaces::BlockRef& current_tip, const interfaces::BlockRef& new_tip) override;
5353

5454
BaseIndex::DB& GetDB() const override { return *m_db; }
5555

src/interfaces/chain.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,6 @@ namespace interfaces {
4141
class Handler;
4242
class Wallet;
4343

44-
//! Hash/height pair to help track and identify blocks.
45-
struct BlockKey {
46-
uint256 hash;
47-
int height = -1;
48-
};
49-
5044
//! Helper for findBlock to selectively return pieces of block data. If block is
5145
//! found, data will be returned by setting specified output variables. If block
5246
//! is not found, output variables will keep their previous values.

src/interfaces/types.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (c) 2024 The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#ifndef BITCOIN_INTERFACES_TYPES_H
6+
#define BITCOIN_INTERFACES_TYPES_H
7+
8+
#include <uint256.h>
9+
10+
namespace interfaces {
11+
12+
//! Hash/height pair to help track and identify blocks.
13+
struct BlockRef {
14+
uint256 hash;
15+
int height = -1;
16+
};
17+
18+
} // namespace interfaces
19+
20+
#endif // BITCOIN_INTERFACES_TYPES_H

0 commit comments

Comments
 (0)