Commit Graph

486 Commits

Author SHA1 Message Date
Rusty Russell 65be18d355 memleak: handle libwally allocations better.
Things allocated by libwally all get the tal_name "wally_tal",
which cost me a few hours trying to find a leak.

In the case where we're making one of the allocations the parent
of the others (e.g. a wally_psbt), we can do better: supply a name
for the tal_wally_end().

So I add a new tal_wally_end_onto() which does the standard
tal_steal() trick, and also changes the (typechecked!) name.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-03-21 10:19:50 +10:30
niftynei d246e9c1a2 tx_parts: as a convenience, copy over the value as the 'satoshi'
Reporting coin movements was crashing for liquid-regtest tests because
we were using an un-initialized field (the tx_part output's satoshi
field).

We fill this in 'as a convenience' for other wally_tx_outputs that are
on liquid elsewhere, here we do the same for tx_parts sent over the
wire to onchaind.
2022-03-05 15:12:12 +10:30
Dustin Dettmer 4386ccd842 bitcoin: Comment typo fix 2022-03-03 11:22:19 +10:30
Simon Vrouwe 905a85dc99 JSON-RPC: getinfo, add field `our_features`
All build flags and (experimental) options make it hard to find
out what features are supported or enabled.

And the undocumented `--list-features-only`, does not account for all
our featurebits, for example bit 55 (keysend).

Changelog-Added: JSON-RPC: `getinfo` result now includes `our_features` (bits) for various Bolt #9 contexts
2022-03-01 09:38:40 +10:30
Rusty Russell f0ea4d60b9 onchaind: fix minor leaks.
Not actually leaks, but they do live longer than they need.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-02-27 07:44:26 +10:30
Sebastian Falbesoner 53d4e9d2b8 bitcoin/tx: remove unused SEGREGATED_WITNESS_FLAG
This define is unused since commit
509bb2c7ae.

Changelog-None
2022-02-16 15:58:10 -06:00
Rusty Russell a55cfab00d elements: fix gross weight differential.
Firstly, we were not adding the extra fee output on our dummy tx,
because the fee amount was 0.  We probably should always do this, even
if it's 0.

Secondly, there are 6 witnesses, not 1, for elements txs.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-01-27 12:22:36 +01:00
Rusty Russell 8a8d7c4243 elements: unify overhead calculation.
And in particular, fix onchaind grinding code which used the
actual number of inputs and outputs (which already includes the
fee output); that breaks with the next patch which fixes other
calculations.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-01-27 12:22:36 +01:00
Rusty Russell c88dc7883e bitcoin: implement bitcoin_tx_2of2_input_witness_weight
Saves us actually creating the witness to measure it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-01-27 12:22:36 +01:00
Rusty Russell 59f1749967 bitcoin: fix tx weight calculation when there are no witnesses, but will be.
We had an out-by-two error when calculating weights, because we grab weights
on unsigned txs.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-01-27 12:22:36 +01:00
ZmnSCPxj jxPCSnmZ d088288daa bitcoin/chainparams.h: Split BIP173 name into onchain and Lightning HRPs.
Fixes: #4937
2021-12-14 11:21:35 +10:30
ZmnSCPxj jxPCSnmZ 3af15d2f5e Revert "bitcoin/chainparams.c: Change `signet` BIP173 name to `tbs`."
This reverts commit a642d9f3dc.
2021-12-14 11:21:35 +10:30
Jan Sarenik 96f28323bd Set default port according to network
The idea is to have different default ports for different networks.

Current default port is `9735` for everything. Let's use it for
the mainnet and reuse the difference added to the default port
from `rpc_port` values in `bitcoin/chainstate.c`.

Testnet would be `19735` (adding rpc_port - 8332 = `10000`).

Signet would be `39735` (adding rpc_port - 8332 = `30000`).

Regtest would be `19846` (adding rpc_port - 8332 = `10111`).

With Vincenzo's kind pair-programming help over tmate.

Two other commits were squashed into this one so that bisecting
never ends up in half-baked state:

1. chainparams: Fix regtest default rpc_port

   bitcoind -help says this:

    -rpcport=<port>
         Listen for JSON-RPC connections on <port> (default: 8332, testnet:
         18332, signet: 38332, regtest: 18443)

2. test_gossip: Default port for regtest

   hex: 2607 is now .... (could be 4d86 but Elements uses another port)
   dec: 9735 is now any port (could be 19846 ^^ but now is for any port)

   The lines which were binding to default port were removed as the
   default port is different on each network.

NOTE: Remember not to modify gossip_store tests which loads everything raw
      including the checksums.

Changelog-Changed: If the port is unspecified, the default port is chosen according to used network similarly to Bitcoin Core.
2021-12-06 17:10:08 +10:30
Rusty Russell d9968bbc0c bitcoin: remove unused functions, or make static.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-12-06 10:05:39 +10:30
Rusty Russell 4ffda340d3 check: make sure all files outside contrib/ include "config.h" first.
And turn "" includes into full-path (which makes it easier to put
config.h first, and finds some cases check-includes.sh missed
previously).

config.h sets _GNU_SOURCE which really needs to be done before any
'#includes': we mainly got away with it with glibc, but other platforms
like Alpine may have stricter requirements.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-12-06 10:05:39 +10:30
ZmnSCPxj jxPCSnmZ a642d9f3dc bitcoin/chainparams.c: Change `signet` BIP173 name to `tbs`.
Fixes: #4924

ChangeLog-Changed: `signet` addresses and invoices now use `tbs` instead of `tb`.
2021-11-27 19:17:56 +01:00
Rusty Russell c503232cde common: use bitcoin_outpoint.
I started pulling this thread, and the entire codebase got unravelled.

Oh well, it's done now!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-10-15 12:09:36 +02:00
Rusty Russell e7a8a0d291 common/type_to_string: formatting for bitcoin_outpoint.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-10-15 12:09:36 +02:00
Rusty Russell 2ab4e5b42b utils: add max_unsigned/min_unsigned helpers.
We are usually dealing with unsigned values, so use this.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-10-15 12:09:36 +02:00
Rusty Russell 8f582e770c BOLT12: use point32 instead of pubkey32.
That's the modern BOLT12 term.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-10-08 13:47:30 +02:00
Devrandom e393791d4b Length prefix bitcoin tx, to fix layer violation 2021-10-07 14:52:18 +02:00
Rusty Russell 24536c5561 common/autodata: use instead of ccan/autodata
This means it needs to be linked ~everywhere.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-21 18:04:43 +02:00
Rusty Russell 7401b26824 cleanup: remove unneeded includes in C files.
Before:
 Ten builds, laptop -j5, no ccache:

```
real	0m36.686000-38.956000(38.608+/-0.65)s
user	2m32.864000-42.253000(40.7545+/-2.7)s
sys	0m16.618000-18.316000(17.8531+/-0.48)s
```

 Ten builds, laptop -j5, ccache (warm):

```
real	0m8.212000-8.577000(8.39989+/-0.13)s
user	0m12.731000-13.212000(12.9751+/-0.17)s
sys	0m3.697000-3.902000(3.83722+/-0.064)s
```

After:
 Ten builds, laptop -j5, no ccache: 8% faster

```
real	0m33.802000-35.773000(35.468+/-0.54)s
user	2m19.073000-27.754000(26.2542+/-2.3)s
sys	0m15.784000-17.173000(16.7165+/-0.37)s
```

 Ten builds, laptop -j5, ccache (warm): 1% faster

```
real	0m8.200000-8.485000(8.30138+/-0.097)s
user	0m12.485000-13.100000(12.7344+/-0.19)s
sys	0m3.702000-3.889000(3.78787+/-0.056)s
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-17 09:43:22 +09:30
Rusty Russell ea30c34d82 cleanup: remove unneeded includes in header files.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-09-17 09:43:22 +09:30
Antoine Poinsot 08d32123d8 bitcoin/tx: check PSBT sanity after parsing
We could end up handing a valid tx containing a NULL PSBT around.

Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
2021-08-14 12:44:33 +09:30
niftynei c9d2748081 lease_rates: add csv lock to modify anchor scripts 2021-07-20 13:28:38 -04:00
niftynei e992b54410 script: add csv_lock to scripts 2021-07-20 13:28:38 -04:00
niftynei 04b6ad06cb change fees: more accurate rounding for change amount
We were getting off-by-one for the total amount that the change is for,
since it rounds the fee *down*, independent of the total weight of the
entire tx.

We fix this by using the diff btw the fee of the total weight (w/ and
w/o the change output)
2021-07-19 16:13:24 -04:00
Michael Schmoock d5f1515b25 chore: fix compile issue discovered by gcc
Changelog-None
2021-06-11 13:53:41 +09:30
niftynei 3c4c8d4fa0 libwally: update to release_0.8.3
Remove hacks to get around empty PSBT deserialization bug
2021-06-03 11:24:33 +09:30
Rusty Russell 25b5e1e099 update-mocks: make sure we cover all test programs.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-05-22 17:53:04 +09:30
niftynei de854fa9d4 psbt: really hacky patch over libwally's 0-input txs parse fail
Issue being tracked at https://github.com/ElementsProject/libwally-core/pull/273
2021-05-12 11:25:41 +09:30
Rusty Russell 16735e1352 bitcoin: allow developer override of signature grinding.
Allows us to precisely replicate test vectors.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-05-03 10:10:32 +09:30
niftynei ff164cf8b3 psbt: temporarily patch over failure to parse the empty tx
libwally has a bug which results in it failing to parse the 'empty tx'
cHNidP8BAAoAAAAAAAAAAAAAAA==. While we wait for the patch to land in
libwally, we patch over it.

Fix at: https://github.com/ElementsProject/libwally-core/pull/273
2021-04-16 15:33:44 +09:30
Rusty Russell 1cfb7b84d0 closingd: add support for handling wrong_funding.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-03-16 13:08:40 +10:30
Rusty Russell 67fc6e6267 bitcoin: add fromwire/towire routines for bitcoin_outpoint.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-03-16 13:08:40 +10:30
niftynei 9a849d6ba6 bitcoin: method for finding weight of 'wally_tx' 2021-03-09 14:55:05 +10:30
niftynei cca6e8db03 psbt: mark psbt arg as const for `psbt_compute_fee` 2021-03-09 14:55:05 +10:30
Rusty Russell db2198e7b9 bitcoin/script: use script opcode constants from wally_script.h
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-03-02 14:42:34 +10:30
Rusty Russell 93d3b0d126 doc: update BOLT quotes (to include LOW-S-standard rule).
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-02-25 13:23:16 +10:30
niftynei 5a11c8aa7a psbt: method to calculate fee paid on PSBT 2021-02-24 10:06:42 -06:00
niftynei 10fce07d96 psbt: method to clone a PSBT onto a context
wally offers up `wally_clone_psbt` but it's a bit clunky (requires
checking return value, starting/stopping the wally_allocation context)

Helper method wraps this all up nice + neat!
2021-02-24 10:06:42 -06:00
Rusty Russell 06a54606a3 check-includes: allow redundant "config.h"
We should actually be including this (as it may define _GNU_SOURCE
etc) before any system headers.  But where we include <assert.h> we
often didn't, because check-includes would complain that the headers
included it too.

Weaken that check, and include config.h in C files before assert.h.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-02-04 12:02:36 +10:30
Rusty Russell 84dc943cf5 common/bolt11_json: extract bolt11->json code.
Our new "decode" command will also handle bolt11.  We make a few cleanups:

1. Avoid type_to_string() in JSON, instead use format functions directly.
2. Don't need to escape description now that JSON core does that for us.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-01-09 14:34:35 +10:30
Rusty Russell f06ad0471c common/bolt12_merkle.h: experimental bolt 12 implementation.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-12-09 16:40:13 +10:30
Rusty Russell 9d656464f5 bitcoin/pubkey: add pubkey32 primitive for xonly pubkey types.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-12-09 16:40:13 +10:30
Rusty Russell 6f205896aa bitcoin/tx: fix type of outpoint (n is a u32), simplify json_to_outpoint
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-12-09 06:56:21 +10:30
Christian Decker 32000b6660 json: Add two param functions to parse string arrs and outpoint arrs
In a couple of places we accept arrays of strings and don't validate
them. If we forward them, e.g., call a JSON-RPC method from the
plugin, we end up embedding the unverified string in the JSON-RPC
call without escaping, which then leads to invalid JSON being passed
on.

This at least partially causes #4238
2020-12-09 06:56:21 +10:30
Rusty Russell e9e6f72d7c bitcoin_tx_check: don't rely on tmpctx.
We assert() this in onchaind while grinding fees; better to free newtx.

Before this we hit 530MB, after a mere 2.5MB.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: onchaind uses much less memory on unilateral closes for old channels.
2020-12-07 14:23:59 +01:00
niftynei b4aebc17a1 bitcoin: break out method to calculate input weight
We have a required minimum witness weight for dual funded opens.
2020-12-02 14:19:08 +10:30