Browse Source

df: incorporate a few spec changes -- serial_id is now 64-bits

And we pass 3-params for feerate so it's a 'pick a range' conversation.
travis-experimental
niftynei 4 years ago
committed by neil saitug
parent
commit
97fd18f0b5
  1. 2
      channeld/channeld.c
  2. 2
      common/psbt_internal.c
  3. 42
      common/psbt_open.c
  4. 14
      common/psbt_open.h
  5. 6
      common/test/exp-run-psbt_diff.c
  6. 8
      lightningd/dual_open_control.c
  7. 67
      openingd/dualopend.c
  8. 2
      openingd/dualopend_wire.csv
  9. 10
      openingd/dualopend_wiregen.c
  10. 6
      openingd/dualopend_wiregen.h
  11. 50
      wire/extracted_peer_experimental_dual_fund_more

2
channeld/channeld.c

@ -2114,7 +2114,7 @@ static void handle_tx_sigs(struct peer *peer, const u8 *msg)
for (size_t i = 0; i < peer->psbt->num_inputs; i++) { for (size_t i = 0; i < peer->psbt->num_inputs; i++) {
struct wally_psbt_input *in = struct wally_psbt_input *in =
&peer->psbt->inputs[i]; &peer->psbt->inputs[i];
u16 in_serial; u64 in_serial;
const struct witness_element **elem; const struct witness_element **elem;
if (!psbt_get_serial_id(&in->unknowns, &in_serial)) { if (!psbt_get_serial_id(&in->unknowns, &in_serial)) {

2
common/psbt_internal.c

@ -56,7 +56,7 @@ psbt_to_witness_stacks(const tal_t *ctx,
enum tx_role side_to_stack) enum tx_role side_to_stack)
{ {
size_t stack_index; size_t stack_index;
u16 serial_id; u64 serial_id;
const struct witness_stack **stacks const struct witness_stack **stacks
= tal_arr(ctx, const struct witness_stack *, psbt->num_inputs); = tal_arr(ctx, const struct witness_stack *, psbt->num_inputs);

42
common/psbt_open.c

@ -9,10 +9,10 @@
#include <common/pseudorand.h> #include <common/pseudorand.h>
#include <common/utils.h> #include <common/utils.h>
bool psbt_get_serial_id(const struct wally_map *map, u16 *serial_id) bool psbt_get_serial_id(const struct wally_map *map, u64 *serial_id)
{ {
size_t value_len; size_t value_len;
beint16_t bev; beint64_t bev;
void *result = psbt_get_lightning(map, PSBT_TYPE_SERIAL_ID, &value_len); void *result = psbt_get_lightning(map, PSBT_TYPE_SERIAL_ID, &value_len);
if (!result) if (!result)
return false; return false;
@ -21,14 +21,14 @@ bool psbt_get_serial_id(const struct wally_map *map, u16 *serial_id)
return false; return false;
memcpy(&bev, result, value_len); memcpy(&bev, result, value_len);
*serial_id = be16_to_cpu(bev); *serial_id = be64_to_cpu(bev);
return true; return true;
} }
static int compare_serials(const struct wally_map *map_a, static int compare_serials(const struct wally_map *map_a,
const struct wally_map *map_b) const struct wally_map *map_b)
{ {
u16 serial_left, serial_right; u64 serial_left, serial_right;
bool ok; bool ok;
ok = psbt_get_serial_id(map_a, &serial_left); ok = psbt_get_serial_id(map_a, &serial_left);
@ -324,10 +324,10 @@ struct psbt_changeset *psbt_get_changeset(const tal_t *ctx,
void psbt_input_set_serial_id(const tal_t *ctx, void psbt_input_set_serial_id(const tal_t *ctx,
struct wally_psbt_input *input, struct wally_psbt_input *input,
u16 serial_id) u64 serial_id)
{ {
u8 *key = psbt_make_key(tmpctx, PSBT_TYPE_SERIAL_ID, NULL); u8 *key = psbt_make_key(tmpctx, PSBT_TYPE_SERIAL_ID, NULL);
beint16_t bev = cpu_to_be16(serial_id); beint64_t bev = cpu_to_be64(serial_id);
psbt_input_set_unknown(ctx, input, key, &bev, sizeof(bev)); psbt_input_set_unknown(ctx, input, key, &bev, sizeof(bev));
} }
@ -335,17 +335,17 @@ void psbt_input_set_serial_id(const tal_t *ctx,
void psbt_output_set_serial_id(const tal_t *ctx, void psbt_output_set_serial_id(const tal_t *ctx,
struct wally_psbt_output *output, struct wally_psbt_output *output,
u16 serial_id) u64 serial_id)
{ {
u8 *key = psbt_make_key(tmpctx, PSBT_TYPE_SERIAL_ID, NULL); u8 *key = psbt_make_key(tmpctx, PSBT_TYPE_SERIAL_ID, NULL);
beint16_t bev = cpu_to_be16(serial_id); beint64_t bev = cpu_to_be64(serial_id);
psbt_output_set_unknown(ctx, output, key, &bev, sizeof(bev)); psbt_output_set_unknown(ctx, output, key, &bev, sizeof(bev));
} }
int psbt_find_serial_input(struct wally_psbt *psbt, u16 serial_id) int psbt_find_serial_input(struct wally_psbt *psbt, u64 serial_id)
{ {
for (size_t i = 0; i < psbt->num_inputs; i++) { for (size_t i = 0; i < psbt->num_inputs; i++) {
u16 in_serial; u64 in_serial;
if (!psbt_get_serial_id(&psbt->inputs[i].unknowns, &in_serial)) if (!psbt_get_serial_id(&psbt->inputs[i].unknowns, &in_serial))
continue; continue;
if (in_serial == serial_id) if (in_serial == serial_id)
@ -354,10 +354,10 @@ int psbt_find_serial_input(struct wally_psbt *psbt, u16 serial_id)
return -1; return -1;
} }
int psbt_find_serial_output(struct wally_psbt *psbt, u16 serial_id) int psbt_find_serial_output(struct wally_psbt *psbt, u64 serial_id)
{ {
for (size_t i = 0; i < psbt->num_outputs; i++) { for (size_t i = 0; i < psbt->num_outputs; i++) {
u16 out_serial; u64 out_serial;
if (!psbt_get_serial_id(&psbt->outputs[i].unknowns, &out_serial)) if (!psbt_get_serial_id(&psbt->outputs[i].unknowns, &out_serial))
continue; continue;
if (out_serial == serial_id) if (out_serial == serial_id)
@ -366,14 +366,14 @@ int psbt_find_serial_output(struct wally_psbt *psbt, u16 serial_id)
return -1; return -1;
} }
static u16 get_random_serial(enum tx_role role) static u64 get_random_serial(enum tx_role role)
{ {
return pseudorand(1 << 15) << 1 | role; return pseudorand_u64() << 1 | role;
} }
u16 psbt_new_input_serial(struct wally_psbt *psbt, enum tx_role role) u64 psbt_new_input_serial(struct wally_psbt *psbt, enum tx_role role)
{ {
u16 serial_id; u64 serial_id;
while ((serial_id = get_random_serial(role)) && while ((serial_id = get_random_serial(role)) &&
psbt_find_serial_input(psbt, serial_id) != -1) { psbt_find_serial_input(psbt, serial_id) != -1) {
@ -383,9 +383,9 @@ u16 psbt_new_input_serial(struct wally_psbt *psbt, enum tx_role role)
return serial_id; return serial_id;
} }
u16 psbt_new_output_serial(struct wally_psbt *psbt, enum tx_role role) u64 psbt_new_output_serial(struct wally_psbt *psbt, enum tx_role role)
{ {
u16 serial_id; u64 serial_id;
while ((serial_id = get_random_serial(role)) && while ((serial_id = get_random_serial(role)) &&
psbt_find_serial_output(psbt, serial_id) != -1) { psbt_find_serial_output(psbt, serial_id) != -1) {
@ -397,7 +397,7 @@ u16 psbt_new_output_serial(struct wally_psbt *psbt, enum tx_role role)
bool psbt_has_required_fields(struct wally_psbt *psbt) bool psbt_has_required_fields(struct wally_psbt *psbt)
{ {
u16 serial_id; u64 serial_id;
for (size_t i = 0; i < psbt->num_inputs; i++) { for (size_t i = 0; i < psbt->num_inputs; i++) {
struct wally_psbt_input *input = &psbt->inputs[i]; struct wally_psbt_input *input = &psbt->inputs[i];
@ -428,7 +428,7 @@ bool psbt_has_required_fields(struct wally_psbt *psbt)
bool psbt_side_finalized(const struct wally_psbt *psbt, enum tx_role role) bool psbt_side_finalized(const struct wally_psbt *psbt, enum tx_role role)
{ {
u16 serial_id; u64 serial_id;
for (size_t i = 0; i < psbt->num_inputs; i++) { for (size_t i = 0; i < psbt->num_inputs; i++) {
if (!psbt_get_serial_id(&psbt->inputs[i].unknowns, if (!psbt_get_serial_id(&psbt->inputs[i].unknowns,
&serial_id)) { &serial_id)) {
@ -446,7 +446,7 @@ bool psbt_side_finalized(const struct wally_psbt *psbt, enum tx_role role)
/* Adds serials to inputs + outputs that don't have one yet */ /* Adds serials to inputs + outputs that don't have one yet */
void psbt_add_serials(struct wally_psbt *psbt, enum tx_role role) void psbt_add_serials(struct wally_psbt *psbt, enum tx_role role)
{ {
u16 serial_id; u64 serial_id;
for (size_t i = 0; i < psbt->num_inputs; i++) { for (size_t i = 0; i < psbt->num_inputs; i++) {
/* Skip ones that already have a serial id */ /* Skip ones that already have a serial id */
if (psbt_get_serial_id(&psbt->inputs[i].unknowns, &serial_id)) if (psbt_get_serial_id(&psbt->inputs[i].unknowns, &serial_id))

14
common/psbt_open.h

@ -48,7 +48,7 @@ struct psbt_changeset {
* Returns false if serial_id is not present * Returns false if serial_id is not present
*/ */
WARN_UNUSED_RESULT bool psbt_get_serial_id(const struct wally_map *map, WARN_UNUSED_RESULT bool psbt_get_serial_id(const struct wally_map *map,
u16 *serial_id); u64 *serial_id);
/* psbt_sort_by_serial_id - Sort PSBT by serial_ids /* psbt_sort_by_serial_id - Sort PSBT by serial_ids
* *
@ -82,7 +82,7 @@ struct psbt_changeset *psbt_get_changeset(const tal_t *ctx,
*/ */
void psbt_input_set_serial_id(const tal_t *ctx, void psbt_input_set_serial_id(const tal_t *ctx,
struct wally_psbt_input *input, struct wally_psbt_input *input,
u16 serial_id); u64 serial_id);
/* psbt_output_set_serial_id - Sets a serial id on given output /* psbt_output_set_serial_id - Sets a serial id on given output
* *
* @ctx - tal context for allocations * @ctx - tal context for allocations
@ -91,7 +91,7 @@ void psbt_input_set_serial_id(const tal_t *ctx,
*/ */
void psbt_output_set_serial_id(const tal_t *ctx, void psbt_output_set_serial_id(const tal_t *ctx,
struct wally_psbt_output *output, struct wally_psbt_output *output,
u16 serial_id); u64 serial_id);
/* psbt_sort_by_serial_id - Sorts the inputs + outputs by serial_id /* psbt_sort_by_serial_id - Sorts the inputs + outputs by serial_id
* *
@ -108,7 +108,7 @@ void psbt_sort_by_serial_id(struct wally_psbt *psbt);
* *
* Returns index of input with matching serial if found or -1 * Returns index of input with matching serial if found or -1
*/ */
int psbt_find_serial_input(struct wally_psbt *psbt, u16 serial_id); int psbt_find_serial_input(struct wally_psbt *psbt, u64 serial_id);
/* psbt_find_serial_output - Checks outputs for provided serial_id /* psbt_find_serial_output - Checks outputs for provided serial_id
* *
@ -117,7 +117,7 @@ int psbt_find_serial_input(struct wally_psbt *psbt, u16 serial_id);
* *
* Returns index of output with matching serial if found or -1 * Returns index of output with matching serial if found or -1
*/ */
int psbt_find_serial_output(struct wally_psbt *psbt, u16 serial_id); int psbt_find_serial_output(struct wally_psbt *psbt, u64 serial_id);
/* psbt_new_input_serial - Generate a new serial for an input for {role} /* psbt_new_input_serial - Generate a new serial for an input for {role}
* *
@ -126,7 +126,7 @@ int psbt_find_serial_output(struct wally_psbt *psbt, u16 serial_id);
* *
* Returns a new, unique serial of the correct parity for the specified {role} * Returns a new, unique serial of the correct parity for the specified {role}
*/ */
u16 psbt_new_input_serial(struct wally_psbt *psbt, enum tx_role role); u64 psbt_new_input_serial(struct wally_psbt *psbt, enum tx_role role);
/* psbt_new_output_serial - Generate a new serial for an output for {role} /* psbt_new_output_serial - Generate a new serial for an output for {role}
* *
@ -135,7 +135,7 @@ u16 psbt_new_input_serial(struct wally_psbt *psbt, enum tx_role role);
* *
* Returns a new, unique serial of the correct parity for the specified {role} * Returns a new, unique serial of the correct parity for the specified {role}
*/ */
u16 psbt_new_output_serial(struct wally_psbt *psbt, enum tx_role role); u64 psbt_new_output_serial(struct wally_psbt *psbt, enum tx_role role);
/* psbt_has_required_fields - Validates psbt field completion /* psbt_has_required_fields - Validates psbt field completion
* *

6
common/test/exp-run-psbt_diff.c

@ -42,9 +42,9 @@ u64 fromwire_u64(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
/* Generated stub for fromwire_u8 */ /* Generated stub for fromwire_u8 */
u8 fromwire_u8(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) u8 fromwire_u8(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_u8 called!\n"); abort(); } { fprintf(stderr, "fromwire_u8 called!\n"); abort(); }
/* Generated stub for pseudorand */ /* Generated stub for pseudorand_u64 */
uint64_t pseudorand(uint64_t max UNNEEDED) uint64_t pseudorand_u64(void)
{ fprintf(stderr, "pseudorand called!\n"); abort(); } { fprintf(stderr, "pseudorand_u64 called!\n"); abort(); }
/* Generated stub for towire */ /* Generated stub for towire */
void towire(u8 **pptr UNNEEDED, const void *data UNNEEDED, size_t len UNNEEDED) void towire(u8 **pptr UNNEEDED, const void *data UNNEEDED, size_t len UNNEEDED)
{ fprintf(stderr, "towire called!\n"); abort(); } { fprintf(stderr, "towire called!\n"); abort(); }

8
lightningd/dual_open_control.c

@ -307,7 +307,7 @@ static bool psbt_side_contribs_changed(struct wally_psbt *orig,
enum side opener_side) enum side opener_side)
{ {
struct psbt_changeset *cs; struct psbt_changeset *cs;
u16 serial_id; u64 serial_id;
bool ok; bool ok;
cs = psbt_get_changeset(tmpctx, orig, new); cs = psbt_get_changeset(tmpctx, orig, new);
@ -636,7 +636,7 @@ static void opener_psbt_changed(struct subd *dualopend,
const u8 *msg) const u8 *msg)
{ {
struct channel_id cid; struct channel_id cid;
u16 funding_serial; u64 funding_serial;
struct wally_psbt *psbt; struct wally_psbt *psbt;
struct json_stream *response; struct json_stream *response;
struct command *cmd = uc->fc->cmd; struct command *cmd = uc->fc->cmd;
@ -656,7 +656,7 @@ static void opener_psbt_changed(struct subd *dualopend,
type_to_string(tmpctx, struct channel_id, &cid)); type_to_string(tmpctx, struct channel_id, &cid));
json_add_psbt(response, "psbt", psbt); json_add_psbt(response, "psbt", psbt);
json_add_bool(response, "commitments_secured", false); json_add_bool(response, "commitments_secured", false);
json_add_num(response, "funding_serial", funding_serial); json_add_u64(response, "funding_serial", funding_serial);
uc->cid = cid; uc->cid = cid;
uc->fc->inflight = true; uc->fc->inflight = true;
@ -911,7 +911,7 @@ cleanup:
static void accepter_psbt_changed(struct subd *dualopend, static void accepter_psbt_changed(struct subd *dualopend,
const u8 *msg) const u8 *msg)
{ {
u16 unused; u64 unused;
struct openchannel2_psbt_payload *payload = struct openchannel2_psbt_payload *payload =
tal(dualopend, struct openchannel2_psbt_payload); tal(dualopend, struct openchannel2_psbt_payload);
payload->dualopend = dualopend; payload->dualopend = dualopend;

67
openingd/dualopend.c

@ -123,7 +123,7 @@ struct state {
struct psbt_changeset *changeset; struct psbt_changeset *changeset;
/* The serial_id of the funding output */ /* The serial_id of the funding output */
u16 funding_serial; u64 funding_serial;
}; };
#if EXPERIMENTAL_FEATURES #if EXPERIMENTAL_FEATURES
@ -142,7 +142,7 @@ static u8 *psbt_changeset_get_next(const tal_t *ctx,
struct channel_id *cid, struct channel_id *cid,
struct psbt_changeset *set) struct psbt_changeset *set)
{ {
u16 serial_id; u64 serial_id;
u8 *msg; u8 *msg;
if (tal_count(set->added_ins) != 0) { if (tal_count(set->added_ins) != 0) {
@ -317,7 +317,7 @@ static bool is_openers(const struct wally_map *unknowns)
* ... * ...
* - MUST send odd `serial_id`s * - MUST send odd `serial_id`s
*/ */
u16 serial_id; u64 serial_id;
if (!psbt_get_serial_id(unknowns, &serial_id)) if (!psbt_get_serial_id(unknowns, &serial_id))
status_failed(STATUS_FAIL_INTERNAL_ERROR, status_failed(STATUS_FAIL_INTERNAL_ERROR,
"PSBTs must have serial_ids set"); "PSBTs must have serial_ids set");
@ -826,7 +826,7 @@ static bool run_tx_interactive(struct state *state,
while (!(we_complete && they_complete)) { while (!(we_complete && they_complete)) {
struct channel_id cid; struct channel_id cid;
enum peer_wire t; enum peer_wire t;
u16 serial_id; u64 serial_id;
/* Reset their_complete to false every round, /* Reset their_complete to false every round,
* they have to re-affirm every time */ * they have to re-affirm every time */
@ -872,7 +872,7 @@ static bool run_tx_interactive(struct state *state,
*/ */
if (serial_id % 2 == our_role) if (serial_id % 2 == our_role)
peer_failed(state->pps, &state->channel_id, peer_failed(state->pps, &state->channel_id,
"Invalid serial_id rcvd. %u", "Invalid serial_id rcvd. %"PRIu64,
serial_id); serial_id);
/* /*
* BOLT-fe0351ca2cea3105c4f2eb18c571afca9d21c85b #2: * BOLT-fe0351ca2cea3105c4f2eb18c571afca9d21c85b #2:
@ -882,7 +882,8 @@ static bool run_tx_interactive(struct state *state,
*/ */
if (psbt_find_serial_input(psbt, serial_id) != -1) if (psbt_find_serial_input(psbt, serial_id) != -1)
peer_failed(state->pps, &state->channel_id, peer_failed(state->pps, &state->channel_id,
"Duplicate serial_id rcvd. %u", serial_id); "Duplicate serial_id rcvd."
" %"PRIu64, serial_id);
/* Convert tx_bytes to a tx! */ /* Convert tx_bytes to a tx! */
len = tal_bytelen(tx_bytes); len = tal_bytelen(tx_bytes);
@ -980,14 +981,14 @@ static bool run_tx_interactive(struct state *state,
* input which is not theirs */ * input which is not theirs */
if (serial_id % 2 == our_role) if (serial_id % 2 == our_role)
peer_failed(state->pps, &state->channel_id, peer_failed(state->pps, &state->channel_id,
"Invalid serial_id rcvd. %u", "Invalid serial_id rcvd. %"PRIu64,
serial_id); serial_id);
input_index = psbt_find_serial_input(psbt, serial_id); input_index = psbt_find_serial_input(psbt, serial_id);
if (input_index == -1) if (input_index == -1)
peer_failed(state->pps, &state->channel_id, peer_failed(state->pps, &state->channel_id,
"No input added with serial_id %u", "No input added with serial_id"
serial_id); " %"PRIu64, serial_id);
psbt_rm_input(psbt, input_index); psbt_rm_input(psbt, input_index);
break; break;
@ -1014,13 +1015,13 @@ static bool run_tx_interactive(struct state *state,
* incorrect parity */ * incorrect parity */
if (serial_id % 2 == our_role) if (serial_id % 2 == our_role)
peer_failed(state->pps, &state->channel_id, peer_failed(state->pps, &state->channel_id,
"Invalid serial_id rcvd. %u", "Invalid serial_id rcvd. %"PRIu64,
serial_id); serial_id);
if (psbt_find_serial_output(psbt, serial_id) != -1) if (psbt_find_serial_output(psbt, serial_id) != -1)
peer_failed(state->pps, &state->channel_id, peer_failed(state->pps, &state->channel_id,
"Duplicate serial_id rcvd. %u", "Duplicate serial_id rcvd."
serial_id); " %"PRIu64, serial_id);
amt = amount_sat(value); amt = amount_sat(value);
out = psbt_append_output(psbt, scriptpubkey, amt); out = psbt_append_output(psbt, scriptpubkey, amt);
psbt_output_set_serial_id(psbt, out, serial_id); psbt_output_set_serial_id(psbt, out, serial_id);
@ -1042,14 +1043,14 @@ static bool run_tx_interactive(struct state *state,
* input which is not theirs */ * input which is not theirs */
if (serial_id % 2 == our_role) if (serial_id % 2 == our_role)
peer_failed(state->pps, &state->channel_id, peer_failed(state->pps, &state->channel_id,
"Invalid serial_id rcvd. %u", "Invalid serial_id rcvd."
serial_id); " %"PRIu64, serial_id);
output_index = psbt_find_serial_output(psbt, serial_id); output_index = psbt_find_serial_output(psbt, serial_id);
if (output_index == -1) if (output_index == -1)
peer_failed(state->pps, &state->channel_id, peer_failed(state->pps, &state->channel_id,
"No output added with serial_id %u", "No output added with serial_id"
serial_id); " %"PRIu64, serial_id);
psbt_rm_output(psbt, output_index); psbt_rm_output(psbt, output_index);
break; break;
} }
@ -1131,13 +1132,16 @@ static u8 *accepter_start(struct state *state, const u8 *oc2_msg)
struct amount_msat our_msats; struct amount_msat our_msats;
struct amount_sat total; struct amount_sat total;
enum dualopend_wire msg_type; enum dualopend_wire msg_type;
u32 feerate_min, feerate_max, feerate_best;
state->our_role = TX_ACCEPTER; state->our_role = TX_ACCEPTER;
open_tlv = tlv_opening_tlvs_new(tmpctx); open_tlv = tlv_opening_tlvs_new(tmpctx);
if (!fromwire_open_channel2(oc2_msg, &chain_hash, if (!fromwire_open_channel2(oc2_msg, &chain_hash,
&state->opening_podle_h2, &state->opening_podle_h2,
&state->feerate_per_kw_funding, &feerate_max,
&feerate_min,
&feerate_best,
&state->opener_funding, &state->opener_funding,
&state->remoteconf.dust_limit, &state->remoteconf.dust_limit,
&state->remoteconf.max_htlc_value_in_flight, &state->remoteconf.max_htlc_value_in_flight,
@ -1223,6 +1227,7 @@ static u8 *accepter_start(struct state *state, const u8 *oc2_msg)
&state->their_points.revocation); &state->their_points.revocation);
/* FIXME: pass the podle back also */ /* FIXME: pass the podle back also */
/* FIXME: pass back the feerate options */
msg = towire_dual_open_got_offer(NULL, msg = towire_dual_open_got_offer(NULL,
state->opener_funding, state->opener_funding,
state->remoteconf.dust_limit, state->remoteconf.dust_limit,
@ -1313,8 +1318,11 @@ static u8 *accepter_start(struct state *state, const u8 *oc2_msg)
tal_count(state->upfront_shutdown_script[LOCAL]), 0); tal_count(state->upfront_shutdown_script[LOCAL]), 0);
} }
/* FIXME: actually look up a good feerate */
state->feerate_per_kw_funding = feerate_best;
msg = towire_accept_channel2(tmpctx, &state->channel_id, msg = towire_accept_channel2(tmpctx, &state->channel_id,
state->accepter_funding, state->accepter_funding,
state->feerate_per_kw_funding,
state->localconf.dust_limit, state->localconf.dust_limit,
state->localconf.max_htlc_value_in_flight, state->localconf.max_htlc_value_in_flight,
state->localconf.htlc_minimum, state->localconf.htlc_minimum,
@ -1541,7 +1549,9 @@ static u8 *opener_start(struct state *state, u8 *msg)
struct bitcoin_tx *remote_commit, *local_commit; struct bitcoin_tx *remote_commit, *local_commit;
struct bitcoin_signature remote_sig, local_sig; struct bitcoin_signature remote_sig, local_sig;
secp256k1_ecdsa_signature *htlc_sigs; secp256k1_ecdsa_signature *htlc_sigs;
u32 feerate_min, feerate_max, feerate_best;
/* FIXME: get these from opener !? */
if (!fromwire_dual_open_opener_init(state, msg, if (!fromwire_dual_open_opener_init(state, msg,
&psbt, &psbt,
&state->opener_funding, &state->opener_funding,
@ -1555,6 +1565,10 @@ static u8 *opener_start(struct state *state, u8 *msg)
state->tx_locktime = psbt->tx->locktime; state->tx_locktime = psbt->tx->locktime;
open_tlv = tlv_opening_tlvs_new(tmpctx); open_tlv = tlv_opening_tlvs_new(tmpctx);
feerate_min = state->feerate_per_kw_funding - 1;
feerate_max = state->feerate_per_kw_funding + 1;
feerate_best = state->feerate_per_kw_funding;
if (state->upfront_shutdown_script[LOCAL]) { if (state->upfront_shutdown_script[LOCAL]) {
open_tlv->option_upfront_shutdown_script = open_tlv->option_upfront_shutdown_script =
tal(open_tlv, tal(open_tlv,
@ -1568,7 +1582,9 @@ static u8 *opener_start(struct state *state, u8 *msg)
msg = towire_open_channel2(NULL, msg = towire_open_channel2(NULL,
&chainparams->genesis_blockhash, &chainparams->genesis_blockhash,
&podle, /* FIXME: podle H2! */ &podle, /* FIXME: podle H2! */
state->feerate_per_kw_funding, feerate_max,
feerate_min,
feerate_best,
state->opener_funding, state->opener_funding,
state->localconf.dust_limit, state->localconf.dust_limit,
state->localconf.max_htlc_value_in_flight, state->localconf.max_htlc_value_in_flight,
@ -1602,6 +1618,7 @@ static u8 *opener_start(struct state *state, u8 *msg)
a_tlv = tlv_accept_tlvs_new(state); a_tlv = tlv_accept_tlvs_new(state);
if (!fromwire_accept_channel2(msg, &cid, if (!fromwire_accept_channel2(msg, &cid,
&state->accepter_funding, &state->accepter_funding,
&state->feerate_per_kw_funding,
&state->remoteconf.dust_limit, &state->remoteconf.dust_limit,
&state->remoteconf.max_htlc_value_in_flight, &state->remoteconf.max_htlc_value_in_flight,
&state->remoteconf.htlc_minimum, &state->remoteconf.htlc_minimum,
@ -1636,6 +1653,20 @@ static u8 *opener_start(struct state *state, u8 *msg)
&state->channel_id), &state->channel_id),
type_to_string(msg, struct channel_id, &cid)); type_to_string(msg, struct channel_id, &cid));
/* BOLT-5fcbda56901af9e3b1d057cc41d0c5cfa60a2b94 #2:
* The receiving node:
* - if the `feerate_funding` is less than the `feerate_funding_min`
* or above the `feerate_funding_max`
* - MUST error.
*/
if (feerate_min > state->feerate_per_kw_funding
|| feerate_max < state->feerate_per_kw_funding)
peer_failed(state->pps, &state->channel_id,
"Invalid feerate %d chosen. Valid min %d,"
" valid max %d", state->feerate_per_kw_funding,
feerate_min, feerate_max);
/* Check that total funding doesn't overflow */ /* Check that total funding doesn't overflow */
if (!amount_sat_add(&total, state->opener_funding, if (!amount_sat_add(&total, state->opener_funding,
state->accepter_funding)) state->accepter_funding))

2
openingd/dualopend_wire.csv

@ -86,7 +86,7 @@ msgdata,dual_open_commit_rcvd,remote_shutdown_scriptpubkey,u8,remote_shutdown_le
# dualopend->master: peer updated the psbt # dualopend->master: peer updated the psbt
msgtype,dual_open_psbt_changed,7107 msgtype,dual_open_psbt_changed,7107
msgdata,dual_open_psbt_changed,channel_id,channel_id, msgdata,dual_open_psbt_changed,channel_id,channel_id,
msgdata,dual_open_psbt_changed,funding_serial,u16, msgdata,dual_open_psbt_changed,funding_serial,u64,
msgdata,dual_open_psbt_changed,psbt,wally_psbt, msgdata,dual_open_psbt_changed,psbt,wally_psbt,
# master->dualopend: we updated the psbt # master->dualopend: we updated the psbt

Can't render this file because it has a wrong number of fields in line 11.

10
openingd/dualopend_wiregen.c

@ -310,18 +310,18 @@ bool fromwire_dual_open_commit_rcvd(const tal_t *ctx, const void *p, struct chan
/* WIRE: DUAL_OPEN_PSBT_CHANGED */ /* WIRE: DUAL_OPEN_PSBT_CHANGED */
/* dualopend->master: peer updated the psbt */ /* dualopend->master: peer updated the psbt */
u8 *towire_dual_open_psbt_changed(const tal_t *ctx, const struct channel_id *channel_id, u16 funding_serial, const struct wally_psbt *psbt) u8 *towire_dual_open_psbt_changed(const tal_t *ctx, const struct channel_id *channel_id, u64 funding_serial, const struct wally_psbt *psbt)
{ {
u8 *p = tal_arr(ctx, u8, 0); u8 *p = tal_arr(ctx, u8, 0);
towire_u16(&p, WIRE_DUAL_OPEN_PSBT_CHANGED); towire_u16(&p, WIRE_DUAL_OPEN_PSBT_CHANGED);
towire_channel_id(&p, channel_id); towire_channel_id(&p, channel_id);
towire_u16(&p, funding_serial); towire_u64(&p, funding_serial);
towire_wally_psbt(&p, psbt); towire_wally_psbt(&p, psbt);
return memcheck(p, tal_count(p)); return memcheck(p, tal_count(p));
} }
bool fromwire_dual_open_psbt_changed(const tal_t *ctx, const void *p, struct channel_id *channel_id, u16 *funding_serial, struct wally_psbt **psbt) bool fromwire_dual_open_psbt_changed(const tal_t *ctx, const void *p, struct channel_id *channel_id, u64 *funding_serial, struct wally_psbt **psbt)
{ {
const u8 *cursor = p; const u8 *cursor = p;
size_t plen = tal_count(p); size_t plen = tal_count(p);
@ -329,7 +329,7 @@ bool fromwire_dual_open_psbt_changed(const tal_t *ctx, const void *p, struct cha
if (fromwire_u16(&cursor, &plen) != WIRE_DUAL_OPEN_PSBT_CHANGED) if (fromwire_u16(&cursor, &plen) != WIRE_DUAL_OPEN_PSBT_CHANGED)
return false; return false;
fromwire_channel_id(&cursor, &plen, channel_id); fromwire_channel_id(&cursor, &plen, channel_id);
*funding_serial = fromwire_u16(&cursor, &plen); *funding_serial = fromwire_u64(&cursor, &plen);
*psbt = fromwire_wally_psbt(ctx, &cursor, &plen); *psbt = fromwire_wally_psbt(ctx, &cursor, &plen);
return cursor != NULL; return cursor != NULL;
} }
@ -479,4 +479,4 @@ bool fromwire_dual_open_dev_memleak_reply(const void *p, bool *leak)
*leak = fromwire_bool(&cursor, &plen); *leak = fromwire_bool(&cursor, &plen);
return cursor != NULL; return cursor != NULL;
} }
// SHA256STAMP:ed548e8b85302ef620646a1aab503b1279fece3b9d9aeedd47a371fa2a9fbe56 // SHA256STAMP:b1bf5b7fc522f2b0d940704f6f9e1699db093da76ca88d3ce7c925d40569ab14

6
openingd/dualopend_wiregen.h

@ -75,8 +75,8 @@ bool fromwire_dual_open_commit_rcvd(const tal_t *ctx, const void *p, struct chan
/* WIRE: DUAL_OPEN_PSBT_CHANGED */ /* WIRE: DUAL_OPEN_PSBT_CHANGED */
/* dualopend->master: peer updated the psbt */ /* dualopend->master: peer updated the psbt */
u8 *towire_dual_open_psbt_changed(const tal_t *ctx, const struct channel_id *channel_id, u16 funding_serial, const struct wally_psbt *psbt); u8 *towire_dual_open_psbt_changed(const tal_t *ctx, const struct channel_id *channel_id, u64 funding_serial, const struct wally_psbt *psbt);
bool fromwire_dual_open_psbt_changed(const tal_t *ctx, const void *p, struct channel_id *channel_id, u16 *funding_serial, struct wally_psbt **psbt); bool fromwire_dual_open_psbt_changed(const tal_t *ctx, const void *p, struct channel_id *channel_id, u64 *funding_serial, struct wally_psbt **psbt);
/* WIRE: DUAL_OPEN_PSBT_UPDATED */ /* WIRE: DUAL_OPEN_PSBT_UPDATED */
/* master->dualopend: we updated the psbt */ /* master->dualopend: we updated the psbt */
@ -109,4 +109,4 @@ bool fromwire_dual_open_dev_memleak_reply(const void *p, bool *leak);
#endif /* LIGHTNING_OPENINGD_DUALOPEND_WIREGEN_H */ #endif /* LIGHTNING_OPENINGD_DUALOPEND_WIREGEN_H */
// SHA256STAMP:ed548e8b85302ef620646a1aab503b1279fece3b9d9aeedd47a371fa2a9fbe56 // SHA256STAMP:b1bf5b7fc522f2b0d940704f6f9e1699db093da76ca88d3ce7c925d40569ab14

50
wire/extracted_peer_experimental_dual_fund_more

@ -0,0 +1,50 @@
--- wire/peer_exp_wire.csv 2020-09-16 20:59:05.170975876 -0500
+++ - 2020-10-22 16:56:33.413063210 -0500
@@ -33,7 +33,7 @@
tlvdata,n2,tlv2,cltv_expiry,tu32,
msgtype,tx_add_input,66
msgdata,tx_add_input,channel_id,channel_id,
-msgdata,tx_add_input,serial_id,u16,
+msgdata,tx_add_input,serial_id,u64,
msgdata,tx_add_input,prevtx_len,u16,
msgdata,tx_add_input,prevtx,byte,prevtx_len
msgdata,tx_add_input,prevtx_vout,u32,
@@ -48,16 +48,16 @@
tlvdata,tx_add_input_tlvs,podle_proof,sig,byte,32
msgtype,tx_add_output,67
msgdata,tx_add_output,channel_id,channel_id,
-msgdata,tx_add_output,serial_id,u16,
+msgdata,tx_add_output,serial_id,u64,
msgdata,tx_add_output,sats,u64,
msgdata,tx_add_output,scriptlen,u16,
msgdata,tx_add_output,script,byte,scriptlen
msgtype,tx_remove_input,68
msgdata,tx_remove_input,channel_id,channel_id,
-msgdata,tx_remove_input,serial_id,u16,
+msgdata,tx_remove_input,serial_id,u64,
msgtype,tx_remove_output,69
msgdata,tx_remove_output,channel_id,channel_id,
-msgdata,tx_remove_output,serial_id,u16,
+msgdata,tx_remove_output,serial_id,u64,
msgtype,tx_complete,70
msgdata,tx_complete,channel_id,channel_id,
msgtype,tx_signatures,71
@@ -125,7 +125,9 @@
msgtype,open_channel2,64
msgdata,open_channel2,chain_hash,chain_hash,
msgdata,open_channel2,podle_h2,sha256,
-msgdata,open_channel2,feerate_per_kw_funding,u32,
+msgdata,open_channel2,feerate_funding_max,u32,
+msgdata,open_channel2,feerate_funding_min,u32,
+msgdata,open_channel2,feerate_funding_best,u32,
msgdata,open_channel2,funding_satoshis,u64,
msgdata,open_channel2,dust_limit_satoshis,u64,
msgdata,open_channel2,max_htlc_value_in_flight_msat,u64,
@@ -148,6 +150,7 @@
msgtype,accept_channel2,65
msgdata,accept_channel2,channel_id,channel_id,
msgdata,accept_channel2,funding_satoshis,u64,
+msgdata,accept_channel2,feerate_funding,u32,
msgdata,accept_channel2,dust_limit_satoshis,u64,
msgdata,accept_channel2,max_htlc_value_in_flight_msat,u64,
msgdata,accept_channel2,htlc_minimum_msat,u64,
Loading…
Cancel
Save