mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 07:04:22 +01:00
spec-update: get rid of max-witness-len
We can use a fixed value and close the channel if they don't cover their amount; this wasn't really helping with anything other than setting a floor for an expected feerate
This commit is contained in:
@@ -324,7 +324,6 @@ u8 *psbt_changeset_get_next(const tal_t *ctx, struct channel_id *cid,
|
||||
|
||||
if (tal_count(set->added_ins) != 0) {
|
||||
const struct input_set *in = &set->added_ins[0];
|
||||
u16 max_witness_len;
|
||||
u8 *script;
|
||||
|
||||
if (!psbt_get_serial_id(&in->input.unknowns, &serial_id))
|
||||
@@ -333,10 +332,6 @@ u8 *psbt_changeset_get_next(const tal_t *ctx, struct channel_id *cid,
|
||||
const u8 *prevtx = linearize_wtx(ctx,
|
||||
in->input.utxo);
|
||||
|
||||
if (!psbt_input_get_max_witness_len(&in->input,
|
||||
&max_witness_len))
|
||||
abort();
|
||||
|
||||
if (in->input.redeem_script_len)
|
||||
script = tal_dup_arr(ctx, u8,
|
||||
in->input.redeem_script,
|
||||
@@ -347,7 +342,6 @@ u8 *psbt_changeset_get_next(const tal_t *ctx, struct channel_id *cid,
|
||||
msg = towire_tx_add_input(ctx, cid, serial_id,
|
||||
prevtx, in->tx_input.index,
|
||||
in->tx_input.sequence,
|
||||
max_witness_len,
|
||||
script,
|
||||
NULL);
|
||||
|
||||
@@ -440,49 +434,15 @@ int psbt_find_serial_output(struct wally_psbt *psbt, u16 serial_id)
|
||||
return -1;
|
||||
}
|
||||
|
||||
void psbt_input_add_max_witness_len(struct wally_psbt_input *input,
|
||||
u16 max_witness_len)
|
||||
{
|
||||
u8 *key = psbt_make_key(tmpctx, PSBT_TYPE_MAX_WITNESS_LEN, NULL);
|
||||
beint16_t bev = cpu_to_be16(max_witness_len);
|
||||
|
||||
psbt_input_add_unknown(input, key, &bev, sizeof(bev));
|
||||
}
|
||||
|
||||
|
||||
bool psbt_input_get_max_witness_len(const struct wally_psbt_input *input,
|
||||
u16 *max_witness_len)
|
||||
{
|
||||
size_t value_len;
|
||||
beint16_t bev;
|
||||
void *result = psbt_get_lightning(&input->unknowns,
|
||||
PSBT_TYPE_MAX_WITNESS_LEN,
|
||||
&value_len);
|
||||
if (!result)
|
||||
return false;
|
||||
|
||||
if (value_len != sizeof(bev))
|
||||
return false;
|
||||
|
||||
memcpy(&bev, result, value_len);
|
||||
*max_witness_len = be16_to_cpu(bev);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool psbt_has_required_fields(struct wally_psbt *psbt)
|
||||
{
|
||||
u16 max_witness, serial_id;
|
||||
u16 serial_id;
|
||||
for (size_t i = 0; i < psbt->num_inputs; i++) {
|
||||
struct wally_psbt_input *input = &psbt->inputs[i];
|
||||
|
||||
if (!psbt_get_serial_id(&input->unknowns, &serial_id))
|
||||
return false;
|
||||
|
||||
/* Inputs had also better have their max_witness_lens
|
||||
* filled in! */
|
||||
if (!psbt_input_get_max_witness_len(input, &max_witness))
|
||||
return false;
|
||||
|
||||
/* Required because we send the full tx over the wire now */
|
||||
if (!input->utxo)
|
||||
return false;
|
||||
|
||||
@@ -124,24 +124,6 @@ int psbt_find_serial_input(struct wally_psbt *psbt, u16 serial_id);
|
||||
*/
|
||||
int psbt_find_serial_output(struct wally_psbt *psbt, u16 serial_id);
|
||||
|
||||
/* psbt_input_add_max_witness_len - Put a max witness len on a thing
|
||||
*
|
||||
* @input - input to add max-witness-len to
|
||||
* @max_witness_len - value
|
||||
*/
|
||||
void psbt_input_add_max_witness_len(struct wally_psbt_input *input,
|
||||
u16 max_witness_len);
|
||||
|
||||
/* psbt_input_get_max_witness_len - Get the max_witness_len
|
||||
*
|
||||
* @input - psbt input to look for max witness len on
|
||||
* @max_witness_len - found length
|
||||
*
|
||||
* Returns false if key not present */
|
||||
WARN_UNUSED_RESULT bool
|
||||
psbt_input_get_max_witness_len(const struct wally_psbt_input *input,
|
||||
u16 *max_witness_len);
|
||||
|
||||
/* psbt_has_required_fields - Validates psbt field completion
|
||||
*
|
||||
* Required fields are:
|
||||
|
||||
@@ -56,7 +56,7 @@ void towire_secp256k1_ecdsa_signature(u8 **pptr UNNEEDED,
|
||||
void towire_sha256(u8 **pptr UNNEEDED, const struct sha256 *sha256 UNNEEDED)
|
||||
{ fprintf(stderr, "towire_sha256 called!\n"); abort(); }
|
||||
/* Generated stub for towire_tx_add_input */
|
||||
u8 *towire_tx_add_input(const tal_t *ctx UNNEEDED, const struct channel_id *channel_id UNNEEDED, u16 serial_id UNNEEDED, const u8 *prevtx UNNEEDED, u32 prevtx_vout UNNEEDED, u32 sequence UNNEEDED, u16 max_witness_len UNNEEDED, const u8 *script UNNEEDED, const struct tlv_tx_add_input_tlvs *tlvs UNNEEDED)
|
||||
u8 *towire_tx_add_input(const tal_t *ctx UNNEEDED, const struct channel_id *channel_id UNNEEDED, u16 serial_id UNNEEDED, const u8 *prevtx UNNEEDED, u32 prevtx_vout UNNEEDED, u32 sequence UNNEEDED, const u8 *script UNNEEDED, const struct tlv_tx_add_input_tlvs *tlvs UNNEEDED)
|
||||
{ fprintf(stderr, "towire_tx_add_input called!\n"); abort(); }
|
||||
/* Generated stub for towire_tx_add_output */
|
||||
u8 *towire_tx_add_output(const tal_t *ctx UNNEEDED, const struct channel_id *channel_id UNNEEDED, u16 serial_id UNNEEDED, u64 sats UNNEEDED, const u8 *script UNNEEDED)
|
||||
@@ -180,8 +180,10 @@ int main(int argc, const char *argv[])
|
||||
diff_count(end, start, 1, 1);
|
||||
|
||||
/* Add some extra unknown info to a PSBT */
|
||||
psbt_input_add_max_witness_len(&end->inputs[1], 100);
|
||||
psbt_input_add_max_witness_len(&start->inputs[1], 100);
|
||||
u8 *key = psbt_make_key(tmpctx, 0x05, NULL);
|
||||
char *val = tal_fmt(tmpctx, "hello");
|
||||
psbt_input_add_unknown(&end->inputs[1], key, val, tal_bytelen(val));
|
||||
psbt_input_add_unknown(&start->inputs[1], key, val, tal_bytelen(val));
|
||||
|
||||
/* Swap locations */
|
||||
struct wally_map_item tmp;
|
||||
@@ -190,7 +192,6 @@ int main(int argc, const char *argv[])
|
||||
end->inputs[1].unknowns.items[1] = tmp;
|
||||
|
||||
/* We expect nothing to change ? */
|
||||
/* FIXME: stable ordering of unknowns ? */
|
||||
diff_count(start, end, 1, 1);
|
||||
diff_count(end, start, 1, 1);
|
||||
|
||||
|
||||
@@ -239,14 +239,6 @@ static size_t psbt_input_weight(struct wally_psbt *psbt,
|
||||
size_t in)
|
||||
{
|
||||
size_t weight;
|
||||
u16 max_witness_len;
|
||||
bool ok;
|
||||
|
||||
/* BOLT-fe0351ca2cea3105c4f2eb18c571afca9d21c85b #2
|
||||
* `max_witness_len` is the total serialized length of the
|
||||
* witness data that will be supplied (e.g. sizeof(varint) +
|
||||
* sizeof(witness) for each) in `funding_signed2`.
|
||||
*/
|
||||
|
||||
/* txid + txout + sequence */
|
||||
weight = (32 + 4 + 4) * 4;
|
||||
@@ -254,10 +246,10 @@ static size_t psbt_input_weight(struct wally_psbt *psbt,
|
||||
(psbt->inputs[in].redeem_script_len +
|
||||
(varint_t) varint_size(psbt->inputs[in].redeem_script_len)) * 4;
|
||||
|
||||
ok = psbt_input_get_max_witness_len(&psbt->inputs[in],
|
||||
&max_witness_len);
|
||||
assert(ok);
|
||||
weight += max_witness_len;
|
||||
/* BOLT-78de9a79b491ae9fb84b1fdb4546bacf642dce87 #2
|
||||
* The minimum witness weight for an input is 110.
|
||||
*/
|
||||
weight += 110;
|
||||
return weight;
|
||||
}
|
||||
|
||||
@@ -590,7 +582,6 @@ static bool run_tx_interactive(struct state *state, struct wally_psbt **orig_psb
|
||||
switch (t) {
|
||||
case WIRE_TX_ADD_INPUT: {
|
||||
const u8 *tx_bytes, *redeemscript;
|
||||
u16 max_witness_len;
|
||||
u32 outnum, sequence;
|
||||
size_t len;
|
||||
struct bitcoin_tx *tx;
|
||||
@@ -603,7 +594,6 @@ static bool run_tx_interactive(struct state *state, struct wally_psbt **orig_psb
|
||||
&serial_id,
|
||||
cast_const2(u8 **, &tx_bytes),
|
||||
&outnum, &sequence,
|
||||
&max_witness_len,
|
||||
cast_const2(u8 **, &redeemscript),
|
||||
add_tlvs))
|
||||
peer_failed(state->pps, &state->channel_id,
|
||||
@@ -697,7 +687,6 @@ static bool run_tx_interactive(struct state *state, struct wally_psbt **orig_psb
|
||||
}
|
||||
|
||||
psbt_input_add_serial_id(in, serial_id);
|
||||
psbt_input_add_max_witness_len(in, max_witness_len);
|
||||
|
||||
/* FIXME: what's in the tlv? */
|
||||
break;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
--- wire/extracted_peer_wire_csv 2020-07-28 12:36:12.063168014 -0500
|
||||
+++ - 2020-08-24 19:16:50.026185750 -0500
|
||||
@@ -31,6 +31,47 @@
|
||||
+++ - 2020-08-31 21:00:40.856646471 -0500
|
||||
@@ -31,6 +31,46 @@
|
||||
tlvdata,n2,tlv1,amount_msat,tu64,
|
||||
tlvtype,n2,tlv2,11
|
||||
tlvdata,n2,tlv2,cltv_expiry,tu32,
|
||||
@@ -11,7 +11,6 @@
|
||||
+msgdata,tx_add_input,prevtx,byte,prevtx_len
|
||||
+msgdata,tx_add_input,prevtx_vout,u32,
|
||||
+msgdata,tx_add_input,sequence,u32,
|
||||
+msgdata,tx_add_input,max_witness_len,u16,
|
||||
+msgdata,tx_add_input,redeemscript_len,u16,
|
||||
+msgdata,tx_add_input,script,byte,redeemscript_len
|
||||
+msgdata,tx_add_input,tlvs,tx_add_input_tlvs,
|
||||
@@ -48,7 +47,7 @@
|
||||
msgtype,open_channel,32
|
||||
msgdata,open_channel,chain_hash,chain_hash,
|
||||
msgdata,open_channel,temporary_channel_id,byte,32
|
||||
@@ -82,6 +123,54 @@
|
||||
@@ -82,6 +122,54 @@
|
||||
msgtype,funding_locked,36
|
||||
msgdata,funding_locked,channel_id,channel_id,
|
||||
msgdata,funding_locked,next_per_commitment_point,point,
|
||||
@@ -103,7 +102,7 @@
|
||||
msgtype,shutdown,38
|
||||
msgdata,shutdown,channel_id,channel_id,
|
||||
msgdata,shutdown,len,u16,
|
||||
@@ -169,6 +258,11 @@
|
||||
@@ -169,6 +257,11 @@
|
||||
msgdata,channel_update,fee_base_msat,u32,
|
||||
msgdata,channel_update,fee_proportional_millionths,u32,
|
||||
msgdata,channel_update,htlc_maximum_msat,u64,,option_channel_htlc_max
|
||||
|
||||
Reference in New Issue
Block a user