BOLT update for 8-byte satoshi values, and other updates.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2017-06-06 09:19:10 +09:30
parent 7389aae26a
commit 6f181e0dc1
16 changed files with 83 additions and 66 deletions

View File

@ -702,7 +702,7 @@ u8 **bitcoin_to_local_spend_revocation(const tal_t *ctx,
* key. The output is a P2WSH, with a witness script:
*
* # To you with revocation key
* OP_DUP OP_HASH160 <RIPEMD160(revocationkey)> OP_EQUAL
* OP_DUP OP_HASH160 <RIPEMD160(SHA256(revocationkey))> OP_EQUAL
* OP_IF
* OP_CHECKSIG
* OP_ELSE
@ -767,7 +767,7 @@ u8 *bitcoin_wscript_htlc_offer(const tal_t *ctx,
* payment preimage. The output is a P2WSH, with a witness script:
*
* # To you with revocation key
* OP_DUP OP_HASH160 <RIPEMD160(revocationkey)> OP_EQUAL
* OP_DUP OP_HASH160 <RIPEMD160(SHA256(revocationkey))> OP_EQUAL
* OP_IF
* OP_CHECKSIG
* OP_ELSE

View File

@ -762,7 +762,7 @@ void handle_channel_update(struct routing_state *rstate, const u8 *update, size_
u32 timestamp;
u16 flags;
u16 expiry;
u32 htlc_minimum_msat;
u64 htlc_minimum_msat;
u32 fee_base_msat;
u32 fee_proportional_millionths;
const tal_t *tmpctx = tal_tmpctx(rstate);

View File

@ -351,9 +351,9 @@ enum channel_add_err channel_add_htlc(struct channel *channel,
* 2. data:
* * [`32`:`channel_id`]
* * [`8`:`id`]
* * [`4`:`amount_msat`]
* * [`4`:`cltv_expiry`]
* * [`8`:`amount_msat`]
* * [`32`:`payment_hash`]
* * [`4`:`cltv_expiry`]
* * [`1366`:`onion_routing_packet`]
*/
htlc->routing = tal_dup_arr(htlc, u8, routing, TOTAL_PACKET_SIZE, 0);
@ -391,6 +391,17 @@ enum channel_add_err channel_add_htlc(struct channel *channel,
goto out;
}
/* 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.
*/
if (htlc->msatoshi & 0xFFFFFFFF00000000ULL) {
e = CHANNEL_ERR_MAX_HTLC_VALUE_EXCEEDED;
goto out;
}
/* Figure out what receiver will already be committed to. */
gather_htlcs(tmpctx, channel, recipient, &committed, &removing, &adding);
htlc_arr_append(&adding, htlc);

View File

@ -316,14 +316,14 @@ static void handle_peer_add_htlc(struct peer *peer, const u8 *msg)
{
struct channel_id channel_id;
u64 id;
u32 amount_msat;
u64 amount_msat;
u32 cltv_expiry;
struct sha256 payment_hash;
u8 onion_routing_packet[TOTAL_PACKET_SIZE];
enum channel_add_err add_err;
if (!fromwire_update_add_htlc(msg, NULL, &channel_id, &id, &amount_msat,
&cltv_expiry, &payment_hash,
&payment_hash, &cltv_expiry,
onion_routing_packet))
peer_failed(io_conn_fd(peer->peer_conn),
&peer->pcs.cs,
@ -1128,7 +1128,8 @@ static void handle_funding_announce_depth(struct peer *peer, const u8 *msg)
static void handle_offer_htlc(struct peer *peer, const u8 *inmsg)
{
u8 *msg;
u32 amount_msat, cltv_expiry;
u32 cltv_expiry;
u64 amount_msat;
struct sha256 payment_hash;
u8 onion_routing_packet[TOTAL_PACKET_SIZE];
enum channel_add_err e;
@ -1156,7 +1157,7 @@ static void handle_offer_htlc(struct peer *peer, const u8 *inmsg)
/* Tell the peer. */
msg = towire_update_add_htlc(peer, &peer->channel_id,
peer->htlc_id, amount_msat,
cltv_expiry, &payment_hash,
&payment_hash, cltv_expiry,
onion_routing_packet);
msg_enqueue(&peer->peer_out, take(msg));
peer->funding_locked[LOCAL] = true;

View File

@ -53,7 +53,7 @@ channel_funding_announce_depth,3
# Tell channel to offer this htlc
channel_offer_htlc,4
channel_offer_htlc,,amount_msat,4
channel_offer_htlc,,amount_msat,8
channel_offer_htlc,,cltv_expiry,4
channel_offer_htlc,,payment_hash,32
channel_offer_htlc,,onion_routing_packet,1366*u8
@ -81,7 +81,7 @@ channel_fail_htlc,,error_pkt,len*u8
# Peer and I are irrevocably committed to this HTLC.
channel_accepted_htlc,7
channel_accepted_htlc,,id,8
channel_accepted_htlc,,amount_msat,4
channel_accepted_htlc,,amount_msat,8
channel_accepted_htlc,,cltv_expiry,4
channel_accepted_htlc,,payment_hash,32
channel_accepted_htlc,,next_onion,1366*u8

1 # Shouldn't happen
53 # Reply; synchronous since IDs have to increment.
54 channel_offer_htlc_reply,104
55 channel_offer_htlc_reply,,id,8
56 # Zero failure code means success.
57 channel_offer_htlc_reply,,failure_code,2
58 channel_offer_htlc_reply,,failurestrlen,2
59 channel_offer_htlc_reply,,failurestr,failurestrlen*u8
81 channel_accepted_htlc,,shared_secret,struct secret
82 # FIXME: Add code to commit current channel state!
83 # The HTLC preimage was given.
84 channel_fulfilled_htlc,8
85 channel_fulfilled_htlc,,id,8
86 channel_fulfilled_htlc,,payment_preimage,struct preimage
87 # This HTLC failed

View File

@ -15,7 +15,7 @@
* * [`8`:`dust_limit_satoshis`]
* * [`8`:`max_htlc_value_in_flight_msat`]
* * [`8`:`channel_reserve_satoshis`]
* * [`4`:`htlc_minimum_msat`]
* * [`8`:`htlc_minimum_msat`]
* * [`4`:`feerate_per_kw`]
* * [`2`:`to_self_delay`]
* * [`2`:`max_accepted_htlcs`]
@ -26,8 +26,8 @@
* * [`8`:`dust_limit_satoshis`]
* * [`8`:`max_htlc_value_in_flight_msat`]
* * [`8`:`channel_reserve_satoshis`]
* * [`8`:`htlc_minimum_msat`]
* * [`4`:`minimum_depth`]
* * [`4`:`htlc_minimum_msat`]
* * [`2`:`to_self_delay`]
* * [`2`:`max_accepted_htlcs`]
*/
@ -35,7 +35,7 @@ struct channel_config {
u64 dust_limit_satoshis;
u64 max_htlc_value_in_flight_msat;
u64 channel_reserve_satoshis;
u32 htlc_minimum_msat;
u64 htlc_minimum_msat;
u16 to_self_delay;
u16 max_accepted_htlcs;
};

View File

@ -964,10 +964,11 @@ static void exchange_init(int fd, struct crypto_state *cs,
/* BOLT #1:
*
* The sending node SHOULD use the minimum lengths required to
* represent the feature fields. The sending node MUST set feature
* bits corresponding to features it requires the peer to support, and
* SHOULD set feature bits corresponding to features it optionally
* supports.
* represent the feature fields.
*
* The sender MUST set feature bits as defined in [BOLT
* #9](09-features.md), and MUST set to zero any feature bits that are
* not defined.
*/
u8 *msg = towire_init(NULL, NULL, NULL);

View File

@ -170,7 +170,8 @@ static struct io_plan *handle_channel_update_sig(struct io_conn *conn,
struct sha256_double hash;
secp256k1_ecdsa_signature sig;
struct short_channel_id scid;
u32 timestamp, htlc_minimum_msat, fee_base_msat, fee_proportional_mill;
u32 timestamp, fee_base_msat, fee_proportional_mill;
u64 htlc_minimum_msat;
u16 flags, cltv_expiry_delta;
u8 *cu;

View File

@ -15,7 +15,7 @@ struct htlc_end {
enum htlc_end_type which_end;
struct peer *peer;
u64 htlc_id;
u32 msatoshis;
u64 msatoshis;
struct htlc_end *other_end;
/* If this is driven by a command. */

View File

@ -123,9 +123,9 @@ static bool handshake_succeeded(struct subd *handshaked,
/* BOLT #1:
*
* The receiving node MUST fail the channels if it receives a
* `globalfeatures` or `localfeatures` with an even bit set which it
* does not understand.
* For unknown feature bits which are non-zero, the receiver
* MUST ignore the bit if the bit number is odd, and MUST fail
* the connection if the bit number is even.
*/
if (has_even_bit(globalfeatures)) {
connection_failed(c, handshaked->log,

View File

@ -107,7 +107,7 @@ static void check_config_bounds(struct state *state,
if (remoteconf->htlc_minimum_msat * (u64)1000 > capacity_msat)
peer_failed(PEER_FD, &state->cs, NULL,
WIRE_OPENING_PEER_BAD_CONFIG,
"Invalid htlc_minimum_msat %u"
"Invalid htlc_minimum_msat %"PRIu64
" for funding_satoshis %"PRIu64
" capacity_msat %"PRIu64,
remoteconf->htlc_minimum_msat,
@ -283,8 +283,8 @@ static u8 *funder_channel(struct state *state,
->max_htlc_value_in_flight_msat,
&state->remoteconf
->channel_reserve_satoshis,
&minimum_depth,
&state->remoteconf->htlc_minimum_msat,
&minimum_depth,
&state->remoteconf->to_self_delay,
&state->remoteconf->max_accepted_htlcs,
&their_funding_pubkey,

View File

@ -836,6 +836,8 @@ static u8 *make_failmsg(const tal_t *ctx, const struct htlc_end *hend,
return towire_invalid_onion_key(ctx, onion_sha);
case WIRE_TEMPORARY_CHANNEL_FAILURE:
return towire_temporary_channel_failure(ctx, channel_update);
case WIRE_CHANNEL_DISABLED:
return towire_channel_disabled(ctx);
case WIRE_PERMANENT_CHANNEL_FAILURE:
return towire_permanent_channel_failure(ctx);
case WIRE_REQUIRED_CHANNEL_FEATURE_MISSING:

View File

@ -59,9 +59,9 @@ enum route_next_case {
* 1. type: `per_hop` (for `realm` 0)
* 2. data:
* * [`8`:`channel_id`]
* * [`4`:`amt_to_forward`]
* * [`8`:`amt_to_forward`]
* * [`4`:`outgoing_cltv_value`]
* * [`16`:`padding`]
* * [`12`:`padding`]
*/
struct hop_data {
u8 realm;

View File

@ -9,20 +9,20 @@ invalid_onion_hmac,BADONION|PERM|5
invalid_onion_hmac,0,sha256_of_onion,32
invalid_onion_key,BADONION|PERM|6
invalid_onion_key,0,sha256_of_onion,32
temporary_channel_failure,7
temporary_channel_failure,UPDATE|7
temporary_channel_failure,0,len,2
temporary_channel_failure,2,channel_update,len
permanent_channel_failure,PERM|8
required_channel_feature_missing,PERM|9
unknown_next_peer,PERM|10
amount_below_minimum,UPDATE|11
amount_below_minimum,0,htlc_msat,4
amount_below_minimum,4,len,2
amount_below_minimum,6,channel_update,len
amount_below_minimum,0,htlc_msat,8
amount_below_minimum,8,len,2
amount_below_minimum,10,channel_update,len
fee_insufficient,UPDATE|12
fee_insufficient,0,htlc_msat,4
fee_insufficient,4,len,2
fee_insufficient,6,channel_update,len
fee_insufficient,0,htlc_msat,8
fee_insufficient,8,len,2
fee_insufficient,10,channel_update,len
incorrect_cltv_expiry,UPDATE|13
incorrect_cltv_expiry,0,cltv_expiry,4
incorrect_cltv_expiry,4,len,2
@ -30,6 +30,7 @@ incorrect_cltv_expiry,6,channel_update,len
expiry_too_soon,UPDATE|14
expiry_too_soon,0,len,2
expiry_too_soon,2,channel_update,len
channel_disabled,UPDATE|20
unknown_payment_hash,PERM|15
incorrect_payment_amount,PERM|16
final_expiry_too_soon,17

View File

@ -22,29 +22,29 @@ open_channel,72,push_msat,8
open_channel,80,dust_limit_satoshis,8
open_channel,88,max_htlc_value_in_flight_msat,8
open_channel,96,channel_reserve_satoshis,8
open_channel,104,htlc_minimum_msat,4
open_channel,108,feerate_per_kw,4
open_channel,112,to_self_delay,2
open_channel,114,max_accepted_htlcs,2
open_channel,116,funding_pubkey,33
open_channel,149,revocation_basepoint,33
open_channel,182,payment_basepoint,33
open_channel,215,delayed_payment_basepoint,33
open_channel,248,first_per_commitment_point,33
open_channel,104,htlc_minimum_msat,8
open_channel,112,feerate_per_kw,4
open_channel,116,to_self_delay,2
open_channel,118,max_accepted_htlcs,2
open_channel,120,funding_pubkey,33
open_channel,153,revocation_basepoint,33
open_channel,186,payment_basepoint,33
open_channel,219,delayed_payment_basepoint,33
open_channel,252,first_per_commitment_point,33
accept_channel,33
accept_channel,0,temporary_channel_id,32
accept_channel,32,dust_limit_satoshis,8
accept_channel,40,max_htlc_value_in_flight_msat,8
accept_channel,48,channel_reserve_satoshis,8
accept_channel,56,minimum_depth,4
accept_channel,60,htlc_minimum_msat,4
accept_channel,64,to_self_delay,2
accept_channel,66,max_accepted_htlcs,2
accept_channel,68,funding_pubkey,33
accept_channel,101,revocation_basepoint,33
accept_channel,134,payment_basepoint,33
accept_channel,167,delayed_payment_basepoint,33
accept_channel,200,first_per_commitment_point,33
accept_channel,56,htlc_minimum_msat,8
accept_channel,64,minimum_depth,4
accept_channel,68,to_self_delay,2
accept_channel,70,max_accepted_htlcs,2
accept_channel,72,funding_pubkey,33
accept_channel,105,revocation_basepoint,33
accept_channel,138,payment_basepoint,33
accept_channel,171,delayed_payment_basepoint,33
accept_channel,204,first_per_commitment_point,33
funding_created,34
funding_created,0,temporary_channel_id,32
funding_created,32,funding_txid,32
@ -67,10 +67,10 @@ closing_signed,40,signature,64
update_add_htlc,128
update_add_htlc,0,channel_id,32
update_add_htlc,32,id,8
update_add_htlc,40,amount_msat,4
update_add_htlc,44,cltv_expiry,4
update_add_htlc,40,amount_msat,8
update_add_htlc,48,payment_hash,32
update_add_htlc,80,onion_routing_packet,1366
update_add_htlc,80,cltv_expiry,4
update_add_htlc,84,onion_routing_packet,1366
update_fulfill_htlc,130
update_fulfill_htlc,0,channel_id,32
update_fulfill_htlc,32,id,8
@ -130,6 +130,6 @@ channel_update,64,short_channel_id,8
channel_update,72,timestamp,4
channel_update,76,flags,2
channel_update,78,cltv_expiry_delta,2
channel_update,80,htlc_minimum_msat,4
channel_update,84,fee_base_msat,4
channel_update,88,fee_proportional_millionths,4
channel_update,80,htlc_minimum_msat,8
channel_update,88,fee_base_msat,4
channel_update,92,fee_proportional_millionths,4

View File

@ -101,8 +101,8 @@ struct msg_accept_channel {
u64 dust_limit_satoshis;
u64 max_htlc_value_in_flight_msat;
u64 channel_reserve_satoshis;
u64 htlc_minimum_msat;
u32 minimum_depth;
u32 htlc_minimum_msat;
u16 to_self_delay;
u16 max_accepted_htlcs;
struct pubkey funding_pubkey;
@ -134,7 +134,7 @@ struct msg_channel_update {
u32 timestamp;
u16 flags;
u16 expiry;
u32 htlc_minimum_msat;
u64 htlc_minimum_msat;
u32 fee_base_msat;
u32 fee_proportional_millionths;
struct short_channel_id short_channel_id;
@ -171,7 +171,7 @@ struct msg_open_channel {
u64 dust_limit_satoshis;
u64 max_htlc_value_in_flight_msat;
u64 channel_reserve_satoshis;
u32 htlc_minimum_msat;
u64 htlc_minimum_msat;
u32 feerate_per_kw;
u16 to_self_delay;
u16 max_accepted_htlcs;
@ -205,7 +205,7 @@ struct msg_init {
struct msg_update_add_htlc {
struct channel_id channel_id;
u64 id;
u32 amount_msat;
u64 amount_msat;
u32 expiry;
struct sha256 payment_hash;
u8 onion_routing_packet[TOTAL_PACKET_SIZE];
@ -304,8 +304,8 @@ static void *towire_struct_accept_channel(const tal_t *ctx,
s->dust_limit_satoshis,
s->max_htlc_value_in_flight_msat,
s->channel_reserve_satoshis,
s->minimum_depth,
s->htlc_minimum_msat,
s->minimum_depth,
s->to_self_delay,
s->max_accepted_htlcs,
&s->funding_pubkey,
@ -324,8 +324,8 @@ static struct msg_accept_channel *fromwire_struct_accept_channel(const tal_t *ct
&s->dust_limit_satoshis,
&s->max_htlc_value_in_flight_msat,
&s->channel_reserve_satoshis,
&s->minimum_depth,
&s->htlc_minimum_msat,
&s->minimum_depth,
&s->to_self_delay,
&s->max_accepted_htlcs,
&s->funding_pubkey,
@ -631,8 +631,8 @@ static void *towire_struct_update_add_htlc(const tal_t *ctx,
&s->channel_id,
s->id,
s->amount_msat,
s->expiry,
&s->payment_hash,
s->expiry,
s->onion_routing_packet);
}
@ -644,8 +644,8 @@ static struct msg_update_add_htlc *fromwire_struct_update_add_htlc(const tal_t *
&s->channel_id,
&s->id,
&s->amount_msat,
&s->expiry,
&s->payment_hash,
&s->expiry,
s->onion_routing_packet))
return s;
return tal_free(s);