Skip to content

Conversation

promag
Copy link
Contributor

@promag promag commented May 12, 2020

Mempool transactions are ignored on import* RPC. This results in unexpected results if the mempool contains transactions relevant for the imported material.

Fixes #18954.

@promag
Copy link
Contributor Author

promag commented May 12, 2020

Q1 - should this be optional? 🤔
Q2 - should include all import calls here? (draft because of this)

@ryanofsky FYI currently using requestMempoolTransactions.

Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK.

From reading the code, the first commit can never pass tests? Maybe squash?

}
}
// Scan mempool for transactions
pwallet->chain().requestMempoolTransactions(*pwallet);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this done even when rescan is turned off? I think this should only be run when rescan is on.

If the user turns off rescan, they know that

  • either no transaction has happened in the past, so rescan is not needed
  • or they do a full rescan later

This also means that this should be added to the rescan RPC.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also means that this should be added to the rescan RPC.

Might be the best approach, it would cover any import that rescans and also manual rescan. So in practice ScanForWalletTransactions where stop_block.IsNull would scan mempool too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So in practice ScanForWalletTransactions where stop_block.IsNull would scan mempool too?

@MarcoFalke is this your suggestion?

@promag
Copy link
Contributor Author

promag commented May 13, 2020

Concept ACK.

From reading the code, the first commit can never pass tests?

Why?

@maflcko
Copy link
Member

maflcko commented May 13, 2020

I assumed that the check after importprivkey might fail because of the missing rescan, but that might not be the case, as the wallet already knows the tx is in the mempool.

@promag
Copy link
Contributor Author

promag commented May 13, 2020

I assumed that the check after importprivkey might fail because of the missing rescan, but that might not be the case, as the wallet already knows the tx is in the mempool.

Correct, that's why the 2nd commit tests importprivkey with a fresh wallet.

@ryanofsky
Copy link
Contributor

This looks very good, and should be extended to work with other import rpcs (also maybe in the future sethdseed, found I needed a rescan recently there too).

I would probably not make this conditioned on the rescan option, just because as a user I can't think of any real world case where I'd want to import a key and not have the wallet detect mempool transactions using that key. This is different from the very real rescan=false use-case, which is to avoid rescanning blocks because rescanning blocks is ridiculously slow. If in the future someone thinks of a use-case for importing keys without scanning the mempool, we could always extend the rescan option

@maflcko
Copy link
Member

maflcko commented May 13, 2020

because rescanning blocks is ridiculously slow

The mempool can have 100s of MBs of transactions. I haven't crunched the numbers, but we should make sure that import RPCs don't get slow either.

@promag
Copy link
Contributor Author

promag commented May 13, 2020

Right, and it would be even worse with big wallets.

@maflcko maflcko added this to the 0.21.0 milestone May 13, 2020
@maflcko
Copy link
Member

maflcko commented May 14, 2020

Suggested doc fixup:

diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp
index 7bf3d169c3..4d1ba7ebf5 100644
--- a/src/wallet/rpcdump.cpp
+++ b/src/wallet/rpcdump.cpp
@@ -103,11 +103,13 @@ UniValue importprivkey(const JSONRPCRequest& request)
                 "Hint: use importmulti to import more than one private key.\n"
             "\nNote: This call can take over an hour to complete if rescan is true, during that time, other rpc calls\n"
             "may report that the imported key exists but related transactions are still missing, leading to temporarily incorrect/bogus balances and unspent outputs until rescan completes.\n"
+            "The rescan parameter can be set to false if the key was never used to create transactions. If it is set to false,\n"
+            "but the key was used to create transactions, rescanwallet needs to be called with the appropriate block range.\n"
             "Note: Use \"getwalletinfo\" to query the scanning progress.\n",
                 {
                     {"privkey", RPCArg::Type::STR, RPCArg::Optional::NO, "The private key (see dumpprivkey)"},
                     {"label", RPCArg::Type::STR, /* default */ "current label if address exists, otherwise \"\"", "An optional label"},
-                    {"rescan", RPCArg::Type::BOOL, /* default */ "true", "Rescan the wallet for transactions"},
+                    {"rescan", RPCArg::Type::BOOL, /* default */ "true", "Scan the chain and mempool for wallet transactions."},
                 },
                 RPCResult{RPCResult::Type::NONE, "", ""},
                 RPCExamples{

@fjahr
Copy link
Contributor

fjahr commented May 25, 2020

Concept ACK

I don't have a good feeling for the performance of a large mempool rescan but I do believe it will have a considerable impact for nodes with large, full mempools. So I agree it should be added to the rescan RPC and it should not be run for the import* RPCs in case of rescan=false.

@laanwj laanwj modified the milestones: 0.21.0, 0.22.0 Oct 8, 2020
@laanwj laanwj removed this from the 22.0 milestone Jun 10, 2021
@DrahtBot
Copy link
Contributor

🐙 This pull request conflicts with the target branch and needs rebase.

Want to unsubscribe from rebase notifications on this pull request? Just convert this pull request to a "draft".

@DrahtBot
Copy link
Contributor

There hasn't been much activity lately and the patch still needs rebase. What is the status here?
  • Is it still relevant? ➡️ Please solve the conflicts to make it ready for review and to ensure the CI passes.
  • Is it no longer relevant? ➡️ Please close.
  • Did the author lose interest or time to work on this? ➡️ Please close it and mark it 'Up for grabs' with the label, so that it can be picked up in the future.

@fanquake
Copy link
Member

@fjahr or @ryanofsky you might be interested in picking this up?

@fanquake fanquake closed this Apr 26, 2022
@fjahr
Copy link
Contributor

fjahr commented May 1, 2022

@fjahr or @ryanofsky you might be interested in picking this up?

I am working on this now, Up for grabs label can be removed

achow101 added a commit that referenced this pull request Jul 18, 2022
1be7964 test, wallet: Add mempool rescan test for import RPCs (Fabian Jahr)
833ce76 rpc, wallet: Document mempool rescan after importdescriptor, importwallet (Fabian Jahr)
0e396d1 rpc, wallet: Document mempool scan after importmulti (Fabian Jahr)
e6d3ef8 rpc, wallet: Document mempool scan after importpubkey (Fabian Jahr)
6d3db52 rpc, wallet: Document and test mempool scan after importprivkey (João Barbosa)
3abdbbb rpc, wallet: Document and test mempool scan after importaddress (João Barbosa)
236239b wallet: Rescan mempool for transactions as well (Fabian Jahr)

Pull request description:

  This PR picks up the work from #18964 and closes #18954.

  It should incorporate all the unaddressed feedback from the PR:
  - Mempool rescan now expanded to all relevant import* RPCs
  - Added documentation in the help of each RPC
  - More tests

ACKs for top commit:
  Sjors:
    re-utACK 1be7964 (only a test change)
  achow101:
    ACK 1be7964
  w0xlt:
    reACK 1be7964

Tree-SHA512: b62fed5f97c6c242b2af417b41c9696a1f18878483d9e1c9429791f9c05257f57a00540a9a84df23c49faf6a61c3109c22972de81540083f38b506217804fcc5
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jul 18, 2022
… attempt

1be7964 test, wallet: Add mempool rescan test for import RPCs (Fabian Jahr)
833ce76 rpc, wallet: Document mempool rescan after importdescriptor, importwallet (Fabian Jahr)
0e396d1 rpc, wallet: Document mempool scan after importmulti (Fabian Jahr)
e6d3ef8 rpc, wallet: Document mempool scan after importpubkey (Fabian Jahr)
6d3db52 rpc, wallet: Document and test mempool scan after importprivkey (João Barbosa)
3abdbbb rpc, wallet: Document and test mempool scan after importaddress (João Barbosa)
236239b wallet: Rescan mempool for transactions as well (Fabian Jahr)

Pull request description:

  This PR picks up the work from bitcoin#18964 and closes bitcoin#18954.

  It should incorporate all the unaddressed feedback from the PR:
  - Mempool rescan now expanded to all relevant import* RPCs
  - Added documentation in the help of each RPC
  - More tests

ACKs for top commit:
  Sjors:
    re-utACK 1be7964 (only a test change)
  achow101:
    ACK 1be7964
  w0xlt:
    reACK bitcoin@1be7964

Tree-SHA512: b62fed5f97c6c242b2af417b41c9696a1f18878483d9e1c9429791f9c05257f57a00540a9a84df23c49faf6a61c3109c22972de81540083f38b506217804fcc5
@bitcoin bitcoin locked and limited conversation to collaborators May 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

import* wallet RPCs don't "rescan" the mempool

7 participants