Commit graph

1217 commits

Author SHA1 Message Date
Andrew Poelstra
569c68a0f2 Merge f8102d9088 into merged_master (Bitcoin PR #18601) 2020-11-26 01:08:25 +00:00
Andrew Poelstra
b7307be8cd Merge b470c75847 into merged_master (Bitcoin PR #15761) 2020-11-26 01:08:25 +00:00
Andrew Poelstra
9192999921 Merge bbb1ba1814 into merged_master (Bitcoin PR #17219)
This modifies the CreateTransaction loop in a way not remotely worth the complexity,
and includes an absurdly fragile test where I had to add a bunch of trace statements
and tweak pretty-much every single hardcoded number. Not to name names, but it was
Sjors. (In fairness, the PR is a pure simplification of the CreateTransaction logic,
and it wasn't hard to merge even. It was just the test that caused my grief.)

Adapting the "use a dummy CTxDestination in the case that we cannot retrieve one from
the wallet" logic to our `mapScriptChange` map was not trivial. On my first attempt I
incorrectly assigned a positive vout index to the dummy script, which caused us to
call `ReturnDestination` later on the (unused) dummy destination. This is harmless now,
but when descriptor wallets are introduced in #16528, they introduce an edge case where
returning a null destination can incorrectly mark the 0th key of a BIP32 range as
unused. This triggered a test failure much later, in #19504, which uses descriptor
wallets in fundrawtransaction. The bug was that we'd import a descriptor, mark the
first key as being used, lock the wallet, call `fundrawtransaction` on a transaction
that did not require change (incorrectly marking the first key as unused but leaving
it in the descriptor ScriptPubKeyMan's cache), then call `fundrawtransaction` again
on a transaction that *did* require change. The wallet would then incorrectly retrieve
the "unused" key from cache and use it for change, rather than correctly failing and
advising the user that it could not produce change with a locked wallet and empty
keypool. This was not a fun bug to track down.

Another interesting observation is that branch-and-bound uses the CT size-overestimate
for change when trying to create changeless outputs, while our normal dust detection
uses Core's unchanged "an output is 133 bytes" logic. So when BnB is used we're willing
to delete a far bigger change output than we are when we don't use BnB.

Lest you think this works in Core, they're also inconsistent because BnB uses a
normal fee estimate for gauging change cost, while non-BnB uses the discardfee rate.

My advice is to hold your nose, pull stuff in from Core as it comes in, and thanks
to Andy's efforts things are getting better. Don't bother reviewing this too closely.
2020-12-03 00:58:01 +00:00
Andrew Poelstra
7acaa0481b Merge c189bfd260 into merged_master (Bitcoin PR #17824) 2020-11-26 01:08:22 +00:00
Andrew Poelstra
23cab4213a Merge 4702cadca9 into merged_master (Bitcoin PR #17954) 2020-11-26 01:08:19 +00:00
Andrew Poelstra
0a87d878fa Merge 63dad67348 into merged_master (Bitcoin PR #18546) 2020-11-26 01:08:12 +00:00
Andrew Poelstra
879cfb6ad8 Merge c5966a87d1 into merged_master (Bitcoin PR #18192) 2020-11-26 01:08:11 +00:00
Andrew Poelstra
44f30e687f Merge 6bdd515ccf into merged_master (Bitcoin PR #16923) 2020-11-26 01:08:08 +00:00
Andrew Poelstra
6fae461783 Merge 9a2b5f22c1 into merged_master (Bitcoin PR #18338) 2020-11-26 01:08:06 +00:00
Andrew Poelstra
55e75466a4 Merge b47d087356 into merged_master (Elements PR #843)
Fixes the change-size estimation bug that I fixed in #17290, though incompletely
(Steven made up a size for the surjection proof which was different from the
size that I made up....this time I actually checked with libsecp to get an upper
bound.) He also found another place we were doing the wrong estimation, which
I had missed on my pass. So between the two of us I think we've done some good.

Also moves some which sets code coin_selection_params.tx_noinputs_size to after
some Elements sanity checks, which I think will have zero observable effect
(or non-observable effect) but it's part of the PR so I'm keeping it. Though
updated since we can now use BnB even with subtract-fee-from-output.
2020-11-26 01:08:05 +00:00
Andrew Poelstra
90c7d5774a Merge ac579ada7e into merged_master (Bitcoin PR #18278) 2020-11-26 01:08:00 +00:00
Andrew Poelstra
cf93edb0be Merge 312d27b11c into merged_master (Bitcoin PR #17477) 2020-11-26 01:07:59 +00:00
Andrew Poelstra
5b9f316537 Merge dcf2ccbfde into merged_master (Bitcoin PR #18115)
I really like this PR, but it wound up being pretty nontrivial to merge.
The crux is that it pulls PSBT signing logic into scriptpubkey manager,
which is where it belongs, but for us this means reasoning about pegins
inside script/sign.cpp.

However, sign.cpp is part of libbitcoin_common, which does not include
anything for reasoning about PoW or RPC (lol) or anything heavy about
that. This means that some pegin validation had to remain split between
the wallet/rpc layer and sign.cpp. I added a new file script/pegins.cpp
which has the (one) method we actually need in sign.cpp.

Aside from that, this diff is very large but is mostly just moving our
code changes to wallet/psbtwallet.* into wallet/wallet.* where those
functions now live. As far as review, it's probably not worthwhile to
spend too much too much time on this since it's going to be change
again in #16528 and others. The test coverage is pretty extensive.
2020-11-26 01:07:51 +00:00
Andrew Poelstra
5bbbba1ce1 Merge 4d80274b99 into merged_master (Bitcoin PR #18241) 2020-11-26 01:07:50 +00:00
Andrew Poelstra
0246b86872 Merge 54a7ef612a into merged_master (Bitcoin PR #17399) 2020-11-26 01:07:48 +00:00
Andrew Poelstra
8e931da20b Merge 225aa5d6d5 into merged_master (Bitcoin PR #18193) 2020-11-26 01:07:45 +00:00
Andrew Poelstra
947e32f011 Merge 051439813e into merged_master (Bitcoin PR #13339) 2020-11-26 01:07:43 +00:00
Andrew Poelstra
3f02ec4810 Merge b30a1f3e39 into merged_master (Bitcoin PR #18052) 2020-11-26 00:29:45 +00:00
Andrew Poelstra
91e195d7cd Merge 2d6e76af24 into merged_master (Bitcoin PR #17261)
Moved GetOnlinePakKey to the scriptpubkey manager; the other blinding
stuff remains in the CWallet. At some point after the rebase we should
consider whether there's a better separation to be had between the PAK
related stuff now that we have wallet boxes.
2020-11-14 17:16:10 +00:00
Andrew Poelstra
04f4f87466 Merge 7fb94c0ed4 into merged_master (Bitcoin PR #17889) 2020-11-14 16:52:08 +00:00
Andrew Poelstra
f1535dde72 Merge f018d0c9cd into merged_master (Bitcoin PR #17924) 2020-11-14 16:52:08 +00:00
Andrew Poelstra
8bbbb28dae Merge ac61ec9da6 into merged_master (Bitcoin PR #17843) 2020-11-14 16:52:07 +00:00
Andrew Poelstra
7c53615bb6 Merge af05bd9e1e into merged_master (Bitcoin PR #17891) 2020-11-14 16:52:07 +00:00
Andrew Poelstra
bf7738a5c8 Merge 6196e93001 into merged_master (Bitcoin PR #16963) 2020-11-14 16:52:05 +00:00
Andrew Poelstra
a5c0140923 Merge cab3859a35 into merged_master (Bitcoin PR #17677) 2020-11-14 16:52:04 +00:00
Andrew Poelstra
4f611f400d Merge bcb4cdcca3 into merged_master (Bitcoin PR #17621) 2020-11-14 16:52:04 +00:00
Andrew Poelstra
dc2a5e5af4 Merge e6acd9f72c into merged_master (Bitcoin PR #17537) 2020-11-14 16:52:00 +00:00
Andrew Poelstra
010703797d Merge 0192bd0652 into merged_master (Bitcoin PR #17369) 2020-11-14 16:51:57 +00:00
Andrew Poelstra
381cd9cd01 Merge 4ee8a58ce7 into merged_master (Bitcoin PR #17373)
This PR associates OutputType::BECH32 to PAK online keys, where before we
were able to directly access keys from the keypool. In a future refactoring
we should give PAK keys their own output type (and own scriptpubkey manager)
so that the wallet won't accept payments "to the PAK key".

Also changes `ReserveDestination::SetBlindingPubKey` to use a visitor pattern
to apply a blinding pubkey to a destination directly, rather than using the
old hacky method of regenerating the destination by pulling its key (which
is no longer contained in the class) out and giving it to a new constructor.
This was a long-overdue refactoring and the minimal-diff way to get the code
compiling (and it's not bad, maybe 10LOC to add a new visitor class) but
nonetheless I apologize for sticking this into a merge commit.
2020-11-14 16:51:54 +00:00
Andrew Poelstra
c7bf5baf96 Merge 526e802d69 into merged_master (Elements PR #755)
This Elements PR includes components of Core PR #17211, which since the
refactors to use effective value landed, no longer provides the right
error message when a user provides an unowned input from a wallet tx.
See https://github.com/bitcoin/bitcoin/pull/17211#pullrequestreview-528389011

This breaks a functional test which was included in this PR, but which
conveniently has been changed in the current version of the Core PR. I
fixed the behavior (commented, in SelectCoins) rather than updating the
test to the most recent version.
2020-11-14 16:51:53 +00:00
Andrew Poelstra
932da45ee4 Merge dcbe024f5e into merged_master (Bitcoin PR #17648) 2020-11-14 16:51:52 +00:00
Andrew Poelstra
27de4bdecf Merge 19698ac6bc into merged_master (Bitcoin PR #17568) 2020-11-14 16:51:51 +00:00
Andrew Poelstra
94e0266084 Merge 2a97d2b1a5 into merged_master (Bitcoin PR #17553) 2020-11-14 16:51:48 +00:00
Andrew Poelstra
58ed0240e9 Merge 7127c31020 into merged_master (Bitcoin PR #17237) 2020-11-14 16:51:48 +00:00
Andrew Poelstra
ba08079170 Merge 0aa72061e5 into merged_master (Bitcoin PR #16944) 2020-11-14 16:51:47 +00:00
Andrew Poelstra
9239882c43 Merge 8aac85d71e into merged_master (Bitcoin PR #17371) 2020-11-14 16:51:41 +00:00
Andrew Poelstra
240f03f586 Merge cef87f7a48 into merged_master (Bitcoin PR #17290)
This one took a little bit of work. Basically everywhere that Andy's new code
didn't compile, I looked for a similarly shaped line in the pre-PR diff between
Bitcoin and Elements and adjusted it in the same way. Was pretty typical; all
CAmounts become CAmountMaps, etc.

I then spent about 7 hours chasing down a coin selection failure in the blocksign
functional tests, which ultimately turned out to be a Core issue. I added a
stopgap fix (commented, search for "stopgap" in wallet.cpp), and opened the issue
https://github.com/bitcoin/bitcoin/issues/20347

There was also a bug where we were not estimating change output sizes correctly
in case we had massive blinded outputs, which I had to fix to get the functional
tests to pass.
2020-11-10 21:59:56 +00:00
Andrew Poelstra
5c15120d59 Merge b7bc9b8330 into merged_master (Bitcoin PR #17444) 2020-11-09 23:10:13 +00:00
Andrew Poelstra
c1d327d827 Merge 4a3b6f47cd into merged_master (Bitcoin PR #17354) 2020-11-09 23:10:09 +00:00
Andrew Poelstra
cfde15703a Merge 99ab3a72c5 into merged_master (Bitcoin PR #15931) 2020-11-09 23:10:09 +00:00
Andrew Poelstra
9ec912e160 Merge 976cc766c4 into merged_master (Bitcoin PR #17381) 2020-11-09 23:10:08 +00:00
Andrew Poelstra
c3b2f1d8c0 Merge bdda137878 into merged_master (Bitcoin PR #16766) 2020-11-09 21:20:51 +00:00
Andrew Poelstra
84bc0faf8f Merge bbc9e4133c into merged_master (Bitcoin PR #17304) 2020-11-09 21:20:51 +00:00
Andrew Poelstra
751d0ac9f4 Merge 100fa0a62a into merged_master (Bitcoin PR #17300) 2020-11-09 21:20:48 +00:00
Andrew Poelstra
e910b15aa8 Merge 6a97e8a060 into merged_master (Bitcoin PR #17260) (multiple commits)
This is the start of some nontrivial wallet refactoring by achow. See
https://github.com/bitcoin-core/bitcoin-devwiki/wiki/Wallet-Class-Structure-Changes
for a high-level design.

This PR moves some stuff out of CWallet into a dummy "box" LegacyScriptPubKeyMan
which is (currently) very tightly coulped to CWallet. Because of the coupling there
are currently null-checks that cannot fail, things which assume non-nullness which
will eventually be wrong, and a plethora of currently-equivalent ways to get from
a CWallet to a provider or back.

Our approach is basically to ignore the refactoring; leave the blinding key stuff
in CWallet and have it call into the wallet's provider when we are obtaining the
underlying keys.

Later, probably in a post-rebase PR, we should rethink how we manage blinding keys
to more closely match Core's "all keys go into providers" model.
2020-11-09 21:20:47 +00:00
Andrew Poelstra
fc2108d672 Merge 8a191148db into merged_master (Bitcoin PR #17154) 2020-11-09 21:20:43 +00:00
Andrew Poelstra
42a1dc16a6 Merge a22b62481a into merged_master (Bitcoin PR #17070) 2020-11-09 21:20:43 +00:00
Andrew Poelstra
c08bbefb33 Merge 0d7e8d66c4 into merged_master (Bitcoin PR #17203) 2020-11-09 21:20:42 +00:00
Andrew Poelstra
821f5256a5 Merge 46d6930f8c into merged_master (Bitcoin PR #16659) 2020-11-09 21:20:41 +00:00
Andrew Poelstra
2640e37921 Merge a3af5b5c13 into merged_master (Bitcoin PR #17138) 2020-11-09 21:20:40 +00:00