Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dual-funding spec edits, cleanup #4410

Merged
merged 7 commits into from
Mar 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bitcoin/psbt.c
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ void psbt_txid(const tal_t *ctx,
wally_tx_free(tx);
}

struct amount_sat psbt_compute_fee(struct wally_psbt *psbt)
struct amount_sat psbt_compute_fee(const struct wally_psbt *psbt)
{
struct amount_sat fee, input_amt;
struct amount_asset asset;
Expand Down
2 changes: 1 addition & 1 deletion bitcoin/psbt.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ struct amount_sat psbt_output_get_amount(const struct wally_psbt *psbt,
*
* @psbt -psbt
*/
struct amount_sat psbt_compute_fee(struct wally_psbt *psbt);
struct amount_sat psbt_compute_fee(const struct wally_psbt *psbt);

/* psbt_has_input - Is this input present on this psbt
*
Expand Down
9 changes: 7 additions & 2 deletions bitcoin/tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,14 +443,19 @@ u8 *linearize_wtx(const tal_t *ctx, const struct wally_tx *wtx)
return arr;
}

size_t bitcoin_tx_weight(const struct bitcoin_tx *tx)
size_t wally_tx_weight(const struct wally_tx *wtx)
{
size_t weight;
int ret = wally_tx_get_weight(tx->wtx, &weight);
int ret = wally_tx_get_weight(wtx, &weight);
assert(ret == WALLY_OK);
return weight;
}

size_t bitcoin_tx_weight(const struct bitcoin_tx *tx)
{
return wally_tx_weight(tx->wtx);
}

void wally_txid(const struct wally_tx *wtx, struct bitcoin_txid *txid)
{
u8 *arr;
Expand Down
1 change: 1 addition & 0 deletions bitcoin/tx.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ u8 *linearize_wtx(const tal_t *ctx, const struct wally_tx *wtx);

/* Get weight of tx in Sipa. */
size_t bitcoin_tx_weight(const struct bitcoin_tx *tx);
size_t wally_tx_weight(const struct wally_tx *wtx);

/* Allocate a tx: you just need to fill in inputs and outputs (they're
* zeroed with inputs' sequence_number set to FFFFFFFF) */
Expand Down
1 change: 0 additions & 1 deletion channeld/channeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -1875,7 +1875,6 @@ static void peer_in(struct peer *peer, const u8 *msg)
return;
case WIRE_INIT_RBF:
case WIRE_ACK_RBF:
case WIRE_BLACKLIST_PODLE:
#endif
break;

Expand Down
20 changes: 19 additions & 1 deletion common/channel_id.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void derive_channel_id_v2(struct channel_id *channel_id,
const struct pubkey *basepoint_1,
const struct pubkey *basepoint_2)
{
/* BOLT-df8bb5994d99e4c78053f7cb57694795f8393dc5 #2:
/* BOLT-f53ca2301232db780843e894f55d95d512f297f9 #2:
* `channel_id`, v2
* For channels established using the v2 protocol, the
* `channel_id` is the
Expand Down Expand Up @@ -47,6 +47,24 @@ void derive_channel_id_v2(struct channel_id *channel_id,
memcpy(channel_id, &sha, sizeof(*channel_id));
}

void derive_tmp_channel_id(struct channel_id *channel_id,
const struct pubkey *opener_basepoint)
{
struct sha256 sha;

/* BOLT-f53ca2301232db780843e894f55d95d512f297f9 #2:
* If the peer's revocation basepoint is unknown
* (e.g. `open_channel2`), a temporary `channel_id` should be
* found by using a zeroed out basepoint for the unknown peer.
*/
u8 der_keys[PUBKEY_CMPR_LEN * 2];
memset(der_keys, 0, PUBKEY_CMPR_LEN);
pubkey_to_der(der_keys + PUBKEY_CMPR_LEN, opener_basepoint);
sha256(&sha, der_keys, sizeof(der_keys));
BUILD_ASSERT(sizeof(*channel_id) == sizeof(sha));
memcpy(channel_id, &sha, sizeof(*channel_id));
}

/* BOLT #2:
*
* The sending node:
Expand Down
10 changes: 9 additions & 1 deletion common/channel_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,22 @@ struct channel_id {
/* Define channel_id_eq (no padding) */
STRUCTEQ_DEF(channel_id, 0, id);

/* For v1 channel establishment */
void derive_channel_id(struct channel_id *channel_id,
const struct bitcoin_txid *txid, u16 txout);

/* For v1 channel establishment */
void temporary_channel_id(struct channel_id *channel_id);

/* For v2 channel establishment */
void derive_channel_id_v2(struct channel_id *channel_id,
const struct pubkey *basepoint_1,
const struct pubkey *basepoint_2);

void temporary_channel_id(struct channel_id *channel_id);
/* For v2 channel establishment */
void derive_tmp_channel_id(struct channel_id *channel_id,
const struct pubkey *opener_basepoint);

/* Marshalling/unmarshalling functions */
void towire_channel_id(u8 **pptr, const struct channel_id *channel_id);
void fromwire_channel_id(const u8 **cursor, size_t *max,
Expand Down
4 changes: 2 additions & 2 deletions common/psbt_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ psbt_to_witness_stacks(const tal_t *ctx,
/* FIXME: throw an error ? */
return NULL;

/* BOLT-78de9a79b491ae9fb84b1fdb4546bacf642dce87 #2:
* - if is the `initiator`:
/* BOLT-f53ca2301232db780843e894f55d95d512f297f9 #2:
* - if is the *initiator*:
* - MUST send even `serial_id`s
*/
if (serial_id % 2 == side_to_stack) {
Expand Down
1 change: 0 additions & 1 deletion gossipd/gossipd.c
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,6 @@ static struct io_plan *peer_msg_in(struct io_conn *conn,
case WIRE_ACCEPT_CHANNEL2:
case WIRE_INIT_RBF:
case WIRE_ACK_RBF:
case WIRE_BLACKLIST_PODLE:
#endif
status_broken("peer %s: relayed unexpected msg of type %s",
type_to_string(tmpctx, struct node_id, &peer->id),
Expand Down
Loading