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

BOLT update, including payment metadata support #5086

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 Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ CCANDIR := ccan

# Where we keep the BOLT RFCs
BOLTDIR := ../lightning-rfc/
DEFAULT_BOLTVERSION := 498f104fd399488c77f449d05cb21c0b604636a2
DEFAULT_BOLTVERSION := e60d594abf436e768116684080997a8d4f960263
# Can be overridden on cmdline.
BOLTVERSION := $(DEFAULT_BOLTVERSION)

Expand Down
60 changes: 33 additions & 27 deletions channeld/channeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,8 @@ static void handle_peer_feechange(struct peer *peer, const u8 *msg)
* A receiving node:
*...
* - if the sender is not responsible for paying the Bitcoin fee:
* - MUST fail the channel.
* - MUST send a `warning` and close the connection, or send an
* `error` and fail the channel.
*/
if (peer->channel->opener != REMOTE)
peer_failed_warn(peer->pps, &peer->channel_id,
Expand All @@ -742,7 +743,8 @@ static void handle_peer_feechange(struct peer *peer, const u8 *msg)
* A receiving node:
* - if the `update_fee` is too low for timely processing, OR is
* unreasonably large:
* - SHOULD fail the channel.
* - MUST send a `warning` and close the connection, or send an
* `error` and fail the channel.
*/
if (!feerate_same_or_better(peer->channel, feerate,
peer->feerate_min, peer->feerate_max))
Expand All @@ -757,7 +759,8 @@ static void handle_peer_feechange(struct peer *peer, const u8 *msg)
*
* - if the sender cannot afford the new fee rate on the receiving
* node's current commitment transaction:
* - SHOULD fail the channel,
* - SHOULD send a `warning` and close the connection, or send an
* `error` and fail the channel.
* - but MAY delay this check until the `update_fee` is committed.
*/
if (!channel_update_feerate(peer->channel, feerate))
Expand Down Expand Up @@ -1104,7 +1107,7 @@ static struct bitcoin_signature *unraw_sigs(const tal_t *ctx,
*...
* * if `option_anchors` applies to this commitment
* transaction, `SIGHASH_SINGLE|SIGHASH_ANYONECANPAY` is
* used.
* used as described in [BOLT #5]
*/
if (option_anchor_outputs)
sigs[i].sighash_type = SIGHASH_SINGLE|SIGHASH_ANYONECANPAY;
Expand Down Expand Up @@ -1627,7 +1630,8 @@ static void handle_peer_commit_sig(struct peer *peer, const u8 *msg)
* - once all pending updates are applied:
* - if `signature` is not valid for its local commitment transaction
* OR non-compliant with LOW-S-standard rule...:
* - MUST fail the channel.
* - MUST send a `warning` and close the connection, or send an
* `error` and fail the channel.
*/
if (!check_tx_sig(txs[0], 0, NULL, funding_wscript,
&peer->channel->funding_pubkey[REMOTE], &commit_sig)) {
Expand All @@ -1651,7 +1655,8 @@ static void handle_peer_commit_sig(struct peer *peer, const u8 *msg)
*...
* - if `num_htlcs` is not equal to the number of HTLC outputs in the
* local commitment transaction:
* - MUST fail the channel.
* - MUST send a `warning` and close the connection, or send an
* `error` and fail the channel.
*/
if (tal_count(htlc_sigs) != tal_count(txs) - 1)
peer_failed_warn(peer->pps, &peer->channel_id,
Expand All @@ -1662,7 +1667,8 @@ static void handle_peer_commit_sig(struct peer *peer, const u8 *msg)
*
* - if any `htlc_signature` is not valid for the corresponding HTLC
* transaction OR non-compliant with LOW-S-standard rule...:
* - MUST fail the channel.
* - MUST send a `warning` and close the connection, or send an
* `error` and fail the channel.
*/
for (i = 0; i < tal_count(htlc_sigs); i++) {
u8 *wscript;
Expand Down Expand Up @@ -1813,13 +1819,13 @@ static void handle_peer_revoke_and_ack(struct peer *peer, const u8 *msg)
* A receiving node:
* - if `per_commitment_secret` is not a valid secret key or does not
* generate the previous `per_commitment_point`:
* - MUST fail the channel.
* - MUST send an `error` and fail the channel.
*/
memcpy(&privkey, &old_commit_secret, sizeof(privkey));
if (!pubkey_from_privkey(&privkey, &per_commit_point)) {
peer_failed_warn(peer->pps, &peer->channel_id,
"Bad privkey %s",
type_to_string(msg, struct privkey, &privkey));
peer_failed_err(peer->pps, &peer->channel_id,
"Bad privkey %s",
type_to_string(msg, struct privkey, &privkey));
}
if (!pubkey_eq(&per_commit_point, &peer->old_remote_per_commit)) {
peer_failed_err(peer->pps, &peer->channel_id,
Expand Down Expand Up @@ -1957,7 +1963,8 @@ static void handle_peer_fail_malformed_htlc(struct peer *peer, const u8 *msg)
*
* - if the `BADONION` bit in `failure_code` is not set for
* `update_fail_malformed_htlc`:
* - MUST fail the channel.
* - MUST send a `warning` and close the connection, or send an
* `error` and fail the channel.
*/
if (!(failure_code & BADONION)) {
peer_failed_warn(peer->pps, &peer->channel_id,
Expand Down Expand Up @@ -2011,17 +2018,18 @@ static void handle_peer_shutdown(struct peer *peer, const u8 *shutdown)
* feature, and the receiving node received a non-zero-length
* `shutdown_scriptpubkey` in `open_channel` or `accept_channel`, and
* that `shutdown_scriptpubkey` is not equal to `scriptpubkey`:
* - MAY send a `warning`.
* - MUST fail the connection.
*/
/* openingd only sets this if feature was negotiated at opening. */
if (tal_count(peer->remote_upfront_shutdown_script)
&& !memeq(scriptpubkey, tal_count(scriptpubkey),
peer->remote_upfront_shutdown_script,
tal_count(peer->remote_upfront_shutdown_script)))
peer_failed_err(peer->pps, &peer->channel_id,
"scriptpubkey %s is not as agreed upfront (%s)",
tal_hex(peer, scriptpubkey),
tal_hex(peer, peer->remote_upfront_shutdown_script));
peer_failed_warn(peer->pps, &peer->channel_id,
"scriptpubkey %s is not as agreed upfront (%s)",
tal_hex(peer, scriptpubkey),
tal_hex(peer, peer->remote_upfront_shutdown_script));

/* We only accept an wrong_funding if:
* 1. It was negotiated.
Expand Down Expand Up @@ -2460,8 +2468,7 @@ static void resend_commitment(struct peer *peer, struct changed_htlc *last)
/* BOLT #2:
*
* A receiving node:
* - if `option_static_remotekey` or `option_anchors` applies to the
* commitment transaction:
* - if `option_static_remotekey` applies to the commitment transaction:
* - if `next_revocation_number` is greater than expected above, AND
* `your_last_per_commitment_secret` is correct for that
* `next_revocation_number` minus 1:
Expand Down Expand Up @@ -2507,7 +2514,7 @@ static void check_future_dataloss_fields(struct peer *peer,

/* BOLT #2:
* - MUST NOT broadcast its commitment transaction.
* - SHOULD fail the channel.
* - SHOULD send an `error` to request the peer to fail the channel.
* - SHOULD store `my_current_per_commitment_point` to
* retrieve funds should the sending node broadcast its
* commitment transaction on-chain.
Expand All @@ -2524,16 +2531,15 @@ static void check_future_dataloss_fields(struct peer *peer,
/* BOLT #2:
*
* A receiving node:
* - if `option_static_remotekey` or `option_anchors` applies to the
* commitment transaction:
* - if `option_static_remotekey` applies to the commitment transaction:
* ...
* - if `your_last_per_commitment_secret` does not match the expected values:
* - SHOULD fail the channel.
* - SHOULD send an `error` and fail the channel.
* - otherwise, if it supports `option_data_loss_protect`:
*...
* - otherwise (`your_last_per_commitment_secret` or
* `my_current_per_commitment_point` do not match the expected values):
* - SHOULD fail the channel.
* - SHOULD send an `error` and fail the channel.
*/
static void check_current_dataloss_fields(struct peer *peer,
u64 next_revocation_number,
Expand Down Expand Up @@ -2789,7 +2795,7 @@ static void peer_reconnect(struct peer *peer,
* of the next `commitment_signed` it expects to receive.
* - MUST set `next_revocation_number` to the commitment number
* of the next `revoke_and_ack` message it expects to receive.
* - if `option_static_remotekey` or `option_anchors` applies to the commitment transaction:
* - if `option_static_remotekey` applies to the commitment transaction:
* - MUST set `my_current_per_commitment_point` to a valid point.
* - otherwise:
* - MUST set `my_current_per_commitment_point` to its commitment
Expand Down Expand Up @@ -2950,10 +2956,10 @@ static void peer_reconnect(struct peer *peer,
* - if `next_revocation_number` is not equal to 1 greater
* than the commitment number of the last `revoke_and_ack` the
* receiving node has sent:
* - SHOULD fail the channel.
* - SHOULD send an `error` and fail the channel.
* - if it has not sent `revoke_and_ack`, AND
* `next_revocation_number` is not equal to 0:
* - SHOULD fail the channel.
* - SHOULD send an `error` and fail the channel.
*/
if (next_revocation_number == peer->next_index[LOCAL] - 2) {
/* Don't try to retransmit revocation index -1! */
Expand Down Expand Up @@ -3021,7 +3027,7 @@ static void peer_reconnect(struct peer *peer,
* - if `next_commitment_number` is not 1 greater than the
* commitment number of the last `commitment_signed` message the
* receiving node has sent:
* - SHOULD fail the channel.
* - SHOULD send an `error` and fail the channel.
*/
} else if (next_commitment_number != peer->next_index[REMOTE])
peer_failed_err(peer->pps,
Expand Down
30 changes: 20 additions & 10 deletions channeld/full_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,8 @@ static enum channel_add_err add_htlc(struct channel *channel,
*...
* - if sending node sets `cltv_expiry` to greater or equal to
* 500000000:
* - SHOULD fail the channel.
* - SHOULD send a `warning` and close the connection, or send an
* `error` and fail the channel.
*/
if (!blocks_to_abs_locktime(cltv_expiry, &htlc->expiry)) {
return CHANNEL_ERR_INVALID_EXPIRY;
Expand All @@ -584,7 +585,8 @@ static enum channel_add_err add_htlc(struct channel *channel,
* A receiving node:
* - receiving an `amount_msat` equal to 0, OR less than its own
* `htlc_minimum_msat`:
* - SHOULD fail the channel.
* - SHOULD send a `warning` and close the connection, or send an
* `error` and fail the channel.
*/
if (amount_msat_eq(htlc->amount, AMOUNT_MSAT(0))) {
return CHANNEL_ERR_HTLC_BELOW_MINIMUM;
Expand Down Expand Up @@ -615,7 +617,8 @@ static enum channel_add_err add_htlc(struct channel *channel,
*
* - if a sending node adds more than receiver `max_accepted_htlcs`
* HTLCs to its local commitment transaction...
* - SHOULD fail the channel.
* - SHOULD send a `warning` and close the connection, or send an
* `error` and fail the channel.
*/
if (htlc_count + 1 > channel->config[recipient].max_accepted_htlcs) {
return CHANNEL_ERR_TOO_MANY_HTLCS;
Expand Down Expand Up @@ -652,7 +655,8 @@ static enum channel_add_err add_htlc(struct channel *channel,
* - if a sending node... adds more than receiver
* `max_htlc_value_in_flight_msat` worth of offered HTLCs to its
* local commitment transaction:
* - SHOULD fail the channel.
* - SHOULD send a `warning` and close the connection, or send an
* `error` and fail the channel.
*/

/* We don't enforce this for channel_force_htlcs: some might already
Expand All @@ -670,7 +674,8 @@ static enum channel_add_err add_htlc(struct channel *channel,
* - receiving an `amount_msat` that the sending node cannot afford at
* the current `feerate_per_kw` (while maintaining its channel
* reserve and any `to_local_anchor` and `to_remote_anchor` costs):
* - SHOULD fail the channel.
* - SHOULD send a `warning` and close the connection, or send an
* `error` and fail the channel.
*/
if (enforce_aggregate_limits) {
struct amount_msat remainder;
Expand Down Expand Up @@ -894,7 +899,8 @@ enum channel_remove_err channel_fulfill_htlc(struct channel *channel,
*
* - if the `payment_preimage` value in `update_fulfill_htlc`
* doesn't SHA256 hash to the corresponding HTLC `payment_hash`:
* - MUST fail the channel.
* - MUST send a `warning` and close the connection, or send an
* `error` and fail the channel.
*/
if (!sha256_eq(&hash, &htlc->rhash))
return CHANNEL_ERR_BAD_PREIMAGE;
Expand All @@ -905,7 +911,8 @@ enum channel_remove_err channel_fulfill_htlc(struct channel *channel,
*
* - if the `id` does not correspond to an HTLC in its current
* commitment transaction:
* - MUST fail the channel.
* - MUST send a `warning` and close the connection, or send an
* `error` and fail the channel.
*/
if (!htlc_has(htlc, HTLC_FLAG(!htlc_owner(htlc), HTLC_F_COMMITTED))) {
status_unusual("channel_fulfill_htlc: %"PRIu64" in state %s",
Expand Down Expand Up @@ -957,7 +964,8 @@ enum channel_remove_err channel_fail_htlc(struct channel *channel,
* A receiving node:
* - if the `id` does not correspond to an HTLC in its current
* commitment transaction:
* - MUST fail the channel.
* - MUST send a `warning` and close the connection, or send an
* `error` and fail the channel.
*/
if (!htlc_has(htlc, HTLC_FLAG(!htlc_owner(htlc), HTLC_F_COMMITTED))) {
status_unusual("channel_fail_htlc: %"PRIu64" in state %s",
Expand Down Expand Up @@ -1145,7 +1153,8 @@ static int change_htlcs(struct channel *channel,
*...
* - if the sender cannot afford the new fee rate on the receiving node's
* current commitment transaction:
* - SHOULD fail the channel,
* - SHOULD send a `warning` and close the connection, or send an
* `error` and fail the channel.
*/
u32 approx_max_feerate(const struct channel *channel)
{
Expand Down Expand Up @@ -1257,7 +1266,8 @@ bool can_opener_afford_feerate(const struct channel *channel, u32 feerate_per_kw
*
* - if the sender cannot afford the new fee rate on the receiving
* node's current commitment transaction:
* - SHOULD fail the channel
* - SHOULD send a `warning` and close the connection, or send an
* `error` and fail the channel.
*/
/* Note: sender == opener */

Expand Down
7 changes: 5 additions & 2 deletions closingd/closingd.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ receive_offer(struct per_peer_state *pps,
* - if the `signature` is not valid for either variant of closing transaction
* specified in [BOLT #3](03-transactions.md#closing-transaction)
* OR non-compliant with LOW-S-standard rule...:
* - MUST fail the connection.
* - MUST send a `warning` and close the connection, or send an
* `error` and fail the channel.
*/
tx = close_tx(tmpctx, chainparams, pps, channel_id,
local_wallet_index,
Expand Down Expand Up @@ -706,8 +707,10 @@ static void do_quickclose(struct amount_sat offer[NUM_SIDES],
/* BOLT #2:
* - if the message contains a `fee_range`:
* - if there is no overlap between that and its own `fee_range`:
* - SHOULD fail the connection
* - SHOULD send a warning
* - MUST fail the channel if it doesn't receive a satisfying `fee_range` after a reasonable amount of time
*/
/* (Note we satisfy the "MUST fail" by our close command unilteraltimeout) */
if (!get_overlap(our_feerange, their_feerange, &overlap)) {
peer_failed_warn(pps, channel_id,
"Unable to agree on a feerate."
Expand Down
Loading