Skip to content

Commit 0a76287

Browse files
author
Antoine Riard
committed
[wallet] Move getBlockHash from Chain::Lock interface to simple Chain
1 parent de13363 commit 0a76287

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

src/interfaces/chain.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,6 @@ bool FillBlock(const CBlockIndex* index, const FoundBlock& block, UniqueLock<Rec
5555

5656
class LockImpl : public Chain::Lock, public UniqueLock<RecursiveMutex>
5757
{
58-
uint256 getBlockHash(int height) override
59-
{
60-
LockAssertion lock(::cs_main);
61-
CBlockIndex* block = ::ChainActive()[height];
62-
assert(block != nullptr);
63-
return block->GetBlockHash();
64-
}
6558
bool haveBlockOnDisk(int height) override
6659
{
6760
LockAssertion lock(::cs_main);
@@ -234,6 +227,13 @@ class ChainImpl : public Chain
234227
}
235228
return nullopt;
236229
}
230+
uint256 getBlockHash(int height) override
231+
{
232+
LOCK(::cs_main);
233+
CBlockIndex* block = ::ChainActive()[height];
234+
assert(block);
235+
return block->GetBlockHash();
236+
}
237237
bool findBlock(const uint256& hash, const FoundBlock& block) override
238238
{
239239
WAIT_LOCK(cs_main, lock);

src/interfaces/chain.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,6 @@ class Chain
8787
public:
8888
virtual ~Lock() {}
8989

90-
//! Get block hash. Height must be valid or this function will abort.
91-
virtual uint256 getBlockHash(int height) = 0;
92-
9390
//! Check that the block is available on disk (i.e. has not been
9491
//! pruned), and contains transactions.
9592
virtual bool haveBlockOnDisk(int height) = 0;
@@ -135,6 +132,9 @@ class Chain
135132
//! included in the current chain.
136133
virtual Optional<int> getBlockHeight(const uint256& hash) = 0;
137134

135+
//! Get block hash. Height must be valid or this function will abort.
136+
virtual uint256 getBlockHash(int height) = 0;
137+
138138
//! Return whether node has the block and optionally return block metadata
139139
//! or contents.
140140
virtual bool findBlock(const uint256& hash, const FoundBlock& block={}) = 0;

src/wallet/wallet.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3943,7 +3943,7 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
39433943

39443944
const Optional<int> tip_height = chain.getHeight();
39453945
if (tip_height) {
3946-
walletInstance->m_last_block_processed = locked_chain->getBlockHash(*tip_height);
3946+
walletInstance->m_last_block_processed = chain.getBlockHash(*tip_height);
39473947
walletInstance->m_last_block_processed_height = *tip_height;
39483948
} else {
39493949
walletInstance->m_last_block_processed.SetNull();
@@ -3989,7 +3989,7 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
39893989

39903990
{
39913991
WalletRescanReserver reserver(*walletInstance);
3992-
if (!reserver.reserve() || (ScanResult::SUCCESS != walletInstance->ScanForWalletTransactions(locked_chain->getBlockHash(rescan_height), rescan_height, {} /* max height */, reserver, true /* update */).status)) {
3992+
if (!reserver.reserve() || (ScanResult::SUCCESS != walletInstance->ScanForWalletTransactions(chain.getBlockHash(rescan_height), rescan_height, {} /* max height */, reserver, true /* update */).status)) {
39933993
error = _("Failed to rescan the wallet during initialization").translated;
39943994
return nullptr;
39953995
}

0 commit comments

Comments
 (0)