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

Open
wants to merge 6 commits into
from

Projects

None yet

6 participants

@luke-jr
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
@jonasschnelli
Member

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.

@gmaxwell
Member

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.

@paveljanik
Contributor

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

@luke-jr
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment