New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option to specify rescan starting timestamp to RPC import calls #6570
Add option to specify rescan starting timestamp to RPC import calls #6570
Conversation
034bfbe
to
ef112f5
Compare
I think this should check if the passed in height is too high, and throw an error if it is. |
I like the idea of not rescanning from genesis in case of a imported key. But i think it should take the creation-timestamp instead of a height as parameter. The height should be calculated out of the given creation time minus a buffer of maybe 288 blocks (or less). |
ef112f5
to
23017ec
Compare
@casey right, done. |
@jonasschnelli what about a mixed solution, if the param is greater than, for instance, 1231006505 (genesis timestamp) then use the param as a timestamp? |
@promag I would guess most users prefer keeping the date when they have created the key instead of the height. Mixes solution sounds to clever at user input level (might be useful on script level to avoid soft-forks). |
Just use importwallet RPC instead of importprivkey...
|
@sipa I think one good use case is to import watch-only addresses and only rescan from a certain point in time. |
Then we should add support for watch-only addresses to importwallet.
|
@sipa maybe I'm not following, but how does |
It supports a birth time for each key, and automatically determines from
where to rescan.
|
@sipa TIL, but |
I also don't think Supporting a creation date in |
@jonasschnelli Can you explain what you mean by "might be useful on script level to avoid soft-forks" in regard to the "mixed solution"? |
The reason I'm advocating importwallet is because I think it's unreasonable
to ask the user to need to decide when to rescan in case of multiple
addresses/keys(/hdchains?) being imported simultaneously. The efficiency is
ridiculous when you rescan for all, and otherwise you at least have
temporarily an inconsistent state where you have wallet keys which are not
scanned for, and need to remember to not rescan exactly once at the end.
Importwallet solves all of that.
I understand that needing a file on disk is not appropriate for all
purposes, but we could easily make a variant that takes the entire
serialized file through RPC.
|
@MarcoFalke: we have such threshold checks on script level (https://github.com/bitcoin/bitcoin/blob/master/src/script/interpreter.cpp#L1133) to allow reusing existing containers. |
@sipa I think that depends on your user. In any case, I think if the |
Precisely what @dcousens said. Importing a single or even multiple addresses from another environment where we know the timestamp to start rescanning is an ideal use case for this change. |
23017ec
to
d2222ee
Compare
Agree with @dcousens and @ruimarinho. |
d2222ee
to
a80b832
Compare
int nTime = params[3].get_int(); | ||
pindex = chainActive.FindLatestBefore(nTime); | ||
if (!pindex) | ||
throw JSONRPCError(RPC_INVALID_PARAMETER, "No block before timestamp"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the current implementation of FindLatestBefore()
this is dead code and can never be thrown?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's also a useless error - the user doesn't care if there was a block before their timestamp... just rescan the entire chain in that case.
Agree @sipa regarding ridiculous inefficiency of doing a rescan for each key, and temporary inconsistent state. I also don't like adding more positional arguments to import*. Getting positional arguments right is a scourge to users. What about an RPC call that acceps an array of {privkey, birthdate, ...} objects? By using an object it could be extendible in case more key metadata is desired. The same code as |
@laanwj, I think |
So everyone agree on a generic import call with an array of multiple objects? |
@dcousens If an external service wants to creates an address then it has to make a call to know the current block count. It is easier to save the creation timestamp along with the address. |
I'd say they are equivalent, as ISO 8601 is interchangeable with unix timestamp. Both could be supported. |
@ruimarinho sure, however I don't think |
Lets say I receive a transaction: Based on this, externally, I generate an address/key pair I'm not against that, a solution is a solution, but, its a bit lame IMHO. edit: reworded |
Just to be clear, I'm fine with |
How do you figure that? Maybe I should, but, from the data I currently have, that isn't the case. |
Off topic, but I was assuming you use blocknotify script, then get the block and txs. |
Looks good to me! |
@laanwj and |
I'm very bad at bikeshedding names, but I'd say |
I'd call it |
Simple: if you want to pass it one, just pass an array of one. You could even pass it an empty array. |
Are you open to a polymorphic method where a JSON object is converted internally to JSON collection of a single item? Not that important, but at least it'd be a little bit more flexible for devs.
|
@promag Any updates on this? |
Hm. Concept wise, I am really unhappy that right now pruning completely disables rescan. This means you can't use pruning with many common use cases. For example, pruning more than a month old + merchant wallet that watchadds right around the time it gives out a key-- without the ability to do a limited rescan you have to get everything exactly right or risk missing a payment. One thought I had on this (before realizing there was already a pull) was simply making it so the existing positional rescan argument can alternatively take a rescan depth. This would avoid adding more arguments. A thing to keep in mind is that a depth is not like a birthday, and I don't think the importwallet arguments apply as strongly. |
@MarcoFalke been busy, but I'll resume soon. |
@promag: will you be adding tests for this feature? |
@nunofgs sure thing mate 😄 |
A lot of redundant code in the import* RPCs - maybe it can be abstracted better? Also, it would be ideal (but not necessary in this PR I suppose) to support rescanning in pruned mode when possible... |
(and Concept ACK for importmulti) |
needs rebase |
Deprecated by #7551. |
No description provided.