aboutsummaryrefslogtreecommitdiff
path: root/src/node/interfaces.cpp
diff options
context:
space:
mode:
authorRussell Yanofsky <russ@yanofsky.org>2020-06-09 18:03:26 -0400
committerRussell Yanofsky <russ@yanofsky.org>2020-12-07 09:09:53 -0400
commit3fbbb9a6403a86fbed3d5d9f7939998922593377 (patch)
treeef269d8c7a027c862b716bfec498c75a1f24cbc8 /src/node/interfaces.cpp
parent5c4911e7e7523fb7643da209254bbc2ef7898d2e (diff)
downloadbitcoin-3fbbb9a6403a86fbed3d5d9f7939998922593377.tar.xz
refactor: Get rid of more redundant chain methods
This just drops three interfaces::Chain methods replacing them with other calls. Motivation for removing these chain methods: - Need to get rid of findFirstBlockWithTimeAndHeight for #10102, which doesn't support overloaded methods - Followup from https://github.com/bitcoin/bitcoin/pull/16426#discussion_r412487403 - phantomcircuit comments about findNextBlock test http://www.erisian.com.au/bitcoin-core-dev/log-2020-06-06.html#l-214 Behavior is not changing in any way here. A TODO comment in ScanForWalletTransactions was removed, but just because it was invalid (see https://github.com/bitcoin/bitcoin/pull/19195#discussion_r448020762), not because it was implemented.
Diffstat (limited to 'src/node/interfaces.cpp')
-rw-r--r--src/node/interfaces.cpp28
1 files changed, 2 insertions, 26 deletions
diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp
index da3e759e38..b08fa39786 100644
--- a/src/node/interfaces.cpp
+++ b/src/node/interfaces.cpp
@@ -311,6 +311,8 @@ bool FillBlock(const CBlockIndex* index, const FoundBlock& block, UniqueLock<Rec
if (block.m_time) *block.m_time = index->GetBlockTime();
if (block.m_max_time) *block.m_max_time = index->GetBlockTimeMax();
if (block.m_mtp_time) *block.m_mtp_time = index->GetMedianTimePast();
+ if (block.m_in_active_chain) *block.m_in_active_chain = ChainActive()[index->nHeight] == index;
+ if (block.m_next_block) FillBlock(ChainActive()[index->nHeight] == index ? ChainActive()[index->nHeight + 1] : nullptr, *block.m_next_block, lock);
if (block.m_data) {
REVERSE_LOCK(lock);
if (!ReadBlockFromDisk(*block.m_data, index, Params().GetConsensus())) block.m_data->SetNull();
@@ -419,15 +421,6 @@ public:
}
return nullopt;
}
- Optional<int> getBlockHeight(const uint256& hash) override
- {
- LOCK(::cs_main);
- CBlockIndex* block = LookupBlockIndex(hash);
- if (block && ::ChainActive().Contains(block)) {
- return block->nHeight;
- }
- return nullopt;
- }
uint256 getBlockHash(int height) override
{
LOCK(::cs_main);
@@ -441,16 +434,6 @@ public:
CBlockIndex* block = ::ChainActive()[height];
return block && ((block->nStatus & BLOCK_HAVE_DATA) != 0) && block->nTx > 0;
}
- Optional<int> findFirstBlockWithTimeAndHeight(int64_t time, int height, uint256* hash) override
- {
- LOCK(cs_main);
- CBlockIndex* block = ::ChainActive().FindEarliestAtLeast(time, height);
- if (block) {
- if (hash) *hash = block->GetBlockHash();
- return block->nHeight;
- }
- return nullopt;
- }
CBlockLocator getTipLocator() override
{
LOCK(cs_main);
@@ -479,13 +462,6 @@ public:
WAIT_LOCK(cs_main, lock);
return FillBlock(ChainActive().FindEarliestAtLeast(min_time, min_height), block, lock);
}
- bool findNextBlock(const uint256& block_hash, int block_height, const FoundBlock& next, bool* reorg) override {
- WAIT_LOCK(cs_main, lock);
- CBlockIndex* block = ChainActive()[block_height];
- if (block && block->GetBlockHash() != block_hash) block = nullptr;
- if (reorg) *reorg = !block;
- return FillBlock(block ? ChainActive()[block_height + 1] : nullptr, next, lock);
- }
bool findAncestorByHeight(const uint256& block_hash, int ancestor_height, const FoundBlock& ancestor_out) override
{
WAIT_LOCK(cs_main, lock);