mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 06:58:57 +01:00
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.
This commit is contained in:
@@ -87,13 +87,6 @@ class LockImpl : public Chain::Lock, public UniqueLock<RecursiveMutex>
|
|||||||
assert(block != nullptr);
|
assert(block != nullptr);
|
||||||
return block->GetBlockTime();
|
return block->GetBlockTime();
|
||||||
}
|
}
|
||||||
int64_t getBlockMedianTimePast(int height) override
|
|
||||||
{
|
|
||||||
LockAssertion lock(::cs_main);
|
|
||||||
CBlockIndex* block = ::ChainActive()[height];
|
|
||||||
assert(block != nullptr);
|
|
||||||
return block->GetMedianTimePast();
|
|
||||||
}
|
|
||||||
bool haveBlockOnDisk(int height) override
|
bool haveBlockOnDisk(int height) override
|
||||||
{
|
{
|
||||||
LockAssertion lock(::cs_main);
|
LockAssertion lock(::cs_main);
|
||||||
|
|||||||
@@ -103,10 +103,6 @@ public:
|
|||||||
//! Get block time. Height must be valid or this function will abort.
|
//! Get block time. Height must be valid or this function will abort.
|
||||||
virtual int64_t getBlockTime(int height) = 0;
|
virtual int64_t getBlockTime(int height) = 0;
|
||||||
|
|
||||||
//! Get block median time past. Height must be valid or this function
|
|
||||||
//! will abort.
|
|
||||||
virtual int64_t getBlockMedianTimePast(int height) = 0;
|
|
||||||
|
|
||||||
//! Check that the block is available on disk (i.e. has not been
|
//! Check that the block is available on disk (i.e. has not been
|
||||||
//! pruned), and contains transactions.
|
//! pruned), and contains transactions.
|
||||||
virtual bool haveBlockOnDisk(int height) = 0;
|
virtual bool haveBlockOnDisk(int height) = 0;
|
||||||
|
|||||||
@@ -1379,20 +1379,13 @@ UniValue importmulti(const JSONRPCRequest& mainRequest)
|
|||||||
EnsureWalletIsUnlocked(pwallet);
|
EnsureWalletIsUnlocked(pwallet);
|
||||||
|
|
||||||
// Verify all timestamps are present before importing any keys.
|
// Verify all timestamps are present before importing any keys.
|
||||||
const Optional<int> tip_height = locked_chain->getHeight();
|
CHECK_NONFATAL(pwallet->chain().findBlock(pwallet->GetLastBlockHash(), FoundBlock().time(nLowestTimestamp).mtpTime(now)));
|
||||||
now = tip_height ? locked_chain->getBlockMedianTimePast(*tip_height) : 0;
|
|
||||||
for (const UniValue& data : requests.getValues()) {
|
for (const UniValue& data : requests.getValues()) {
|
||||||
GetImportTimestamp(data, now);
|
GetImportTimestamp(data, now);
|
||||||
}
|
}
|
||||||
|
|
||||||
const int64_t minimumTimestamp = 1;
|
const int64_t minimumTimestamp = 1;
|
||||||
|
|
||||||
if (fRescan && tip_height) {
|
|
||||||
nLowestTimestamp = locked_chain->getBlockTime(*tip_height);
|
|
||||||
} else {
|
|
||||||
fRescan = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const UniValue& data : requests.getValues()) {
|
for (const UniValue& data : requests.getValues()) {
|
||||||
const int64_t timestamp = std::max(GetImportTimestamp(data, now), minimumTimestamp);
|
const int64_t timestamp = std::max(GetImportTimestamp(data, now), minimumTimestamp);
|
||||||
const UniValue result = ProcessImport(pwallet, data, timestamp);
|
const UniValue result = ProcessImport(pwallet, data, timestamp);
|
||||||
|
|||||||
@@ -152,6 +152,7 @@ BOOST_FIXTURE_TEST_CASE(importmulti_rescan, TestChain100Setup)
|
|||||||
{
|
{
|
||||||
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
||||||
wallet->SetupLegacyScriptPubKeyMan();
|
wallet->SetupLegacyScriptPubKeyMan();
|
||||||
|
WITH_LOCK(wallet->cs_wallet, wallet->SetLastBlockProcessed(newTip->nHeight, newTip->GetBlockHash()));
|
||||||
AddWallet(wallet);
|
AddWallet(wallet);
|
||||||
UniValue keys;
|
UniValue keys;
|
||||||
keys.setArray();
|
keys.setArray();
|
||||||
|
|||||||
Reference in New Issue
Block a user