Commit graph

1090 commits

Author SHA1 Message Date
Martin Zumsande
856ba34e21 test: Call ceildiv helper with integer
It returns an incorrect result when called with a Decimal,
for which the "//" operator works differently.
Also drop unnecessary call to satoshi_round.

Github-Pull: #24239
Rebased-From: d1fab9d5d2
(cherry picked from commit 269553fe73b17f8acda3071a48836c66092d31d0)

NB: This code is commented out in elements and the cherry-pick is done
commenting out the code too.
2022-12-07 20:08:16 +00:00
Andrew Chow
2c72896bb3 tests: Calculate fees more similarly to CFeeRate::GetFee
Because of floating point precision issues, not all of the rounding done
is always correct. To fix this, the fee calculation for
assert_fee_amount is changed to better reflect how CFeeRate::GetFee does
it.

First the feerate is converted to an int representing sat/kvb. Then this
is multiplied by the transaction size, divivided by 1000, and rounded up
to the nearest sat. The result is then converted back to BTC (divided by
1e8) and then rounded down to the nearest sat to avoid precision errors.

Github-Pull: #22949
Rebased-From: 80dc829be7
(cherry picked from commit c768bfa08af034c744402d4294cc323d653b97b8)
2022-12-07 11:11:30 +00:00
Pieter Wuille
069bec11b3 Swap out hashlib.ripemd160 for own implementation
Github-Pull: 23716
Rebased-From: 5b559dc7ec
2022-09-07 14:13:27 +00:00
Pieter Wuille
0f6967033d Add pure Python RIPEMD-160
Github-Pull: 23716
Rebased-From: ad3e9e1f21
2022-09-07 14:13:13 +00:00
Glenn Willen
5889a844db Merge 2dda79cf61 into merged_master (Elements PR ElementsProject/elements#1094) 2022-04-21 15:54:34 -07:00
Glenn Willen
f035196ceb Merge 586e5c7dd7 into merged_master (Elements PR ElementsProject/elements#1062) 2022-04-20 21:51:53 -07:00
Glenn Willen
bf7f050aeb Raise max P2P message size to account for larger elements dynafed header size 2022-03-01 14:21:52 -08:00
Pablo Greco
85c3c2b819 Deprecate con_dyna_deploy_start in favor of evbparams 2021-11-23 14:36:03 +00:00
Andrew Poelstra
6c368ab1a3 Merge a1726c555b into merged_master (Elements PR ElementsProject/elements#1045) 2021-09-21 20:32:03 +00:00
Andrew Poelstra
0907fa0f6f test: support asset issuance in test framework sighashes
Replaces #932
2021-09-19 20:58:07 +00:00
Andrew Poelstra
dc31deacff Merge bc0494cc39 into merged_master (Elements PR ElementsProject/elements#1040) 2021-09-18 14:58:14 +00:00
Andrew Poelstra
e57b4c51ad regtest: change network magic away from liquid v1
We don't want connectivity issues between Liquid and custom test networks.
2021-09-10 17:20:20 +00:00
Andrew Poelstra
6387aaf765 Merge feee029d29 into merged_master (Elements PR ElementsProject/elements#1020)
Messy merge conflicts because this PR backported some ad-hoc stuff from
upstream while keeping a few things that upstream deleted. Hopefully
reviewing is easier than doing this in the first place, since ultimately
all I did was delete code from one side or another of the conflicts.
(Ok, I also changed some boost optional stuff to std::optional, and had
to patch up a test file for test framework changes.)

When reviewing the detailed crypto, bear in mind that taptweaks, like all
hashes are the kind of crypto that cannot be subtly wrong -- it will either
fail very hard or be correct. And we have independent implementations in
C++ and Python that cross-check each other, si it's unlikely to be the former.
2021-09-05 13:42:34 +00:00
Andrew Poelstra
7d1c77f0a1 Merge 1ba24fe9b3 into merged_master (Elements PR ElementsProject/elements#1002)
This forward-ports the new Taproot sighash but does not fix a couple
22-blocked TODOs related to the MissingDataBehavior enum. Should be fixed
in a followup commit.

One nontrivial change I had to make was feeding the genesis hash to SignTransaction
(the "global" one in script/sign.cpp) so that it could correctly compute
the sighash at signing time.
2021-09-04 22:14:42 +00:00
Andrew Poelstra
36e5e2a7f1 Merge 9a154599fe into merged_master (Elements PR ElementsProject/elements#900)
Surprisingly easy to do. Almost all of the diff resolution was mechanically
  * replacing boost::variant with std::variant
  * replacing Optional with std::optional
     * then replacing `nullopt` with `std::nullopt`
  * updating the RPC functions for the new RPCArg::Default type
  * update the tests/ directory to make new (since 22) tests use arrays for
    createrawtransaction outputs
  * other ad-hoc changes to function parameters etc (not too many of these)

I had to "really" change the code in PrecomputePSBTData, which was introduced
in 22.0 and affected by PSET, but this function was like 8 lines long so it
was easy.

Reviewing the diff may be a bit difficult because of the mix of mechanical
changes and ad-hoc things. Probably the most straightforward thing to do
is to redo the merge, `sed -i` to fix the boost::variant and Optional stuff,
then diff the remaining conflicts against this commit.

TODO: grep for `blindpsbt` and you will see that this RPC is still referenced
in documentation and help text even though it was deleted. Need to fix this
in 0.21 in a separate PR.
2021-09-04 19:34:14 +00:00
Andrew Poelstra
64194498cf
Merge ElementsProject/elements#1025: Introduce blech32m format for v1+ witness programs
c72c949d29 blech32: copy ubsan suppression for bech32 to blech32 (Andrew Poelstra)
d13fb4994b blech32: add test vectors for blech32 and blech32m (Andrew Poelstra)
15a826ea27 blech32: add functional tests for blech32m (Andrew Poelstra)
c01e09e8c3 blech32: add blech32m format and use it to decode witness v1+ addresses (Andrew Poelstra)
18fcec8714 naming nits (Fabian Jahr)
8515f40fed Add signet support to gen_key_io_test_vectors.py (Pieter Wuille)
b3df66f82e Use Bech32m encoding for v1+ segwit addresses (Pieter Wuille)
42f43a1bcb Add Bech32m test vectors (Pieter Wuille)
b1d1d94e01 Implement Bech32m encoding/decoding (Pieter Wuille)
c607835bad Better error messages for invalid addresses (Bezdrighin)

Pull request description:

  Includes backports of https://github.com/bitcoin/bitcoin/pull/20832 (1 commit) and https://github.com/bitcoin/bitcoin/pull/20861 (5 commits)

ACKs for top commit:
  gwillen:
    utACK c72c949.

Tree-SHA512: af96a6ef31b1cab72b0350197dcb34761e9ffb2ec43685084408b5fafcda0adee1945045003194600372652f7cca65d721bda3ed9b6be7e9543d3199e2cbe145
2021-08-30 18:59:25 +00:00
sanket1729
2c5c7eb87b Update tapscript leaf version 2021-08-27 19:24:07 +00:00
sanket1729
937343c75c Add tests for crypto opcodes 2021-08-27 19:24:07 +00:00
sanket1729
3e7b8c6aed Test arithmetic opcodes 2021-08-26 20:28:01 +00:00
sanket1729
6092d94c1d Add tests for introspection 2021-08-26 20:28:01 +00:00
sanket1729
007912eea4 Implement tests for sha256 streaming opcodes 2021-08-26 20:28:01 +00:00
Pieter Wuille
b3df66f82e Use Bech32m encoding for v1+ segwit addresses
This also includes updates to the Python test framework implementation,
test vectors, and release notes.

https://github.com/bitcoin/bitcoin/pull/20861 (3/5)
2021-08-17 22:32:47 +00:00
Andrew Poelstra
fc9e070952 Merge e4487fd5bb into merged_master (Bitcoin PR bitcoin/bitcoin#22096) 2021-08-03 15:17:22 +00:00
Andrew Poelstra
6361a13268 Merge a88fa1a555 into merged_master (Bitcoin PR bitcoin/bitcoin#22211) 2021-08-02 19:21:52 +00:00
Andrew Poelstra
2e6ff43f2d Merge d1e4c56309 into merged_master (Bitcoin PR bitcoin/bitcoin#22363) 2021-07-31 15:28:34 +00:00
Andrew Poelstra
083e08cf82 Merge d6a59166a1 into merged_master (Bitcoin PR bitcoin/bitcoin#22257)
Just as mechanical and annoying as it looks.
2021-07-28 21:06:57 +00:00
Andrew Poelstra
01766fafdf Merge c93e123dc7 into merged_master (Bitcoin PR bitcoin/bitcoin#22308) 2021-07-28 12:52:10 +00:00
Andrew Poelstra
2a28a2f2d1 Merge 672870ab7b into merged_master (Bitcoin PR bitcoin/bitcoin#22201) 2021-07-28 04:50:06 +00:00
Andrew Poelstra
8e462c9a98 Merge 74013641e0 into merged_master (Bitcoin PR bitcoin/bitcoin#22089) 2021-07-28 03:33:26 +00:00
Andrew Poelstra
cfa325712a Merge e172ea8804 into merged_master (Bitcoin PR bitcoin/bitcoin#22210) 2021-07-27 22:06:32 +00:00
Andrew Poelstra
be04e946b9 Merge 964d91b193 into merged_master (Bitcoin PR bitcoin/bitcoin#22130) 2021-07-25 15:24:50 +00:00
Andrew Poelstra
fcc12d7e2a Merge 3c393ef9e1 into merged_master (Bitcoin PR bitcoin/bitcoin#22149) 2021-07-23 00:28:01 +00:00
Andrew Poelstra
f806c13661 Merge 260b1d74fe into merged_master (Bitcoin PR bitcoin/bitcoin#22092) 2021-07-22 18:31:32 +00:00
Andrew Poelstra
f46e4fdf55 Merge 7e83e74e7f into merged_master (Bitcoin PR bitcoin/bitcoin#21178) 2021-07-20 12:32:17 +00:00
fanquake
e4487fd5bb
Merge bitcoin/bitcoin#22096: p2p: AddrFetch - don't disconnect on self-announcements
5730a43703 test: Add functional test for AddrFetch connections (Martin Zumsande)
c34ad3309f net, rpc: Enable AddrFetch connections for functional testing (Martin Zumsande)
533500d907 p2p: Add timeout for AddrFetch peers (Martin Zumsande)
b6c5d1e450 p2p: AddrFetch - don't disconnect on self-announcements (Martin Zumsande)

Pull request description:

  AddrFetch connections (old name: oneshots) are intended to be short-lived connections on which we ask a peer for addresses via `getaddr` and disconnect after receiving them.

  This is done by disconnecting after receiving the first `addr`. However, it is no longer working as intended, because nowadays, the first `addr` a typical bitcoin core node sends is its self-announcement.
  So we'll disconnect before the peer gets a chance to answer our `getaddr`.

  I checked that this affects both `-seednode` peers specified manually, and DNS seeds when AddrFetch is used as a fallback if DNS doesn't work for us.

  The current behavior of getting peers via AddrFetch when starting with an empty addrman would be to connect to the peer, receive its self-announcement and add it to addrman, disconnect, reconnect to the same peer again as a full outbound (no other addresses in addrman) and then receive more `addr`. This is silly and not in line with AddrFetch peer being intended to be short-lived peers. 

  Fix this by only disconnecting after receiving an `addr` message of size > 1.

  [Edit] As per review discussion, this PR now also adds a timeout after which we disconnect if we haven't received any suitable `addr`, and a functional test.

ACKs for top commit:
  amitiuttarwar:
    reACK 5730a43703
  naumenkogs:
    ACK 5730a43703
  jnewbery:
    ACK 5730a43703

Tree-SHA512: 8a81234f37e827705138eb254223f7f3b3bf44a06cb02126fc7990b0d231b9bd8f07d38d185cc30d55bf35548a6fdc286b69602498d875b937e7c58332158bf9
2021-07-20 20:27:21 +08:00
Andrew Poelstra
01b1d5f844 Merge c5ee0cc11a into merged_master (Bitcoin PR bitcoin/bitcoin#21989) 2021-07-19 13:07:08 +00:00
Andrew Poelstra
ec674d3ecb Merge d7a6bba949 into merged_master (Bitcoin PR bitcoin/bitcoin#22103) 2021-07-19 06:12:28 +00:00
W. J. van der Laan
a88fa1a555
Merge bitcoin/bitcoin#22211: net: relay I2P addresses even if not reachable (by us)
7593b06bd1 test: ensure I2P addresses are relayed (Vasil Dimov)
e7468139a1 test: make CAddress in functional tests comparable (Vasil Dimov)
33e211d2a4 test: implement ser/unser of I2P addresses in functional tests (Vasil Dimov)
86742811ce test: use NODE_* constants instead of magic numbers (Vasil Dimov)
ba45f02708 net: relay I2P addresses even if not reachable (by us) (Vasil Dimov)

Pull request description:

  Nodes that can reach the I2P network (have set `-i2psam=`) will relay
  I2P addresses even without this patch. However, nodes that can't reach
  the I2P network will not. This was done as a precaution in
  https://github.com/bitcoin/bitcoin/pull/20119 before anybody could
  connect to I2P because then, for sure, it would have been useless.

  Now, however, we have I2P support and a bunch of I2P nodes, so get all
  nodes on the network to relay I2P addresses to help with propagation,
  similarly to what we do with Tor addresses.

ACKs for top commit:
  jonatack:
    ACK 7593b06bd1
  naumenkogs:
    ACK 7593b06bd1.
  laanwj:
    Code review ACK 7593b06bd1
  kristapsk:
    ACK 7593b06bd1. Code looks correct, tested that functional test suite passes and also that `test/functional/p2p_addrv2_replay.py` fails if I undo changes in `IsRelayable()`.

Tree-SHA512: c9feec4a9546cc06bc2fec6d74f999a3c0abd3d15b7c421c21fcf2d610eb94611489e33d61bdcd5a4f42041a6d84aa892f7ae293b0d4f755309a8560b113b735
2021-07-15 16:53:34 +02:00
Andrew Poelstra
ff5c2de782 Merge 0a909073dc into merged_master (Bitcoin PR bitcoin/bitcoin#22048) 2021-07-12 21:04:54 +00:00
Andrew Poelstra
11548bb33c Merge 778b920179 into merged_master (Bitcoin PR bitcoin/bitcoin#21945) 2021-07-12 12:52:18 +00:00
Martin Zumsande
c34ad3309f net, rpc: Enable AddrFetch connections for functional testing
Co-authored-by: Amiti Uttarwar <amiti@uttarwar.org>
2021-07-12 02:16:45 +02:00
Andrew Poelstra
7447a3b352 Merge d8ae29ec8f into merged_master (Bitcoin PR bitcoin/bitcoin#21900) 2021-07-08 18:04:18 +00:00
Andrew Poelstra
1ba24fe9b3
Merge ElementsProject/elements#1002: Implement Taproot Sighash
14f93579a5 Add pegins and issuance test (sanket1729)
edf8455fe4 Fix bug in CAssetIssuance decoding (sanket1729)
cdd75d4251 Update OP_SUCCESS for elements with allowed opcodes (sanket1729)
4618097ab4 Implement taphash for elements (sanket1729)
6c985308d7 Implement Taphash in test framework (sanket1729)
a26f6fead6 Expose only blockchain hash twice in header (sanket1729)
afb9e7b727 taproot: feed genesis hash and parent pegged asset to sighash function (Andrew Poelstra)

Pull request description:

ACKs for top commit:
  apoelstra:
    ACK 14f93579a5

Tree-SHA512: f0a3f6ef9f8958bc948cc42375600767f39aadc0dac096fe8e7823dc69ddc4204360e504af7801d05bb19ae4e6ace6a271842531c192e330167381cf2690c856
2021-07-07 20:58:41 +00:00
Andrew Poelstra
ab1e80eb09 Merge 779aaa7f03 into merged_master (Bitcoin PR bitcoin/bitcoin#21754)
What a pain in the ass. This changes the `feature_cltv` functional test
to use the `MiniWallet`, an internal Pythonic wallet that produces
"signatures" consisting of several OP_NOPs in a row, so that this test
can be used when the wallet is disabled.

This means that the functions in feature_cltv which add a CLTV check and
change the locktime/sequence number no longer need to re-sign when they
change the txid, so they don't...HOWEVER, our Elements-specific
`feature_block_v4` test calls these functions with a real transaction
and depended on the re-signing behavior.

After several attempts at min-effort min-diff fixes I landed on this,
which simply sets the locktime at transaction creation and avoids having
to re-sign at all.

Also, I had to change the number of NOPs in the fake wallet code to make
a vsize assertion pass, presumably because of differences in Bitcoin/Elements
transaction serialization.
2021-07-06 13:53:02 +00:00
Sebastian Falbesoner
905d672b74 test: use script_util helpers for creating P2W{PKH,SH} scripts 2021-07-05 20:40:52 +02:00
Sebastian Falbesoner
285a65ccfd test: use script_util helpers for creating P2SH scripts 2021-07-05 20:40:47 +02:00
Andrew Poelstra
c4182106af Merge 2b45cf0bcd into merged_master (Bitcoin PR bitcoin/bitcoin#19521)
This is part of the "UTXO Set Statistics" project in Core, which aims
to make things like "checking coin supply" faster. This stuff, and
related things in coinstats.cpp, have always been broken for Elements
in the sense that we consider only explicit outputs and we ignore
assets (so everything just gets added together to get a meaningless
total). It probably wouldn't be too hard to restrict this to only
consider policyAsset, but it's out of scope for a rebase IMO.

Also, I think this situation is fine .. I don't understand the motivation
for this or why Core is merging this when they refuse to merge an address
index .. but I guess we'll see if there are users who care about this data
and who care about it being meaningful on Elements.

Also, apologies for the big diff -- there were some mechanical changes
to deal with CT amounts, but most of the changes related to the difference
in how fees are accounted for. While I'm not thrilled with this PR, its
functional test is really good! So I think what I eventually came up with
is internally consistent.
2021-07-04 19:51:38 +00:00
Andrew Poelstra
4485d3c785 Merge 40310f5e8c into merged_master (Bitcoin PR bitcoin/bitcoin#21792) 2021-07-03 22:18:16 +00:00
Andrew Poelstra
6b565b9878 Merge fb66dbe786 into merged_master (Bitcoin PR bitcoin/bitcoin#21762) 2021-07-03 13:46:53 +00:00
Andrew Poelstra
a02abbc35a Merge 7f37a1d560 into merged_master (Bitcoin PR bitcoin/bitcoin#21785) 2021-07-03 08:56:11 +00:00