Commit Graph

329 Commits

Author SHA1 Message Date
niftynei bf4cac7fb8 tx: strip out witscript
now that witness script data is saved into the tx/psbt which is
serialized across the wire, there's no reason to use witscript to do
this. good bye witscript!
2020-05-21 18:45:07 +09:30
niftynei 559f88faa1 psbt: add serialize to/from wire for psbts 2020-05-21 18:45:07 +09:30
niftynei 5d0fc176e8 psbt: create new_psbt method
Move all psbt creation into single method, new_psbt

note that if a psbt is init'd for a transaction that's
deserialized with scripts etc already attached, then set_global_tx
will fail. instead, we empty all of this out first.

if the tx is being re-init'd from a tx source that had a psbt attached
(e.g. fromwire_) then the script/witness data will get populated
appropriatel from there.
2020-05-21 18:45:07 +09:30
niftynei a848df67f1 psbt: populate scriptsigs + witnesses
Pass scriptSig + witness info down to the PSBT struct
2020-05-21 18:45:07 +09:30
niftynei 2055b53425 psbt: update global tx output amount also 2020-05-21 18:45:07 +09:30
niftynei cf9de86dba psbt: add transaction inputs to the psbt struct
Make sure that we permute them also!

Fixes weird spacing also
2020-05-21 18:45:07 +09:30
niftynei a1e1073752 tx: move to tal_dup_arr 2020-05-21 18:45:07 +09:30
niftynei b076f40cf3 psbt: move witness script storage into the psbt
we can now keep associated witness data with the output in the psbt
struct, so we do that.
2020-05-21 18:45:07 +09:30
niftynei 2d5c61dfc1 psbt: methods to mutate psbt in place
add the missing psbt helpers for adding and removing an input and output
2020-05-21 18:45:07 +09:30
niftynei 7a0624797e psbt: add psbt to bitcoin tx struct 2020-05-21 18:45:07 +09:30
Rusty Russell f1426bad8e bitcoin/tx: fix bug in fromwire_bitcoin_tx.
If we fail to unmarshal the tx (shouldn't happen, but...) we must
not dereference NULL.

Also tighten the check: towire_ must send 0 or all inputs.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-05-20 11:36:13 +02:00
Rusty Russell b920d4d21b wire: make fromwire_fail return non-const, use it more
It returns NULL, so you can simply `return fromwire_fail(...)`
if you want to return NULL in this case.  Use that more.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-05-20 11:36:13 +02:00
niftynei fbe50e087a setup: create a common setup which will handle the wally-context
Since we now over-write the wally malloc/free functions, we need to do
so for tests as well. Here we pull up all of the common setup/teardown
logic into a separate place, and update the tests that use libwally to
use the new common_setup core

Changelog-None
2020-05-19 13:35:42 +09:30
Rusty Russell cfb320c972 wire: move remaining bitcoin functions out to bitcoin/ files.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-05-18 14:51:12 +02:00
Rusty Russell 197d1bcef2 wire: move towire/fromwire_short_channel_id out to bitcoin/short_channel_id.c
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-05-18 14:51:12 +02:00
Rusty Russell 4dbfce6057 wire: move towire/fromwire_preimage out to bitcoin/preimage.c.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-05-18 14:51:12 +02:00
Rusty Russell 27220646c3 common/wire: move bitcoin-specific marshalling functions into bitcoin files.
We did this originally because these types are referred to in the bolts, and we
had no way of injecting the correct include lines into those.  Now we do, so
there's less excuse for this.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-05-18 14:51:12 +02:00
Rusty Russell 4bcac3032c bitcoin: remove unused struct bitcoin_tx_input.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-05-15 09:55:59 +09:30
lisa neigut 824e8fa72b tx: split 'compute fee' into two, with one that takes an input value
Transactions that we 'get' from bitciond don't have the input values
available on the transaction; for these cases we'll sum up the inputs
amounts using a different data source than the transaction's
`input_amounts`. So we need to expose it here.
2020-05-12 15:46:58 +09:30
lisa neigut 3d241bc261 tx: expose elements 'is fee' calculation
we'll use it when figuring out what outputs to account for during
a withdrawal.
2020-05-12 15:46:58 +09:30
lisa neigut c110f3662c bitcoin_tx: add helper for extracting output amount 2020-05-07 08:43:00 +09:30
Rusty Russell d881a4bd66 BOLT: update to latest version.
This is all typo/clarity fixes, no substantive changes.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-03-31 13:36:02 +02:00
Christian Decker c236bf0fbd tx: Make elements_add_fee_output private 2020-03-24 09:52:33 +10:30
Christian Decker 42a63e4416 tx: Strengthen transaction construction checks
We roll the `elements_add_fee_output` function and the cropping of
overallocated arrays into the `bitcoin_tx_finalize` function. This is supposed
to be the final cleanup and compaction step before a tx can be sent to bitcoin
or passed off to other daemons.

This is the cleanup promised in #3491
2020-03-24 09:52:33 +10:30
Rusty Russell 2aad3ffcf8 common: tal_dup_talarr() helper.
This is a common thing to do, so create a macro.

Unfortunately, it still needs the type arg, because the paramter may
be const, and the return cannot be, and C doesn't have a general
"(-const)" cast.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-02-27 14:16:16 +10:30
Christian Decker 9521549c49 elements: Fix missing witness script entry for fee outputs
Fixes #3487
2020-02-08 14:26:12 +01:00
Ken Sedgwick 5c8f881a75
hsmd: Added fields to hsm_sign_remote_commitment_tx to allow complete validation.
Changelog-Added: hsmd: Added fields to hsm_sign_remote_commitment_tx to allow complete validation by signing daemon.
2020-02-04 10:40:43 +10:30
darosior 273029f244 wallet: set nLockTime to the tip for withdrawal transactions
This sets the nLockTime to the tip (and accordingly each input's nSequence to
0xfffffffe) for withdrawal transactions.

Even if the anti fee-sniping argument might not be valid until some time yet,
this makes our regular wallet transactions far less distinguishable from
bitcoind's ones since it now defaults to using native Segwit transactions
(like us). Moreover other wallets are likely to implement this (if they
haven't already).

Changelog-Added: wallet: withdrawal transactions now sets nlocktime to the current tip.
2020-02-03 00:45:27 +00:00
Christian Decker 234252016d cleanup: Remove block header fields we don't use 2020-01-28 20:03:55 +01:00
Christian Decker a61b044056 elements: Implement dynafed block format support
Changelog-Added: elements: Added support for the dynafed block header format and elementsd >=0.18.1
2020-01-28 20:03:55 +01:00
Christian Decker c99786e720 bitcoin: Use the block hash we computed while deserializing it
Since we now compute the hash while deserializing the block header we can now
just use it, no reason to serialize the header just to hash it again. This
also allows us to throw away all the added dynafed fields in the next commit
instead of having to carry them around.
2020-01-28 20:03:55 +01:00
Christian Decker fce05d74e1 elements: Construct the block header hash while we parse it 2020-01-28 20:03:55 +01:00
Christian Decker 8839be641a sha256: Add primitive to add a varint-encoded int to a hash
We're about to push a couple of varints as part of the dynafed blockparsing,
so we might as well make it easier for us.
2020-01-28 20:03:55 +01:00
Christian Decker 4de0d1ca22 bitcoin: Compute block hash while parsing
This avoids having to re-serialize the block header just to compute the
hash. It also frees us from having to carry around all the details in the
header and we can hand around a minimal version.
2020-01-28 20:03:55 +01:00
Christian Decker c2434ad4fb bitcoin: Compute block hash while parsing
This avoids having to re-serialize the block header just to compute the
hash. It also frees us from having to carry around all the details in the
header and we can hand around a minimal version.
2020-01-27 22:48:42 +01:00
darosior 4b13b88f6c bitcoin/chainparams: add an utility to retrieve chainparams for all networks 2019-11-29 21:17:08 +01:00
lisa neigut 3705b5f605 devtools: add privkey+hash printing to mkcommit/mkgossip
We updated the protocol spec tests to verify a sig from a hash
and a private key; this updates mkcommit + mkgossip utilities
to print out the procotol compatible SIG() notation for all signatures.

--verbose will print a computed signature and more data as well.

Also adds --verbose flag to mkgossip.

Changelog-None
2019-11-21 01:17:33 +00:00
lisa neigut 861b12b21a dump_tx: fixup compiliation errs
When we refactored bitcoin_tx to use wally_tx, this (uncompiled)
debug statement rotted. This unrots it.
2019-11-21 01:17:33 +00:00
gorazdko a3851f2943 wallet: always create signatures with low r-value 2019-10-29 18:51:09 -05:00
Christian Decker be49a599bc elements: Do not get upset if we see a confidential asset or value
I made some assumptions that turn out not to be true, mea culpa.
2019-10-18 16:10:17 +02:00
Christian Decker d35ec902f4 elements: Work around libwally getting upset with helpful flags
libwally really is pedantic about the kind of hints it will accept.

Signed-off-by: Christian Decker <@cdecker>
2019-10-18 16:10:17 +02:00
lisa neigut cbfa045f91 tx: remove input size assertion
this is unnecessary, and actually severely limits the functionality
of `wally_tx_add_input`, which will expand the allocated input
length if there's not enough room for the additional input

```external/libwally-core/src/transaction.c
    if (tx->num_inputs >= tx->inputs_allocation_len) {
        /* Expand the inputs array */
        struct wally_tx_input *p;
        p = realloc_array(tx->inputs, tx->inputs_allocation_len,
                          tx->num_inputs + 1, sizeof(*tx->inputs));
        ...
        tx->inputs = p;
        tx->inputs_allocation_len += 1;
```
2019-10-10 05:57:45 +00:00
lisa neigut 496d2cae5f varint: Add helper function for getting varlen size
Needed to calculate somethings for building dual funding txs
2019-10-10 05:57:45 +00:00
lisa neigut cb2cad8c94 script: add helper for checking if a 'known type'
To be used for verifying remote inputs' validity
2019-10-10 05:57:45 +00:00
Christian Decker ff4a2bf38f onchaind: Annotate inputs and outputs not the transactions 2019-10-07 20:03:24 -05:00
Yash Bhutwala 30ec739c15 check for return code in the else block 2019-10-06 22:36:05 -05:00
Christian Decker 7283efa5b5 elements: Add amount_asset to support more than just plain satoshis
Currently the only source for amount_asset is the value getter on a tx output,
and we don't hand it too far around (mainly ignoring it if it isn't the
chain's main currency). Eventually we could bubble them up to the wallet, use
them to select outputs or actually support assets in the channels.

Since we don't hand them around too widely I thought it was ok for them to be
pass-by-value rather than having to allocate them and pass them around by
reference. They're just 41 bytes currently so the overhead should be ok.

Signed-off-by: Christian Decker <@cdecker>
2019-10-03 04:32:57 +00:00
Christian Decker c38afc5512 tx: Switch to amount_sat for fee computations
Suggested-by: Rusty Russell <@rustyrussell>
2019-10-03 04:32:57 +00:00
Christian Decker d5f0c08a88 elements: Remove global is_elements variable in favor of chainparams
No need to keep duplicate globals.
2019-10-03 04:32:57 +00:00
Christian Decker ef7a63d8f8 elements: Move from a global is_elements to a global chainparams
We now have a pointer to chainparams, that fails valgrind if we do anything
chain-specific before setting it.

Suggested-by: Rusty Russell <@rustyrussell>
2019-10-03 04:32:57 +00:00