Browse Source

channeld: fix up BOLT references.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
b40b6240ce
  1. 217
      channeld/channel.c
  2. 37
      channeld/commit_tx.c
  3. 85
      channeld/full_channel.c
  4. 31
      channeld/test/run-full_channel.c

217
channeld/channel.c

@ -96,8 +96,10 @@ struct peer {
/* BOLT #2:
*
* A sending node MUST set `id` to 0 for the first HTLC it offers, and
* increase the value by 1 for each successive offer.
* A sending node:
*...
* - for the first HTLC it offers:
* - MUST set `id` to 0.
*/
u64 htlc_id;
@ -472,9 +474,9 @@ static void channel_announcement_negotiate(struct peer *peer)
}
/* BOLT #7:
*
* If sent, `announcement_signatures` messages MUST NOT be sent until
* `funding_locked` has been sent and the funding transaction has
* at least 6 confirmations.
* - MUST NOT send `announcement_signatures` messages until
* `funding_locked` has been sent AND the funding transaction has
* at least six confirmations.
*/
if (peer->announce_depth_reached && !peer->have_sigs[LOCAL]) {
send_announcement_signatures(peer);
@ -494,8 +496,10 @@ static void handle_peer_funding_locked(struct peer *peer, const u8 *msg)
/* BOLT #2:
*
* On reconnection, a node MUST ignore a redundant `funding_locked` if
* it receives one.
* A node:
*...
* - upon reconnection:
* - MUST ignore any redundant `funding_locked` it receives.
*/
if (peer->funding_locked[REMOTE])
return;
@ -632,8 +636,10 @@ static void handle_peer_feechange(struct peer *peer, const u8 *msg)
/* BOLT #2:
*
* A receiving node MUST fail the channel if the sender is not
* responsible for paying the bitcoin fee.
* A receiving node:
*...
* - if the sender is not responsible for paying the Bitcoin fee:
* - MUST fail the channel.
*/
if (peer->channel->funder != REMOTE)
peer_failed(&peer->cs,
@ -645,8 +651,10 @@ static void handle_peer_feechange(struct peer *peer, const u8 *msg)
/* BOLT #2:
*
* A receiving node SHOULD fail the channel if the `update_fee` is too
* low for timely processing, or unreasonably large.
* A receiving node:
* - if the `update_fee` is too low for timely processing, OR is
* unreasonably large:
* - SHOULD fail the channel.
*/
if (feerate < peer->feerate_min || feerate > peer->feerate_max)
peer_failed(&peer->cs,
@ -656,10 +664,10 @@ static void handle_peer_feechange(struct peer *peer, const u8 *msg)
/* BOLT #2:
*
* A receiving node SHOULD fail the channel if the sender cannot
* afford the new fee rate on the receiving node's current commitment
* transaction, but it MAY delay this check until the `update_fee` is
* committed.
* - if the sender cannot afford the new fee rate on the receiving
* node's current commitment transaction:
* - SHOULD fail the channel,
* - but MAY delay this check until the `update_fee` is committed.
*/
if (!channel_update_feerate(peer->channel, feerate))
peer_failed(&peer->cs,
@ -715,8 +723,11 @@ static bool shutdown_complete(const struct peer *peer)
/* BOLT #2:
*
* A node MUST NOT send a `shutdown` if there are updates pending on
* the receiving node's commitment transaction.
* A sending node:
*...
* - if there are updates pending on the receiving node's commitment
* transaction:
* - MUST NOT send a `shutdown`.
*/
/* So we only call this after reestablish or immediately after sending commit */
static void maybe_send_shutdown(struct peer *peer)
@ -845,9 +856,11 @@ static struct commit_sigs *calc_commitsigs(const tal_t *ctx,
/* BOLT #2:
*
* A node MUST include one `htlc_signature` for every HTLC transaction
* corresponding to BIP69 lexicographic ordering of the commitment
* transaction.
* A sending node:
*...
* - MUST include one `htlc_signature` for every HTLC transaction
* corresponding to BIP69 lexicographic ordering of the commitment
* transaction.
*/
commit_sigs->htlc_sigs = tal_arr(commit_sigs, secp256k1_ecdsa_signature,
tal_count(txs) - 1);
@ -941,8 +954,9 @@ static void send_commit(struct peer *peer)
/* BOLT #2:
*
* A node MUST NOT send a `commitment_signed` message which does not
* include any updates.
* A sending node:
* - MUST NOT send a `commitment_signed` message that does not include
* any updates.
*/
changed_htlcs = tal_arr(tmpctx, const struct htlc *, 0);
if (!channel_sending_commit(peer->channel, &changed_htlcs)) {
@ -1137,8 +1151,9 @@ static void handle_peer_commit_sig(struct peer *peer, const u8 *msg)
if (!channel_rcvd_commit(peer->channel, &changed_htlcs)) {
/* BOLT #2:
*
* A node MUST NOT send a `commitment_signed` message which
* does not include any updates.
* A sending node:
* - MUST NOT send a `commitment_signed` message that does not
* include any updates.
*/
peer_failed(&peer->cs,
&peer->channel_id,
@ -1177,9 +1192,10 @@ static void handle_peer_commit_sig(struct peer *peer, const u8 *msg)
type_to_string(tmpctx, struct pubkey, &point));
/* BOLT #2:
*
* A receiving node MUST fail the channel if `signature` is not valid
* for its local commitment transaction once all pending updates are
* applied.
* A receiving node:
* - once all pending updates are applied:
* - if `signature` is not valid for its local commitment transaction:
* - MUST fail the channel.
*/
if (!check_tx_sig(txs[0], 0, NULL, wscripts[0],
&peer->channel->funding_pubkey[REMOTE], &commit_sig)) {
@ -1199,9 +1215,11 @@ static void handle_peer_commit_sig(struct peer *peer, const u8 *msg)
/* BOLT #2:
*
* A receiving node MUST fail the channel if `num_htlcs` is not equal
* to the number of HTLC outputs in the local commitment transaction
* once all pending updates are applied.
* A receiving node:
*...
* - if `num_htlcs` is not equal to the number of HTLC outputs in the
* local commitment transaction:
* - MUST fail the channel.
*/
if (tal_count(htlc_sigs) != tal_count(txs) - 1)
peer_failed(&peer->cs,
@ -1211,9 +1229,9 @@ static void handle_peer_commit_sig(struct peer *peer, const u8 *msg)
/* BOLT #2:
*
* A receiving node MUST fail
* the channel if any `htlc_signature` is not valid for the
* corresponding HTLC transaction.
* - if any `htlc_signature` is not valid for the corresponding HTLC
* transaction:
* - MUST fail the channel.
*/
for (i = 0; i < tal_count(htlc_sigs); i++) {
if (!check_tx_sig(txs[1+i], 0, NULL, wscripts[1+i],
@ -1289,9 +1307,10 @@ static void handle_peer_revoke_and_ack(struct peer *peer, const u8 *msg)
/* BOLT #2:
*
* A receiving node MUST check that `per_commitment_secret` generates
* the previous `per_commitment_point`, and MUST fail if it does
* not.
* A receiving node:
* - if `per_commitment_secret` does not generate the previous
* `per_commitment_point`:
* - MUST fail the channel.
*/
memcpy(&privkey, &old_commit_secret, sizeof(privkey));
if (!pubkey_from_privkey(&privkey, &per_commit_point)) {
@ -1430,8 +1449,9 @@ static void handle_peer_fail_malformed_htlc(struct peer *peer, const u8 *msg)
/* BOLT #2:
*
* A receiving node MUST fail the channel if the `BADONION` bit in
* `failure_code` is not set for `update_fail_malformed_htlc`.
* - if the `BADONION` bit in `failure_code` is not set for
* `update_fail_malformed_htlc`:
* - MUST fail the channel.
*/
if (!(failure_code & BADONION)) {
peer_failed(&peer->cs,
@ -1446,19 +1466,20 @@ static void handle_peer_fail_malformed_htlc(struct peer *peer, const u8 *msg)
/* FIXME: Do this! */
/* BOLT #2:
*
* A receiving node MAY check the `sha256_of_onion`
* in `update_fail_malformed_htlc` and MAY retry or choose an
* alternate error response if it does not match the onion it
* sent.
* - if the `sha256_of_onion` in `update_fail_malformed_htlc`
* doesn't match the onion it sent:
* - MAY retry or choose an alternate error response.
*/
/* BOLT #2:
*
* Otherwise, a receiving node which has an outgoing HTLC
* canceled by `update_fail_malformed_htlc` MUST return an
* error in the `update_fail_htlc` sent to the link which
* originally sent the HTLC using the `failure_code` given and
* setting the data to `sha256_of_onion`.
* - otherwise, a receiving node which has an outgoing HTLC
* canceled by `update_fail_malformed_htlc`:
*
* - MUST return an error in the `update_fail_htlc` sent to
* the link which originally sent the HTLC, using the
* `failure_code` given and setting the data to
* `sha256_of_onion`.
*/
fail = tal_arr(htlc, u8, 0);
towire_u16(&fail, failure_code);
@ -1653,10 +1674,11 @@ static void resend_commitment(struct peer *peer, const struct changed_htlc *last
/* BOLT #2:
*
* If `next_local_commitment_number` is equal to the commitment number
* of the last `commitment_signed` message the receiving node has
* sent, it MUST reuse the same commitment number for its next
* `commitment_signed`
* - if `next_local_commitment_number` is equal to the commitment
* number of the last `commitment_signed` message the receiving node
* has sent:
* - MUST reuse the same commitment number for its next
* `commitment_signed`.
*/
/* In our case, we consider ourselves already committed to this, so
* retransmission is simplest. */
@ -1748,16 +1770,20 @@ static void peer_reconnect(struct peer *peer)
/* BOLT #2:
*
* On reconnection, a node MUST transmit `channel_reestablish` for
* each channel, and MUST wait for to receive the other node's
* `channel_reestablish` message before sending any other messages for
* that channel.
* - upon reconnection:
* - if a channel is in an error state:
* - SHOULD retransmit the error packet and ignore any other packets for
* that channel.
* - otherwise:
* - MUST transmit `channel_reestablish` for each channel.
* - MUST wait to receive the other node's `channel_reestablish`
* message before sending any other messages for that channel.
*
* The sending node MUST set `next_local_commitment_number` to the
* commitment number of the next `commitment_signed` it expects to
* receive, and MUST set `next_remote_revocation_number` to the
* commitment number of the next `revoke_and_ack` message it expects
* to receive.
* The sending node:
* - MUST set `next_local_commitment_number` to the commitment number
* of the next `commitment_signed` it expects to receive.
* - MUST set `next_remote_revocation_number` to the commitment number
* of the next `revoke_and_ack` message it expects to receive.
*/
msg = towire_channel_reestablish(NULL, &peer->channel_id,
peer->next_index[LOCAL],
@ -1787,9 +1813,11 @@ static void peer_reconnect(struct peer *peer)
/* BOLT #2:
*
* If `next_local_commitment_number` is 1 in both the
* `channel_reestablish` it sent and received, then the node MUST
* retransmit `funding_locked`, otherwise it MUST NOT.
* - if `next_local_commitment_number` is 1 in both the
* `channel_reestablish` it sent and received:
* - MUST retransmit `funding_locked`.
* - otherwise:
* - MUST NOT retransmit `funding_locked`.
*/
if (peer->funding_locked[LOCAL]
&& peer->next_index[LOCAL] == 1
@ -1811,13 +1839,16 @@ static void peer_reconnect(struct peer *peer)
/* BOLT #2:
*
* If `next_remote_revocation_number` is equal to the commitment
* number of the last `revoke_and_ack` the receiving node has sent and the receiving node has not already received a `closing_signed`, it
* MUST re-send the `revoke_and_ack`, otherwise if
* `next_remote_revocation_number` is not equal to one greater than
* the commitment number of the last `revoke_and_ack` the receiving
* node has sent (or equal to zero if none have been sent), it SHOULD
* fail the channel.
* - if `next_local_commitment_number` is equal to the commitment
* number of the last `commitment_signed` message the receiving node
* has sent:
* - MUST reuse the same commitment number for its next
* `commitment_signed`.
* - otherwise:
* - if `next_local_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.
*/
if (next_remote_revocation_number == peer->next_index[LOCAL] - 2) {
/* Don't try to retransmit revocation index -1! */
@ -1846,10 +1877,11 @@ static void peer_reconnect(struct peer *peer)
/* BOLT #2:
*
* If `next_local_commitment_number` is equal to the commitment number
* of the last `commitment_signed` message the receiving node has
* sent, it MUST reuse the same commitment number for its next
* `commitment_signed`
* - if `next_local_commitment_number` is equal to the commitment
* number of the last `commitment_signed` message the receiving node
* has sent:
* - MUST reuse the same commitment number for its next
* `commitment_signed`.
*/
if (next_local_commitment_number == peer->next_index[REMOTE] - 1) {
/* We completed opening, we don't re-transmit that one! */
@ -1864,9 +1896,11 @@ static void peer_reconnect(struct peer *peer)
/* BOLT #2:
*
* ... otherwise if `next_local_commitment_number` is not one greater
* than the commitment number of the last `commitment_signed` message
* the receiving node has sent, it SHOULD fail the channel.
* - otherwise:
* - if `next_local_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.
*/
} else if (next_local_commitment_number != peer->next_index[REMOTE])
peer_failed(&peer->cs,
@ -1882,11 +1916,11 @@ static void peer_reconnect(struct peer *peer)
/* BOLT #2:
*
* On reconnection if the node has sent a previous `closing_signed` it
* MUST send another `closing_signed`, otherwise if the node has sent
* a previous `shutdown` it MUST retransmit it.
* - upon reconnection:
* - if it has sent a previous `shutdown`:
* - MUST retransmit `shutdown`.
*/
/* If we had sent `closing_signed`, we'd be in closingd. */
/* (If we had sent `closing_signed`, we'd be in closingd). */
maybe_send_shutdown(peer);
/* Corner case: we didn't send shutdown before because update_add_htlc
@ -2051,18 +2085,19 @@ static void handle_feerates(struct peer *peer, const u8 *inmsg)
/* BOLT #2:
*
* The node which is responsible for paying the bitcoin fee SHOULD
* send `update_fee` to ensure the current fee rate is sufficient for
* timely processing of the commitment transaction by a significant
* margin. */
* The node _responsible_ for paying the Bitcoin fee:
* - SHOULD send `update_fee` to ensure the current fee rate is
* sufficient (by a significant margin) for timely processing of the
* commitment transaction.
*/
if (peer->channel->funder == LOCAL) {
peer->desired_feerate = feerate;
start_commit_timer(peer);
} else {
/* BOLT #2:
*
* The node which is not responsible for paying the bitcoin
* fee MUST NOT send `update_fee`.
* The node _not responsible_ for paying the Bitcoin fee:
* - MUST NOT send `update_fee`.
*/
/* FIXME: We could drop to chain if fees are too low, but
* that's fraught too. */
@ -2285,9 +2320,11 @@ static void handle_ping_cmd(struct peer *peer, const u8 *inmsg)
/* BOLT #1:
*
* if `num_pong_bytes` is less than 65532 it MUST respond by sending a
* `pong` message with `byteslen` equal to `num_pong_bytes`, otherwise
* it MUST ignore the `ping`.
* - if `num_pong_bytes` is less than 65532:
* - MUST respond by sending a `pong` message, with `byteslen` equal
* to `num_pong_bytes`.
* - otherwise (`num_pong_bytes` is **not** less than 65532):
* - MUST ignore the `ping`.
*/
if (num_pong_bytes >= 65532)
wire_sync_write(MASTER_FD,

37
channeld/commit_tx.c

@ -19,21 +19,24 @@ static bool trim(const struct htlc *htlc,
/* BOLT #3:
*
* For every offered HTLC, if the HTLC amount minus the HTLC-timeout
* fee would be less than `dust_limit_satoshis` set by the transaction
* owner, the commitment transaction MUST NOT contain that output,
* otherwise it MUST be generated as specified in [Offered HTLC
* Outputs](#offered-htlc-outputs).
* - for every offered HTLC:
* - if the HTLC amount minus the HTLC-timeout fee would be less than
* `dust_limit_satoshis` set by the transaction owner:
* - MUST NOT contain that output.
* - otherwise:
* - MUST be generated as specified in
* [Offered HTLC Outputs](#offered-htlc-outputs).
*/
if (htlc_owner(htlc) == side)
htlc_fee = htlc_timeout_fee(feerate_per_kw);
/* BOLT #3:
*
* For every received HTLC, if the HTLC amount minus the HTLC-success
* fee would be less than `dust_limit_satoshis` set by the transaction
* owner, the commitment transaction MUST NOT contain that output,
* otherwise it MUST be generated as specified in [Received HTLC
* Outputs](#received-htlc-outputs).
* - for every received HTLC:
* - if the HTLC amount minus the HTLC-success fee would be less than
* `dust_limit_satoshis` set by the transaction owner:
* - MUST NOT contain that output.
* - otherwise:
* - MUST be generated as specified in
*/
else
htlc_fee = htlc_success_fee(feerate_per_kw);
@ -129,7 +132,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
/* BOLT #3:
*
* 3. Subtract this base fee from the funder (either `to_local` or
* `to_remote`), with a floor of zero (see [Fee Payment](#fee-payment)).
* `to_remote`), with a floor of 0 (see [Fee Payment](#fee-payment)).
*/
try_subtract_fee(funder, side, base_fee_msat,
&self_pay_msat, &other_pay_msat);
@ -197,7 +200,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
*
* 5. If the `to_local` amount is greater or equal to
* `dust_limit_satoshis`, add a [`to_local`
* Output](#to-local-output).
* output](#to-local-output).
*/
if (self_pay_msat / 1000 >= dust_limit_satoshis) {
u8 *wscript = to_self_wscript(tmpctx, to_self_delay,keyset);
@ -215,15 +218,15 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
*
* 6. If the `to_remote` amount is greater or equal to
* `dust_limit_satoshis`, add a [`to_remote`
* Output](#to-remote-output).
* output](#to-remote-output).
*/
if (other_pay_msat / 1000 >= dust_limit_satoshis) {
/* BOLT #3:
*
* #### `to_remote` Output
*
* This output sends funds to the other peer, thus is a simple
* P2WPKH to `remotekey`.
* This output sends funds to the other peer and thus is a simple
* P2WPKH to `remotepubkey`.
*/
tx->output[n].amount = other_pay_msat / 1000;
tx->output[n].script = scriptpubkey_p2wpkh(tx,
@ -261,7 +264,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
/* BOLT #3:
*
* * locktime: upper 8 bits are 0x20, lower 24 bits are the lower
* 24 bits of the obscured commitment transaction number.
* 24 bits of the obscured commitment transaction number
*/
tx->lock_time
= (0x20000000 | (obscured_commitment_number & 0xFFFFFF));
@ -278,7 +281,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
/* BOLT #3:
*
* * `txin[0]` sequence: upper 8 bits are 0x80, lower 24 bits are
* upper 24 bits of the obscured commitment transaction number.
* upper 24 bits of the obscured commitment transaction number
*/
tx->input[0].sequence_number
= (0x80000000 | ((obscured_commitment_number>>24) & 0xFFFFFF));

85
channeld/full_channel.c

@ -313,8 +313,11 @@ static enum channel_add_err add_htlc(struct channel *channel,
/* BOLT #2:
*
* A receiving node SHOULD fail the channel if a sending node... sets
* `cltv_expiry` to greater or equal to 500000000.
* A receiving node:
*...
* - if sending node sets `cltv_expiry` to greater or equal to
* 500000000:
* - SHOULD fail the channel.
*/
if (!blocks_to_abs_locktime(cltv_expiry, &htlc->expiry)) {
return CHANNEL_ERR_INVALID_EXPIRY;
@ -342,9 +345,10 @@ static enum channel_add_err add_htlc(struct channel *channel,
/* BOLT #2:
*
* A receiving node SHOULD fail the channel if it receives an
* `amount_msat` equal to zero, below its own `htlc_minimum_msat`,
* or...
* A receiving node:
* - receiving an `amount_msat` equal to 0, OR less than its own
* `htlc_minimum_msat`:
* - SHOULD fail the channel.
*/
if (htlc->msatoshi == 0) {
return CHANNEL_ERR_HTLC_BELOW_MINIMUM;
@ -355,9 +359,8 @@ static enum channel_add_err add_htlc(struct channel *channel,
/* BOLT #2:
*
* For channels with `chain_hash` identifying the Bitcoin blockchain,
* the sending node MUST set the 4 most significant bytes of
* `amount_msat` to zero.
* - for channels with `chain_hash` identifying the Bitcoin blockchain:
* - MUST set the four most significant bytes of `amount_msat` to 0.
*/
if (htlc->msatoshi & 0xFFFFFFFF00000000ULL) {
return CHANNEL_ERR_MAX_HTLC_VALUE_EXCEEDED;
@ -369,9 +372,10 @@ static enum channel_add_err add_htlc(struct channel *channel,
/* BOLT #2:
*
* A receiving node SHOULD fail the channel if a sending node
* adds more than its `max_accepted_htlcs` HTLCs to its local
* commitment transaction */
* - if a sending node adds more than its `max_accepted_htlcs` HTLCs to
* its local commitment transaction...
* - SHOULD fail the channel.
*/
if (enforce_aggregate_limits
&& tal_count(committed) - tal_count(removing) + tal_count(adding)
> max_accepted_htlcs(channel, recipient)) {
@ -384,9 +388,11 @@ static enum channel_add_err add_htlc(struct channel *channel,
/* BOLT #2:
*
* A receiving node SHOULD fail the channel if a sending node ... or
* adds more than its `max_htlc_value_in_flight_msat` worth of offered
* HTLCs to its local commitment transaction */
* - if a sending node... adds more than its
* `max_htlc_value_in_flight_msat` worth of offered HTLCs to its
* local commitment transaction:
* - SHOULD fail the channel.
*/
if (enforce_aggregate_limits
&& msat_in_htlcs > max_htlc_value_in_flight_msat(channel, recipient)) {
return CHANNEL_ERR_MAX_HTLC_VALUE_EXCEEDED;
@ -394,8 +400,12 @@ static enum channel_add_err add_htlc(struct channel *channel,
/* BOLT #2:
*
* or which the sending node cannot afford at the current
* `feerate_per_kw` while maintaining its channel reserve.
* A receiving node:
*...
* - receiving an `amount_msat` that the sending node cannot afford at
* the current `feerate_per_kw` (while maintaining its channel
* reserve):
* - SHOULD fail the channel.
*/
if (channel->funder == htlc_owner(htlc)) {
u32 feerate = view->feerate_per_kw;
@ -501,9 +511,9 @@ enum channel_remove_err channel_fulfill_htlc(struct channel *channel,
sha256(&hash, preimage, sizeof(*preimage));
/* BOLT #2:
*
* A receiving node MUST check that the `payment_preimage` value in
* `update_fulfill_htlc` SHA256 hashes to the corresponding HTLC
* `payment_hash`, and MUST fail the channel if it does not.
* - if the `payment_preimage` value in `update_fulfill_htlc`
* doesn't SHA256 hash to the corresponding HTLC `payment_hash`:
* - MUST fail the channel.
*/
if (!structeq(&hash, &htlc->rhash))
return CHANNEL_ERR_BAD_PREIMAGE;
@ -512,9 +522,9 @@ enum channel_remove_err channel_fulfill_htlc(struct channel *channel,
/* BOLT #2:
*
* A receiving node MUST check that `id` corresponds to an HTLC in its
* current commitment transaction, and MUST fail the channel if it
* does not.
* - if the `id` does not correspond to an HTLC in its current
* commitment transaction:
* - MUST fail the channel.
*/
if (!htlc_has(htlc, HTLC_FLAG(!htlc_owner(htlc), HTLC_F_COMMITTED))) {
status_trace("channel_fulfill_htlc: %"PRIu64" in state %s",
@ -526,9 +536,12 @@ enum channel_remove_err channel_fulfill_htlc(struct channel *channel,
* based on: */
/* BOLT #2:
*
* A node MUST NOT send an `update_fulfill_htlc`, `update_fail_htlc`
* or `update_fail_malformed_htlc` until the corresponding HTLC is
* irrevocably committed in both sides' commitment transactions.
* A node:
*...
* - until the corresponding HTLC is irrevocably committed in both
* sides' commitment transactions:
* - MUST NOT send an `update_fulfill_htlc`, `update_fail_htlc`, or
* `update_fail_malformed_htlc`.
*/
if (htlc->state == SENT_ADD_ACK_REVOCATION)
htlc->state = RCVD_REMOVE_HTLC;
@ -559,9 +572,10 @@ enum channel_remove_err channel_fail_htlc(struct channel *channel,
/* BOLT #2:
*
* A receiving node MUST check that `id` corresponds to an HTLC in its
* current commitment transaction, and MUST fail the channel if it
* does not.
* A receiving node:
* - if the `id` does not correspond to an HTLC in its current
* commitment transaction:
* - MUST fail the channel.
*/
if (!htlc_has(htlc, HTLC_FLAG(!htlc_owner(htlc), HTLC_F_COMMITTED))) {
status_trace("channel_fail_htlc: %"PRIu64" in state %s",
@ -674,9 +688,11 @@ static int change_htlcs(struct channel *channel,
/* FIXME: The sender's requirements are *implied* by this, not stated! */
/* BOLT #2:
*
* A receiving node SHOULD fail the channel if the sender cannot
* afford the new fee rate on the receiving node's current commitment
* transaction
* A receiving node:
*...
* - if the sender cannot afford the new fee rate on the receiving node's
* current commitment transaction:
* - SHOULD fail the channel,
*/
u32 approx_max_feerate(const struct channel *channel)
{
@ -715,9 +731,10 @@ bool can_funder_afford_feerate(const struct channel *channel, u32 feerate_per_kw
/* BOLT #2:
*
* A receiving node SHOULD fail the channel if the sender cannot afford
* the new fee rate on the receiving node's current commitment
* transaction */
* - if the sender cannot afford the new fee rate on the receiving
* node's current commitment transaction:
* - SHOULD fail the channel
*/
/* Note: sender == funder */
/* How much does it think it has? Must be >= reserve + fee */

31
channeld/test/run-full_channel.c

@ -350,24 +350,23 @@ int main(void)
* # Appendix C: Commitment and HTLC Transaction Test Vectors
*
* In the following:
* - we consider *local* transactions, which implies that all payments
* to *local* are delayed
* - we assume that *local* is the funder
* - private keys are displayed as 32 bytes plus a trailing 1
* (bitcoin's convention for "compressed" private keys, i.e. keys
* for which the public key is compressed)
* - *local* transactions are considered, which implies that all
* payments to *local* are delayed.
* - It's assumed that *local* is the funder.
* - Private keys are displayed as 32 bytes plus a trailing 1
* (Bitcoin's convention for "compressed" private keys, i.e. keys for
* which the public key is compressed).
* - Transaction signatures are all deterministic, using RFC6979 (using
* HMAC-SHA256).
*
* - transaction signatures are all deterministic, using
* RFC6979 (using HMAC-SHA256)
*
* We start by defining common basic parameters for each test vector:
* To start, common basic parameters for each test vector are defined:
* the HTLCs are not used for the first "simple commitment tx with no
* HTLCs" test.
*
* funding_tx_id: 8984484a580b825b9972d7adb15050b3ab624ccd731946b3eeddb92f4e7ef6be
* funding_output_index: 0
* funding_amount_satoshi: 10000000
*...
* commitment_number: 42
* local_delay: 144
* local_dust_limit_satoshi: 546
*/
@ -469,10 +468,10 @@ int main(void)
*/
local_per_commitment_point = pubkey_from_hex("025f7117a78150fe2ef97db7cfc83bd57b2e2c0d0dd25eaf467a4a1c2a45ce1486");
/* BOLT #3:
* localkey: 030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e7
* remotekey: 0394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b
* local_delayedkey: 03fd5960528dc152014952efdb702a88f71e3c1653b2314431701ec77e57fde83c
* local_revocation_key: 0212a140cd0c6539d07cd08dfe09984dec3251ea808b892efeac3ede9402bf2b19
* localpubkey: 030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e7
* remotepubkey: 0394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b
* local_delayedpubkey: 03fd5960528dc152014952efdb702a88f71e3c1653b2314431701ec77e57fde83c
* local_revocation_pubkey: 0212a140cd0c6539d07cd08dfe09984dec3251ea808b892efeac3ede9402bf2b19
*/
keyset.self_payment_key = pubkey_from_hex("030d417a46946384f88d5f3337267c5e579765875dc4daca813e21734b140639e7");
keyset.other_payment_key = pubkey_from_hex("0394854aa6eab5b2a8122cc726e9dded053a2184d88256816826d6231c068d4a5b");
@ -507,7 +506,7 @@ int main(void)
/* BOLT #3:
*
* name: commitment tx with all 5 HTLCs untrimmed (minimum feerate)
* name: commitment tx with all five HTLCs untrimmed (minimum feerate)
* to_local_msat: 6988000000
* to_remote_msat: 3000000000
* local_feerate_per_kw: 0

Loading…
Cancel
Save