diff --git a/src/interfaces/chain.h b/src/interfaces/chain.h --- a/src/interfaces/chain.h +++ b/src/interfaces/chain.h @@ -108,9 +108,6 @@ 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; @@ -161,6 +158,9 @@ //! included in the current chain. virtual Optional 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, diff --git a/src/interfaces/chain.cpp b/src/interfaces/chain.cpp --- a/src/interfaces/chain.cpp +++ b/src/interfaces/chain.cpp @@ -66,12 +66,6 @@ } class LockImpl : public Chain::Lock, public UniqueLock { - 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]; @@ -257,6 +251,12 @@ } 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); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -4313,7 +4313,7 @@ const Optional 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(); @@ -4375,9 +4375,8 @@ (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;