Browse Source

Massive BOLT text underscore and formatting updates.

This brings us up to 61b5b3f7b4145c9d6d66973b6bfbf28e6c0a0791.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 8 years ago
parent
commit
7389aae26a
  1. 30
      bitcoin/script.c
  2. 8
      daemon/routing.c
  3. 2
      daemon/sphinx.h
  4. 30
      lightningd/channel.c
  5. 12
      lightningd/channel.h
  6. 12
      lightningd/channel/channel.c
  7. 38
      lightningd/channel_config.h
  8. 26
      lightningd/commit_tx.c
  9. 2
      lightningd/commit_tx.h
  10. 2
      lightningd/cryptomsg.c
  11. 8
      lightningd/derive_basepoints.c
  12. 4
      lightningd/handshake/handshake.c
  13. 6
      lightningd/htlc_tx.c
  14. 61
      lightningd/key_derive.c
  15. 2
      lightningd/lightningd.h
  16. 66
      lightningd/opening/opening.c
  17. 41
      lightningd/peer_control.c
  18. 2
      lightningd/peer_failed.c
  19. 44
      lightningd/sphinx.h
  20. 2
      lightningd/test/run-channel.c
  21. 2
      lightningd/test/run-commit_tx.c
  22. 8
      wire/fromwire.c

30
bitcoin/script.c

@ -627,12 +627,12 @@ u8 **bitcoin_witness_htlc(const tal_t *ctx,
* *
* OP_IF * OP_IF
* # Penalty transaction * # Penalty transaction
* <revocation-pubkey> * <revocationkey>
* OP_ELSE * OP_ELSE
* `to-self-delay` * `to_self_delay`
* OP_CSV * OP_CSV
* OP_DROP * OP_DROP
* <local-delayedkey> * <local_delayedkey>
* OP_ENDIF * OP_ENDIF
* OP_CHECKSIG * OP_CHECKSIG
*/ */
@ -660,10 +660,10 @@ u8 **bitcoin_to_local_spend_delayedkey(const tal_t *ctx,
/* BOLT #3: /* BOLT #3:
* *
* It is spent by a transaction with `nSequence` field set to * It is spent by a transaction with `nSequence` field set to
* `to-self-delay` (which can only be valid after that duration has * `to_self_delay` (which can only be valid after that duration has
* passed), and witness: * passed), and witness:
* *
* <local-delayedsig> 0 * <local_delayedsig> 0
*/ */
u8 **witness = tal_arr(ctx, u8 *, 3); u8 **witness = tal_arr(ctx, u8 *, 3);
@ -682,7 +682,7 @@ u8 **bitcoin_to_local_spend_revocation(const tal_t *ctx,
* If a revoked commitment transaction is published, the other party * If a revoked commitment transaction is published, the other party
* can spend this output immediately with the following witness: * can spend this output immediately with the following witness:
* *
* <revocation-sig> 1 * <revocation_sig> 1
*/ */
u8 **witness = tal_arr(ctx, u8 *, 3); u8 **witness = tal_arr(ctx, u8 *, 3);
@ -702,7 +702,7 @@ u8 **bitcoin_to_local_spend_revocation(const tal_t *ctx,
* key. The output is a P2WSH, with a witness script: * key. The output is a P2WSH, with a witness script:
* *
* # To you with revocation key * # To you with revocation key
* OP_DUP OP_HASH160 <revocationkey-hash> OP_EQUAL * OP_DUP OP_HASH160 <RIPEMD160(revocationkey)> OP_EQUAL
* OP_IF * OP_IF
* OP_CHECKSIG * OP_CHECKSIG
* OP_ELSE * OP_ELSE
@ -712,7 +712,7 @@ u8 **bitcoin_to_local_spend_revocation(const tal_t *ctx,
* OP_DROP 2 OP_SWAP <localkey> 2 OP_CHECKMULTISIG * OP_DROP 2 OP_SWAP <localkey> 2 OP_CHECKMULTISIG
* OP_ELSE * OP_ELSE
* # To you with preimage. * # To you with preimage.
* OP_HASH160 <ripemd-of-payment-hash> OP_EQUALVERIFY * OP_HASH160 <RIPEMD160(payment_hash)> OP_EQUALVERIFY
* OP_CHECKSIG * OP_CHECKSIG
* OP_ENDIF * OP_ENDIF
* OP_ENDIF * OP_ENDIF
@ -767,7 +767,7 @@ u8 *bitcoin_wscript_htlc_offer(const tal_t *ctx,
* payment preimage. The output is a P2WSH, with a witness script: * payment preimage. The output is a P2WSH, with a witness script:
* *
* # To you with revocation key * # To you with revocation key
* OP_DUP OP_HASH160 <revocationkey-hash> OP_EQUAL * OP_DUP OP_HASH160 <RIPEMD160(revocationkey)> OP_EQUAL
* OP_IF * OP_IF
* OP_CHECKSIG * OP_CHECKSIG
* OP_ELSE * OP_ELSE
@ -775,11 +775,11 @@ u8 *bitcoin_wscript_htlc_offer(const tal_t *ctx,
* OP_SIZE 32 OP_EQUAL * OP_SIZE 32 OP_EQUAL
* OP_IF * OP_IF
* # To me via HTLC-success transaction. * # To me via HTLC-success transaction.
* OP_HASH160 <ripemd-of-payment-hash> OP_EQUALVERIFY * OP_HASH160 <RIPEMD160(payment_hash)> OP_EQUALVERIFY
* 2 OP_SWAP <localkey> 2 OP_CHECKMULTISIG * 2 OP_SWAP <localkey> 2 OP_CHECKMULTISIG
* OP_ELSE * OP_ELSE
* # To you after timeout. * # To you after timeout.
* OP_DROP <locktime> OP_CHECKLOCKTIMEVERIFY OP_DROP * OP_DROP <cltv_expiry> OP_CHECKLOCKTIMEVERIFY OP_DROP
* OP_CHECKSIG * OP_CHECKSIG
* OP_ENDIF * OP_ENDIF
* OP_ENDIF * OP_ENDIF
@ -834,7 +834,7 @@ u8 *bitcoin_wscript_htlc_receive(const tal_t *ctx,
* ## HTLC-Timeout and HTLC-Success Transactions * ## HTLC-Timeout and HTLC-Success Transactions
* *
*... *...
* * `txin[0]` witness stack: `0 <remotesig> <localsig> <payment-preimage>` for HTLC-Success, `0 <remotesig> <localsig> 0` for HTLC-Timeout. * * `txin[0]` witness stack: `0 <remotesig> <localsig> <payment_preimage>` for HTLC-Success, `0 <remotesig> <localsig> 0` for HTLC-Timeout.
*/ */
u8 **bitcoin_htlc_offer_spend_timeout(const tal_t *ctx, u8 **bitcoin_htlc_offer_spend_timeout(const tal_t *ctx,
const secp256k1_ecdsa_signature *localsig, const secp256k1_ecdsa_signature *localsig,
@ -882,12 +882,12 @@ u8 *bitcoin_wscript_htlc_tx(const tal_t *ctx,
* *
* OP_IF * OP_IF
* # Penalty transaction * # Penalty transaction
* <revocation-pubkey> * <revocationkey>
* OP_ELSE * OP_ELSE
* `to-self-delay` * `to_self_delay`
* OP_CSV * OP_CSV
* OP_DROP * OP_DROP
* <local-delayedkey> * <local_delayedkey>
* OP_ENDIF * OP_ENDIF
* OP_CHECKSIG * OP_CHECKSIG
*/ */

8
daemon/routing.c

@ -551,9 +551,9 @@ bool add_channel_direction(struct routing_state *rstate,
* *
* The following `address descriptor` types are defined: * The following `address descriptor` types are defined:
* *
* 1. `0`: padding. data = none (length 0). * * `0`: padding. data = none (length 0).
* 1. `1`: IPv4. data = `[4:ipv4-addr][2:port]` (length 6) * * `1`: ipv4. data = `[4:ipv4_addr][2:port]` (length 6)
* 2. `2`: IPv6. data = `[16:ipv6-addr][2:port]` (length 18) * * `2`: ipv6. data = `[16:ipv6_addr][2:port]` (length 18)
*/ */
/* FIXME: Don't just take first one, depends whether we have IPv6 ourselves */ /* FIXME: Don't just take first one, depends whether we have IPv6 ourselves */
@ -622,7 +622,7 @@ bool read_ip(const tal_t *ctx, const u8 *addresses, char **hostname,
* used for aligning fields following `addresses`. * used for aligning fields following `addresses`.
* *
* The creating node MUST NOT create a type 1 or type 2 address descriptor * The creating node MUST NOT create a type 1 or type 2 address descriptor
* with `port` equal to zero, and SHOULD ensure `ipv4-addr` and `ipv6-addr` * with `port` equal to zero, and SHOULD ensure `ipv4_addr` and `ipv6_addr`
* are routable addresses. The creating node MUST NOT include more than one * are routable addresses. The creating node MUST NOT include more than one
* `address descriptor` of the same type. * `address descriptor` of the same type.
*/ */

2
daemon/sphinx.h

@ -35,7 +35,7 @@ enum route_next_case {
ONION_FORWARD = 1, ONION_FORWARD = 1,
}; };
/* BOLT #4: /* FIXME-OLD #4:
* *
* The format of the per-hop-payload for a version 0 packet is as follows: * The format of the per-hop-payload for a version 0 packet is as follows:
``` ```

30
lightningd/channel.c

@ -338,7 +338,7 @@ enum channel_add_err channel_add_htlc(struct channel *channel,
/* BOLT #2: /* BOLT #2:
* *
* A receiving node SHOULD fail the channel if a sending node... sets * A receiving node SHOULD fail the channel if a sending node... sets
* `cltv-expiry` to greater or equal to 500000000. * `cltv_expiry` to greater or equal to 500000000.
*/ */
if (!blocks_to_abs_locktime(cltv_expiry, &htlc->expiry)) if (!blocks_to_abs_locktime(cltv_expiry, &htlc->expiry))
return CHANNEL_ERR_INVALID_EXPIRY; return CHANNEL_ERR_INVALID_EXPIRY;
@ -349,12 +349,12 @@ enum channel_add_err channel_add_htlc(struct channel *channel,
* *
* 1. type: 128 (`update_add_htlc`) * 1. type: 128 (`update_add_htlc`)
* 2. data: * 2. data:
* * [32:channel-id] * * [`32`:`channel_id`]
* * [8:id] * * [`8`:`id`]
* * [4:amount-msat] * * [`4`:`amount_msat`]
* * [4:cltv-expiry] * * [`4`:`cltv_expiry`]
* * [32:payment-hash] * * [`32`:`payment_hash`]
* * [1366:onion-routing-packet] * * [`1366`:`onion_routing_packet`]
*/ */
htlc->routing = tal_dup_arr(htlc, u8, routing, TOTAL_PACKET_SIZE, 0); htlc->routing = tal_dup_arr(htlc, u8, routing, TOTAL_PACKET_SIZE, 0);
@ -379,7 +379,7 @@ enum channel_add_err channel_add_htlc(struct channel *channel,
/* BOLT #2: /* BOLT #2:
* *
* A receiving node SHOULD fail the channel if it receives an * A receiving node SHOULD fail the channel if it receives an
* `amount-sat` equal to zero, below its own `htlc-minimum-msat`, * `amount_msat` equal to zero, below its own `htlc_minimum_msat`,
* or... * or...
*/ */
if (htlc->msatoshi == 0) { if (htlc->msatoshi == 0) {
@ -398,7 +398,7 @@ enum channel_add_err channel_add_htlc(struct channel *channel,
/* BOLT #2: /* BOLT #2:
* *
* A receiving node SHOULD fail the channel if a sending node * A receiving node SHOULD fail the channel if a sending node
* adds more than its `max-accepted-htlcs` HTLCs to its local * adds more than its `max_accepted_htlcs` HTLCs to its local
* commitment transaction */ * commitment transaction */
if (tal_count(committed) - tal_count(removing) + tal_count(adding) if (tal_count(committed) - tal_count(removing) + tal_count(adding)
> max_accepted_htlcs(channel, recipient)) { > max_accepted_htlcs(channel, recipient)) {
@ -413,7 +413,7 @@ enum channel_add_err channel_add_htlc(struct channel *channel,
/* BOLT #2: /* BOLT #2:
* *
* A receiving node SHOULD fail the channel if a sending node ... or * 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 * adds more than its `max_htlc_value_in_flight_msat` worth of offered
* HTLCs to its local commitment transaction */ * HTLCs to its local commitment transaction */
if (msat_in_htlcs > max_htlc_value_in_flight_msat(channel, recipient)) { if (msat_in_htlcs > max_htlc_value_in_flight_msat(channel, recipient)) {
e = CHANNEL_ERR_MAX_HTLC_VALUE_EXCEEDED; e = CHANNEL_ERR_MAX_HTLC_VALUE_EXCEEDED;
@ -422,8 +422,8 @@ enum channel_add_err channel_add_htlc(struct channel *channel,
/* BOLT #2: /* BOLT #2:
* *
* or which the sending node cannot afford at the current `fee-rate` * or which the sending node cannot afford at the current
* while maintaining its channel reserve. * `feerate_per_kw` while maintaining its channel reserve.
*/ */
if (channel->funder == htlc_owner(htlc)) { if (channel->funder == htlc_owner(htlc)) {
u64 feerate = view->feerate_per_kw; u64 feerate = view->feerate_per_kw;
@ -498,9 +498,9 @@ enum channel_remove_err channel_fulfill_htlc(struct channel *channel,
sha256(&hash, preimage, sizeof(*preimage)); sha256(&hash, preimage, sizeof(*preimage));
/* BOLT #2: /* BOLT #2:
* *
* A receiving node MUST check that the `payment-preimage` value in * A receiving node MUST check that the `payment_preimage` value in
* `update-fulfill_htlc` SHA256 hashes to the corresponding HTLC * `update_fulfill_htlc` SHA256 hashes to the corresponding HTLC
* `payment-hash`, and MUST fail the channel if it does not. * `payment_hash`, and MUST fail the channel if it does not.
*/ */
if (!structeq(&hash, &htlc->rhash)) if (!structeq(&hash, &htlc->rhash))
return CHANNEL_ERR_BAD_PREIMAGE; return CHANNEL_ERR_BAD_PREIMAGE;

12
lightningd/channel.h

@ -64,7 +64,7 @@ struct channel {
/* BOLT #2: /* BOLT #2:
* *
* `dust-limit-satoshis` is the threshold below which output should be * `dust_limit_satoshis` is the threshold below which output should be
* generated for this node's commitment or HTLC transaction */ * generated for this node's commitment or HTLC transaction */
static inline u64 dust_limit_satoshis(const struct channel *channel, static inline u64 dust_limit_satoshis(const struct channel *channel,
enum side side) enum side side)
@ -73,7 +73,7 @@ static inline u64 dust_limit_satoshis(const struct channel *channel,
} }
/* BOLT #2: /* BOLT #2:
* *
* `max-htlc-value-in-inflight-msat` is a cap on total value of * `max_htlc_value_in_flight_msat` is a cap on total value of
* outstanding HTLCs, which allows a node to limit its exposure to * outstanding HTLCs, which allows a node to limit its exposure to
* HTLCs */ * HTLCs */
static inline u64 max_htlc_value_in_flight_msat(const struct channel *channel, static inline u64 max_htlc_value_in_flight_msat(const struct channel *channel,
@ -83,7 +83,7 @@ static inline u64 max_htlc_value_in_flight_msat(const struct channel *channel,
} }
/* BOLT #2: /* BOLT #2:
* *
* similarly `max-accepted-htlcs` limits the number of outstanding * similarly `max_accepted_htlcs` limits the number of outstanding
* HTLCs the other node can offer. */ * HTLCs the other node can offer. */
static inline u16 max_accepted_htlcs(const struct channel *channel, static inline u16 max_accepted_htlcs(const struct channel *channel,
enum side recipient) enum side recipient)
@ -92,7 +92,7 @@ static inline u16 max_accepted_htlcs(const struct channel *channel,
} }
/* BOLT #2: /* BOLT #2:
* *
* `channel-reserve-satoshis` is the minimum amount that the other * `channel_reserve_satoshis` is the minimum amount that the other
* node is to keep as a direct payment. */ * node is to keep as a direct payment. */
static inline u64 channel_reserve_msat(const struct channel *channel, static inline u64 channel_reserve_msat(const struct channel *channel,
enum side side) enum side side)
@ -101,7 +101,7 @@ static inline u64 channel_reserve_msat(const struct channel *channel,
} }
/* BOLT #2: /* BOLT #2:
* *
* `htlc-minimum-msat` indicates the smallest value HTLC this node will accept. * `htlc_minimum_msat` indicates the smallest value HTLC this node will accept.
*/ */
static inline u32 htlc_minimum_msat(const struct channel *channel, static inline u32 htlc_minimum_msat(const struct channel *channel,
enum side recipient) enum side recipient)
@ -110,7 +110,7 @@ static inline u32 htlc_minimum_msat(const struct channel *channel,
} }
/* BOLT #2: /* BOLT #2:
* *
* `to-self-delay` is the number of blocks that the other nodes * `to_self_delay` is the number of blocks that the other nodes
* to-self outputs must be delayed, using `OP_CHECKSEQUENCEVERIFY` * to-self outputs must be delayed, using `OP_CHECKSEQUENCEVERIFY`
* delays */ * delays */
static inline u16 to_self_delay(const struct channel *channel, enum side side) static inline u16 to_self_delay(const struct channel *channel, enum side side)

12
lightningd/channel/channel.c

@ -408,7 +408,7 @@ static void send_commit(struct peer *peer)
/* BOLT #2: /* BOLT #2:
* *
* A node MUST include one `htlc-signature` for every HTLC transaction * A node MUST include one `htlc_signature` for every HTLC transaction
* corresponding to BIP69 lexicographic ordering of the commitment * corresponding to BIP69 lexicographic ordering of the commitment
* transaction. * transaction.
*/ */
@ -519,7 +519,7 @@ static void handle_peer_commit_sig(struct peer *peer, const u8 *msg)
/* BOLT #2: /* BOLT #2:
* *
* A receiving node MUST fail the channel if `num-htlcs` is not equal * A receiving node MUST fail the channel if `num_htlcs` is not equal
* to the number of HTLC outputs in the local commitment transaction * to the number of HTLC outputs in the local commitment transaction
* once all pending updates are applied. * once all pending updates are applied.
*/ */
@ -534,7 +534,7 @@ static void handle_peer_commit_sig(struct peer *peer, const u8 *msg)
/* BOLT #2: /* BOLT #2:
* *
* A receiving node MUST fail * A receiving node MUST fail
* the channel if any `htlc-signature` is not valid for the * the channel if any `htlc_signature` is not valid for the
* corresponding HTLC transaction. * corresponding HTLC transaction.
*/ */
for (i = 0; i < tal_count(htlc_sigs); i++) { for (i = 0; i < tal_count(htlc_sigs); i++) {
@ -701,8 +701,8 @@ static void handle_peer_revoke_and_ack(struct peer *peer, const u8 *msg)
/* BOLT #2: /* BOLT #2:
* *
* A receiving node MUST check that `per-commitment-secret` generates * A receiving node MUST check that `per_commitment_secret` generates
* the previous `per-commitment-point`, and MUST fail if it does * the previous `per_commitment_point`, and MUST fail if it does
* not. * not.
*/ */
memcpy(&privkey, &old_commit_secret, sizeof(privkey)); memcpy(&privkey, &old_commit_secret, sizeof(privkey));
@ -727,7 +727,7 @@ static void handle_peer_revoke_and_ack(struct peer *peer, const u8 *msg)
/* BOLT #2: /* BOLT #2:
* *
* A receiving node MAY fail if the `per-commitment-secret` was not * A receiving node MAY fail if the `per_commitment_secret` was not
* generated by the protocol in [BOLT #3] * generated by the protocol in [BOLT #3]
*/ */
if (!shachain_add_hash(&peer->their_shachain, if (!shachain_add_hash(&peer->their_shachain,

38
lightningd/channel_config.h

@ -8,28 +8,28 @@
* *
* 1. type: 32 (`open_channel`) * 1. type: 32 (`open_channel`)
* 2. data: * 2. data:
* * [32:chain-hash] * * [`32`:`chain_hash`]
* * [32:temporary-channel-id] * * [`32`:`temporary_channel_id`]
* * [8:funding-satoshis] * * [`8`:`funding_satoshis`]
* * [8:push-msat] * * [`8`:`push_msat`]
* * [8:dust-limit-satoshis] * * [`8`:`dust_limit_satoshis`]
* * [8:max-htlc-value-in-flight-msat] * * [`8`:`max_htlc_value_in_flight_msat`]
* * [8:channel-reserve-satoshis] * * [`8`:`channel_reserve_satoshis`]
* * [4:htlc-minimum-msat] * * [`4`:`htlc_minimum_msat`]
* * [4:feerate-per-kw] * * [`4`:`feerate_per_kw`]
* * [2:to-self-delay] * * [`2`:`to_self_delay`]
* * [2:max-accepted-htlcs] * * [`2`:`max_accepted_htlcs`]
*... *...
* 1. type: 33 (`accept_channel`) * 1. type: 33 (`accept_channel`)
* 2. data: * 2. data:
* * [32:temporary-channel-id] * * [`32`:`temporary_channel_id`]
* * [8:dust-limit-satoshis] * * [`8`:`dust_limit_satoshis`]
* * [8:max-htlc-value-in-flight-msat] * * [`8`:`max_htlc_value_in_flight_msat`]
* * [8:channel-reserve-satoshis] * * [`8`:`channel_reserve_satoshis`]
* * [4:minimum-depth] * * [`4`:`minimum_depth`]
* * [4:htlc-minimum-msat] * * [`4`:`htlc_minimum_msat`]
* * [2:to-self-delay] * * [`2`:`to_self_delay`]
* * [2:max-accepted-htlcs] * * [`2`:`max_accepted_htlcs`]
*/ */
struct channel_config { struct channel_config {
u64 dust_limit_satoshis; u64 dust_limit_satoshis;

26
lightningd/commit_tx.c

@ -15,7 +15,7 @@
* The 48-bit commitment transaction number is obscured by `XOR` with * The 48-bit commitment transaction number is obscured by `XOR` with
* the lower 48 bits of: * the lower 48 bits of:
* *
* SHA256(payment-basepoint from open_channel || payment-basepoint from accept_channel) * SHA256(payment_basepoint from open_channel || payment_basepoint from accept_channel)
*/ */
u64 commit_number_obscurer(const struct pubkey *opener_payment_basepoint, u64 commit_number_obscurer(const struct pubkey *opener_payment_basepoint,
const struct pubkey *accepter_payment_basepoint) const struct pubkey *accepter_payment_basepoint)
@ -55,7 +55,7 @@ u64 htlc_timeout_fee(u64 feerate_per_kw)
* *
* The fee for an HTLC-timeout transaction MUST BE calculated to match: * The fee for an HTLC-timeout transaction MUST BE calculated to match:
* *
* 1. Multiply `feerate-per-kw` by 663 and divide by 1000 (rounding * 1. Multiply `feerate_per_kw` by 663 and divide by 1000 (rounding
* down). * down).
*/ */
return feerate_per_kw * 663 / 1000; return feerate_per_kw * 663 / 1000;
@ -67,7 +67,7 @@ u64 htlc_success_fee(u64 feerate_per_kw)
* *
* The fee for an HTLC-success transaction MUST BE calculated to match: * The fee for an HTLC-success transaction MUST BE calculated to match:
* *
* 1. Multiply `feerate-per-kw` by 703 and divide by 1000 (rounding * 1. Multiply `feerate_per_kw` by 703 and divide by 1000 (rounding
* down). * down).
*/ */
return feerate_per_kw * 703 / 1000; return feerate_per_kw * 703 / 1000;
@ -82,7 +82,7 @@ static bool trim(const struct htlc *htlc,
/* BOLT #3: /* BOLT #3:
* *
* For every offered HTLC, if the HTLC amount minus the HTLC-timeout * For every offered HTLC, if the HTLC amount minus the HTLC-timeout
* fee would be less than `dust-limit-satoshis` set by the transaction * fee would be less than `dust_limit_satoshis` set by the transaction
* owner, the commitment transaction MUST NOT contain that output, * owner, the commitment transaction MUST NOT contain that output,
* otherwise it MUST be generated as specified in [Offered HTLC * otherwise it MUST be generated as specified in [Offered HTLC
* Outputs](#offered-htlc-outputs). * Outputs](#offered-htlc-outputs).
@ -92,7 +92,7 @@ static bool trim(const struct htlc *htlc,
/* BOLT #3: /* BOLT #3:
* *
* For every received HTLC, if the HTLC amount minus the HTLC-success * For every received HTLC, if the HTLC amount minus the HTLC-success
* fee would be less than `dust-limit-satoshis` set by the transaction * fee would be less than `dust_limit_satoshis` set by the transaction
* owner, the commitment transaction MUST NOT contain that output, * owner, the commitment transaction MUST NOT contain that output,
* otherwise it MUST be generated as specified in [Received HTLC * otherwise it MUST be generated as specified in [Received HTLC
* Outputs](#received-htlc-outputs). * Outputs](#received-htlc-outputs).
@ -138,7 +138,7 @@ u64 commit_tx_base_fee(u64 feerate_per_kw, size_t num_untrimmed_htlcs)
/* BOLT #3: /* BOLT #3:
* *
* 3. Multiply `feerate-per-kw` by `weight`, divide by 1000 * 3. Multiply `feerate_per_kw` by `weight`, divide by 1000
* (rounding down). * (rounding down).
*/ */
return feerate_per_kw * weight / 1000; return feerate_per_kw * weight / 1000;
@ -225,8 +225,8 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
/* BOLT #3: /* BOLT #3:
* *
* 3. Subtract this base fee from the funder (either `to-local` or * 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 zero (see [Fee Payment](#fee-payment)).
*/ */
subtract_fee(funder, side, base_fee_msat, subtract_fee(funder, side, base_fee_msat,
&self_pay_msat, &other_pay_msat); &self_pay_msat, &other_pay_msat);
@ -294,8 +294,8 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
/* BOLT #3: /* BOLT #3:
* *
* 5. If the `to-local` amount is greater or equal to * 5. If the `to_local` amount is greater or equal to
* `dust-limit-satoshis`, add a [To-Local * `dust_limit_satoshis`, add a [`to_local`
* Output](#to-local-output). * Output](#to-local-output).
*/ */
if (self_pay_msat / 1000 >= dust_limit_satoshis) { if (self_pay_msat / 1000 >= dust_limit_satoshis) {
@ -315,14 +315,14 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
/* BOLT #3: /* BOLT #3:
* *
* 6. If the `to-remote` amount is greater or equal to * 6. If the `to_remote` amount is greater or equal to
* `dust-limit-satoshis`, add a [To-Remote * `dust_limit_satoshis`, add a [`to_remote`
* Output](#to-remote-output). * Output](#to-remote-output).
*/ */
if (other_pay_msat / 1000 >= dust_limit_satoshis) { if (other_pay_msat / 1000 >= dust_limit_satoshis) {
/* BOLT #3: /* BOLT #3:
* *
* #### To-Remote Output * #### `to_remote` Output
* *
* This output sends funds to the other peer, thus is a simple * This output sends funds to the other peer, thus is a simple
* P2WPKH to `remotekey`. * P2WPKH to `remotekey`.

2
lightningd/commit_tx.h

@ -10,7 +10,7 @@ struct sha256_double;
* *
* This obscures the number of commitments made on the channel in the * This obscures the number of commitments made on the channel in the
* case of unilateral close, yet still provides a useful index for * case of unilateral close, yet still provides a useful index for
* both nodes (who know the payment-basepoints) to quickly find a * both nodes (who know the `payment_basepoint`s) to quickly find a
* revoked commitment transaction. * revoked commitment transaction.
*/ */
u64 commit_number_obscurer(const struct pubkey *opener_payment_basepoint, u64 commit_number_obscurer(const struct pubkey *opener_payment_basepoint,

2
lightningd/cryptomsg.c

@ -167,7 +167,7 @@ bool cryptomsg_decrypt_header(struct crypto_state *cs, u8 hdr[18], u16 *lenp)
* *
* * Let the encrypted length prefix be known as `lc` * * Let the encrypted length prefix be known as `lc`
* *
* * Decrypt `lc` using `ChaCha20-Poy1305`, `rn`, and `rk` to * * Decrypt `lc` using `ChaCha20-Poly1305`, `rn`, and `rk` to
* obtain size of the encrypted packet `l`. * obtain size of the encrypted packet `l`.
* * A zero-length byte slice is to be passed as the AD * * A zero-length byte slice is to be passed as the AD
* (associated data). * (associated data).

8
lightningd/derive_basepoints.c

@ -54,9 +54,9 @@ bool derive_basepoints(const struct privkey *seed,
/* BOLT #3: /* BOLT #3:
* *
* The `per-commitment-point` is generated using EC multiplication: * The `per_commitment_point` is generated using EC multiplication:
* *
* per-commitment-point = per-commitment-secret * G * per_commitment_point = per_commitment_secret * G
*/ */
if (per_commit_point) { if (per_commit_point) {
if (secp256k1_ec_pubkey_create(secp256k1_ctx, if (secp256k1_ec_pubkey_create(secp256k1_ctx,
@ -89,9 +89,9 @@ bool next_per_commit_point(const struct sha256 *shaseed,
/* BOLT #3: /* BOLT #3:
* *
* The `per-commitment-point` is generated using EC multiplication: * The `per_commitment_point` is generated using EC multiplication:
* *
* per-commitment-point = per-commitment-secret * G * per_commitment_point = per_commitment_secret * G
*/ */
if (secp256k1_ec_pubkey_create(secp256k1_ctx, if (secp256k1_ec_pubkey_create(secp256k1_ctx,
&per_commit_point->pubkey, &per_commit_point->pubkey,

4
lightningd/handshake/handshake.c

@ -228,7 +228,7 @@ static struct handshake *new_handshake(const tal_t *ctx,
* *
* 1. `h = SHA-256(protocolName)` * 1. `h = SHA-256(protocolName)`
* * where `protocolName = "Noise_XK_secp256k1_ChaChaPoly_SHA256"` * * where `protocolName = "Noise_XK_secp256k1_ChaChaPoly_SHA256"`
* encoded as an ascii string. * encoded as an ASCII string.
*/ */
sha256(&handshake->h, "Noise_XK_secp256k1_ChaChaPoly_SHA256", sha256(&handshake->h, "Noise_XK_secp256k1_ChaChaPoly_SHA256",
strlen("Noise_XK_secp256k1_ChaChaPoly_SHA256")); strlen("Noise_XK_secp256k1_ChaChaPoly_SHA256"));
@ -245,7 +245,7 @@ static struct handshake *new_handshake(const tal_t *ctx,
/* BOLT #8: /* BOLT #8:
* *
* 3. `h = SHA-256(h || prologue)` * 3. `h = SHA-256(h || prologue)`
* * where `prologue` is the ascii string: `lightning`. * * where `prologue` is the ASCII string: `lightning`.
*/ */
sha_mix_in(&handshake->h, "lightning", strlen("lightning")); sha_mix_in(&handshake->h, "lightning", strlen("lightning"));

6
lightningd/htlc_tx.c

@ -33,7 +33,7 @@ static struct bitcoin_tx *htlc_tx(const tal_t *ctx,
assert(tx->version == 2); assert(tx->version == 2);
/* BOLT #3: /* BOLT #3:
* * locktime: `0` for HTLC-Success, `htlc-timeout` for HTLC-Timeout. * * locktime: `0` for HTLC-Success, `cltv_expiry` for HTLC-Timeout.
*/ */
tx->lock_time = locktime; tx->lock_time = locktime;
@ -81,7 +81,7 @@ struct bitcoin_tx *htlc_success_tx(const tal_t *ctx,
u64 feerate_per_kw) u64 feerate_per_kw)
{ {
/* BOLT #3: /* BOLT #3:
* * locktime: `0` for HTLC-Success, `htlc-timeout` for HTLC-Timeout. * * locktime: `0` for HTLC-Success, `cltv_expiry` for HTLC-Timeout.
*/ */
return htlc_tx(ctx, commit_txid, commit_output_number, received_htlc, return htlc_tx(ctx, commit_txid, commit_output_number, received_htlc,
to_self_delay, revocation_pubkey, local_delayedkey, to_self_delay, revocation_pubkey, local_delayedkey,
@ -125,7 +125,7 @@ struct bitcoin_tx *htlc_timeout_tx(const tal_t *ctx,
u64 feerate_per_kw) u64 feerate_per_kw)
{ {
/* BOLT #3: /* BOLT #3:
* * locktime: `0` for HTLC-Success, `htlc-timeout` for HTLC-Timeout. * * locktime: `0` for HTLC-Success, `cltv_expiry` for HTLC-Timeout.
*/ */
return htlc_tx(ctx, commit_txid, commit_output_number, offered_htlc, return htlc_tx(ctx, commit_txid, commit_output_number, offered_htlc,
to_self_delay, revocation_pubkey, local_delayedkey, to_self_delay, revocation_pubkey, local_delayedkey,

61
lightningd/key_derive.c

@ -7,17 +7,17 @@
/* BOLT #3: /* BOLT #3:
* *
* ### `localkey`, `remotekey`, `local-delayedkey` and `remote-delayedkey` Derivation * ### `localkey`, `remotekey`, `local_delayedkey` and `remote_delayedkey` Derivation
* *
* These keys are simply generated by addition from their base points: * These keys are simply generated by addition from their base points:
* *
* pubkey = basepoint + SHA256(per-commitment-point || basepoint)*G * pubkey = basepoint + SHA256(per_commitment_point || basepoint)*G
* *
* The `localkey` uses the local node's `payment-basepoint`, `remotekey` * The `localkey` uses the local node's `payment_basepoint`, `remotekey`
* uses the remote node's `payment-basepoint`, the `local-delayedkey` * uses the remote node's `payment_basepoint`, the `local_delayedkey`
* uses the local node's `delayed-payment-basepoint`, and the * uses the local node's `delayed_payment_basepoint`, and the
* `remote-delayedkey` uses the remote node's * `remote_delayedkey` uses the remote node's
* `delayed-payment-basepoint`. * `delayed_payment_basepoint`.
*/ */
bool derive_simple_key(const struct pubkey *basepoint, bool derive_simple_key(const struct pubkey *basepoint,
const struct pubkey *per_commitment_point, const struct pubkey *per_commitment_point,
@ -30,7 +30,7 @@ bool derive_simple_key(const struct pubkey *basepoint,
pubkey_to_der(der_keys + PUBKEY_DER_LEN, basepoint); pubkey_to_der(der_keys + PUBKEY_DER_LEN, basepoint);
sha256(&sha, der_keys, sizeof(der_keys)); sha256(&sha, der_keys, sizeof(der_keys));
#ifdef SUPERVERBOSE #ifdef SUPERVERBOSE
printf("# SHA256(per-commitment-point || basepoint)\n"); printf("# SHA256(per_commitment_point || basepoint)\n");
printf("# => SHA256(0x%s || 0x%s)\n", printf("# => SHA256(0x%s || 0x%s)\n",
tal_hexstr(tmpctx, der_keys, PUBKEY_DER_LEN), tal_hexstr(tmpctx, der_keys, PUBKEY_DER_LEN),
tal_hexstr(tmpctx, der_keys + PUBKEY_DER_LEN, PUBKEY_DER_LEN)); tal_hexstr(tmpctx, der_keys + PUBKEY_DER_LEN, PUBKEY_DER_LEN));
@ -54,9 +54,9 @@ bool derive_simple_key(const struct pubkey *basepoint,
/* BOLT #3: /* BOLT #3:
* *
* The corresponding private keys can be derived similarly if the basepoint * The corresponding private keys can be derived similarly if the basepoint
* secrets are known (i.e., `localkey` and `local-delayedkey` only): * secrets are known (i.e., `localkey` and `local_delayedkey` only):
* *
* secretkey = basepoint-secret + SHA256(per-commitment-point || basepoint) * secretkey = basepoint_secret + SHA256(per_commitment_point || basepoint)
*/ */
bool derive_simple_privkey(const struct secret *base_secret, bool derive_simple_privkey(const struct secret *base_secret,
const struct pubkey *basepoint, const struct pubkey *basepoint,
@ -70,7 +70,7 @@ bool derive_simple_privkey(const struct secret *base_secret,
pubkey_to_der(der_keys + PUBKEY_DER_LEN, basepoint); pubkey_to_der(der_keys + PUBKEY_DER_LEN, basepoint);
sha256(&sha, der_keys, sizeof(der_keys)); sha256(&sha, der_keys, sizeof(der_keys));
#ifdef SUPERVERBOSE #ifdef SUPERVERBOSE
printf("# SHA256(per-commitment-point || basepoint)\n"); printf("# SHA256(per_commitment_point || basepoint)\n");
printf("# => SHA256(0x%s || 0x%s)\n", printf("# => SHA256(0x%s || 0x%s)\n",
tal_hexstr(tmpctx, der_keys, PUBKEY_DER_LEN), tal_hexstr(tmpctx, der_keys, PUBKEY_DER_LEN),
tal_hexstr(tmpctx, der_keys + PUBKEY_DER_LEN, PUBKEY_DER_LEN)); tal_hexstr(tmpctx, der_keys + PUBKEY_DER_LEN, PUBKEY_DER_LEN));
@ -92,19 +92,22 @@ bool derive_simple_privkey(const struct secret *base_secret,
/* BOLT #3: /* BOLT #3:
* *
* The revocationkey is a blinded key: the remote node provides the base, * The `revocationkey` is a blinded key: when a node wishes to create a new
* and the local node provides the blinding factor which it later * commitment for a remote node, it uses its own `revocation_basepoint` and
* reveals, so the remote node can use the secret revocationkey for a * the remote node's `per_commitment_point` to derive a new `revocationkey`
* penalty transaction. * for the commitment. Once the remote node reveals (thereby revoking that
* commitment) the `per_commitment_secret` used, the node can now derive the
* `revocationsecretkey` as they now know the two secrets necessary to derive
* the key (`revocation_basepoint_secret` and `per_commitment_secret`).
* *
* The `per-commitment-point` is generated using EC multiplication: * The `per_commitment_point` is generated using EC multiplication:
* *
* per-commitment-point = per-commitment-secret * G * per_commitment_point = per_commitment_secret * G
* *
* And this is used to derive the revocation key from the remote node's * And this is used to derive the revocation key from the remote node's
* `revocation-basepoint`: * `revocation_basepoint`:
* *
* revocationkey = revocation-basepoint * SHA256(revocation-basepoint || per-commitment-point) + per-commitment-point*SHA256(per-commitment-point || revocation-basepoint) * revocationkey = revocation_basepoint * SHA256(revocation_basepoint || per_commitment_point) + per_commitment_point*SHA256(per_commitment_point || revocation_basepoint)
*/ */
bool derive_revocation_key(const struct pubkey *basepoint, bool derive_revocation_key(const struct pubkey *basepoint,
const struct pubkey *per_commitment_point, const struct pubkey *per_commitment_point,
@ -119,7 +122,7 @@ bool derive_revocation_key(const struct pubkey *basepoint,
pubkey_to_der(der_keys + PUBKEY_DER_LEN, per_commitment_point); pubkey_to_der(der_keys + PUBKEY_DER_LEN, per_commitment_point);
sha256(&sha, der_keys, sizeof(der_keys)); sha256(&sha, der_keys, sizeof(der_keys));
#ifdef SUPERVERBOSE #ifdef SUPERVERBOSE
printf("# SHA256(revocation-basepoint || per-commitment-point)\n"); printf("# SHA256(revocation_basepoint || per_commitment_point)\n");
printf("# => SHA256(0x%s || 0x%s)\n", printf("# => SHA256(0x%s || 0x%s)\n",
tal_hexstr(tmpctx, der_keys, PUBKEY_DER_LEN), tal_hexstr(tmpctx, der_keys, PUBKEY_DER_LEN),
tal_hexstr(tmpctx, der_keys + PUBKEY_DER_LEN, PUBKEY_DER_LEN)); tal_hexstr(tmpctx, der_keys + PUBKEY_DER_LEN, PUBKEY_DER_LEN));
@ -130,7 +133,7 @@ bool derive_revocation_key(const struct pubkey *basepoint,
if (secp256k1_ec_pubkey_tweak_mul(secp256k1_ctx, &add[0], sha.u.u8) != 1) if (secp256k1_ec_pubkey_tweak_mul(secp256k1_ctx, &add[0], sha.u.u8) != 1)
return false; return false;
#ifdef SUPERVERBOSE #ifdef SUPERVERBOSE
printf("# x revocation-basepoint = 0x%s\n", printf("# x revocation_basepoint = 0x%s\n",
type_to_string(tmpctx, secp256k1_pubkey, &add[0])); type_to_string(tmpctx, secp256k1_pubkey, &add[0]));
#endif #endif
@ -138,7 +141,7 @@ bool derive_revocation_key(const struct pubkey *basepoint,
pubkey_to_der(der_keys + PUBKEY_DER_LEN, basepoint); pubkey_to_der(der_keys + PUBKEY_DER_LEN, basepoint);
sha256(&sha, der_keys, sizeof(der_keys)); sha256(&sha, der_keys, sizeof(der_keys));
#ifdef SUPERVERBOSE #ifdef SUPERVERBOSE
printf("# SHA256(per-commitment-point || revocation-basepoint)\n"); printf("# SHA256(per_commitment_point || revocation_basepoint)\n");
printf("# => SHA256(0x%s || 0x%s)\n", printf("# => SHA256(0x%s || 0x%s)\n",
tal_hexstr(tmpctx, der_keys, PUBKEY_DER_LEN), tal_hexstr(tmpctx, der_keys, PUBKEY_DER_LEN),
tal_hexstr(tmpctx, der_keys + PUBKEY_DER_LEN, PUBKEY_DER_LEN)); tal_hexstr(tmpctx, der_keys + PUBKEY_DER_LEN, PUBKEY_DER_LEN));
@ -149,7 +152,7 @@ bool derive_revocation_key(const struct pubkey *basepoint,
if (secp256k1_ec_pubkey_tweak_mul(secp256k1_ctx, &add[1], sha.u.u8) != 1) if (secp256k1_ec_pubkey_tweak_mul(secp256k1_ctx, &add[1], sha.u.u8) != 1)
return false; return false;
#ifdef SUPERVERBOSE #ifdef SUPERVERBOSE
printf("# x per-commitment-point = 0x%s\n", printf("# x per_commitment_point = 0x%s\n",
type_to_string(tmpctx, secp256k1_pubkey, &add[1])); type_to_string(tmpctx, secp256k1_pubkey, &add[1]));
#endif #endif
@ -170,10 +173,10 @@ bool derive_revocation_key(const struct pubkey *basepoint,
/* BOLT #3: /* BOLT #3:
* *
* The corresponding private key can be derived once the `per-commitment-secret` * The corresponding private key can be derived once the `per_commitment_secret`
* is known: * is known:
* *
* revocationsecretkey = revocation-basepoint-secret * SHA256(revocation-basepoint || per-commitment-point) + per-commitment-secret*SHA256(per-commitment-point || revocation-basepoint) * revocationsecretkey = revocation_basepoint_secret * SHA256(revocation_basepoint || per_commitment_point) + per_commitment_secret*SHA256(per_commitment_point || revocation_basepoint)
*/ */
bool derive_revocation_privkey(const struct secret *base_secret, bool derive_revocation_privkey(const struct secret *base_secret,
const struct secret *per_commitment_secret, const struct secret *per_commitment_secret,
@ -189,7 +192,7 @@ bool derive_revocation_privkey(const struct secret *base_secret,
pubkey_to_der(der_keys + PUBKEY_DER_LEN, per_commitment_point); pubkey_to_der(der_keys + PUBKEY_DER_LEN, per_commitment_point);
sha256(&sha, der_keys, sizeof(der_keys)); sha256(&sha, der_keys, sizeof(der_keys));
#ifdef SUPERVERBOSE #ifdef SUPERVERBOSE
printf("# SHA256(revocation-basepoint || per-commitment-point)\n"); printf("# SHA256(revocation_basepoint || per_commitment_point)\n");
printf("# => SHA256(0x%s || 0x%s)\n", printf("# => SHA256(0x%s || 0x%s)\n",
tal_hexstr(tmpctx, der_keys, PUBKEY_DER_LEN), tal_hexstr(tmpctx, der_keys, PUBKEY_DER_LEN),
tal_hexstr(tmpctx, der_keys + PUBKEY_DER_LEN, PUBKEY_DER_LEN)); tal_hexstr(tmpctx, der_keys + PUBKEY_DER_LEN, PUBKEY_DER_LEN));
@ -202,7 +205,7 @@ bool derive_revocation_privkey(const struct secret *base_secret,
!= 1) != 1)
return false; return false;
#ifdef SUPERVERBOSE #ifdef SUPERVERBOSE
printf("# * revocation-basepoint-secret (0x%s)", printf("# * revocation_basepoint_secret (0x%s)",
tal_hexstr(tmpctx, base_secret, sizeof(*base_secret))), tal_hexstr(tmpctx, base_secret, sizeof(*base_secret))),
printf("# = 0x%s\n", tal_hexstr(tmpctx, key, sizeof(*key))), printf("# = 0x%s\n", tal_hexstr(tmpctx, key, sizeof(*key))),
#endif #endif
@ -211,7 +214,7 @@ bool derive_revocation_privkey(const struct secret *base_secret,
pubkey_to_der(der_keys + PUBKEY_DER_LEN, basepoint); pubkey_to_der(der_keys + PUBKEY_DER_LEN, basepoint);
sha256(&sha, der_keys, sizeof(der_keys)); sha256(&sha, der_keys, sizeof(der_keys));
#ifdef SUPERVERBOSE #ifdef SUPERVERBOSE
printf("# SHA256(per-commitment-point || revocation-basepoint)\n"); printf("# SHA256(per_commitment_point || revocation_basepoint)\n");
printf("# => SHA256(0x%s || 0x%s)\n", printf("# => SHA256(0x%s || 0x%s)\n",
tal_hexstr(tmpctx, der_keys, PUBKEY_DER_LEN), tal_hexstr(tmpctx, der_keys, PUBKEY_DER_LEN),
tal_hexstr(tmpctx, der_keys + PUBKEY_DER_LEN, PUBKEY_DER_LEN)); tal_hexstr(tmpctx, der_keys + PUBKEY_DER_LEN, PUBKEY_DER_LEN));
@ -223,7 +226,7 @@ bool derive_revocation_privkey(const struct secret *base_secret,
sha.u.u8) != 1) sha.u.u8) != 1)
return false; return false;
#ifdef SUPERVERBOSE #ifdef SUPERVERBOSE
printf("# * per-commitment-secret (0x%s)", printf("# * per_commitment_secret (0x%s)",
tal_hexstr(tmpctx, per_commitment_secret, tal_hexstr(tmpctx, per_commitment_secret,
sizeof(*per_commitment_secret))), sizeof(*per_commitment_secret))),
printf("# = 0x%s\n", tal_hexstr(tmpctx, &part2, sizeof(part2))); printf("# = 0x%s\n", tal_hexstr(tmpctx, &part2, sizeof(part2)));

2
lightningd/lightningd.h

@ -10,7 +10,7 @@
/* BOLT #1: /* BOLT #1:
* *
* The default TCP port is 9735. This corresponds to hexadecimal * The default TCP port is 9735. This corresponds to hexadecimal
* `0x2607`, the unicode code point for LIGHTNING. * `0x2607`, the Unicode code point for LIGHTNING.
*/ */
#define DEFAULT_PORT 0x2607 #define DEFAULT_PORT 0x2607

66
lightningd/opening/opening.c

@ -65,7 +65,7 @@ static void check_config_bounds(struct state *state,
/* BOLT #2: /* BOLT #2:
* *
* The receiving node MUST fail the channel if `to-self-delay` is * The receiving node MUST fail the channel if `to_self_delay` is
* unreasonably large. * unreasonably large.
*/ */
if (remoteconf->to_self_delay > state->max_to_self_delay) if (remoteconf->to_self_delay > state->max_to_self_delay)
@ -76,12 +76,12 @@ static void check_config_bounds(struct state *state,
/* BOLT #2: /* BOLT #2:
* *
* The receiver MAY fail the channel if `funding-satoshis` is too * The receiver MAY fail the channel if `funding_satoshis` is too
* small, and MUST fail the channel if `push-msat` is greater than * small, and MUST fail the channel if `push_msat` is greater than
* `funding-amount` * 1000. The receiving node MAY fail the channel * `funding_satoshis` * 1000. The receiving node MAY fail the channel
* if it considers `htlc-minimum-msat` too large, * if it considers `htlc_minimum_msat` too large,
* `max-htlc-value-in-flight` too small, `channel-reserve-satoshis` * `max_htlc_value_in_flight_msat` too small, `channel_reserve_satoshis`
* too large, or `max-accepted-htlcs` too small. * too large, or `max_accepted_htlcs` too small.
*/ */
/* We accumulate this into an effective bandwidth minimum. */ /* We accumulate this into an effective bandwidth minimum. */
@ -137,7 +137,7 @@ static void check_config_bounds(struct state *state,
/* BOLT #2: /* BOLT #2:
* *
* It MUST fail the channel if `max-accepted-htlcs` is greater * It MUST fail the channel if `max_accepted_htlcs` is greater
* than 483. * than 483.
*/ */
if (remoteconf->max_accepted_htlcs > 483) if (remoteconf->max_accepted_htlcs > 483)
@ -155,7 +155,7 @@ static void set_reserve(u64 *reserve, u64 funding)
/* BOLT #2: /* BOLT #2:
* *
* A sending node MUST ensure `temporary-channel-id` is unique from any other * A sending node MUST ensure `temporary_channel_id` is unique from any other
* channel id with the same peer. * channel id with the same peer.
*/ */
static void temporary_channel_id(struct channel_id *channel_id) static void temporary_channel_id(struct channel_id *channel_id)
@ -230,15 +230,15 @@ static u8 *funder_channel(struct state *state,
/* BOLT #2: /* BOLT #2:
* *
* The sender MUST set `funding-satoshis` to less than 2^24 satoshi. */ * The sender MUST set `funding_satoshis` to less than 2^24 satoshi. */
if (state->funding_satoshis >= 1 << 24) if (state->funding_satoshis >= 1 << 24)
peer_failed(PEER_FD, &state->cs, NULL, WIRE_OPENING_BAD_PARAM, peer_failed(PEER_FD, &state->cs, NULL, WIRE_OPENING_BAD_PARAM,
"funding_satoshis must be < 2^24"); "funding_satoshis must be < 2^24");
/* BOLT #2: /* BOLT #2:
* *
* The sender MUST set `push-msat` to equal or less than to 1000 * * The sender MUST set `push_msat` to equal or less than to 1000 *
* `funding-satoshis`. * `funding_satoshis`.
*/ */
if (state->push_msat > 1000 * state->funding_satoshis) if (state->push_msat > 1000 * state->funding_satoshis)
peer_failed(PEER_FD, &state->cs, NULL, WIRE_OPENING_BAD_PARAM, peer_failed(PEER_FD, &state->cs, NULL, WIRE_OPENING_BAD_PARAM,
@ -272,9 +272,9 @@ static u8 *funder_channel(struct state *state,
/* BOLT #2: /* BOLT #2:
* *
* The receiver MUST fail the channel if `funding-pubkey`, * The receiver MUST fail the channel if `funding_pubkey`,
* `revocation-basepoint`, `payment-basepoint` or * `revocation_basepoint`, `payment_basepoint` or
* `delayed-payment-basepoint` are not valid DER-encoded compressed * `delayed_payment_basepoint` are not valid DER-encoded compressed
* secp256k1 pubkeys. * secp256k1 pubkeys.
*/ */
if (!fromwire_accept_channel(msg, NULL, &id_in, if (!fromwire_accept_channel(msg, NULL, &id_in,
@ -297,8 +297,8 @@ static u8 *funder_channel(struct state *state,
/* BOLT #2: /* BOLT #2:
* *
* The `temporary-channel-id` MUST be the same as the * The `temporary_channel_id` MUST be the same as the
* `temporary-channel-id` in the `open_channel` message. */ * `temporary_channel_id` in the `open_channel` message. */
if (!structeq(&id_in, &channel_id)) if (!structeq(&id_in, &channel_id))
peer_failed(PEER_FD, &state->cs, NULL, WIRE_OPENING_PEER_READ_FAILED, peer_failed(PEER_FD, &state->cs, NULL, WIRE_OPENING_PEER_READ_FAILED,
"accept_channel ids don't match: sent %s got %s", "accept_channel ids don't match: sent %s got %s",
@ -307,7 +307,7 @@ static u8 *funder_channel(struct state *state,
/* BOLT #2: /* BOLT #2:
* *
* The receiver MAY reject the `minimum-depth` if it considers it * The receiver MAY reject the `minimum_depth` if it considers it
* unreasonably large. * unreasonably large.
* *
* Other fields have the same requirements as their counterparts in * Other fields have the same requirements as their counterparts in
@ -398,10 +398,10 @@ static u8 *funder_channel(struct state *state,
/* BOLT #2: /* BOLT #2:
* *
* This message introduces the `channel-id` to identify the channel, which * This message introduces the `channel_id` to identify the channel, which
* is derived from the funding transaction by combining the * is derived from the funding transaction by combining the
* `funding-txid` and the `funding-output-index` using big-endian * `funding_txid` and the `funding_output_index` using big-endian
* exclusive-OR (ie. `funding-output-index` alters the last two * exclusive-OR (ie. `funding_output_index` alters the last two
* bytes). * bytes).
*/ */
derive_channel_id(&channel_id, derive_channel_id(&channel_id,
@ -472,9 +472,9 @@ static u8 *fundee_channel(struct state *state,
/* BOLT #2: /* BOLT #2:
* *
* The receiver MUST fail the channel if `funding-pubkey`, * The receiver MUST fail the channel if `funding_pubkey`,
* `revocation-basepoint`, `payment-basepoint` or * `revocation_basepoint`, `payment_basepoint` or
* `delayed-payment-basepoint` are not valid DER-encoded compressed * `delayed_payment_basepoint` are not valid DER-encoded compressed
* secp256k1 pubkeys. * secp256k1 pubkeys.
*/ */
if (!fromwire_open_channel(peer_msg, NULL, &chain_hash.sha, &channel_id, if (!fromwire_open_channel(peer_msg, NULL, &chain_hash.sha, &channel_id,
@ -497,7 +497,7 @@ static u8 *fundee_channel(struct state *state,
/* BOLT #2: /* BOLT #2:
* *
* The receiving MUST reject the channel if the `chain-hash` value * The receiving MUST reject the channel if the `chain_hash` value
* within the `open_channel` message is set to a hash of a chain * within the `open_channel` message is set to a hash of a chain
* unknown to the receiver. * unknown to the receiver.
*/ */
@ -520,8 +520,8 @@ static u8 *fundee_channel(struct state *state,
/* BOLT #2: /* BOLT #2:
* *
* The receiving node ... MUST fail the channel if `push-msat` is * The receiving node ... MUST fail the channel if `push_msat` is
* greater than `funding-amount` * 1000. * greater than `funding_satoshis` * 1000.
*/ */
if (state->push_msat > state->funding_satoshis * 1000) if (state->push_msat > state->funding_satoshis * 1000)
peer_failed(PEER_FD, &state->cs, NULL, WIRE_OPENING_PEER_BAD_FUNDING, peer_failed(PEER_FD, &state->cs, NULL, WIRE_OPENING_PEER_BAD_FUNDING,
@ -531,7 +531,7 @@ static u8 *fundee_channel(struct state *state,
/* BOLT #2: /* BOLT #2:
* *
* The receiver MUST fail the channel if it considers `feerate-per-kw` * The receiver MUST fail the channel if it considers `feerate_per_kw`
* too small for timely processing, or unreasonably large. * too small for timely processing, or unreasonably large.
*/ */
if (state->feerate_per_kw < min_feerate) if (state->feerate_per_kw < min_feerate)
@ -581,8 +581,8 @@ static u8 *fundee_channel(struct state *state,
/* BOLT #2: /* BOLT #2:
* *
* The sender MUST set `temporary-channel-id` the same as the * The sender MUST set `temporary_channel_id` the same as the
* `temporary-channel-id` in the `open_channel` message. */ * `temporary_channel_id` in the `open_channel` message. */
if (!structeq(&id_in, &channel_id)) if (!structeq(&id_in, &channel_id))
peer_failed(PEER_FD, &state->cs, NULL, WIRE_OPENING_PEER_READ_FAILED, peer_failed(PEER_FD, &state->cs, NULL, WIRE_OPENING_PEER_READ_FAILED,
"funding_created ids don't match: sent %s got %s", "funding_created ids don't match: sent %s got %s",
@ -625,10 +625,10 @@ static u8 *fundee_channel(struct state *state,
/* BOLT #2: /* BOLT #2:
* *
* This message introduces the `channel-id` to identify the channel, * This message introduces the `channel_id` to identify the channel,
* which is derived from the funding transaction by combining the * which is derived from the funding transaction by combining the
* `funding-txid` and the `funding-output-index` using big-endian * `funding_txid` and the `funding_output_index` using big-endian
* exclusive-OR (ie. `funding-output-index` alters the last two * exclusive-OR (ie. `funding_output_index` alters the last two
* bytes). * bytes).
*/ */
derive_channel_id(&channel_id, derive_channel_id(&channel_id,

41
lightningd/peer_control.c

@ -875,11 +875,11 @@ static u8 *make_failmsg(const tal_t *ctx, const struct htlc_end *hend,
* processing an incoming Sphinx packet along with the HTLC message it's * processing an incoming Sphinx packet along with the HTLC message it's
* encapsulated within, if the following inequality doesn't hold, then the * encapsulated within, if the following inequality doesn't hold, then the
* HTLC should be rejected as it indicates a prior node in the path has * HTLC should be rejected as it indicates a prior node in the path has
* deviated from the specified paramters: * deviated from the specified parameters:
* *
* incoming_htlc_amt - fee >= amt_to_forward * incoming_htlc_amt - fee >= amt_to_forward
* *
* Where `fee` is calculated according to the receving node's advertised fee * Where `fee` is calculated according to the receiving node's advertised fee
* schema as described in [BOLT 7](https://github.com/lightningnetwork/lightning-rfc/blob/master/07-routing-gossip.md#htlc-fees), or 0 if this node is the * schema as described in [BOLT 7](https://github.com/lightningnetwork/lightning-rfc/blob/master/07-routing-gossip.md#htlc-fees), or 0 if this node is the
* final hop. * final hop.
*/ */
@ -899,15 +899,15 @@ static bool check_amount(struct htlc_end *hend,
* * `outgoing_cltv_value` - The CLTV value that the _outgoing_ HTLC carrying * * `outgoing_cltv_value` - The CLTV value that the _outgoing_ HTLC carrying
* the packet should have. * the packet should have.
* *
* cltv-expiry - cltv-expiry-delta = outgoing_cltv_value * cltv_expiry - cltv_expiry_delta = outgoing_cltv_value
* *
* Inclusion of this field allows a node to both authenticate the information * Inclusion of this field allows a node to both authenticate the information
* specified by the original sender and the paramaters of the HTLC forwarded, * specified by the original sender and the parameters of the HTLC forwarded,
* and ensure the original sender is using the current `cltv-expiry-delta` value. * and ensure the original sender is using the current `cltv_expiry_delta` value.
* If there is no next hop, `cltv-expiry-delta` is zero. * If there is no next hop, `cltv_expiry_delta` is zero.
* If the values don't correspond, then the HTLC should be failed+rejected as * If the values don't correspond, then the HTLC should be failed+rejected as
* this indicates the incoming node has tampered with the intended HTLC * this indicates the incoming node has tampered with the intended HTLC
* values, or the origin has an obsolete `cltv-expiry-delta` value. * values, or the origin has an obsolete `cltv_expiry_delta` value.
* The node MUST be consistent in responding to an unexpected * The node MUST be consistent in responding to an unexpected
* `outgoing_cltv_value` whether it is the final hop or not, to avoid * `outgoing_cltv_value` whether it is the final hop or not, to avoid
* leaking that information. * leaking that information.
@ -948,12 +948,12 @@ static void handle_localpay(struct htlc_end *hend,
/* BOLT #4: /* BOLT #4:
* *
* If the `amt_to_forward` does not match the `incoming_htlc_amt` of * If the `amt_to_forward` is higher than `incoming_htlc_amt` of
* the HTLC at the final hop: * the HTLC at the final hop:
* *
* 1. type: 19 (`final_incorrect_htlc_amount`) * 1. type: 19 (`final_incorrect_htlc_amount`)
* 2. data: * 2. data:
* * [4:incoming-htlc-amt] * * [`4`:`incoming_htlc_amt`]
*/ */
if (!check_amount(hend, amt_to_forward, hend->msatoshis, 0)) { if (!check_amount(hend, amt_to_forward, hend->msatoshis, 0)) {
err = towire_final_incorrect_htlc_amount(hend, hend->msatoshis); err = towire_final_incorrect_htlc_amount(hend, hend->msatoshis);
@ -962,12 +962,12 @@ static void handle_localpay(struct htlc_end *hend,
/* BOLT #4: /* BOLT #4:
* *
* If the `outgoing_cltv_value` does not match the `ctlv-expiry` of * If the `outgoing_cltv_value` does not match the `ctlv_expiry` of
* the HTLC at the final hop: * the HTLC at the final hop:
* *
* 1. type: 18 (`final_incorrect_cltv_expiry`) * 1. type: 18 (`final_incorrect_cltv_expiry`)
* 2. data: * 2. data:
* * [4:cltv-expiry] * * [`4`:`cltv_expiry`]
*/ */
if (!check_ctlv(hend, cltv_expiry, outgoing_cltv_value, 0)) { if (!check_ctlv(hend, cltv_expiry, outgoing_cltv_value, 0)) {
err = towire_final_incorrect_cltv_expiry(hend, cltv_expiry); err = towire_final_incorrect_cltv_expiry(hend, cltv_expiry);
@ -1000,7 +1000,7 @@ static void handle_localpay(struct htlc_end *hend,
/* BOLT #4: /* BOLT #4:
* *
* If the `cltv-expiry` is too low, the final node MUST fail the HTLC: * If the `cltv_expiry` is too low, the final node MUST fail the HTLC:
*/ */
if (get_block_height(hend->peer->ld->topology) if (get_block_height(hend->peer->ld->topology)
+ hend->peer->ld->dstate.config.deadline_blocks >= cltv_expiry) { + hend->peer->ld->dstate.config.deadline_blocks >= cltv_expiry) {
@ -1110,7 +1110,7 @@ static void forward_htlc(struct htlc_end *hend,
* The node creating `channel_update` SHOULD accept HTLCs which pay a * The node creating `channel_update` SHOULD accept HTLCs which pay a
* fee equal or greater than: * fee equal or greater than:
* *
* fee-base-msat + htlc-amount-msat * fee-proportional-millionths / 1000000 * fee_base_msat + amount_msat * fee_proportional_millionths / 1000000
*/ */
if (mul_overflows_u64(amt_to_forward, if (mul_overflows_u64(amt_to_forward,
ld->dstate.config.fee_per_satoshi)) { ld->dstate.config.fee_per_satoshi)) {
@ -1139,8 +1139,8 @@ static void forward_htlc(struct htlc_end *hend,
* setting for the outgoing channel: * setting for the outgoing channel:
* 1. type: UPDATE|14 (`expiry_too_soon`) * 1. type: UPDATE|14 (`expiry_too_soon`)
* 2. data: * 2. data:
* * [2:len] * * [`2`:`len`]
* * [len:channel_update] * * [`len`:`channel_update`]
*/ */
if (get_block_height(next->ld->topology) if (get_block_height(next->ld->topology)
+ next->ld->dstate.config.deadline_blocks >= outgoing_cltv_value) { + next->ld->dstate.config.deadline_blocks >= outgoing_cltv_value) {
@ -1739,7 +1739,7 @@ static void channel_config(struct lightningd *ld,
/* BOLT #2: /* BOLT #2:
* *
* The sender SHOULD set `dust-limit-satoshis` to a sufficient * The sender SHOULD set `dust_limit_satoshis` to a sufficient
* value to allow commitment transactions to propagate through * value to allow commitment transactions to propagate through
* the Bitcoin network. * the Bitcoin network.
*/ */
@ -1751,7 +1751,7 @@ static void channel_config(struct lightningd *ld,
/* BOLT #2: /* BOLT #2:
* *
* The sender SHOULD set `to-self-delay` sufficient to ensure * The sender SHOULD set `to_self_delay` sufficient to ensure
* the sender can irreversibly spend a commitment transaction * the sender can irreversibly spend a commitment transaction
* output in case of misbehavior by the receiver. * output in case of misbehavior by the receiver.
*/ */
@ -1759,7 +1759,7 @@ static void channel_config(struct lightningd *ld,
/* BOLT #2: /* BOLT #2:
* *
* It MUST fail the channel if `max-accepted-htlcs` is greater than * It MUST fail the channel if `max_accepted_htlcs` is greater than
* 483. * 483.
*/ */
ours->max_accepted_htlcs = 483; ours->max_accepted_htlcs = 483;
@ -1803,8 +1803,9 @@ void peer_fundee_open(struct peer *peer, const u8 *from_peer)
/* BOLT #2: /* BOLT #2:
* *
* The sender SHOULD set `minimum-depth` to an amount where * The sender SHOULD set `minimum_depth` to a number of blocks it
* the sender considers reorganizations to be low risk. * considers reasonable to avoid double-spending of the funding
* transaction.
*/ */
peer->minimum_depth = ld->dstate.config.anchor_confirms; peer->minimum_depth = ld->dstate.config.anchor_confirms;

2
lightningd/peer_failed.c

@ -19,7 +19,7 @@ void peer_failed(int peer_fd, struct crypto_state *cs,
/* BOLT #1: /* BOLT #1:
* *
* The channel is referred to by `channel-id` unless `channel-id` is * The channel is referred to by `channel_id` unless `channel_id` is
* zero (ie. all bytes zero), in which case it refers to all channels. * zero (ie. all bytes zero), in which case it refers to all channels.
*/ */
if (!channel_id) { if (!channel_id) {

44
lightningd/sphinx.h

@ -35,22 +35,34 @@ enum route_next_case {
/* BOLT #4: /* BOLT #4:
* *
* The hops_data field is a structure that holds obfuscated versions of the next hop's address, transfer information and the associated HMAC. It is 1060 bytes long, and has the following structure: * The `hops_data` field is a structure that holds obfuscated versions of the
* next hop's address, transfer information and the associated HMAC. It is
``` * 1300 bytes long, and has the following structure:
+-----------+-------------+----------+-----------+-------------+----------+-----------+ *
| n_1 realm | n_1 per-hop | n_1 HMAC | n_2 realm | n_2 per-hop | n_2 HMAC | ...filler | * 1. type: `hops_data`
+-----------+-------------+----------+----------+--------------+----------+------------+ * 2. data:
``` * * [`1`:`realm`]
* * [`32`:`per_hop`]
The realm byte determines the format of the per-hop; so far only realm 0 is defined, and for that, the per-hop format is: * * [`32`:`HMAC`]
* * ...
``` * * `filler`
+----------------------+--------------------------+-------------------------------+--------------------+ *
| channel_id (8 bytes) | amt_to_forward (4 bytes) | outgoing_cltv_value (4 bytes) | padding (16 bytes) | * Where the `realm`, `HMAC` and `per_hop` (whose contents depend on `realm`)
+----------------------+--------------------------+-------------------------------+--------------------+ * are repeated for each hop, and `filler` consists of obfuscated
``` * deterministically generated padding. For details about how the `filler` is
*/ * generated please see below. In addition, `hops_data` is incrementally
* obfuscated at each hop.
*
* The `realm` byte determines the format of the `per_hop`; so far only
* `realm` 0 is defined, and for that, the `per_hop` format is:
*
* 1. type: `per_hop` (for `realm` 0)
* 2. data:
* * [`8`:`channel_id`]
* * [`4`:`amt_to_forward`]
* * [`4`:`outgoing_cltv_value`]
* * [`16`:`padding`]
*/
struct hop_data { struct hop_data {
u8 realm; u8 realm;
struct short_channel_id channel_id; struct short_channel_id channel_id;

2
lightningd/test/run-channel.c

@ -479,7 +479,7 @@ int main(void)
/* BOLT #3: /* BOLT #3:
* *
* name: commitment tx with all 5 htlcs untrimmed (minimum feerate) * name: commitment tx with all 5 HTLCs untrimmed (minimum feerate)
* to_local_msat: 6988000000 * to_local_msat: 6988000000
* to_remote_msat: 3000000000 * to_remote_msat: 3000000000
* local_feerate_per_kw: 0 * local_feerate_per_kw: 0

2
lightningd/test/run-commit_tx.c

@ -716,7 +716,7 @@ int main(void)
/* BOLT #3: /* BOLT #3:
* *
* name: commitment tx with all 5 htlcs untrimmed (minimum feerate) * name: commitment tx with all 5 HTLCs untrimmed (minimum feerate)
* to_local_msat: 6988000000 * to_local_msat: 6988000000
* to_remote_msat: 3000000000 * to_remote_msat: 3000000000
* local_feerate_per_kw: 0 * local_feerate_per_kw: 0

8
wire/fromwire.c

@ -209,10 +209,10 @@ REGISTER_TYPE_TO_HEXSTR(channel_id);
/* BOLT #2: /* BOLT #2:
* *
* This message introduces the `channel-id` to identify the channel, which is * This message introduces the `channel_id` to identify the channel, which is
* derived from the funding transaction by combining the `funding-txid` and * derived from the funding transaction by combining the `funding_txid` and
* the `funding-output-index` using big-endian exclusive-OR * the `funding_output_index` using big-endian exclusive-OR
* (ie. `funding-output-index` alters the last two bytes). * (ie. `funding_output_index` alters the last two bytes).
*/ */
void derive_channel_id(struct channel_id *channel_id, void derive_channel_id(struct channel_id *channel_id,
struct sha256_double *txid, u16 txout) struct sha256_double *txid, u16 txout)

Loading…
Cancel
Save