mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-03 18:57:06 +01:00
push_tx: Don't create BIP 144 invalid transactions
If no witnesses are present on any inputs, then extended serialisation should not be used. [ Amended to make adding new flags clearer in future -- RR ] Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
ff1a466ef3
commit
505a249966
1 changed files with 9 additions and 14 deletions
23
bitcoin/tx.c
23
bitcoin/tx.c
|
@ -80,29 +80,24 @@ static void push_witnesses(const struct bitcoin_tx *tx,
|
||||||
|
|
||||||
static void push_tx(const struct bitcoin_tx *tx,
|
static void push_tx(const struct bitcoin_tx *tx,
|
||||||
void (*push)(const void *, size_t, void *), void *pushp,
|
void (*push)(const void *, size_t, void *), void *pushp,
|
||||||
bool extended)
|
bool bip144)
|
||||||
{
|
{
|
||||||
varint_t i;
|
varint_t i;
|
||||||
u8 flag = 0;
|
u8 flag = 0;
|
||||||
|
|
||||||
push_le32(tx->version, push, pushp);
|
push_le32(tx->version, push, pushp);
|
||||||
|
|
||||||
if (extended) {
|
if (bip144 && uses_witness(tx))
|
||||||
u8 marker;
|
flag |= SEGREGATED_WITNESS_FLAG;
|
||||||
|
|
||||||
|
/* BIP 141: The flag MUST be a 1-byte non-zero value. */
|
||||||
|
/* ie. if no flags set, we fallback to pre-BIP144-style */
|
||||||
|
if (flag) {
|
||||||
|
u8 marker = 0;
|
||||||
/* BIP 144 */
|
/* BIP 144 */
|
||||||
/* marker char Must be zero */
|
/* marker char Must be zero */
|
||||||
/* flag char Must be nonzero */
|
/* flag char Must be nonzero */
|
||||||
marker = 0;
|
|
||||||
push(&marker, 1, pushp);
|
push(&marker, 1, pushp);
|
||||||
/* BIP 141: The flag MUST be a 1-byte non-zero
|
|
||||||
* value. Currently, 0x01 MUST be used.
|
|
||||||
*
|
|
||||||
* BUT: Current segwit4 branch breaks fundrawtransaction;
|
|
||||||
* it sees 0 inputs and thinks it's extended format.
|
|
||||||
* Make it really an extended format, but without
|
|
||||||
* witness. */
|
|
||||||
if (uses_witness(tx))
|
|
||||||
flag = SEGREGATED_WITNESS_FLAG;
|
|
||||||
push(&flag, 1, pushp);
|
push(&flag, 1, pushp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,7 +251,7 @@ static void push_linearize(const void *data, size_t len, void *pptr_)
|
||||||
u8 *linearize_tx(const tal_t *ctx, const struct bitcoin_tx *tx)
|
u8 *linearize_tx(const tal_t *ctx, const struct bitcoin_tx *tx)
|
||||||
{
|
{
|
||||||
u8 *arr = tal_arr(ctx, u8, 0);
|
u8 *arr = tal_arr(ctx, u8, 0);
|
||||||
push_tx(tx, push_linearize, &arr, uses_witness(tx));
|
push_tx(tx, push_linearize, &arr, true);
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue