diff options
| author | Russell Yanofsky <[email protected]> | 2020-01-16 16:38:30 -0500 |
|---|---|---|
| committer | Russell Yanofsky <[email protected]> | 2020-03-31 08:36:02 -0500 |
| commit | c1694ce6bb7e19a8722d5583cd85ad17da40bb67 (patch) | |
| tree | 21e0b8bdd3d8cba56623e3f63696f31a9d6a6517 /src/wallet | |
| parent | wallet refactor: Avoid use of Chain::Lock in qt wallettests (diff) | |
| download | discoin-c1694ce6bb7e19a8722d5583cd85ad17da40bb67.tar.xz discoin-c1694ce6bb7e19a8722d5583cd85ad17da40bb67.zip | |
wallet: Avoid use of Chain::Lock in importprunedfunds
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 the "Block not found in chain" error
will be stricter and not allow importing data from a blocks between the wallet
last processed tip and the current node tip.
Diffstat (limited to 'src/wallet')
| -rw-r--r-- | src/wallet/rpcdump.cpp | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index e4d0a3fa6..1d6b4832e 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -28,6 +28,8 @@ +using interfaces::FoundBlock; + std::string static EncodeDumpString(const std::string &str) { std::stringstream ret; for (const unsigned char c : str) { @@ -359,8 +361,9 @@ UniValue importprunedfunds(const JSONRPCRequest& request) } auto locked_chain = pwallet->chain().lock(); - Optional<int> height = locked_chain->getBlockHeight(merkleBlock.header.GetHash()); - if (height == nullopt) { + LOCK(pwallet->cs_wallet); + int height; + if (!pwallet->chain().findAncestorByHash(pwallet->GetLastBlockHash(), merkleBlock.header.GetHash(), FoundBlock().height(height))) { throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found in chain"); } @@ -371,11 +374,9 @@ UniValue importprunedfunds(const JSONRPCRequest& request) unsigned int txnIndex = vIndex[it - vMatch.begin()]; - CWalletTx::Confirmation confirm(CWalletTx::Status::CONFIRMED, *height, merkleBlock.header.GetHash(), txnIndex); + CWalletTx::Confirmation confirm(CWalletTx::Status::CONFIRMED, height, merkleBlock.header.GetHash(), txnIndex); wtx.m_confirm = confirm; - LOCK(pwallet->cs_wallet); - if (pwallet->IsMine(*wtx.tx)) { pwallet->AddToWallet(wtx, false); return NullUniValue; |