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

Relax closing fee requirements, implement quickclose #4599

Merged
merged 10 commits into from
Sep 9, 2021
Merged
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 := 3508e4e85d26240ae7492c3d2e02770cdc360fe9
DEFAULT_BOLTVERSION := 498f104fd399488c77f449d05cb21c0b604636a2
# Can be overridden on cmdline.
BOLTVERSION := $(DEFAULT_BOLTVERSION)

Expand Down
12 changes: 8 additions & 4 deletions channeld/channeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -1173,7 +1173,7 @@ static struct bitcoin_signature *unraw_sigs(const tal_t *ctx,
/* BOLT #3:
* ## HTLC-Timeout and HTLC-Success Transactions
*...
* * if `option_anchor_outputs` applies to this commitment
* * if `option_anchors` applies to this commitment
* transaction, `SIGHASH_SINGLE|SIGHASH_ANYONECANPAY` is
* used.
*/
Expand Down Expand Up @@ -2489,7 +2489,8 @@ static void resend_commitment(struct peer *peer, struct changed_htlc *last)
/* BOLT #2:
*
* A receiving node:
* - if `option_static_remotekey` applies to the commitment transaction:
* - if `option_static_remotekey` or `option_anchors` 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 @@ -2552,7 +2553,8 @@ static void check_future_dataloss_fields(struct peer *peer,
/* BOLT #2:
*
* A receiving node:
* - if `option_static_remotekey` applies to the commitment transaction:
* - if `option_static_remotekey` or `option_anchors` applies to the
* commitment transaction:
* ...
* - if `your_last_per_commitment_secret` does not match the expected values:
* - SHOULD fail the channel.
Expand Down Expand Up @@ -2764,7 +2766,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` applies to the commitment transaction:
* - if `option_static_remotekey` or `option_anchors` 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 @@ -3789,6 +3791,8 @@ static void init_channel(struct peer *peer)
&funding_pubkey[REMOTE],
option_static_remotekey,
option_anchor_outputs,
feature_offered(peer->their_features,
OPT_LARGE_CHANNELS),
opener);

if (!channel_force_htlcs(peer->channel,
Expand Down
6 changes: 3 additions & 3 deletions channeld/commit_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
base_fee.satoshis /* Raw: spec uses raw numbers */);

/* BOLT #3:
* If `option_anchor_outputs` applies to the commitment
* If `option_anchors` applies to the commitment
* transaction, also subtract two times the fixed anchor size
* of 330 sats from the funder (either `to_local` or
* `to_remote`).
Expand Down Expand Up @@ -281,7 +281,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
*
* #### `to_remote` Output
*
* If `option_anchor_outputs` applies to the commitment
* If `option_anchors` applies to the commitment
* transaction, the `to_remote` output is encumbered by a one
* block csv lock.
* <remote_pubkey> OP_CHECKSIGVERIFY 1 OP_CHECKSEQUENCEVERIFY
Expand Down Expand Up @@ -329,7 +329,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,

/* BOLT #3:
*
* 8. If `option_anchor_outputs` applies to the commitment transaction:
* 8. If `option_anchors` applies to the commitment transaction:
* * if `to_local` exists or there are untrimmed HTLCs, add a
* [`to_local_anchor` output]...
* * if `to_remote` exists or there are untrimmed HTLCs, add a
Expand Down
14 changes: 9 additions & 5 deletions channeld/full_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ struct channel *new_full_channel(const tal_t *ctx,
const struct pubkey *remote_funding_pubkey,
bool option_static_remotekey,
bool option_anchor_outputs,
bool option_wumbo,
enum side opener)
{
struct channel *channel = new_initial_channel(ctx,
Expand All @@ -128,6 +129,7 @@ struct channel *new_full_channel(const tal_t *ctx,
remote_funding_pubkey,
option_static_remotekey,
option_anchor_outputs,
option_wumbo,
opener);

if (channel) {
Expand Down Expand Up @@ -576,15 +578,17 @@ static enum channel_add_err add_htlc(struct channel *channel,
return CHANNEL_ERR_HTLC_BELOW_MINIMUM;
}

/* BOLT #2:
/* FIXME: There used to be a requirement that we not send more than
* 2^32 msat, *but* only electrum enforced it. Remove in next version:
*
* A sending node:
*...
* - for channels with `chain_hash` identifying the Bitcoin blockchain:
* - MUST set the four most significant bytes of `amount_msat` to 0.
*/
if (sender == LOCAL
&& amount_msat_greater(htlc->amount, chainparams->max_payment)) {
&& amount_msat_greater(htlc->amount, chainparams->max_payment)
&& !channel->option_wumbo) {
return CHANNEL_ERR_MAX_HTLC_VALUE_EXCEEDED;
}

Expand Down Expand Up @@ -676,7 +680,7 @@ static enum channel_add_err add_htlc(struct channel *channel,
return CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED;

/* BOLT #3:
* If `option_anchor_outputs` applies to the commitment
* If `option_anchors` applies to the commitment
* transaction, also subtract two times the fixed anchor size
* of 330 sats from the funder (either `to_local` or
* `to_remote`).
Expand Down Expand Up @@ -1098,7 +1102,7 @@ u32 approx_max_feerate(const struct channel *channel)
avail = amount_msat_to_sat_round_down(channel->view[!channel->opener].owed[channel->opener]);

/* BOLT #3:
* If `option_anchor_outputs` applies to the commitment
* If `option_anchors` applies to the commitment
* transaction, also subtract two times the fixed anchor size
* of 330 sats from the funder (either `to_local` or
* `to_remote`).
Expand Down Expand Up @@ -1139,7 +1143,7 @@ bool can_opener_afford_feerate(const struct channel *channel, u32 feerate_per_kw
channel->option_anchor_outputs);

/* BOLT #3:
* If `option_anchor_outputs` applies to the commitment
* If `option_anchors` applies to the commitment
* transaction, also subtract two times the fixed anchor size
* of 330 sats from the funder (either `to_local` or
* `to_remote`).
Expand Down
2 changes: 2 additions & 0 deletions channeld/full_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ struct existing_htlc;
* @remote_fundingkey: remote funding key
* @option_static_remotekey: use `option_static_remotekey`.
* @option_anchor_outputs: use `option_anchor_outputs`.
* @option_wumbo: large channel negotiated.
* @opener: which side initiated it.
*
* Returns state, or NULL if malformed.
Expand All @@ -52,6 +53,7 @@ struct channel *new_full_channel(const tal_t *ctx,
const struct pubkey *remote_funding_pubkey,
bool option_static_remotekey,
bool option_anchor_outputs,
bool option_wumbo,
enum side opener);

/**
Expand Down
2 changes: 1 addition & 1 deletion channeld/test/run-commit_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@ int main(int argc, const char *argv[])
option_anchor_outputs);

/* BOLT #3:
* If `option_anchor_outputs` applies to the commitment
* If `option_anchors` applies to the commitment
* transaction, also subtract two times the fixed anchor size
* of 330 sats from the funder (either `to_local` or
* `to_remote`).
Expand Down
Loading