From 0a76287387950bc9c5b634e95c5cd5fb1029f42d Mon Sep 17 00:00:00 2001 From: Antoine Riard Date: Tue, 16 Jul 2019 15:20:01 -0400 Subject: [PATCH] [wallet] Move getBlockHash from Chain::Lock interface to simple Chain --- src/interfaces/chain.cpp | 14 +++++++------- src/interfaces/chain.h | 6 +++--- src/wallet/wallet.cpp | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/interfaces/chain.cpp b/src/interfaces/chain.cpp index ccdbf1f1d..a4702558d 100644 --- a/src/interfaces/chain.cpp +++ b/src/interfaces/chain.cpp @@ -55,13 +55,6 @@ bool FillBlock(const CBlockIndex* index, const FoundBlock& block, UniqueLock { - uint256 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); @@ -234,6 +227,13 @@ public: } return nullopt; } + uint256 getBlockHash(int height) override + { + LOCK(::cs_main); + CBlockIndex* block = ::ChainActive()[height]; + assert(block); + return block->GetBlockHash(); + } bool findBlock(const uint256& hash, const FoundBlock& block) override { WAIT_LOCK(cs_main, lock); diff --git a/src/interfaces/chain.h b/src/interfaces/chain.h index b85484c11..c82ade889 100644 --- a/src/interfaces/chain.h +++ b/src/interfaces/chain.h @@ -87,9 +87,6 @@ public: public: virtual ~Lock() {} - //! Get block hash. Height must be valid or this function will abort. - virtual uint256 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; @@ -135,6 +132,9 @@ public: //! included in the current chain. virtual Optional getBlockHeight(const uint256& hash) = 0; + //! Get block hash. Height must be valid or this function will abort. + virtual uint256 getBlockHash(int height) = 0; + //! Return whether node has the block and optionally return block metadata //! or contents. virtual bool findBlock(const uint256& hash, const FoundBlock& block={}) = 0; diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index b7117e2e5..859a52f3e 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3943,7 +3943,7 @@ std::shared_ptr CWallet::CreateWalletFromFile(interfaces::Chain& chain, const Optional tip_height = chain.getHeight(); if (tip_height) { - walletInstance->m_last_block_processed = locked_chain->getBlockHash(*tip_height); + walletInstance->m_last_block_processed = chain.getBlockHash(*tip_height); walletInstance->m_last_block_processed_height = *tip_height; } else { walletInstance->m_last_block_processed.SetNull(); @@ -3989,7 +3989,7 @@ std::shared_ptr CWallet::CreateWalletFromFile(interfaces::Chain& chain, { WalletRescanReserver reserver(*walletInstance); - if (!reserver.reserve() || (ScanResult::SUCCESS != walletInstance->ScanForWalletTransactions(locked_chain->getBlockHash(rescan_height), rescan_height, {} /* max height */, reserver, true /* update */).status)) { + if (!reserver.reserve() || (ScanResult::SUCCESS != walletInstance->ScanForWalletTransactions(chain.getBlockHash(rescan_height), rescan_height, {} /* max height */, reserver, true /* update */).status)) { error = _("Failed to rescan the wallet during initialization").translated; return nullptr; }