mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-06 07:34:21 +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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user