Skip to content

Commit

Permalink
[wallet] Move getBlockHash from Chain::Lock interface to simple Chain
Browse files Browse the repository at this point in the history
Summary:
Backport of Core [[bitcoin/bitcoin#16426 | PR16426]] part [3/5] : bitcoin/bitcoin@0a76287

Depends on D7935

Test Plan:
  ninja all check-all

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D7936
  • Loading branch information
Antoine Riard authored and deadalnix committed Oct 15, 2020
1 parent 87c5aec commit 890765d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
12 changes: 6 additions & 6 deletions src/interfaces/chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,6 @@ namespace {
}

class LockImpl : public Chain::Lock, public UniqueLock<RecursiveMutex> {
BlockHash getBlockHash(int height) override {
LockAssertion lock(::cs_main);
CBlockIndex *block = ::ChainActive()[height];
assert(block != nullptr);
return block->GetBlockHash();
}
bool haveBlockOnDisk(int height) override {
LockAssertion lock(::cs_main);
CBlockIndex *block = ::ChainActive()[height];
Expand Down Expand Up @@ -257,6 +251,12 @@ namespace {
}
return nullopt;
}
BlockHash getBlockHash(int height) override {
LOCK(::cs_main);
CBlockIndex *block = ::ChainActive()[height];
assert(block);
return block->GetBlockHash();
}
bool findBlock(const BlockHash &hash,
const FoundBlock &block) override {
WAIT_LOCK(cs_main, lock);
Expand Down
6 changes: 3 additions & 3 deletions src/interfaces/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,6 @@ class Chain {
public:
virtual ~Lock() {}

//! Get block hash. Height must be valid or this function will abort.
virtual BlockHash getBlockHash(int height) = 0;

//! Check that the block is available on disk (i.e. has not been
//! pruned), and contains transactions.
virtual bool haveBlockOnDisk(int height) = 0;
Expand Down Expand Up @@ -161,6 +158,9 @@ class Chain {
//! included in the current chain.
virtual Optional<int> getBlockHeight(const BlockHash &hash) = 0;

//! Get block hash. Height must be valid or this function will abort.
virtual BlockHash getBlockHash(int height) = 0;

//! Return whether node has the block and optionally return block metadata
//! or contents.
virtual bool findBlock(const BlockHash &hash,
Expand Down
7 changes: 3 additions & 4 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4313,7 +4313,7 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(
const Optional<int> tip_height = chain.getHeight();
if (tip_height) {
walletInstance->m_last_block_processed =
locked_chain->getBlockHash(*tip_height);
chain.getBlockHash(*tip_height);
walletInstance->m_last_block_processed_height = *tip_height;
} else {
walletInstance->m_last_block_processed.SetNull();
Expand Down Expand Up @@ -4375,9 +4375,8 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(
(ScanResult::SUCCESS !=
walletInstance
->ScanForWalletTransactions(
locked_chain->getBlockHash(rescan_height),
rescan_height, {} /* max height */, reserver,
true /* update */)
chain.getBlockHash(rescan_height), rescan_height,
{} /* max height */, reserver, true /* update */)
.status)) {
error = _("Failed to rescan the wallet during initialization");
return nullptr;
Expand Down

0 comments on commit 890765d

Please sign in to comment.