Wallet/RPC: sweepprivkeys method to scan UTXO set and send to local wallet #9152

Open
wants to merge 6 commits into
from

Conversation

Projects
None yet
8 participants
Member

luke-jr commented Nov 13, 2016

Does this look like a good approach?

TODO:

  • rawtransaction sweep functionality
  • GUI sweep (Receive tab?)
  • abstract shared sweep logic
  • RPC tests
Member

jonasschnelli commented Nov 14, 2016

Concept ACK (Haven't really looked at the code).
I think a sweep function would be a great feature. One could import "old" private keys into a new HD wallet for example.

Possible extension: sweepseed could be an extended version of that, moving all funds form a HD seed to a new one, generating large lookup-windows on different chainpathes. It could also be UTXO set only not requiring a -rescan.

Member

gmaxwell commented Nov 15, 2016

From a raw flow perspective, the generation of the sweep transaction is something that works from public information and should be possible on an online node without access to the private keys... so that one should be a 'createrawsweeptransaction' which takes a list of adresses/pubkeys/redeemscripts (and maybe private keys ... maybe some kind of BIP32 chain spec) and returns a transaction that spends all coins assigned to matching keys, potentially with arguments to limit the set of inputs collected.

Contributor

paveljanik commented Nov 17, 2016

Hmm, what about extending RPC importprivkey with another optional argument sweep defaulting to false?

Member

luke-jr commented Nov 17, 2016

sweepprivkeys is intended for users, and not to import keys. Users should never use importprivkey.

@ryanofsky ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Dec 9, 2016

@ryanofsky ryanofsky Make CCoinsViewCache::Cursor() return latest data
Change CCoinsViewCache::Cursor() method to return a cursor yielding the latest
CCoins entries, instead of just previous entries prior to the last cache flush.

The CCoinsViewCache::Cursor method is not currently used. This change just
enables new features that rely on scanning the UXTO set to work correctly (for
example bitcoin#9152, which adds a
sweepprivkeys RPC, and bitcoin#9137, which
improves handling of imported keys for nodes with pruning enabled.)
6494980

@ryanofsky ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Dec 15, 2016

@ryanofsky ryanofsky Make CCoinsViewCache::Cursor() return latest data
Change CCoinsViewCache::Cursor() method to return a cursor yielding the latest
CCoins entries, instead of just previous entries prior to the last cache flush.

The CCoinsViewCache::Cursor method is not currently used. This change just
enables new features that rely on scanning the UXTO set to work correctly (for
example bitcoin#9152, which adds a
sweepprivkeys RPC, and bitcoin#9137, which
improves handling of imported keys for nodes with pruning enabled.)
59a77a6

@ryanofsky ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Dec 19, 2016

@ryanofsky ryanofsky coins-cursor
Make CCoinsViewCache::Cursor() return latest data

Change CCoinsViewCache::Cursor() method to return a cursor yielding the latest
CCoins entries, instead of just previous entries prior to the last cache flush.

The CCoinsViewCache::Cursor method is not currently used. This change just
enables new features that rely on scanning the UXTO set to work correctly (for
example bitcoin#9152, which adds a
sweepprivkeys RPC, and bitcoin#9137, which
improves handling of imported keys for nodes with pruning enabled.)
ef97df2

@luke-jr luke-jr added a commit to bitcoinknots/bitcoin that referenced this pull request Dec 21, 2016

@luke-jr luke-jr CCoinsView::FindScriptPubKey to search the UTXO set
Github-Pull: #9152
Rebased-From: 220750d
155e1cf

@luke-jr luke-jr added a commit to bitcoinknots/bitcoin that referenced this pull request Dec 21, 2016

@luke-jr luke-jr Wallet/RPC: Abstract common WIF privkey parsing into ParseWIFPrivKey …
…function

Github-Pull: #9152
Rebased-From: 4437a5f
f73bc4f

@luke-jr luke-jr added a commit to bitcoinknots/bitcoin that referenced this pull request Dec 21, 2016

@luke-jr luke-jr Wallet/RPC: sweepprivkeys method to scan UTXO set and send to local w…
…allet

Github-Pull: #9152
Rebased-From: fdc6778
29caf46
@ryanofsky

Re: "Refactor sweepprivkeys to deal with CCoinsView::Cursor limitations," I think I could extend #9306 to return a working cursor for CCoinsViewMemPool, if that would help.

+ LOCK(cs_main);
+ mempool.FindScriptPubKey(setscriptSearch, mapcoins);
+ FlushStateToDisk();
+ pcoinsTip->FindScriptPubKey(setscriptSearch, mapcoins);
@ryanofsky

ryanofsky Dec 28, 2016 edited

Contributor

It might be appropriate to loop over mapCoins calling CTxMemPool::pruneSpent, on each entry, to avoid trying to sweep from an output that is already in the process of being spent.

@luke-jr luke-jr added a commit to bitcoinknots/bitcoin that referenced this pull request Dec 31, 2016

@luke-jr luke-jr Document limitations of CCoinsView::Cursor implementations
Github-Pull: #9152
Rebased-From: dd089ad
2d594e7

@luke-jr luke-jr added a commit to bitcoinknots/bitcoin that referenced this pull request Dec 31, 2016

@luke-jr luke-jr Refactor sweepprivkeys to deal with CCoinsView::Cursor limitations
Github-Pull: #9152
Rebased-From: ed60474
f3f5c79

@ryanofsky ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Jan 2, 2017

@ryanofsky ryanofsky coins-cursor
Make CCoinsViewCache::Cursor() return latest data

Change CCoinsViewCache::Cursor() method to return a cursor yielding the latest
CCoins entries, instead of just previous entries prior to the last cache flush.

The CCoinsViewCache::Cursor method is not currently used. This change just
enables new features that rely on scanning the UXTO set to work correctly (for
example bitcoin#9152, which adds a
sweepprivkeys RPC, and bitcoin#9137, which
improves handling of imported keys for nodes with pruning enabled.)
96a1834

@ryanofsky ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Jan 2, 2017

@ryanofsky ryanofsky coins-cursor
Make CCoinsViewCache::Cursor() return latest data

Change CCoinsViewCache::Cursor() method to return a cursor yielding the latest
CCoins entries, instead of just previous entries prior to the last cache flush.

The CCoinsViewCache::Cursor method is not currently used. This change just
enables new features that rely on scanning the UXTO set to work correctly (for
example bitcoin#9152, which adds a
sweepprivkeys RPC, and bitcoin#9137, which
improves handling of imported keys for nodes with pruning enabled.)
2ca75bc
Owner

laanwj commented Feb 27, 2017

Concept ACK.

Hmm, what about extending RPC importprivkey with another optional argument sweep defaulting to false?

Please don't do this. People confuse import and sweep all over the place. The least we can do is make them separate RPCs with separate documentation.

laanwj added this to the 0.15.0 milestone Feb 27, 2017

@ryanofsky ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Jun 2, 2017

@ryanofsky ryanofsky Make CCoinsViewCache::Cursor() return latest data
Change CCoinsViewCache::Cursor() method to return a cursor yielding the latest
CCoins entries, instead of just previous entries prior to the last cache flush.

The CCoinsViewCache::Cursor method is not currently used. This change just
enables new features that rely on scanning the UXTO set to work correctly (for
example bitcoin#9152, which adds a
sweepprivkeys RPC, and bitcoin#9137, which
improves handling of imported keys for nodes with pruning enabled.)
d58b56d

@ryanofsky ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Jun 12, 2017

@ryanofsky ryanofsky Make CCoinsViewCache::Cursor() return latest data
Change CCoinsViewCache::Cursor() method to return a cursor yielding the latest
CCoins entries, instead of just previous entries prior to the last cache flush.

The CCoinsViewCache::Cursor method is not currently used. This change just
enables new features that rely on scanning the UXTO set to work correctly (for
example bitcoin#9152, which adds a
sweepprivkeys RPC, and bitcoin#9137, which
improves handling of imported keys for nodes with pruning enabled.)
095c2e7
Owner

sipa commented Jul 12, 2017

Seems this won't be making it for 0.15. Untagging.

sipa removed this from the 0.15.0 milestone Jul 12, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment