Skip to content

Commit bc96a9b

Browse files
committed
wallet: Avoid use of Chain::Lock in importmulti
This is a step toward removing the Chain::Lock class and reducing cs_main locking. This change only affects behavior in the case where wallet last block processed falls behind the chain tip, in which case it may use a more accurate rescan time.
1 parent 25a9fcf commit bc96a9b

File tree

4 files changed

+2
-19
lines changed

4 files changed

+2
-19
lines changed

src/interfaces/chain.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,6 @@ class LockImpl : public Chain::Lock, public UniqueLock<RecursiveMutex>
8787
assert(block != nullptr);
8888
return block->GetBlockTime();
8989
}
90-
int64_t getBlockMedianTimePast(int height) override
91-
{
92-
LockAssertion lock(::cs_main);
93-
CBlockIndex* block = ::ChainActive()[height];
94-
assert(block != nullptr);
95-
return block->GetMedianTimePast();
96-
}
9790
bool haveBlockOnDisk(int height) override
9891
{
9992
LockAssertion lock(::cs_main);

src/interfaces/chain.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,6 @@ class Chain
103103
//! Get block time. Height must be valid or this function will abort.
104104
virtual int64_t getBlockTime(int height) = 0;
105105

106-
//! Get block median time past. Height must be valid or this function
107-
//! will abort.
108-
virtual int64_t getBlockMedianTimePast(int height) = 0;
109-
110106
//! Check that the block is available on disk (i.e. has not been
111107
//! pruned), and contains transactions.
112108
virtual bool haveBlockOnDisk(int height) = 0;

src/wallet/rpcdump.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,20 +1379,13 @@ UniValue importmulti(const JSONRPCRequest& mainRequest)
13791379
EnsureWalletIsUnlocked(pwallet);
13801380

13811381
// Verify all timestamps are present before importing any keys.
1382-
const Optional<int> tip_height = locked_chain->getHeight();
1383-
now = tip_height ? locked_chain->getBlockMedianTimePast(*tip_height) : 0;
1382+
CHECK_NONFATAL(pwallet->chain().findBlock(pwallet->GetLastBlockHash(), FoundBlock().time(nLowestTimestamp).mtpTime(now)));
13841383
for (const UniValue& data : requests.getValues()) {
13851384
GetImportTimestamp(data, now);
13861385
}
13871386

13881387
const int64_t minimumTimestamp = 1;
13891388

1390-
if (fRescan && tip_height) {
1391-
nLowestTimestamp = locked_chain->getBlockTime(*tip_height);
1392-
} else {
1393-
fRescan = false;
1394-
}
1395-
13961389
for (const UniValue& data : requests.getValues()) {
13971390
const int64_t timestamp = std::max(GetImportTimestamp(data, now), minimumTimestamp);
13981391
const UniValue result = ProcessImport(pwallet, data, timestamp);

src/wallet/test/wallet_tests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ BOOST_FIXTURE_TEST_CASE(importmulti_rescan, TestChain100Setup)
152152
{
153153
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
154154
wallet->SetupLegacyScriptPubKeyMan();
155+
WITH_LOCK(wallet->cs_wallet, wallet->SetLastBlockProcessed(newTip->nHeight, newTip->GetBlockHash()));
155156
AddWallet(wallet);
156157
UniValue keys;
157158
keys.setArray();

0 commit comments

Comments
 (0)