diff --git a/channeld/Makefile b/channeld/Makefile index 8fb4cc12ff87..49261924a287 100644 --- a/channeld/Makefile +++ b/channeld/Makefile @@ -38,6 +38,7 @@ CHANNELD_COMMON_OBJS := \ common/blockheight_states.o \ common/channel_config.o \ common/channel_id.o \ + common/channel_type.o \ common/crypto_state.o \ common/crypto_sync.o \ common/cryptomsg.o \ diff --git a/channeld/channeld.c b/channeld/channeld.c index 67e994d78f7e..9147b8cc9224 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -33,11 +33,11 @@ #include #include #include +#include #include #include #include #include -#include #include #include #include @@ -360,12 +360,6 @@ static bool handle_master_request_later(struct peer *peer, const u8 *msg) return false; } -static bool channel_type_eq(const struct channel_type *a, - const struct channel_type *b) -{ - return featurebits_eq(a->features, b->features); -} - static bool match_type(const struct channel_type *desired, const struct channel_type *current, struct channel_type **upgradable) @@ -377,31 +371,28 @@ static bool match_type(const struct channel_type *desired, if (channel_type_eq(desired, current)) return true; - for (size_t i = 0; i < tal_count(upgradable); i++) { - if (channel_type_eq(desired, upgradable[i])) - return true; - } - - return false; + return channel_type_eq_any(desired, upgradable); } static void set_channel_type(struct channel *channel, const struct channel_type *type) { - const struct channel_type *cur = channel_type(tmpctx, channel); + const struct channel_type *cur = channel->type; if (channel_type_eq(cur, type)) return; /* We only allow one upgrade at the moment, so that's it. */ - assert(!channel->option_static_remotekey); + assert(!channel_has(channel, OPT_STATIC_REMOTEKEY)); assert(feature_offered(type->features, OPT_STATIC_REMOTEKEY)); /* Do upgrade, tell master. */ - channel->option_static_remotekey = true; + tal_free(channel->type); + channel->type = channel_type_dup(channel, type); status_unusual("Upgraded channel to [%s]", fmt_featurebits(tmpctx, type->features)); - wire_sync_write(MASTER_FD, take(towire_channeld_upgraded(NULL, true))); + wire_sync_write(MASTER_FD, + take(towire_channeld_upgraded(NULL, channel->type))); } #else /* !EXPERIMENTAL_FEATURES */ static bool handle_master_request_later(struct peer *peer, const u8 *msg) @@ -1064,7 +1055,8 @@ static struct bitcoin_signature *calc_commitsigs(const tal_t *ctx, msg = towire_hsmd_sign_remote_commitment_tx(NULL, txs[0], &peer->channel->funding_pubkey[REMOTE], &peer->remote_per_commit, - peer->channel->option_static_remotekey); + channel_has(peer->channel, + OPT_STATIC_REMOTEKEY)); msg = hsm_req(tmpctx, take(msg)); if (!fromwire_hsmd_sign_tx_reply(msg, commit_sig)) @@ -1104,7 +1096,8 @@ static struct bitcoin_signature *calc_commitsigs(const tal_t *ctx, txs[i+1]->wtx->inputs[0].index); msg = towire_hsmd_sign_remote_htlc_tx(NULL, txs[i + 1], wscript, &peer->remote_per_commit, - peer->channel->option_anchor_outputs); + channel_has(peer->channel, + OPT_ANCHOR_OUTPUTS)); msg = hsm_req(tmpctx, take(msg)); if (!fromwire_hsmd_sign_tx_reply(msg, &htlc_sigs[i])) @@ -1632,7 +1625,7 @@ static void handle_peer_commit_sig(struct peer *peer, const u8 *msg) /* SIGHASH_ALL is implied. */ commit_sig.sighash_type = SIGHASH_ALL; htlc_sigs = unraw_sigs(tmpctx, raw_sigs, - peer->channel->option_anchor_outputs); + channel_has(peer->channel, OPT_ANCHOR_OUTPUTS)); txs = channel_txs(tmpctx, &htlc_map, NULL, @@ -2710,7 +2703,7 @@ static void peer_reconnect(struct peer *peer, /* Both these options give us extra fields to check. */ check_extra_fields - = dataloss_protect || peer->channel->option_static_remotekey; + = dataloss_protect || channel_has(peer->channel, OPT_STATIC_REMOTEKEY); /* Our current per-commitment point is the commitment point in the last * received signed commitment */ @@ -2744,7 +2737,8 @@ static void peer_reconnect(struct peer *peer, * to. * - MAY not set `upgradable` if it would be empty. */ - send_tlvs->current_type = channel_type(send_tlvs, peer->channel); + send_tlvs->current_type = tal_dup(send_tlvs, struct channel_type, + peer->channel->type); send_tlvs->upgradable = channel_upgradable_types(send_tlvs, peer->channel); } @@ -2780,7 +2774,7 @@ static void peer_reconnect(struct peer *peer, * - MUST set `your_last_per_commitment_secret` to the last * `per_commitment_secret` it received */ - if (peer->channel->option_static_remotekey) { + if (channel_has(peer->channel, OPT_STATIC_REMOTEKEY)) { msg = towire_channel_reestablish (NULL, &peer->channel_id, peer->next_index[LOCAL], @@ -2943,7 +2937,9 @@ static void peer_reconnect(struct peer *peer, check_future_dataloss_fields(peer, next_revocation_number, &last_local_per_commitment_secret, - peer->channel->option_static_remotekey ? NULL : + channel_has(peer->channel, + OPT_STATIC_REMOTEKEY) + ? NULL : &remote_current_per_commitment_point); } else retransmit_revoke_and_ack = false; @@ -2991,7 +2987,8 @@ static void peer_reconnect(struct peer *peer, next_revocation_number, next_commitment_number, &last_local_per_commitment_secret, - peer->channel->option_static_remotekey + channel_has(peer->channel, + OPT_STATIC_REMOTEKEY) ? NULL : &remote_current_per_commitment_point); @@ -3648,9 +3645,9 @@ static void init_channel(struct peer *peer) struct secret last_remote_per_commit_secret; secp256k1_ecdsa_signature *remote_ann_node_sig; secp256k1_ecdsa_signature *remote_ann_bitcoin_sig; - bool option_static_remotekey, option_anchor_outputs; struct penalty_base *pbases; u8 *reestablish_only; + struct channel_type *channel_type; #if !DEVELOPER bool dev_fail_process_onionpacket; /* Ignored */ #endif @@ -3711,8 +3708,7 @@ static void init_channel(struct peer *peer) &peer->remote_upfront_shutdown_script, &remote_ann_node_sig, &remote_ann_bitcoin_sig, - &option_static_remotekey, - &option_anchor_outputs, + &channel_type, &dev_fast_gossip, &dev_fail_process_onionpacket, &pbases, @@ -3721,7 +3717,8 @@ static void init_channel(struct peer *peer) } status_debug("option_static_remotekey = %u, option_anchor_outputs = %u", - option_static_remotekey, option_anchor_outputs); + channel_type_has(channel_type, OPT_STATIC_REMOTEKEY), + channel_type_has(channel_type, OPT_ANCHOR_OUTPUTS)); /* Keeping an array of pointers is better since it allows us to avoid * extra allocations later. */ @@ -3752,8 +3749,6 @@ static void init_channel(struct peer *peer) type_to_string(tmpctx, struct height_states, blockheight_states), peer->our_blockheight); - status_debug("option_static_remotekey = %u", option_static_remotekey); - if (remote_ann_node_sig && remote_ann_bitcoin_sig) { peer->announcement_node_sigs[REMOTE] = *remote_ann_node_sig; peer->announcement_bitcoin_sigs[REMOTE] = *remote_ann_bitcoin_sig; @@ -3789,8 +3784,7 @@ static void init_channel(struct peer *peer) &points[LOCAL], &points[REMOTE], &funding_pubkey[LOCAL], &funding_pubkey[REMOTE], - option_static_remotekey, - option_anchor_outputs, + take(channel_type), feature_offered(peer->their_features, OPT_LARGE_CHANNELS), opener); diff --git a/channeld/channeld_wire.csv b/channeld/channeld_wire.csv index def355dea902..daf0eaa3e05e 100644 --- a/channeld/channeld_wire.csv +++ b/channeld/channeld_wire.csv @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -71,8 +72,7 @@ msgdata,channeld_init,upfront_shutdown_script_len,u16, msgdata,channeld_init,upfront_shutdown_script,u8,upfront_shutdown_script_len msgdata,channeld_init,remote_ann_node_sig,?secp256k1_ecdsa_signature, msgdata,channeld_init,remote_ann_bitcoin_sig,?secp256k1_ecdsa_signature, -msgdata,channeld_init,option_static_remotekey,bool, -msgdata,channeld_init,option_anchor_outputs,bool, +msgdata,channeld_init,desired_type,channel_type, msgdata,channeld_init,dev_fast_gossip,bool, msgdata,channeld_init,dev_fail_process_onionpacket,bool, msgdata,channeld_init,num_penalty_bases,u32, @@ -233,7 +233,7 @@ msgtype,channeld_dev_quiesce_reply,1109 # Tell master we're upgrading the commitment tx. msgtype,channeld_upgraded,1011 -msgdata,channeld_upgraded,option_static_remotekey,bool, +msgdata,channeld_upgraded,new_type,channel_type, # Tell peer about our latest and greatest blockheight. msgtype,channeld_blockheight,1012 diff --git a/channeld/channeld_wiregen.c b/channeld/channeld_wiregen.c index d0f252459fa6..a6133921e110 100644 --- a/channeld/channeld_wiregen.c +++ b/channeld/channeld_wiregen.c @@ -100,7 +100,7 @@ bool channeld_wire_is_defined(u16 type) /* WIRE: CHANNELD_INIT */ /* Begin! (passes gossipd-client fd) */ -u8 *towire_channeld_init(const tal_t *ctx, const struct chainparams *chainparams, const struct feature_set *our_features, const struct channel_id *channel_id, const struct bitcoin_txid *funding_txid, u16 funding_txout, struct amount_sat funding_satoshi, u32 minimum_depth, u32 our_blockheight, const struct height_states *blockheight_states, u32 lease_expiry, const struct channel_config *our_config, const struct channel_config *their_config, const struct fee_states *fee_states, u32 feerate_min, u32 feerate_max, u32 feerate_penalty, const struct bitcoin_signature *first_commit_sig, const struct per_peer_state *per_peer_state, const struct pubkey *remote_fundingkey, const struct basepoints *remote_basepoints, const struct pubkey *remote_per_commit, const struct pubkey *old_remote_per_commit, enum side opener, u32 fee_base, u32 fee_proportional, struct amount_msat local_msatoshi, const struct basepoints *our_basepoints, const struct pubkey *our_funding_pubkey, const struct node_id *local_node_id, const struct node_id *remote_node_id, u32 commit_msec, u16 cltv_delta, bool last_was_revoke, const struct changed_htlc *last_sent_commit, u64 next_index_local, u64 next_index_remote, u64 revocations_received, u64 next_htlc_id, const struct existing_htlc **htlcs, bool local_funding_locked, bool remote_funding_locked, const struct short_channel_id *funding_short_id, bool reestablish, bool send_shutdown, bool remote_shutdown_received, const u8 *final_scriptpubkey, u8 flags, const u8 *init_peer_pkt, bool reached_announce_depth, const struct secret *last_remote_secret, const u8 *their_features, const u8 *upfront_shutdown_script, const secp256k1_ecdsa_signature *remote_ann_node_sig, const secp256k1_ecdsa_signature *remote_ann_bitcoin_sig, bool option_static_remotekey, bool option_anchor_outputs, bool dev_fast_gossip, bool dev_fail_process_onionpacket, const struct penalty_base *pbases, const u8 *reestablish_only) +u8 *towire_channeld_init(const tal_t *ctx, const struct chainparams *chainparams, const struct feature_set *our_features, const struct channel_id *channel_id, const struct bitcoin_txid *funding_txid, u16 funding_txout, struct amount_sat funding_satoshi, u32 minimum_depth, u32 our_blockheight, const struct height_states *blockheight_states, u32 lease_expiry, const struct channel_config *our_config, const struct channel_config *their_config, const struct fee_states *fee_states, u32 feerate_min, u32 feerate_max, u32 feerate_penalty, const struct bitcoin_signature *first_commit_sig, const struct per_peer_state *per_peer_state, const struct pubkey *remote_fundingkey, const struct basepoints *remote_basepoints, const struct pubkey *remote_per_commit, const struct pubkey *old_remote_per_commit, enum side opener, u32 fee_base, u32 fee_proportional, struct amount_msat local_msatoshi, const struct basepoints *our_basepoints, const struct pubkey *our_funding_pubkey, const struct node_id *local_node_id, const struct node_id *remote_node_id, u32 commit_msec, u16 cltv_delta, bool last_was_revoke, const struct changed_htlc *last_sent_commit, u64 next_index_local, u64 next_index_remote, u64 revocations_received, u64 next_htlc_id, const struct existing_htlc **htlcs, bool local_funding_locked, bool remote_funding_locked, const struct short_channel_id *funding_short_id, bool reestablish, bool send_shutdown, bool remote_shutdown_received, const u8 *final_scriptpubkey, u8 flags, const u8 *init_peer_pkt, bool reached_announce_depth, const struct secret *last_remote_secret, const u8 *their_features, const u8 *upfront_shutdown_script, const secp256k1_ecdsa_signature *remote_ann_node_sig, const secp256k1_ecdsa_signature *remote_ann_bitcoin_sig, const struct channel_type *desired_type, bool dev_fast_gossip, bool dev_fail_process_onionpacket, const struct penalty_base *pbases, const u8 *reestablish_only) { u16 num_last_sent_commit = tal_count(last_sent_commit); u16 num_existing_htlcs = tal_count(htlcs); @@ -185,8 +185,7 @@ u8 *towire_channeld_init(const tal_t *ctx, const struct chainparams *chainparams towire_bool(&p, true); towire_secp256k1_ecdsa_signature(&p, remote_ann_bitcoin_sig); } - towire_bool(&p, option_static_remotekey); - towire_bool(&p, option_anchor_outputs); + towire_channel_type(&p, desired_type); towire_bool(&p, dev_fast_gossip); towire_bool(&p, dev_fail_process_onionpacket); towire_u32(&p, num_penalty_bases); @@ -197,7 +196,7 @@ u8 *towire_channeld_init(const tal_t *ctx, const struct chainparams *chainparams return memcheck(p, tal_count(p)); } -bool fromwire_channeld_init(const tal_t *ctx, const void *p, const struct chainparams **chainparams, struct feature_set **our_features, struct channel_id *channel_id, struct bitcoin_txid *funding_txid, u16 *funding_txout, struct amount_sat *funding_satoshi, u32 *minimum_depth, u32 *our_blockheight, struct height_states **blockheight_states, u32 *lease_expiry, struct channel_config *our_config, struct channel_config *their_config, struct fee_states **fee_states, u32 *feerate_min, u32 *feerate_max, u32 *feerate_penalty, struct bitcoin_signature *first_commit_sig, struct per_peer_state **per_peer_state, struct pubkey *remote_fundingkey, struct basepoints *remote_basepoints, struct pubkey *remote_per_commit, struct pubkey *old_remote_per_commit, enum side *opener, u32 *fee_base, u32 *fee_proportional, struct amount_msat *local_msatoshi, struct basepoints *our_basepoints, struct pubkey *our_funding_pubkey, struct node_id *local_node_id, struct node_id *remote_node_id, u32 *commit_msec, u16 *cltv_delta, bool *last_was_revoke, struct changed_htlc **last_sent_commit, u64 *next_index_local, u64 *next_index_remote, u64 *revocations_received, u64 *next_htlc_id, struct existing_htlc ***htlcs, bool *local_funding_locked, bool *remote_funding_locked, struct short_channel_id *funding_short_id, bool *reestablish, bool *send_shutdown, bool *remote_shutdown_received, u8 **final_scriptpubkey, u8 *flags, u8 **init_peer_pkt, bool *reached_announce_depth, struct secret *last_remote_secret, u8 **their_features, u8 **upfront_shutdown_script, secp256k1_ecdsa_signature **remote_ann_node_sig, secp256k1_ecdsa_signature **remote_ann_bitcoin_sig, bool *option_static_remotekey, bool *option_anchor_outputs, bool *dev_fast_gossip, bool *dev_fail_process_onionpacket, struct penalty_base **pbases, u8 **reestablish_only) +bool fromwire_channeld_init(const tal_t *ctx, const void *p, const struct chainparams **chainparams, struct feature_set **our_features, struct channel_id *channel_id, struct bitcoin_txid *funding_txid, u16 *funding_txout, struct amount_sat *funding_satoshi, u32 *minimum_depth, u32 *our_blockheight, struct height_states **blockheight_states, u32 *lease_expiry, struct channel_config *our_config, struct channel_config *their_config, struct fee_states **fee_states, u32 *feerate_min, u32 *feerate_max, u32 *feerate_penalty, struct bitcoin_signature *first_commit_sig, struct per_peer_state **per_peer_state, struct pubkey *remote_fundingkey, struct basepoints *remote_basepoints, struct pubkey *remote_per_commit, struct pubkey *old_remote_per_commit, enum side *opener, u32 *fee_base, u32 *fee_proportional, struct amount_msat *local_msatoshi, struct basepoints *our_basepoints, struct pubkey *our_funding_pubkey, struct node_id *local_node_id, struct node_id *remote_node_id, u32 *commit_msec, u16 *cltv_delta, bool *last_was_revoke, struct changed_htlc **last_sent_commit, u64 *next_index_local, u64 *next_index_remote, u64 *revocations_received, u64 *next_htlc_id, struct existing_htlc ***htlcs, bool *local_funding_locked, bool *remote_funding_locked, struct short_channel_id *funding_short_id, bool *reestablish, bool *send_shutdown, bool *remote_shutdown_received, u8 **final_scriptpubkey, u8 *flags, u8 **init_peer_pkt, bool *reached_announce_depth, struct secret *last_remote_secret, u8 **their_features, u8 **upfront_shutdown_script, secp256k1_ecdsa_signature **remote_ann_node_sig, secp256k1_ecdsa_signature **remote_ann_bitcoin_sig, struct channel_type **desired_type, bool *dev_fast_gossip, bool *dev_fail_process_onionpacket, struct penalty_base **pbases, u8 **reestablish_only) { u16 num_last_sent_commit; u16 num_existing_htlcs; @@ -297,8 +296,7 @@ bool fromwire_channeld_init(const tal_t *ctx, const void *p, const struct chainp *remote_ann_bitcoin_sig = tal(ctx, secp256k1_ecdsa_signature); fromwire_secp256k1_ecdsa_signature(&cursor, &plen, *remote_ann_bitcoin_sig); } - *option_static_remotekey = fromwire_bool(&cursor, &plen); - *option_anchor_outputs = fromwire_bool(&cursor, &plen); + *desired_type = fromwire_channel_type(ctx, &cursor, &plen); *dev_fast_gossip = fromwire_bool(&cursor, &plen); *dev_fail_process_onionpacket = fromwire_bool(&cursor, &plen); num_penalty_bases = fromwire_u32(&cursor, &plen); @@ -1140,23 +1138,23 @@ bool fromwire_channeld_dev_quiesce_reply(const void *p) /* WIRE: CHANNELD_UPGRADED */ /* Tell master we're upgrading the commitment tx. */ -u8 *towire_channeld_upgraded(const tal_t *ctx, bool option_static_remotekey) +u8 *towire_channeld_upgraded(const tal_t *ctx, const struct channel_type *new_type) { u8 *p = tal_arr(ctx, u8, 0); towire_u16(&p, WIRE_CHANNELD_UPGRADED); - towire_bool(&p, option_static_remotekey); + towire_channel_type(&p, new_type); return memcheck(p, tal_count(p)); } -bool fromwire_channeld_upgraded(const void *p, bool *option_static_remotekey) +bool fromwire_channeld_upgraded(const tal_t *ctx, const void *p, struct channel_type **new_type) { const u8 *cursor = p; size_t plen = tal_count(p); if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_UPGRADED) return false; - *option_static_remotekey = fromwire_bool(&cursor, &plen); + *new_type = fromwire_channel_type(ctx, &cursor, &plen); return cursor != NULL; } @@ -1181,4 +1179,4 @@ bool fromwire_channeld_blockheight(const void *p, u32 *blockheight) *blockheight = fromwire_u32(&cursor, &plen); return cursor != NULL; } -// SHA256STAMP:6f130803e485882bd3fee03f792036434d0a7062e1ba4ec6bc97756460d6b21a +// SHA256STAMP:d00ca466d1339c66bbed6afc95227ca89177dab02344de8e333cc11f85e82cd9 diff --git a/channeld/channeld_wiregen.h b/channeld/channeld_wiregen.h index 3ee7f2addf9b..0dd587a0d9b3 100644 --- a/channeld/channeld_wiregen.h +++ b/channeld/channeld_wiregen.h @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -94,8 +95,8 @@ bool channeld_wire_is_defined(u16 type); /* WIRE: CHANNELD_INIT */ /* Begin! (passes gossipd-client fd) */ -u8 *towire_channeld_init(const tal_t *ctx, const struct chainparams *chainparams, const struct feature_set *our_features, const struct channel_id *channel_id, const struct bitcoin_txid *funding_txid, u16 funding_txout, struct amount_sat funding_satoshi, u32 minimum_depth, u32 our_blockheight, const struct height_states *blockheight_states, u32 lease_expiry, const struct channel_config *our_config, const struct channel_config *their_config, const struct fee_states *fee_states, u32 feerate_min, u32 feerate_max, u32 feerate_penalty, const struct bitcoin_signature *first_commit_sig, const struct per_peer_state *per_peer_state, const struct pubkey *remote_fundingkey, const struct basepoints *remote_basepoints, const struct pubkey *remote_per_commit, const struct pubkey *old_remote_per_commit, enum side opener, u32 fee_base, u32 fee_proportional, struct amount_msat local_msatoshi, const struct basepoints *our_basepoints, const struct pubkey *our_funding_pubkey, const struct node_id *local_node_id, const struct node_id *remote_node_id, u32 commit_msec, u16 cltv_delta, bool last_was_revoke, const struct changed_htlc *last_sent_commit, u64 next_index_local, u64 next_index_remote, u64 revocations_received, u64 next_htlc_id, const struct existing_htlc **htlcs, bool local_funding_locked, bool remote_funding_locked, const struct short_channel_id *funding_short_id, bool reestablish, bool send_shutdown, bool remote_shutdown_received, const u8 *final_scriptpubkey, u8 flags, const u8 *init_peer_pkt, bool reached_announce_depth, const struct secret *last_remote_secret, const u8 *their_features, const u8 *upfront_shutdown_script, const secp256k1_ecdsa_signature *remote_ann_node_sig, const secp256k1_ecdsa_signature *remote_ann_bitcoin_sig, bool option_static_remotekey, bool option_anchor_outputs, bool dev_fast_gossip, bool dev_fail_process_onionpacket, const struct penalty_base *pbases, const u8 *reestablish_only); -bool fromwire_channeld_init(const tal_t *ctx, const void *p, const struct chainparams **chainparams, struct feature_set **our_features, struct channel_id *channel_id, struct bitcoin_txid *funding_txid, u16 *funding_txout, struct amount_sat *funding_satoshi, u32 *minimum_depth, u32 *our_blockheight, struct height_states **blockheight_states, u32 *lease_expiry, struct channel_config *our_config, struct channel_config *their_config, struct fee_states **fee_states, u32 *feerate_min, u32 *feerate_max, u32 *feerate_penalty, struct bitcoin_signature *first_commit_sig, struct per_peer_state **per_peer_state, struct pubkey *remote_fundingkey, struct basepoints *remote_basepoints, struct pubkey *remote_per_commit, struct pubkey *old_remote_per_commit, enum side *opener, u32 *fee_base, u32 *fee_proportional, struct amount_msat *local_msatoshi, struct basepoints *our_basepoints, struct pubkey *our_funding_pubkey, struct node_id *local_node_id, struct node_id *remote_node_id, u32 *commit_msec, u16 *cltv_delta, bool *last_was_revoke, struct changed_htlc **last_sent_commit, u64 *next_index_local, u64 *next_index_remote, u64 *revocations_received, u64 *next_htlc_id, struct existing_htlc ***htlcs, bool *local_funding_locked, bool *remote_funding_locked, struct short_channel_id *funding_short_id, bool *reestablish, bool *send_shutdown, bool *remote_shutdown_received, u8 **final_scriptpubkey, u8 *flags, u8 **init_peer_pkt, bool *reached_announce_depth, struct secret *last_remote_secret, u8 **their_features, u8 **upfront_shutdown_script, secp256k1_ecdsa_signature **remote_ann_node_sig, secp256k1_ecdsa_signature **remote_ann_bitcoin_sig, bool *option_static_remotekey, bool *option_anchor_outputs, bool *dev_fast_gossip, bool *dev_fail_process_onionpacket, struct penalty_base **pbases, u8 **reestablish_only); +u8 *towire_channeld_init(const tal_t *ctx, const struct chainparams *chainparams, const struct feature_set *our_features, const struct channel_id *channel_id, const struct bitcoin_txid *funding_txid, u16 funding_txout, struct amount_sat funding_satoshi, u32 minimum_depth, u32 our_blockheight, const struct height_states *blockheight_states, u32 lease_expiry, const struct channel_config *our_config, const struct channel_config *their_config, const struct fee_states *fee_states, u32 feerate_min, u32 feerate_max, u32 feerate_penalty, const struct bitcoin_signature *first_commit_sig, const struct per_peer_state *per_peer_state, const struct pubkey *remote_fundingkey, const struct basepoints *remote_basepoints, const struct pubkey *remote_per_commit, const struct pubkey *old_remote_per_commit, enum side opener, u32 fee_base, u32 fee_proportional, struct amount_msat local_msatoshi, const struct basepoints *our_basepoints, const struct pubkey *our_funding_pubkey, const struct node_id *local_node_id, const struct node_id *remote_node_id, u32 commit_msec, u16 cltv_delta, bool last_was_revoke, const struct changed_htlc *last_sent_commit, u64 next_index_local, u64 next_index_remote, u64 revocations_received, u64 next_htlc_id, const struct existing_htlc **htlcs, bool local_funding_locked, bool remote_funding_locked, const struct short_channel_id *funding_short_id, bool reestablish, bool send_shutdown, bool remote_shutdown_received, const u8 *final_scriptpubkey, u8 flags, const u8 *init_peer_pkt, bool reached_announce_depth, const struct secret *last_remote_secret, const u8 *their_features, const u8 *upfront_shutdown_script, const secp256k1_ecdsa_signature *remote_ann_node_sig, const secp256k1_ecdsa_signature *remote_ann_bitcoin_sig, const struct channel_type *desired_type, bool dev_fast_gossip, bool dev_fail_process_onionpacket, const struct penalty_base *pbases, const u8 *reestablish_only); +bool fromwire_channeld_init(const tal_t *ctx, const void *p, const struct chainparams **chainparams, struct feature_set **our_features, struct channel_id *channel_id, struct bitcoin_txid *funding_txid, u16 *funding_txout, struct amount_sat *funding_satoshi, u32 *minimum_depth, u32 *our_blockheight, struct height_states **blockheight_states, u32 *lease_expiry, struct channel_config *our_config, struct channel_config *their_config, struct fee_states **fee_states, u32 *feerate_min, u32 *feerate_max, u32 *feerate_penalty, struct bitcoin_signature *first_commit_sig, struct per_peer_state **per_peer_state, struct pubkey *remote_fundingkey, struct basepoints *remote_basepoints, struct pubkey *remote_per_commit, struct pubkey *old_remote_per_commit, enum side *opener, u32 *fee_base, u32 *fee_proportional, struct amount_msat *local_msatoshi, struct basepoints *our_basepoints, struct pubkey *our_funding_pubkey, struct node_id *local_node_id, struct node_id *remote_node_id, u32 *commit_msec, u16 *cltv_delta, bool *last_was_revoke, struct changed_htlc **last_sent_commit, u64 *next_index_local, u64 *next_index_remote, u64 *revocations_received, u64 *next_htlc_id, struct existing_htlc ***htlcs, bool *local_funding_locked, bool *remote_funding_locked, struct short_channel_id *funding_short_id, bool *reestablish, bool *send_shutdown, bool *remote_shutdown_received, u8 **final_scriptpubkey, u8 *flags, u8 **init_peer_pkt, bool *reached_announce_depth, struct secret *last_remote_secret, u8 **their_features, u8 **upfront_shutdown_script, secp256k1_ecdsa_signature **remote_ann_node_sig, secp256k1_ecdsa_signature **remote_ann_bitcoin_sig, struct channel_type **desired_type, bool *dev_fast_gossip, bool *dev_fail_process_onionpacket, struct penalty_base **pbases, u8 **reestablish_only); /* WIRE: CHANNELD_FUNDING_DEPTH */ /* master->channeld funding hit new depth(funding locked if >= lock depth) */ @@ -230,8 +231,8 @@ bool fromwire_channeld_dev_quiesce_reply(const void *p); /* WIRE: CHANNELD_UPGRADED */ /* Tell master we're upgrading the commitment tx. */ -u8 *towire_channeld_upgraded(const tal_t *ctx, bool option_static_remotekey); -bool fromwire_channeld_upgraded(const void *p, bool *option_static_remotekey); +u8 *towire_channeld_upgraded(const tal_t *ctx, const struct channel_type *new_type); +bool fromwire_channeld_upgraded(const tal_t *ctx, const void *p, struct channel_type **new_type); /* WIRE: CHANNELD_BLOCKHEIGHT */ /* Tell peer about our latest and greatest blockheight. */ @@ -240,4 +241,4 @@ bool fromwire_channeld_blockheight(const void *p, u32 *blockheight); #endif /* LIGHTNING_CHANNELD_CHANNELD_WIREGEN_H */ -// SHA256STAMP:6f130803e485882bd3fee03f792036434d0a7062e1ba4ec6bc97756460d6b21a +// SHA256STAMP:d00ca466d1339c66bbed6afc95227ca89177dab02344de8e333cc11f85e82cd9 diff --git a/channeld/full_channel.c b/channeld/full_channel.c index 39fb3dacb8a7..4dcd6668808b 100644 --- a/channeld/full_channel.c +++ b/channeld/full_channel.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -100,15 +101,14 @@ struct channel *new_full_channel(const tal_t *ctx, u32 lease_expiry, struct amount_sat funding, struct amount_msat local_msat, - const struct fee_states *fee_states, + const struct fee_states *fee_states TAKES, const struct channel_config *local, const struct channel_config *remote, const struct basepoints *local_basepoints, const struct basepoints *remote_basepoints, const struct pubkey *local_funding_pubkey, const struct pubkey *remote_funding_pubkey, - bool option_static_remotekey, - bool option_anchor_outputs, + const struct channel_type *type TAKES, bool option_wumbo, enum side opener) { @@ -127,8 +127,7 @@ struct channel *new_full_channel(const tal_t *ctx, remote_basepoints, local_funding_pubkey, remote_funding_pubkey, - option_static_remotekey, - option_anchor_outputs, + type, option_wumbo, opener); @@ -262,6 +261,7 @@ static void add_htlcs(struct bitcoin_tx ***txs, size_t i; struct bitcoin_txid txid; u32 feerate_per_kw = channel_feerate(channel, side); + bool option_anchor_outputs = channel_has(channel, OPT_ANCHOR_OUTPUTS); /* Get txid of commitment transaction */ bitcoin_txid((*txs)[0], &txid); @@ -278,7 +278,7 @@ static void add_htlcs(struct bitcoin_tx ***txs, if (htlc_owner(htlc) == side) { ripemd160(&ripemd, htlc->rhash.u.u8, sizeof(htlc->rhash.u.u8)); wscript = htlc_offered_wscript(tmpctx, &ripemd, keyset, - channel->option_anchor_outputs); + option_anchor_outputs); tx = htlc_timeout_tx(*txs, chainparams, &txid, i, wscript, htlc->amount, @@ -286,19 +286,19 @@ static void add_htlcs(struct bitcoin_tx ***txs, channel->config[!side].to_self_delay, feerate_per_kw, keyset, - channel->option_anchor_outputs); + option_anchor_outputs); } else { ripemd160(&ripemd, htlc->rhash.u.u8, sizeof(htlc->rhash.u.u8)); wscript = htlc_received_wscript(tmpctx, &ripemd, &htlc->expiry, keyset, - channel->option_anchor_outputs); + option_anchor_outputs); tx = htlc_success_tx(*txs, chainparams, &txid, i, wscript, htlc->amount, channel->config[!side].to_self_delay, feerate_per_kw, keyset, - channel->option_anchor_outputs); + option_anchor_outputs); } /* Append to array. */ @@ -323,7 +323,7 @@ struct bitcoin_tx **channel_txs(const tal_t *ctx, if (!derive_keyset(per_commitment_point, &channel->basepoints[side], &channel->basepoints[!side], - channel->option_static_remotekey, + channel_has(channel, OPT_STATIC_REMOTEKEY), &keyset)) return NULL; @@ -350,7 +350,7 @@ struct bitcoin_tx **channel_txs(const tal_t *ctx, channel->config[side].dust_limit, channel->view[side].owed[side], channel->view[side].owed[!side], committed, htlcmap, direct_outputs, commitment_number ^ channel->commitment_number_obscurer, - channel->option_anchor_outputs, + channel_has(channel, OPT_ANCHOR_OUTPUTS), side); /* Set the remote/local pubkeys on the commitment tx psbt */ @@ -431,13 +431,13 @@ static struct amount_sat fee_for_htlcs(const struct channel *channel, u32 feerate = channel_feerate(channel, side); struct amount_sat dust_limit = channel->config[side].dust_limit; size_t untrimmed; + bool option_anchor_outputs = channel_has(channel, OPT_ANCHOR_OUTPUTS); untrimmed = num_untrimmed_htlcs(side, dust_limit, feerate, - channel->option_anchor_outputs, + option_anchor_outputs, committed, adding, removing); - return commit_tx_base_fee(feerate, untrimmed, - channel->option_anchor_outputs); + return commit_tx_base_fee(feerate, untrimmed, option_anchor_outputs); } /* @@ -474,6 +474,7 @@ static bool local_opener_has_fee_headroom(const struct channel *channel, u32 feerate = channel_feerate(channel, LOCAL); size_t untrimmed; struct amount_sat fee; + bool option_anchor_outputs = channel_has(channel, OPT_ANCHOR_OUTPUTS); assert(channel->opener == LOCAL); @@ -481,13 +482,13 @@ static bool local_opener_has_fee_headroom(const struct channel *channel, * only *reduce* this number, so use current feerate here! */ untrimmed = num_untrimmed_htlcs(LOCAL, channel->config[LOCAL].dust_limit, feerate, - channel->option_anchor_outputs, + option_anchor_outputs, committed, adding, removing); /* Now, how much would it cost us if feerate increases 100% and we added * another HTLC? */ fee = commit_tx_base_fee(2 * feerate, untrimmed + 1, - channel->option_anchor_outputs); + option_anchor_outputs); if (amount_msat_greater_eq_sat(remainder, fee)) return true; @@ -517,6 +518,7 @@ static enum channel_add_err add_htlc(struct channel *channel, const struct htlc **committed, **adding, **removing; const struct channel_view *view; size_t htlc_count; + bool option_anchor_outputs = channel_has(channel, OPT_ANCHOR_OUTPUTS); htlc = tal(tmpctx, struct htlc); @@ -685,7 +687,7 @@ static enum channel_add_err add_htlc(struct channel *channel, * of 330 sats from the funder (either `to_local` or * `to_remote`). */ - if (channel->option_anchor_outputs + if (option_anchor_outputs && channel->opener == sender && !amount_msat_sub_sat(&remainder, remainder, AMOUNT_SAT(660))) return CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED; @@ -719,7 +721,7 @@ static enum channel_add_err add_htlc(struct channel *channel, &remainder)) return CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED; - if (channel->option_anchor_outputs + if (option_anchor_outputs && channel->opener != sender && !amount_msat_sub_sat(&remainder, remainder, AMOUNT_SAT(660))) return CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED; @@ -1089,6 +1091,7 @@ u32 approx_max_feerate(const struct channel *channel) u64 weight; struct amount_sat avail; const struct htlc **committed, **adding, **removing; + bool option_anchor_outputs = channel_has(channel, OPT_ANCHOR_OUTPUTS); gather_htlcs(tmpctx, channel, !channel->opener, &committed, &removing, &adding); @@ -1096,7 +1099,7 @@ u32 approx_max_feerate(const struct channel *channel) /* Assume none are trimmed; this gives lower bound on feerate. */ num = tal_count(committed) + tal_count(adding) - tal_count(removing); - weight = commit_tx_base_weight(num, channel->option_anchor_outputs); + weight = commit_tx_base_weight(num, option_anchor_outputs); /* Available is their view */ avail = amount_msat_to_sat_round_down(channel->view[!channel->opener].owed[channel->opener]); @@ -1107,7 +1110,7 @@ u32 approx_max_feerate(const struct channel *channel) * of 330 sats from the funder (either `to_local` or * `to_remote`). */ - if (channel->option_anchor_outputs + if (option_anchor_outputs && !amount_sat_sub(&avail, avail, AMOUNT_SAT(660))) { avail = AMOUNT_SAT(0); } else { @@ -1126,21 +1129,23 @@ bool can_opener_afford_feerate(const struct channel *channel, u32 feerate_per_kw struct amount_sat dust_limit = channel->config[!channel->opener].dust_limit; size_t untrimmed; const struct htlc **committed, **adding, **removing; + bool option_anchor_outputs = channel_has(channel, OPT_ANCHOR_OUTPUTS); + gather_htlcs(tmpctx, channel, !channel->opener, &committed, &removing, &adding); untrimmed = commit_tx_num_untrimmed(committed, feerate_per_kw, dust_limit, - channel->option_anchor_outputs, + option_anchor_outputs, !channel->opener) + commit_tx_num_untrimmed(adding, feerate_per_kw, dust_limit, - channel->option_anchor_outputs, + option_anchor_outputs, !channel->opener) - commit_tx_num_untrimmed(removing, feerate_per_kw, dust_limit, - channel->option_anchor_outputs, + option_anchor_outputs, !channel->opener); fee = commit_tx_base_fee(feerate_per_kw, untrimmed, - channel->option_anchor_outputs); + option_anchor_outputs); /* BOLT #3: * If `option_anchors` applies to the commitment @@ -1148,7 +1153,7 @@ bool can_opener_afford_feerate(const struct channel *channel, u32 feerate_per_kw * of 330 sats from the funder (either `to_local` or * `to_remote`). */ - if (channel->option_anchor_outputs + if (option_anchor_outputs && !amount_sat_add(&fee, fee, AMOUNT_SAT(660))) status_failed(STATUS_FAIL_INTERNAL_ERROR, "Cannot add 660 sats to %s for anchor", diff --git a/channeld/full_channel.h b/channeld/full_channel.h index 689a873c339b..8351de8defd0 100644 --- a/channeld/full_channel.h +++ b/channeld/full_channel.h @@ -28,8 +28,7 @@ struct existing_htlc; * @remote_basepoints: remote basepoints. * @local_fundingkey: local funding key * @remote_fundingkey: remote funding key - * @option_static_remotekey: use `option_static_remotekey`. - * @option_anchor_outputs: use `option_anchor_outputs`. + * @type: type for this channel * @option_wumbo: large channel negotiated. * @opener: which side initiated it. * @@ -44,15 +43,14 @@ struct channel *new_full_channel(const tal_t *ctx, u32 lease_expiry, struct amount_sat funding, struct amount_msat local_msat, - const struct fee_states *fee_states, + const struct fee_states *fee_states TAKES, const struct channel_config *local, const struct channel_config *remote, const struct basepoints *local_basepoints, const struct basepoints *remote_basepoints, const struct pubkey *local_funding_pubkey, const struct pubkey *remote_funding_pubkey, - bool option_static_remotekey, - bool option_anchor_outputs, + const struct channel_type *type TAKES, bool option_wumbo, enum side opener); diff --git a/channeld/test/Makefile b/channeld/test/Makefile index 7847f022291c..73faebf121ae 100644 --- a/channeld/test/Makefile +++ b/channeld/test/Makefile @@ -9,7 +9,9 @@ ALL_TEST_PROGRAMS += $(CHANNELD_TEST_PROGRAMS) CHANNELD_TEST_COMMON_OBJS := \ common/amount.o \ + common/channel_type.o \ common/daemon_conn.o \ + common/features.o \ common/htlc_state.o \ common/htlc_trim.o \ common/htlc_tx.o \ diff --git a/channeld/test/run-commit_tx.c b/channeld/test/run-commit_tx.c index eb167f7d27ac..03bce950fb05 100644 --- a/channeld/test/run-commit_tx.c +++ b/channeld/test/run-commit_tx.c @@ -1,5 +1,6 @@ #include #include +#include #include static bool print_superverbose; #define SUPERVERBOSE(...) \ diff --git a/channeld/test/run-full_channel.c b/channeld/test/run-full_channel.c index a9cb50362fbc..037bda5e0ed7 100644 --- a/channeld/test/run-full_channel.c +++ b/channeld/test/run-full_channel.c @@ -30,9 +30,6 @@ void memleak_add_helper_(const tal_t *p UNNEEDED, void (*cb)(struct htable *memt /* Generated stub for memleak_remove_htable */ void memleak_remove_htable(struct htable *memtable UNNEEDED, const struct htable *ht UNNEEDED) { fprintf(stderr, "memleak_remove_htable called!\n"); abort(); } -/* Generated stub for set_feature_bit */ -void set_feature_bit(u8 **ptr UNNEEDED, u32 bit UNNEEDED) -{ fprintf(stderr, "set_feature_bit called!\n"); abort(); } /* Generated stub for status_failed */ void status_failed(enum status_failreason code UNNEEDED, const char *fmt UNNEEDED, ...) @@ -493,7 +490,7 @@ int main(int argc, const char *argv[]) &localbase, &remotebase, &local_funding_pubkey, &remote_funding_pubkey, - false, false, false, LOCAL); + take(channel_type_none(NULL)), false, LOCAL); rchannel = new_full_channel(tmpctx, &cid, &funding_txid, funding_output_index, 0, take(new_height_states(NULL, REMOTE, &blockheight)), @@ -506,7 +503,7 @@ int main(int argc, const char *argv[]) &remotebase, &localbase, &remote_funding_pubkey, &local_funding_pubkey, - false, false, false, REMOTE); + take(channel_type_none(NULL)), false, REMOTE); /* BOLT #3: * diff --git a/channeld/watchtower.c b/channeld/watchtower.c index 994f643d0980..efb13468e2c7 100644 --- a/channeld/watchtower.c +++ b/channeld/watchtower.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -32,7 +33,7 @@ penalty_tx_create(const tal_t *ctx, struct amount_sat fee, min_out, amt; struct bitcoin_signature sig; u32 locktime = 0; - bool option_static_remotekey = channel->option_static_remotekey; + bool option_static_remotekey = channel_has(channel, OPT_STATIC_REMOTEKEY); u8 **witness; u32 remote_to_self_delay = channel->config[REMOTE].to_self_delay; const struct amount_sat dust_limit = channel->config[LOCAL].dust_limit; diff --git a/closingd/closingd.c b/closingd/closingd.c index b71b2c60a20a..9e76842aa6ce 100644 --- a/closingd/closingd.c +++ b/closingd/closingd.c @@ -595,7 +595,7 @@ static void calc_fee_bounds(size_t expected_weight, *minfee = amount_tx_fee(min_feerate, expected_weight); *desiredfee = amount_tx_fee(desired_feerate, expected_weight); - /* BOLT-closing-fee_range #2: + /* BOLT #2: * - if it is not the funder: * - SHOULD set `max_fee_satoshis` to at least the `max_fee_satoshis` * received @@ -605,7 +605,9 @@ static void calc_fee_bounds(size_t expected_weight, */ if (opener == REMOTE) { *maxfee = funding; - /* BOLT-closing-fee_range #2: + + /* This used to appear in BOLT #2: we still set it for non-anchor + * peers who may still enforce it: * - If the channel does not use `option_anchor_outputs`: * - MUST set `fee_satoshis` less than or equal to the base fee of * the final commitment transaction, as calculated in @@ -685,7 +687,7 @@ static void do_quickclose(struct amount_sat offer[NUM_SIDES], struct tlv_closing_signed_tlvs_fee_range overlap; - /* BOLT-closing-fee_range #2: + /* BOLT #2: * - if the message contains a `fee_range`: * - if there is no overlap between that and its own `fee_range`: * - SHOULD fail the connection @@ -715,12 +717,12 @@ static void do_quickclose(struct amount_sat offer[NUM_SIDES], type_to_string(tmpctx, struct amount_sat, &overlap.max_fee_satoshis)); - /* BOLT-closing-fee_range #2: + /* BOLT #2: * - otherwise: * - if it is the funder: * - if `fee_satoshis` is not in the overlap between the sent * and received `fee_range`: - * - SHOULD fail the connection + * - MUST fail the channel * - otherwise: * - MUST reply with the same `fee_satoshis`. */ @@ -758,11 +760,11 @@ static void do_quickclose(struct amount_sat offer[NUM_SIDES], our_feerange); } } else { - /* BOLT-closing-fee_range #2: + /* BOLT #2: * - otherwise (it is not the funder): * - if it has already sent a `closing_signed`: * - if `fee_satoshis` is not the same as the value it sent: - * - SHOULD fail the connection. + * - MUST fail the channel * - otherwise: * - MUST propose a `fee_satoshis` in the overlap between * received and (about-to-be) sent `fee_range`. @@ -810,12 +812,12 @@ static void do_quickclose(struct amount_sat offer[NUM_SIDES], wrong_funding, closing_txid, NULL); - /* BOLT-closing-fee_range #2: + /* BOLT #2: * - otherwise (it is not the funder): * - if it has already sent a `closing_signed`: * - if `fee_satoshis` is not the same as the value * it sent: - * - SHOULD fail the connection. + * - MUST fail the channel */ if (!amount_sat_eq(offer[LOCAL], offer[REMOTE])) { peer_failed_warn(pps, channel_id, diff --git a/closingd/closingd_wiregen.c b/closingd/closingd_wiregen.c index c8c8b6c3ec9e..9412bba5fca3 100644 --- a/closingd/closingd_wiregen.c +++ b/closingd/closingd_wiregen.c @@ -209,4 +209,4 @@ bool fromwire_closingd_complete(const void *p) return false; return cursor != NULL; } -// SHA256STAMP:be6dbb532dfd3c159212838acedd4bad3c8b4b16b5193b8c2a752697a15c8ab1 +// SHA256STAMP:0d0d56c4ec5230461ead5cfac728e57e75db7bff1b53b1b0aaef20b82ce76362 diff --git a/closingd/closingd_wiregen.h b/closingd/closingd_wiregen.h index 5a02f8036a5e..e4162fa3f706 100644 --- a/closingd/closingd_wiregen.h +++ b/closingd/closingd_wiregen.h @@ -56,4 +56,4 @@ bool fromwire_closingd_complete(const void *p); #endif /* LIGHTNING_CLOSINGD_CLOSINGD_WIREGEN_H */ -// SHA256STAMP:be6dbb532dfd3c159212838acedd4bad3c8b4b16b5193b8c2a752697a15c8ab1 +// SHA256STAMP:0d0d56c4ec5230461ead5cfac728e57e75db7bff1b53b1b0aaef20b82ce76362 diff --git a/common/Makefile b/common/Makefile index aeadc739a1d2..f0e68d2e615c 100644 --- a/common/Makefile +++ b/common/Makefile @@ -17,6 +17,7 @@ COMMON_SRC_NOGEN := \ common/bolt12_merkle.c \ common/channel_config.c \ common/channel_id.c \ + common/channel_type.c \ common/coin_mvt.c \ common/close_tx.c \ common/configdir.c \ diff --git a/common/channel_type.c b/common/channel_type.c new file mode 100644 index 000000000000..9a7abf0c2198 --- /dev/null +++ b/common/channel_type.c @@ -0,0 +1,143 @@ +#include +#include + +/* BOLT #2: + * Channel types are an explicit enumeration: for convenience of future + * definitions they reuse even feature bits, but they are not an + * arbitrary combination (they represent the persistent features which + * affect the channel operation). + * + * The currently defined types are: + * - no features (no bits set) + * - `option_static_remotekey` (bit 12) + * - `option_anchor_outputs` and `option_static_remotekey` (bits 20 and 12) + * - `option_anchors_zero_fee_htlc_tx` and `option_static_remotekey` (bits 22 + * and 12) + */ +struct channel_type *channel_type_none(const tal_t *ctx) +{ + struct channel_type *type = tal(ctx, struct channel_type); + + type->features = tal_arr(type, u8, 0); + return type; +} + +struct channel_type *channel_type_static_remotekey(const tal_t *ctx) +{ + struct channel_type *type = channel_type_none(ctx); + + set_feature_bit(&type->features, + COMPULSORY_FEATURE(OPT_STATIC_REMOTEKEY)); + return type; +} + +struct channel_type *channel_type_anchor_outputs(const tal_t *ctx) +{ + struct channel_type *type = channel_type_none(ctx); + + set_feature_bit(&type->features, + COMPULSORY_FEATURE(OPT_ANCHOR_OUTPUTS)); + set_feature_bit(&type->features, + COMPULSORY_FEATURE(OPT_STATIC_REMOTEKEY)); + return type; +} + +struct channel_type *default_channel_type(const tal_t *ctx, + const struct feature_set *our_features, + const u8 *their_features) +{ + /* BOLT #2: + * Both peers: + * - if `channel_type` was present in both `open_channel` and `accept_channel`: + * - This is the `channel_type` (they must be equal, required above) + * - otherwise: + */ + /* BOLT #2: + * - otherwise, if `option_anchor_outputs` was negotiated: + * - the `channel_type` is `option_anchor_outputs` and + * `option_static_remotekey` (bits 20 and 12) + */ + if (feature_negotiated(our_features, their_features, + OPT_ANCHOR_OUTPUTS)) + return channel_type_anchor_outputs(ctx); + /* BOLT #2: + * - otherwise, if `option_static_remotekey` was negotiated: + * - the `channel_type` is `option_static_remotekey` (bit 12) + */ + else if (feature_negotiated(our_features, their_features, + OPT_STATIC_REMOTEKEY)) + return channel_type_static_remotekey(ctx); + /* BOLT #2: + * - otherwise: + * - the `channel_type` is empty + */ + else + return channel_type_none(ctx); +} + +bool channel_type_has(const struct channel_type *type, int feature) +{ + return feature_offered(type->features, feature); +} + +bool channel_type_eq(const struct channel_type *a, + const struct channel_type *b) +{ + return featurebits_eq(a->features, b->features); +} + +bool channel_type_eq_any(const struct channel_type *t, + struct channel_type **arr) +{ + for (size_t i = 0; i < tal_count(arr); i++) { + if (channel_type_eq(t, arr[i])) + return true; + } + return false; +} + +struct channel_type *channel_type_dup(const tal_t *ctx, + const struct channel_type *t) +{ + struct channel_type *ret = tal(ctx, struct channel_type); + ret->features = tal_dup_talarr(ret, u8, t->features); + return ret; +} + +struct channel_type *channel_type_accept(const tal_t *ctx, + const u8 *t, + const struct feature_set *our_features, + const u8 *their_features) +{ + struct channel_type *ctype; + static const size_t feats[] = { OPT_ANCHOR_OUTPUTS, + OPT_STATIC_REMOTEKEY }; + + for (size_t i = 0; i < ARRAY_SIZE(feats); i++) { + size_t f = feats[i]; + + if (feature_offered(t, f)) { + /* If we don't offer a feature, we don't allow it. */ + if (!feature_offered(our_features->bits[INIT_FEATURE], f)) + return NULL; + } else { + /* We assume that if we *require* a feature, we require + * channels have that. */ + if (feature_is_set(our_features->bits[INIT_FEATURE], + COMPULSORY_FEATURE(f))) + return NULL; + } + } + + /* Otherwise, just needs to be a known channel type. */ + ctype = channel_type_none(tmpctx); + if (featurebits_eq(t, ctype->features)) + return tal_steal(ctx, ctype); + ctype = channel_type_static_remotekey(tmpctx); + if (featurebits_eq(t, ctype->features)) + return tal_steal(ctx, ctype); + ctype = channel_type_anchor_outputs(tmpctx); + if (featurebits_eq(t, ctype->features)) + return tal_steal(ctx, ctype); + return NULL; +} diff --git a/common/channel_type.h b/common/channel_type.h new file mode 100644 index 000000000000..e34ee52bfd5d --- /dev/null +++ b/common/channel_type.h @@ -0,0 +1,38 @@ +/* This represents a channel type: i.e. the sticky feature bits. */ +#ifndef LIGHTNING_COMMON_CHANNEL_TYPE_H +#define LIGHTNING_COMMON_CHANNEL_TYPE_H +#include "config.h" +#include +#include + +/* Explicit channel types */ +struct channel_type *channel_type_none(const tal_t *ctx); +struct channel_type *channel_type_static_remotekey(const tal_t *ctx); +struct channel_type *channel_type_anchor_outputs(const tal_t *ctx); + +/* Duplicate a channel_type */ +struct channel_type *channel_type_dup(const tal_t *ctx, + const struct channel_type *t); + +/* Derive channel type from feature negotiation */ +struct channel_type *default_channel_type(const tal_t *ctx, + const struct feature_set *our_features, + const u8 *their_features); + +/* Does this type include this feature? */ +bool channel_type_has(const struct channel_type *type, int feature); + +/* Are these two channel_types equivalent? */ +bool channel_type_eq(const struct channel_type *a, + const struct channel_type *b); + +/* Is channel_type_eq() for any type in this array? */ +bool channel_type_eq_any(const struct channel_type *t, + struct channel_type **arr); + +/* Return channel_type if this is acceptable, otherwise NULL */ +struct channel_type *channel_type_accept(const tal_t *ctx, + const u8 *t, + const struct feature_set *our_features, + const u8 *their_features); +#endif /* LIGHTNING_COMMON_CHANNEL_TYPE_H */ diff --git a/common/initial_channel.c b/common/initial_channel.c index 19e6291cbd5e..cb6ec9100df8 100644 --- a/common/initial_channel.c +++ b/common/initial_channel.c @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include #include @@ -33,8 +33,7 @@ struct channel *new_initial_channel(const tal_t *ctx, const struct basepoints *remote_basepoints, const struct pubkey *local_funding_pubkey, const struct pubkey *remote_funding_pubkey, - bool option_static_remotekey, - bool option_anchor_outputs, + const struct channel_type *type TAKES, bool option_wumbo, enum side opener) { @@ -82,11 +81,10 @@ struct channel *new_initial_channel(const tal_t *ctx, = commit_number_obscurer(&channel->basepoints[opener].payment, &channel->basepoints[!opener].payment); - channel->option_static_remotekey = option_static_remotekey; - channel->option_anchor_outputs = option_anchor_outputs; channel->option_wumbo = option_wumbo; - if (option_anchor_outputs) - assert(option_static_remotekey); + /* takes() if necessary */ + channel->type = tal_dup(channel, struct channel_type, type); + return channel; } @@ -109,7 +107,7 @@ struct bitcoin_tx *initial_channel_tx(const tal_t *ctx, if (!derive_keyset(per_commitment_point, &channel->basepoints[side], &channel->basepoints[!side], - channel->option_static_remotekey, + channel_has(channel, OPT_STATIC_REMOTEKEY), &keyset)) { *err_reason = "Cannot derive keyset"; return NULL; @@ -145,7 +143,7 @@ struct bitcoin_tx *initial_channel_tx(const tal_t *ctx, 0 ^ channel->commitment_number_obscurer, direct_outputs, side, csv_lock, - channel->option_anchor_outputs, + channel_has(channel, OPT_ANCHOR_OUTPUTS), err_reason); if (init_tx) { @@ -169,62 +167,13 @@ u32 channel_blockheight(const struct channel *channel, enum side side) channel->opener, side); } -#if EXPERIMENTAL_FEATURES -/* BOLT-upgrade_protocol #2: - * Channel features are explicitly enumerated as `channel_type` bitfields, - * using odd features bits. The currently defined types are: - * - no features (no bits set) - * - `option_static_remotekey` (bit 13) - * - `option_anchor_outputs` and `option_static_remotekey` (bits 21 and 13) - * - `option_anchors_zero_fee_htlc_tx` and `option_static_remotekey` (bits 23 - * and 13) - */ -static struct channel_type *new_channel_type(const tal_t *ctx) -{ - struct channel_type *type = tal(ctx, struct channel_type); - - type->features = tal_arr(type, u8, 0); - return type; -} - -static struct channel_type *type_static_remotekey(const tal_t *ctx) -{ - struct channel_type *type = new_channel_type(ctx); - - set_feature_bit(&type->features, - OPTIONAL_FEATURE(OPT_STATIC_REMOTEKEY)); - return type; -} - -static struct channel_type *type_anchor_outputs(const tal_t *ctx) -{ - struct channel_type *type = new_channel_type(ctx); - - set_feature_bit(&type->features, - OPTIONAL_FEATURE(OPT_ANCHOR_OUTPUTS)); - set_feature_bit(&type->features, - OPTIONAL_FEATURE(OPT_STATIC_REMOTEKEY)); - return type; -} - -struct channel_type *channel_type(const tal_t *ctx, - const struct channel *channel) -{ - if (channel->option_anchor_outputs) - return type_anchor_outputs(ctx); - if (channel->option_static_remotekey) - return type_static_remotekey(ctx); - - return new_channel_type(ctx); -} - struct channel_type **channel_upgradable_types(const tal_t *ctx, const struct channel *channel) { struct channel_type **arr = tal_arr(ctx, struct channel_type *, 0); - if (!channel->option_static_remotekey) - tal_arr_expand(&arr, type_static_remotekey(arr)); + if (!channel_has(channel, OPT_STATIC_REMOTEKEY)) + tal_arr_expand(&arr, channel_type_static_remotekey(arr)); return arr; } @@ -233,13 +182,17 @@ struct channel_type *channel_desired_type(const tal_t *ctx, const struct channel *channel) { /* We don't actually want to downgrade anchors! */ - if (channel->option_anchor_outputs) - return type_anchor_outputs(ctx); + if (channel_has(channel, OPT_ANCHOR_OUTPUTS)) + return channel_type_anchor_outputs(ctx); /* For now, we just want option_static_remotekey */ - return type_static_remotekey(ctx); + return channel_type_static_remotekey(ctx); +} + +bool channel_has(const struct channel *channel, int feature) +{ + return channel_type_has(channel->type, feature); } -#endif /* EXPERIMENTAL_FEATURES */ static char *fmt_channel_view(const tal_t *ctx, const struct channel_view *view) { diff --git a/common/initial_channel.h b/common/initial_channel.h index dde829e68c23..a084cf3b680c 100644 --- a/common/initial_channel.h +++ b/common/initial_channel.h @@ -69,11 +69,8 @@ struct channel { /* What it looks like to each side. */ struct channel_view view[NUM_SIDES]; - /* Is this using option_static_remotekey? */ - bool option_static_remotekey; - - /* Is this using option_anchor_outputs? */ - bool option_anchor_outputs; + /* Features which apply to this channel. */ + struct channel_type *type; /* Are we using big channels? */ bool option_wumbo; @@ -100,8 +97,7 @@ struct channel { * @remote_basepoints: remote basepoints. * @local_fundingkey: local funding key * @remote_fundingkey: remote funding key - * @option_static_remotekey: was this created with option_static_remotekey? - * @option_anchor_outputs: was this created with option_anchor_outputs? + * @type: type for this channel * @option_wumbo: has peer currently negotiated wumbo? * @opener: which side initiated it. * @@ -123,8 +119,7 @@ struct channel *new_initial_channel(const tal_t *ctx, const struct basepoints *remote_basepoints, const struct pubkey *local_funding_pubkey, const struct pubkey *remote_funding_pubkey, - bool option_static_remotekey, - bool option_anchor_outputs, + const struct channel_type *type TAKES, bool option_wumbo, enum side opener); @@ -163,14 +158,10 @@ u32 channel_feerate(const struct channel *channel, enum side side); */ u32 channel_blockheight(const struct channel *channel, enum side side); -#if EXPERIMENTAL_FEATURES /* BOLT-upgrade_protocol #2: * Channel features are explicitly enumerated as `channel_type` bitfields, * using odd features bits. */ -struct channel_type *channel_type(const tal_t *ctx, - const struct channel *channel); - /* What features can we upgrade? (Returns NULL if none). */ struct channel_type **channel_upgradable_types(const tal_t *ctx, const struct channel *channel); @@ -178,6 +169,7 @@ struct channel_type **channel_upgradable_types(const tal_t *ctx, /* What features do we want? */ struct channel_type *channel_desired_type(const tal_t *ctx, const struct channel *channel); -#endif /* EXPERIMENTAL_FEATURES */ +/* Convenience for querying channel->type */ +bool channel_has(const struct channel *channel, int feature); #endif /* LIGHTNING_COMMON_INITIAL_CHANNEL_H */ diff --git a/common/peer_status_wiregen.c b/common/peer_status_wiregen.c index 15d6779589e3..b49df4f58672 100644 --- a/common/peer_status_wiregen.c +++ b/common/peer_status_wiregen.c @@ -80,4 +80,4 @@ bool fromwire_status_peer_error(const tal_t *ctx, const void *p, struct channel_ fromwire_u8_array(&cursor, &plen, *error_for_them, len); return cursor != NULL; } -// SHA256STAMP:4606ed7d72f93f4fe260080b8b6810ef1b0efa60e96d22b987a6bd16213e365f +// SHA256STAMP:a247441c5a012c0dcaab043780943604354ff5c4f360f83b87fcea94816eab8e diff --git a/common/peer_status_wiregen.h b/common/peer_status_wiregen.h index 06a07885640a..1c7bce968ddc 100644 --- a/common/peer_status_wiregen.h +++ b/common/peer_status_wiregen.h @@ -34,4 +34,4 @@ bool fromwire_status_peer_error(const tal_t *ctx, const void *p, struct channel_ #endif /* LIGHTNING_COMMON_PEER_STATUS_WIREGEN_H */ -// SHA256STAMP:4606ed7d72f93f4fe260080b8b6810ef1b0efa60e96d22b987a6bd16213e365f +// SHA256STAMP:a247441c5a012c0dcaab043780943604354ff5c4f360f83b87fcea94816eab8e diff --git a/common/status_wiregen.c b/common/status_wiregen.c index 46b1aec4c840..2537a1079093 100644 --- a/common/status_wiregen.c +++ b/common/status_wiregen.c @@ -214,4 +214,4 @@ bool fromwire_status_version(const tal_t *ctx, const void *p, wirestring **versi *version = fromwire_wirestring(ctx, &cursor, &plen); return cursor != NULL; } -// SHA256STAMP:2649c615ee63c7855d66cd8d9731deb4819dd4e442d59f59d2616ea7be0fed71 +// SHA256STAMP:9a7b4598fad40c5df016c17464c3c8f7b067a17eb993cc65fea42486e3ffb3f7 diff --git a/common/status_wiregen.h b/common/status_wiregen.h index d5b59d53aac5..fea26f6aff65 100644 --- a/common/status_wiregen.h +++ b/common/status_wiregen.h @@ -58,4 +58,4 @@ bool fromwire_status_version(const tal_t *ctx, const void *p, wirestring **versi #endif /* LIGHTNING_COMMON_STATUS_WIREGEN_H */ -// SHA256STAMP:2649c615ee63c7855d66cd8d9731deb4819dd4e442d59f59d2616ea7be0fed71 +// SHA256STAMP:9a7b4598fad40c5df016c17464c3c8f7b067a17eb993cc65fea42486e3ffb3f7 diff --git a/common/test/run-bolt12_merkle-json.c b/common/test/run-bolt12_merkle-json.c index e3181fb83e61..e567f9592a4f 100644 --- a/common/test/run-bolt12_merkle-json.c +++ b/common/test/run-bolt12_merkle-json.c @@ -18,6 +18,7 @@ #include #include #include +#include #include /* AUTOGENERATED MOCKS START */ @@ -25,6 +26,9 @@ void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct channel_id *channel_id UNNEEDED) { fprintf(stderr, "fromwire_channel_id called!\n"); abort(); } +/* Generated stub for fromwire_channel_type */ +struct channel_type *fromwire_channel_type(const tal_t *ctx UNNEEDED, const u8 **cursor UNNEEDED, size_t *plen UNNEEDED) +{ fprintf(stderr, "fromwire_channel_type called!\n"); abort(); } /* Generated stub for fromwire_node_id */ void fromwire_node_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct node_id *id UNNEEDED) { fprintf(stderr, "fromwire_node_id called!\n"); abort(); } @@ -50,6 +54,9 @@ void towire_bool(u8 **pptr UNNEEDED, bool v UNNEEDED) /* Generated stub for towire_channel_id */ void towire_channel_id(u8 **pptr UNNEEDED, const struct channel_id *channel_id UNNEEDED) { fprintf(stderr, "towire_channel_id called!\n"); abort(); } +/* Generated stub for towire_channel_type */ +void towire_channel_type(u8 **p UNNEEDED, const struct channel_type *channel_type UNNEEDED) +{ fprintf(stderr, "towire_channel_type called!\n"); abort(); } /* Generated stub for towire_node_id */ void towire_node_id(u8 **pptr UNNEEDED, const struct node_id *id UNNEEDED) { fprintf(stderr, "towire_node_id called!\n"); abort(); } diff --git a/common/test/run-bolt12_merkle.c b/common/test/run-bolt12_merkle.c index db6baae7b5f8..7d04e12e1c99 100644 --- a/common/test/run-bolt12_merkle.c +++ b/common/test/run-bolt12_merkle.c @@ -10,6 +10,7 @@ #include #include #include +#include /* Definition of n1 from the spec */ #include @@ -24,12 +25,18 @@ int features_unsupported(const struct feature_set *our_features UNNEEDED, void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct channel_id *channel_id UNNEEDED) { fprintf(stderr, "fromwire_channel_id called!\n"); abort(); } +/* Generated stub for fromwire_channel_type */ +struct channel_type *fromwire_channel_type(const tal_t *ctx UNNEEDED, const u8 **cursor UNNEEDED, size_t *plen UNNEEDED) +{ fprintf(stderr, "fromwire_channel_type called!\n"); abort(); } /* Generated stub for fromwire_onionmsg_path */ struct onionmsg_path *fromwire_onionmsg_path(const tal_t *ctx UNNEEDED, const u8 **cursor UNNEEDED, size_t *plen UNNEEDED) { fprintf(stderr, "fromwire_onionmsg_path called!\n"); abort(); } /* Generated stub for towire_channel_id */ void towire_channel_id(u8 **pptr UNNEEDED, const struct channel_id *channel_id UNNEEDED) { fprintf(stderr, "towire_channel_id called!\n"); abort(); } +/* Generated stub for towire_channel_type */ +void towire_channel_type(u8 **p UNNEEDED, const struct channel_type *channel_type UNNEEDED) +{ fprintf(stderr, "towire_channel_type called!\n"); abort(); } /* Generated stub for towire_onionmsg_path */ void towire_onionmsg_path(u8 **p UNNEEDED, const struct onionmsg_path *onionmsg_path UNNEEDED) { fprintf(stderr, "towire_onionmsg_path called!\n"); abort(); } diff --git a/common/test/run-gossmap_local.c b/common/test/run-gossmap_local.c index fecfcbd8041f..31a191c15efa 100644 --- a/common/test/run-gossmap_local.c +++ b/common/test/run-gossmap_local.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -19,12 +20,18 @@ bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct channel_id *channel_id UNNEEDED) { fprintf(stderr, "fromwire_channel_id called!\n"); abort(); } +/* Generated stub for fromwire_channel_type */ +struct channel_type *fromwire_channel_type(const tal_t *ctx UNNEEDED, const u8 **cursor UNNEEDED, size_t *plen UNNEEDED) +{ fprintf(stderr, "fromwire_channel_type called!\n"); abort(); } /* Generated stub for towire_bigsize */ void towire_bigsize(u8 **pptr UNNEEDED, const bigsize_t val UNNEEDED) { fprintf(stderr, "towire_bigsize called!\n"); abort(); } /* Generated stub for towire_channel_id */ void towire_channel_id(u8 **pptr UNNEEDED, const struct channel_id *channel_id UNNEEDED) { fprintf(stderr, "towire_channel_id called!\n"); abort(); } +/* Generated stub for towire_channel_type */ +void towire_channel_type(u8 **p UNNEEDED, const struct channel_type *channel_type UNNEEDED) +{ fprintf(stderr, "towire_channel_type called!\n"); abort(); } /* Generated stub for type_to_string_ */ const char *type_to_string_(const tal_t *ctx UNNEEDED, const char *typename UNNEEDED, union printable_types u UNNEEDED) diff --git a/common/test/run-json.c b/common/test/run-json.c index f14a66b53825..96f0796237da 100644 --- a/common/test/run-json.c +++ b/common/test/run-json.c @@ -7,9 +7,13 @@ #include #include #include +#include #include /* AUTOGENERATED MOCKS START */ +/* Generated stub for fromwire_channel_type */ +struct channel_type *fromwire_channel_type(const tal_t *ctx UNNEEDED, const u8 **cursor UNNEEDED, size_t *plen UNNEEDED) +{ fprintf(stderr, "fromwire_channel_type called!\n"); abort(); } /* Generated stub for fromwire_tlv */ bool fromwire_tlv(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, const struct tlv_record_type *types UNNEEDED, size_t num_types UNNEEDED, @@ -19,6 +23,9 @@ bool fromwire_tlv(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, bool tlv_fields_valid(const struct tlv_field *fields UNNEEDED, u64 *allow_extra UNNEEDED, size_t *err_index UNNEEDED) { fprintf(stderr, "tlv_fields_valid called!\n"); abort(); } +/* Generated stub for towire_channel_type */ +void towire_channel_type(u8 **p UNNEEDED, const struct channel_type *channel_type UNNEEDED) +{ fprintf(stderr, "towire_channel_type called!\n"); abort(); } /* Generated stub for towire_tlv */ void towire_tlv(u8 **pptr UNNEEDED, const struct tlv_record_type *types UNNEEDED, size_t num_types UNNEEDED, diff --git a/common/test/run-param.c b/common/test/run-param.c index b4a577c9a3cc..b2d486a6c5d9 100644 --- a/common/test/run-param.c +++ b/common/test/run-param.c @@ -10,6 +10,7 @@ #include #include #include +#include #include char *fail_msg = NULL; @@ -40,6 +41,9 @@ struct command_result *command_fail(struct command *cmd, } /* AUTOGENERATED MOCKS START */ +/* Generated stub for fromwire_channel_type */ +struct channel_type *fromwire_channel_type(const tal_t *ctx UNNEEDED, const u8 **cursor UNNEEDED, size_t *plen UNNEEDED) +{ fprintf(stderr, "fromwire_channel_type called!\n"); abort(); } /* Generated stub for fromwire_tlv */ bool fromwire_tlv(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, const struct tlv_record_type *types UNNEEDED, size_t num_types UNNEEDED, @@ -86,6 +90,9 @@ int segwit_addr_decode( bool tlv_fields_valid(const struct tlv_field *fields UNNEEDED, u64 *allow_extra UNNEEDED, size_t *err_index UNNEEDED) { fprintf(stderr, "tlv_fields_valid called!\n"); abort(); } +/* Generated stub for towire_channel_type */ +void towire_channel_type(u8 **p UNNEEDED, const struct channel_type *channel_type UNNEEDED) +{ fprintf(stderr, "towire_channel_type called!\n"); abort(); } /* Generated stub for towire_tlv */ void towire_tlv(u8 **pptr UNNEEDED, const struct tlv_record_type *types UNNEEDED, size_t num_types UNNEEDED, diff --git a/common/test/run-route-specific.c b/common/test/run-route-specific.c index d2c402388590..6998ca1ab13b 100644 --- a/common/test/run-route-specific.c +++ b/common/test/run-route-specific.c @@ -6,6 +6,7 @@ * {'channels': [{'active': True, 'short_id': '6990x2x1/1', 'fee_per_kw': 10, 'delay': 5, 'message_flags': 0, 'channel_flags': 1, 'destination': '0230ad0e74ea03976b28fda587bb75bdd357a1938af4424156a18265167f5e40ae', 'source': '02ea622d5c8d6143f15ed3ce1d501dd0d3d09d3b1c83a44d0034949f8a9ab60f06', 'last_update': 1504064344}, {'active': True, 'short_id': '6989x2x1/0', 'fee_per_kw': 10, 'delay': 5, 'message_flags': 0, 'channel_flags': 0, 'destination': '03c173897878996287a8100469f954dd820fcd8941daed91c327f168f3329be0bf', 'source': '0230ad0e74ea03976b28fda587bb75bdd357a1938af4424156a18265167f5e40ae', 'last_update': 1504064344}, {'active': True, 'short_id': '6990x2x1/0', 'fee_per_kw': 10, 'delay': 5, 'message_flags': 0, 'channel_flags': 0, 'destination': '02ea622d5c8d6143f15ed3ce1d501dd0d3d09d3b1c83a44d0034949f8a9ab60f06', 'source': '0230ad0e74ea03976b28fda587bb75bdd357a1938af4424156a18265167f5e40ae', 'last_update': 1504064344}, {'active': True, 'short_id': '6989x2x1/1', 'fee_per_kw': 10, 'delay': 5, 'message_flags': 0, 'channel_flags': 1, 'destination': '0230ad0e74ea03976b28fda587bb75bdd357a1938af4424156a18265167f5e40ae', 'source': '03c173897878996287a8100469f954dd820fcd8941daed91c327f168f3329be0bf', 'last_update': 1504064344}]} */ #include +#include #include #include #include @@ -24,6 +25,9 @@ bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct channel_id *channel_id UNNEEDED) { fprintf(stderr, "fromwire_channel_id called!\n"); abort(); } +/* Generated stub for fromwire_channel_type */ +struct channel_type *fromwire_channel_type(const tal_t *ctx UNNEEDED, const u8 **cursor UNNEEDED, size_t *plen UNNEEDED) +{ fprintf(stderr, "fromwire_channel_type called!\n"); abort(); } /* Generated stub for fromwire_tlv */ bool fromwire_tlv(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, const struct tlv_record_type *types UNNEEDED, size_t num_types UNNEEDED, @@ -39,6 +43,9 @@ void towire_bigsize(u8 **pptr UNNEEDED, const bigsize_t val UNNEEDED) /* Generated stub for towire_channel_id */ void towire_channel_id(u8 **pptr UNNEEDED, const struct channel_id *channel_id UNNEEDED) { fprintf(stderr, "towire_channel_id called!\n"); abort(); } +/* Generated stub for towire_channel_type */ +void towire_channel_type(u8 **p UNNEEDED, const struct channel_type *channel_type UNNEEDED) +{ fprintf(stderr, "towire_channel_type called!\n"); abort(); } /* Generated stub for towire_tlv */ void towire_tlv(u8 **pptr UNNEEDED, const struct tlv_record_type *types UNNEEDED, size_t num_types UNNEEDED, diff --git a/common/test/run-route.c b/common/test/run-route.c index d2a08700d6d6..fb9d756a4542 100644 --- a/common/test/run-route.c +++ b/common/test/run-route.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -17,6 +18,9 @@ bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED) void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct channel_id *channel_id UNNEEDED) { fprintf(stderr, "fromwire_channel_id called!\n"); abort(); } +/* Generated stub for fromwire_channel_type */ +struct channel_type *fromwire_channel_type(const tal_t *ctx UNNEEDED, const u8 **cursor UNNEEDED, size_t *plen UNNEEDED) +{ fprintf(stderr, "fromwire_channel_type called!\n"); abort(); } /* Generated stub for fromwire_tlv */ bool fromwire_tlv(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, const struct tlv_record_type *types UNNEEDED, size_t num_types UNNEEDED, @@ -32,6 +36,9 @@ void towire_bigsize(u8 **pptr UNNEEDED, const bigsize_t val UNNEEDED) /* Generated stub for towire_channel_id */ void towire_channel_id(u8 **pptr UNNEEDED, const struct channel_id *channel_id UNNEEDED) { fprintf(stderr, "towire_channel_id called!\n"); abort(); } +/* Generated stub for towire_channel_type */ +void towire_channel_type(u8 **p UNNEEDED, const struct channel_type *channel_type UNNEEDED) +{ fprintf(stderr, "towire_channel_type called!\n"); abort(); } /* Generated stub for towire_tlv */ void towire_tlv(u8 **pptr UNNEEDED, const struct tlv_record_type *types UNNEEDED, size_t num_types UNNEEDED, diff --git a/connectd/connectd_gossipd_wiregen.c b/connectd/connectd_gossipd_wiregen.c index 1394358718fe..f738142531f8 100644 --- a/connectd/connectd_gossipd_wiregen.c +++ b/connectd/connectd_gossipd_wiregen.c @@ -161,4 +161,4 @@ bool fromwire_gossipd_get_addrs_reply(const tal_t *ctx, const void *p, struct wi fromwire_wireaddr(&cursor, &plen, *addrs + i); return cursor != NULL; } -// SHA256STAMP:f046184497c8415e2e1337f2b82412bc0094c9c7935e5a3312560331ca6c9f32 +// SHA256STAMP:69dd930932c97655f56c92bd396446582b149e27ca26e0dcd3a29005ea078158 diff --git a/connectd/connectd_gossipd_wiregen.h b/connectd/connectd_gossipd_wiregen.h index 36934ba14f08..719fb19da5eb 100644 --- a/connectd/connectd_gossipd_wiregen.h +++ b/connectd/connectd_gossipd_wiregen.h @@ -54,4 +54,4 @@ bool fromwire_gossipd_get_addrs_reply(const tal_t *ctx, const void *p, struct wi #endif /* LIGHTNING_CONNECTD_CONNECTD_GOSSIPD_WIREGEN_H */ -// SHA256STAMP:f046184497c8415e2e1337f2b82412bc0094c9c7935e5a3312560331ca6c9f32 +// SHA256STAMP:69dd930932c97655f56c92bd396446582b149e27ca26e0dcd3a29005ea078158 diff --git a/connectd/connectd_wiregen.c b/connectd/connectd_wiregen.c index 2426dacaa9c2..4f682f12bad0 100644 --- a/connectd/connectd_wiregen.c +++ b/connectd/connectd_wiregen.c @@ -443,4 +443,4 @@ bool fromwire_connectd_dev_memleak_reply(const void *p, bool *leak) *leak = fromwire_bool(&cursor, &plen); return cursor != NULL; } -// SHA256STAMP:685593d3211a88f48474420db7f114a48d0619ee00eb7ec337fe8d78deecf426 +// SHA256STAMP:3b0f7e87bf73dc1fd4f7181f61fc648f2fc0c4aad946edc9d9c80d90c99e9bcf diff --git a/connectd/connectd_wiregen.h b/connectd/connectd_wiregen.h index eb1c87b561e6..b0a7c4667ad6 100644 --- a/connectd/connectd_wiregen.h +++ b/connectd/connectd_wiregen.h @@ -110,4 +110,4 @@ bool fromwire_connectd_dev_memleak_reply(const void *p, bool *leak); #endif /* LIGHTNING_CONNECTD_CONNECTD_WIREGEN_H */ -// SHA256STAMP:685593d3211a88f48474420db7f114a48d0619ee00eb7ec337fe8d78deecf426 +// SHA256STAMP:3b0f7e87bf73dc1fd4f7181f61fc648f2fc0c4aad946edc9d9c80d90c99e9bcf diff --git a/devtools/Makefile b/devtools/Makefile index 76ef117bdbab..1cd72ceea824 100644 --- a/devtools/Makefile +++ b/devtools/Makefile @@ -43,6 +43,7 @@ DEVTOOLS_COMMON_OBJS := \ common/wireaddr.o \ wire/onion$(EXP)_wiregen.o \ wire/peer$(EXP)_wiregen.o \ + wire/channel_type_wiregen.o \ wire/tlvstream.o devtools/bolt11-cli: $(DEVTOOLS_COMMON_OBJS) $(JSMN_OBJS) $(CCAN_OBJS) $(BITCOIN_OBJS) wire/fromwire.o wire/towire.o devtools/bolt11-cli.o @@ -70,7 +71,7 @@ devtools/gossipwith: $(DEVTOOLS_COMMON_OBJS) $(JSMN_OBJS) $(CCAN_OBJS) $(BITCOIN $(DEVTOOLS_OBJS) $(DEVTOOLS_TOOL_OBJS): wire/wire.h -devtools/mkcommit: $(DEVTOOLS_COMMON_OBJS) $(CCAN_OBJS) $(BITCOIN_OBJS) common/derive_basepoints.o common/keyset.o common/key_derive.o common/initial_commit_tx.o common/permute_tx.o wire/fromwire.o wire/towire.o devtools/mkcommit.o channeld/full_channel.o common/initial_channel.o common/htlc_state.o common/pseudorand.o common/htlc_tx.o channeld/commit_tx.o common/htlc_trim.o +devtools/mkcommit: $(DEVTOOLS_COMMON_OBJS) $(CCAN_OBJS) $(BITCOIN_OBJS) common/derive_basepoints.o common/channel_type.o common/keyset.o common/key_derive.o common/initial_commit_tx.o common/permute_tx.o wire/fromwire.o wire/towire.o devtools/mkcommit.o channeld/full_channel.o common/initial_channel.o common/htlc_state.o common/pseudorand.o common/htlc_tx.o channeld/commit_tx.o common/htlc_trim.o devtools/mkfunding: $(DEVTOOLS_COMMON_OBJS) $(CCAN_OBJS) $(BITCOIN_OBJS) wire/fromwire.o wire/towire.o common/key_derive.o devtools/mkfunding.o diff --git a/devtools/mkcommit.c b/devtools/mkcommit.c index b0f26b5707cd..221bebffd166 100644 --- a/devtools/mkcommit.c +++ b/devtools/mkcommit.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -271,6 +272,7 @@ int main(int argc, char *argv[]) struct privkey local_htlc_privkey, remote_htlc_privkey; struct pubkey local_htlc_pubkey, remote_htlc_pubkey; bool option_static_remotekey = false, option_anchor_outputs = false; + const struct channel_type *channel_type; struct sha256_double hash; u32 blockheight = 0; @@ -393,6 +395,13 @@ int main(int argc, char *argv[]) /* FIXME: option for v2? */ derive_channel_id(&cid, &funding_txid, funding_outnum); + if (option_anchor_outputs) + channel_type = channel_type_anchor_outputs(NULL); + else if (option_static_remotekey) + channel_type = channel_type_static_remotekey(NULL); + else + channel_type = channel_type_none(NULL); + channel = new_full_channel(NULL, &cid, &funding_txid, funding_outnum, 1, @@ -406,8 +415,7 @@ int main(int argc, char *argv[]) &localconfig, &remoteconfig, &localbase, &remotebase, &funding_localkey, &funding_remotekey, - option_static_remotekey, - option_anchor_outputs, + channel_type, false, fee_payer); diff --git a/gossipd/gossip_store_wiregen.c b/gossipd/gossip_store_wiregen.c index adcda3ddf1bb..d50903cf4ce1 100644 --- a/gossipd/gossip_store_wiregen.c +++ b/gossipd/gossip_store_wiregen.c @@ -210,4 +210,4 @@ bool fromwire_gossipd_local_add_channel_obs(const tal_t *ctx, const void *p, str fromwire_u8_array(&cursor, &plen, *features, flen); return cursor != NULL; } -// SHA256STAMP:9bf21787d4ea17d2ae119c2120fd14d025824ab239b12855720addae5a919b2b +// SHA256STAMP:f145d927f4dfe0434bf705f22e3cfae212f96ef95c1cd4dc31fe53c000ef5adb diff --git a/gossipd/gossip_store_wiregen.h b/gossipd/gossip_store_wiregen.h index 203966c2c832..546d3953a51d 100644 --- a/gossipd/gossip_store_wiregen.h +++ b/gossipd/gossip_store_wiregen.h @@ -63,4 +63,4 @@ bool fromwire_gossipd_local_add_channel_obs(const tal_t *ctx, const void *p, str #endif /* LIGHTNING_GOSSIPD_GOSSIP_STORE_WIREGEN_H */ -// SHA256STAMP:9bf21787d4ea17d2ae119c2120fd14d025824ab239b12855720addae5a919b2b +// SHA256STAMP:f145d927f4dfe0434bf705f22e3cfae212f96ef95c1cd4dc31fe53c000ef5adb diff --git a/gossipd/gossipd_peerd_wiregen.c b/gossipd/gossipd_peerd_wiregen.c index 86518988fb43..2bf02e54ad7d 100644 --- a/gossipd/gossipd_peerd_wiregen.c +++ b/gossipd/gossipd_peerd_wiregen.c @@ -161,4 +161,4 @@ bool fromwire_gossipd_local_channel_announcement(const tal_t *ctx, const void *p fromwire_u8_array(&cursor, &plen, *cannount, len); return cursor != NULL; } -// SHA256STAMP:d90ca8e3167dc1e0d140bedca5963b94de835eaae18aba97c99e79f500c068d1 +// SHA256STAMP:b3c6474e393f3aa6427a63a1b1ad873badc6d0592ae8247add28a099815cdbdd diff --git a/gossipd/gossipd_peerd_wiregen.h b/gossipd/gossipd_peerd_wiregen.h index 6a0cbc33d6bf..85d01ef81b29 100644 --- a/gossipd/gossipd_peerd_wiregen.h +++ b/gossipd/gossipd_peerd_wiregen.h @@ -57,4 +57,4 @@ bool fromwire_gossipd_local_channel_announcement(const tal_t *ctx, const void *p #endif /* LIGHTNING_GOSSIPD_GOSSIPD_PEERD_WIREGEN_H */ -// SHA256STAMP:d90ca8e3167dc1e0d140bedca5963b94de835eaae18aba97c99e79f500c068d1 +// SHA256STAMP:b3c6474e393f3aa6427a63a1b1ad873badc6d0592ae8247add28a099815cdbdd diff --git a/gossipd/gossipd_wiregen.c b/gossipd/gossipd_wiregen.c index 85fc20f5b837..7bc4111218cd 100644 --- a/gossipd/gossipd_wiregen.c +++ b/gossipd/gossipd_wiregen.c @@ -777,4 +777,4 @@ bool fromwire_gossipd_new_lease_rates(const void *p, struct lease_rates *rates) fromwire_lease_rates(&cursor, &plen, rates); return cursor != NULL; } -// SHA256STAMP:6252e4a2529ea03470fbb950ebe3d616c6a8ffedf199ff3091608f2d9f18efcf +// SHA256STAMP:1e4178d4f98e129e7779fd49321404eb7ec8bad4ca58655ed7e3039be9b24fe0 diff --git a/gossipd/gossipd_wiregen.h b/gossipd/gossipd_wiregen.h index 0d3b1385dcdb..ab24b7835152 100644 --- a/gossipd/gossipd_wiregen.h +++ b/gossipd/gossipd_wiregen.h @@ -188,4 +188,4 @@ bool fromwire_gossipd_new_lease_rates(const void *p, struct lease_rates *rates); #endif /* LIGHTNING_GOSSIPD_GOSSIPD_WIREGEN_H */ -// SHA256STAMP:6252e4a2529ea03470fbb950ebe3d616c6a8ffedf199ff3091608f2d9f18efcf +// SHA256STAMP:1e4178d4f98e129e7779fd49321404eb7ec8bad4ca58655ed7e3039be9b24fe0 diff --git a/gossipd/test/run-check_channel_announcement.c b/gossipd/test/run-check_channel_announcement.c index 411ae4c604ce..58e489332b79 100644 --- a/gossipd/test/run-check_channel_announcement.c +++ b/gossipd/test/run-check_channel_announcement.c @@ -29,6 +29,7 @@ In particular, we set feature bit 19. The spec says we should set feature bit 1 #include "../common/wire_error.c" #include "../routing.c" +#include #include #include #include @@ -42,6 +43,9 @@ bool cupdate_different(struct gossip_store *gs UNNEEDED, /* Generated stub for fmt_wireaddr_without_port */ char *fmt_wireaddr_without_port(const tal_t *ctx UNNEEDED, const struct wireaddr *a UNNEEDED) { fprintf(stderr, "fmt_wireaddr_without_port called!\n"); abort(); } +/* Generated stub for fromwire_channel_type */ +struct channel_type *fromwire_channel_type(const tal_t *ctx UNNEEDED, const u8 **cursor UNNEEDED, size_t *plen UNNEEDED) +{ fprintf(stderr, "fromwire_channel_type called!\n"); abort(); } /* Generated stub for fromwire_wireaddr_array */ struct wireaddr *fromwire_wireaddr_array(const tal_t *ctx UNNEEDED, const u8 *ser UNNEEDED) { fprintf(stderr, "fromwire_wireaddr_array called!\n"); abort(); } @@ -124,6 +128,9 @@ void status_fmt(enum log_level level UNNEEDED, const char *fmt UNNEEDED, ...) { fprintf(stderr, "status_fmt called!\n"); abort(); } +/* Generated stub for towire_channel_type */ +void towire_channel_type(u8 **p UNNEEDED, const struct channel_type *channel_type UNNEEDED) +{ fprintf(stderr, "towire_channel_type called!\n"); abort(); } /* AUTOGENERATED MOCKS END */ int main(int argc, char *argv[]) diff --git a/gossipd/test/run-check_node_announcement.c b/gossipd/test/run-check_node_announcement.c index 5017ce3d14c2..995ff193f50a 100644 --- a/gossipd/test/run-check_node_announcement.c +++ b/gossipd/test/run-check_node_announcement.c @@ -2,6 +2,7 @@ #include #include #include +#include /* AUTOGENERATED MOCKS START */ /* Generated stub for find_peer */ @@ -10,6 +11,9 @@ struct peer *find_peer(struct daemon *daemon UNNEEDED, const struct node_id *id /* Generated stub for fmt_wireaddr_without_port */ char *fmt_wireaddr_without_port(const tal_t *ctx UNNEEDED, const struct wireaddr *a UNNEEDED) { fprintf(stderr, "fmt_wireaddr_without_port called!\n"); abort(); } +/* Generated stub for fromwire_channel_type */ +struct channel_type *fromwire_channel_type(const tal_t *ctx UNNEEDED, const u8 **cursor UNNEEDED, size_t *plen UNNEEDED) +{ fprintf(stderr, "fromwire_channel_type called!\n"); abort(); } /* Generated stub for fromwire_gossipd_local_channel_update */ bool fromwire_gossipd_local_channel_update(const void *p UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, bool *disable UNNEEDED, u16 *cltv_expiry_delta UNNEEDED, struct amount_msat *htlc_minimum_msat UNNEEDED, u32 *fee_base_msat UNNEEDED, u32 *fee_proportional_millionths UNNEEDED, struct amount_msat *htlc_maximum_msat UNNEEDED) { fprintf(stderr, "fromwire_gossipd_local_channel_update called!\n"); abort(); } @@ -74,6 +78,9 @@ void status_fmt(enum log_level level UNNEEDED, const char *fmt UNNEEDED, ...) { fprintf(stderr, "status_fmt called!\n"); abort(); } +/* Generated stub for towire_channel_type */ +void towire_channel_type(u8 **p UNNEEDED, const struct channel_type *channel_type UNNEEDED) +{ fprintf(stderr, "towire_channel_type called!\n"); abort(); } /* Generated stub for towire_hsmd_cupdate_sig_req */ u8 *towire_hsmd_cupdate_sig_req(const tal_t *ctx UNNEEDED, const u8 *cu UNNEEDED) { fprintf(stderr, "towire_hsmd_cupdate_sig_req called!\n"); abort(); } diff --git a/gossipd/test/run-crc32_of_update.c b/gossipd/test/run-crc32_of_update.c index 239354883a6e..2f51c910ca0c 100644 --- a/gossipd/test/run-crc32_of_update.c +++ b/gossipd/test/run-crc32_of_update.c @@ -3,6 +3,7 @@ int unused_main(int argc, char *argv[]); #include "../queries.c" #include "../gossip_generation.c" #undef main +#include #include #include @@ -31,6 +32,9 @@ struct peer *find_peer(struct daemon *daemon UNNEEDED, const struct node_id *id /* Generated stub for fmt_wireaddr_without_port */ char *fmt_wireaddr_without_port(const tal_t *ctx UNNEEDED, const struct wireaddr *a UNNEEDED) { fprintf(stderr, "fmt_wireaddr_without_port called!\n"); abort(); } +/* Generated stub for fromwire_channel_type */ +struct channel_type *fromwire_channel_type(const tal_t *ctx UNNEEDED, const u8 **cursor UNNEEDED, size_t *plen UNNEEDED) +{ fprintf(stderr, "fromwire_channel_type called!\n"); abort(); } /* Generated stub for fromwire_gossipd_dev_set_max_scids_encode_size */ bool fromwire_gossipd_dev_set_max_scids_encode_size(const void *p UNNEEDED, u32 *max UNNEEDED) { fprintf(stderr, "fromwire_gossipd_dev_set_max_scids_encode_size called!\n"); abort(); } @@ -113,6 +117,9 @@ void status_fmt(enum log_level level UNNEEDED, const char *fmt UNNEEDED, ...) { fprintf(stderr, "status_fmt called!\n"); abort(); } +/* Generated stub for towire_channel_type */ +void towire_channel_type(u8 **p UNNEEDED, const struct channel_type *channel_type UNNEEDED) +{ fprintf(stderr, "towire_channel_type called!\n"); abort(); } /* Generated stub for towire_hsmd_cupdate_sig_req */ u8 *towire_hsmd_cupdate_sig_req(const tal_t *ctx UNNEEDED, const u8 *cu UNNEEDED) { fprintf(stderr, "towire_hsmd_cupdate_sig_req called!\n"); abort(); } diff --git a/gossipd/test/run-extended-info.c b/gossipd/test/run-extended-info.c index 4400e2b44c80..3cba5011380f 100644 --- a/gossipd/test/run-extended-info.c +++ b/gossipd/test/run-extended-info.c @@ -4,6 +4,7 @@ #include "../queries.c" #include +#include #include #include #include @@ -36,6 +37,9 @@ struct short_channel_id *decode_short_ids(const tal_t *ctx UNNEEDED, const u8 *e /* Generated stub for fmt_wireaddr_without_port */ char *fmt_wireaddr_without_port(const tal_t *ctx UNNEEDED, const struct wireaddr *a UNNEEDED) { fprintf(stderr, "fmt_wireaddr_without_port called!\n"); abort(); } +/* Generated stub for fromwire_channel_type */ +struct channel_type *fromwire_channel_type(const tal_t *ctx UNNEEDED, const u8 **cursor UNNEEDED, size_t *plen UNNEEDED) +{ fprintf(stderr, "fromwire_channel_type called!\n"); abort(); } /* Generated stub for fromwire_gossipd_dev_set_max_scids_encode_size */ bool fromwire_gossipd_dev_set_max_scids_encode_size(const void *p UNNEEDED, u32 *max UNNEEDED) { fprintf(stderr, "fromwire_gossipd_dev_set_max_scids_encode_size called!\n"); abort(); } @@ -82,6 +86,9 @@ void queue_peer_from_store(struct peer *peer UNNEEDED, /* Generated stub for queue_peer_msg */ void queue_peer_msg(struct peer *peer UNNEEDED, const u8 *msg TAKES UNNEEDED) { fprintf(stderr, "queue_peer_msg called!\n"); abort(); } +/* Generated stub for towire_channel_type */ +void towire_channel_type(u8 **p UNNEEDED, const struct channel_type *channel_type UNNEEDED) +{ fprintf(stderr, "towire_channel_type called!\n"); abort(); } /* Generated stub for towire_warningfmt */ u8 *towire_warningfmt(const tal_t *ctx UNNEEDED, const struct channel_id *channel UNNEEDED, diff --git a/gossipd/test/run-next_block_range.c b/gossipd/test/run-next_block_range.c index 246dfe4ef55b..b8a7bdaa364d 100644 --- a/gossipd/test/run-next_block_range.c +++ b/gossipd/test/run-next_block_range.c @@ -1,5 +1,6 @@ #include "../seeker.c" #include +#include #include #include #include @@ -10,6 +11,9 @@ /* Generated stub for fmt_wireaddr_without_port */ char *fmt_wireaddr_without_port(const tal_t *ctx UNNEEDED, const struct wireaddr *a UNNEEDED) { fprintf(stderr, "fmt_wireaddr_without_port called!\n"); abort(); } +/* Generated stub for fromwire_channel_type */ +struct channel_type *fromwire_channel_type(const tal_t *ctx UNNEEDED, const u8 **cursor UNNEEDED, size_t *plen UNNEEDED) +{ fprintf(stderr, "fromwire_channel_type called!\n"); abort(); } /* Generated stub for json_add_member */ void json_add_member(struct json_stream *js UNNEEDED, const char *fieldname UNNEEDED, @@ -68,6 +72,9 @@ void status_fmt(enum log_level level UNNEEDED, const char *fmt UNNEEDED, ...) { fprintf(stderr, "status_fmt called!\n"); abort(); } +/* Generated stub for towire_channel_type */ +void towire_channel_type(u8 **p UNNEEDED, const struct channel_type *channel_type UNNEEDED) +{ fprintf(stderr, "towire_channel_type called!\n"); abort(); } /* Generated stub for would_ratelimit_cupdate */ bool would_ratelimit_cupdate(struct routing_state *rstate UNNEEDED, const struct half_chan *hc UNNEEDED, diff --git a/gossipd/test/run-txout_failure.c b/gossipd/test/run-txout_failure.c index bc811554a80d..a196f90f85bc 100644 --- a/gossipd/test/run-txout_failure.c +++ b/gossipd/test/run-txout_failure.c @@ -1,5 +1,6 @@ #include "../routing.c" #include "../common/timeout.c" +#include #include #include #include @@ -13,6 +14,9 @@ bool cupdate_different(struct gossip_store *gs UNNEEDED, /* Generated stub for fmt_wireaddr_without_port */ char *fmt_wireaddr_without_port(const tal_t *ctx UNNEEDED, const struct wireaddr *a UNNEEDED) { fprintf(stderr, "fmt_wireaddr_without_port called!\n"); abort(); } +/* Generated stub for fromwire_channel_type */ +struct channel_type *fromwire_channel_type(const tal_t *ctx UNNEEDED, const u8 **cursor UNNEEDED, size_t *plen UNNEEDED) +{ fprintf(stderr, "fromwire_channel_type called!\n"); abort(); } /* Generated stub for fromwire_wireaddr_array */ struct wireaddr *fromwire_wireaddr_array(const tal_t *ctx UNNEEDED, const u8 *ser UNNEEDED) { fprintf(stderr, "fromwire_wireaddr_array called!\n"); abort(); } @@ -89,6 +93,9 @@ void status_fmt(enum log_level level UNNEEDED, const char *fmt UNNEEDED, ...) { fprintf(stderr, "status_fmt called!\n"); abort(); } +/* Generated stub for towire_channel_type */ +void towire_channel_type(u8 **p UNNEEDED, const struct channel_type *channel_type UNNEEDED) +{ fprintf(stderr, "towire_channel_type called!\n"); abort(); } /* Generated stub for towire_warningfmt */ u8 *towire_warningfmt(const tal_t *ctx UNNEEDED, const struct channel_id *channel UNNEEDED, diff --git a/hsmd/hsmd_wiregen.c b/hsmd/hsmd_wiregen.c index 42047696fb37..5ddc95a56a48 100644 --- a/hsmd/hsmd_wiregen.c +++ b/hsmd/hsmd_wiregen.c @@ -1331,4 +1331,4 @@ bool fromwire_hsmd_sign_option_will_fund_offer_reply(const void *p, secp256k1_ec fromwire_secp256k1_ecdsa_signature(&cursor, &plen, rsig); return cursor != NULL; } -// SHA256STAMP:ca4451abdbde0ac4c8a542e9ba48d2075fb7fcd12a30be739371966dcd8b3d9e +// SHA256STAMP:a4574dbaca95afe998846ff0252826cb9ec827a614eb8018c7decfb2c863f377 diff --git a/hsmd/hsmd_wiregen.h b/hsmd/hsmd_wiregen.h index 6bbeee96e538..aff8b4c4dd3d 100644 --- a/hsmd/hsmd_wiregen.h +++ b/hsmd/hsmd_wiregen.h @@ -295,4 +295,4 @@ bool fromwire_hsmd_sign_option_will_fund_offer_reply(const void *p, secp256k1_ec #endif /* LIGHTNING_HSMD_HSMD_WIREGEN_H */ -// SHA256STAMP:ca4451abdbde0ac4c8a542e9ba48d2075fb7fcd12a30be739371966dcd8b3d9e +// SHA256STAMP:a4574dbaca95afe998846ff0252826cb9ec827a614eb8018c7decfb2c863f377 diff --git a/lightningd/Makefile b/lightningd/Makefile index 21109e62b2e0..2b5a59a1100a 100644 --- a/lightningd/Makefile +++ b/lightningd/Makefile @@ -75,8 +75,9 @@ LIGHTNINGD_COMMON_OBJS := \ common/bolt11_json.o \ common/bolt12.o \ common/bolt12_merkle.o \ - common/channel_id.o \ common/channel_config.o \ + common/channel_id.o \ + common/channel_type.o \ common/coin_mvt.o \ common/configdir.o \ common/crypto_state.o \ diff --git a/lightningd/channel.c b/lightningd/channel.c index ead10e2f2bf5..c5eef7a439b2 100644 --- a/lightningd/channel.c +++ b/lightningd/channel.c @@ -284,7 +284,7 @@ struct channel *new_unsaved_channel(struct peer *peer, * | `option_anchor_outputs` */ channel->static_remotekey_start[LOCAL] = channel->static_remotekey_start[REMOTE] = 0; - channel->option_anchor_outputs = true; + channel->type = channel_type_anchor_outputs(channel); channel->future_per_commitment_point = NULL; channel->lease_commit_sig = NULL; @@ -358,7 +358,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid, const u8 *remote_upfront_shutdown_script, u64 local_static_remotekey_start, u64 remote_static_remotekey_start, - bool option_anchor_outputs, + const struct channel_type *type STEALS, enum side closer, enum state_change reason, /* NULL or stolen */ @@ -454,7 +454,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid, = tal_steal(channel, remote_upfront_shutdown_script); channel->static_remotekey_start[LOCAL] = local_static_remotekey_start; channel->static_remotekey_start[REMOTE] = remote_static_remotekey_start; - channel->option_anchor_outputs = option_anchor_outputs; + channel->type = tal_steal(channel, type); channel->forgets = tal_arr(channel, struct command *, 0); channel->lease_expiry = lease_expiry; diff --git a/lightningd/channel.h b/lightningd/channel.h index 8c54a7db5b1a..eb7988a7d61e 100644 --- a/lightningd/channel.h +++ b/lightningd/channel.h @@ -3,6 +3,7 @@ #include "config.h" #include #include +#include #include #include #include @@ -204,8 +205,8 @@ struct channel { /* At what commit numbers does `option_static_remotekey` apply? */ u64 static_remotekey_start[NUM_SIDES]; - /* Was this negotiated with `option_anchor_outputs? */ - bool option_anchor_outputs; + /* What features apply to this channel? */ + const struct channel_type *type; /* Any commands trying to forget us. */ struct command **forgets; @@ -294,7 +295,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid, const u8 *remote_upfront_shutdown_script STEALS, u64 local_static_remotekey_start, u64 remote_static_remotekey_start, - bool option_anchor_outputs, + const struct channel_type *type STEALS, enum side closer, enum state_change reason, /* NULL or stolen */ @@ -451,6 +452,11 @@ static inline bool channel_closed(const struct channel *channel) || channel->state == CLOSED; } +static inline bool channel_has(const struct channel *channel, int f) +{ + return channel_type_has(channel->type, f); +} + void get_channel_basepoints(struct lightningd *ld, const struct node_id *peer_id, const u64 dbid, diff --git a/lightningd/channel_control.c b/lightningd/channel_control.c index de95ef90f716..7ab03b5efa85 100644 --- a/lightningd/channel_control.c +++ b/lightningd/channel_control.c @@ -431,14 +431,32 @@ void forget_channel(struct channel *channel, const char *why) static void handle_channel_upgrade(struct channel *channel, const u8 *msg) { - bool option_static_remotekey; + struct channel_type *newtype; - if (!fromwire_channeld_upgraded(msg, &option_static_remotekey)) { + if (!fromwire_channeld_upgraded(msg, msg, &newtype)) { channel_internal_error(channel, "bad handle_channel_upgrade: %s", tal_hex(tmpctx, msg)); return; } + /* You can currently only upgrade to turn on option_static_remotekey: + * if they somehow thought anything else we need to close channel! */ + if (channel->static_remotekey_start[LOCAL] != 0x7FFFFFFFFFFFFFFFULL) { + channel_internal_error(channel, + "channel_upgrade already static_remotekey? %s", + tal_hex(tmpctx, msg)); + return; + } + + if (!channel_type_eq(newtype, channel_type_static_remotekey(tmpctx))) { + channel_internal_error(channel, + "channel_upgrade must be static_remotekey, not %s", + fmt_featurebits(tmpctx, newtype->features)); + return; + } + + tal_free(channel->type); + channel->type = channel_type_dup(channel, newtype); channel->static_remotekey_start[LOCAL] = channel->next_index[LOCAL]; channel->static_remotekey_start[REMOTE] = channel->next_index[REMOTE]; log_debug(channel->log, @@ -692,10 +710,7 @@ void peer_start_channeld(struct channel *channel, channel->remote_upfront_shutdown_script, remote_ann_node_sig, remote_ann_bitcoin_sig, - /* Set at channel open, even if not - * negotiated now! */ - channel->next_index[LOCAL] >= channel->static_remotekey_start[LOCAL], - channel->option_anchor_outputs, + channel->type, IFDEV(ld->dev_fast_gossip, false), IFDEV(dev_fail_process_onionpacket, false), pbases, diff --git a/lightningd/closing_control.c b/lightningd/closing_control.c index ccf189a995d5..f9e9f9ac09d3 100644 --- a/lightningd/closing_control.c +++ b/lightningd/closing_control.c @@ -199,6 +199,7 @@ void peer_start_closingd(struct channel *channel, int hsmfd; struct lightningd *ld = channel->peer->ld; u32 final_commit_feerate; + bool option_anchor_outputs = channel_has(channel, OPT_ANCHOR_OUTPUTS); if (!channel->shutdown_scriptpubkey[REMOTE]) { channel_internal_error(channel, @@ -243,7 +244,7 @@ void peer_start_closingd(struct channel *channel, final_commit_feerate = get_feerate(channel->fee_states, channel->opener, LOCAL); feelimit = commit_tx_base_fee(final_commit_feerate, 0, - channel->option_anchor_outputs); + option_anchor_outputs); /* If we can't determine feerate, start at half unilateral feerate. */ feerate = mutual_close_feerate(ld->topology); @@ -255,7 +256,7 @@ void peer_start_closingd(struct channel *channel, /* We use a feerate if anchor_outputs, otherwise max fee is set by * the final unilateral. */ - if (channel->option_anchor_outputs) { + if (option_anchor_outputs) { max_feerate = tal(tmpctx, u32); /* Aim for reasonable max, but use final if we don't know. */ *max_feerate = unilateral_feerate(ld->topology); @@ -316,7 +317,7 @@ void peer_start_closingd(struct channel *channel, (channel->closing_fee_negotiation_step == 50 && channel->closing_fee_negotiation_step_unit == CLOSING_FEE_NEGOTIATION_STEP_UNIT_PERCENTAGE) /* Always use quickclose with anchors */ - || channel->option_anchor_outputs, + || option_anchor_outputs, IFDEV(ld->dev_fast_gossip, false), channel->shutdown_wrong_funding); diff --git a/lightningd/onchain_control.c b/lightningd/onchain_control.c index 33faacbd2bc3..cc46f927b9f4 100644 --- a/lightningd/onchain_control.c +++ b/lightningd/onchain_control.c @@ -705,7 +705,7 @@ enum watch_result onchaind_funding_spent(struct channel *channel, &channel->channel_info.remote_fundingkey, channel->static_remotekey_start[LOCAL], channel->static_remotekey_start[REMOTE], - channel->option_anchor_outputs, + channel_has(channel, OPT_ANCHOR_OUTPUTS), is_replay, feerate_min(ld, NULL)); subd_send_msg(channel->owner, take(msg)); diff --git a/lightningd/opening_common.h b/lightningd/opening_common.h index b499407e6437..27ad45d5bbc8 100644 --- a/lightningd/opening_common.h +++ b/lightningd/opening_common.h @@ -78,6 +78,9 @@ struct funding_channel { /* Channel, subsequent owner of us */ struct uncommitted_channel *uc; + /* Channel type we ended up negotiating. */ + struct channel_type *channel_type; + /* The scriptpubkey to pay (once started) */ u8 *funding_scriptpubkey; diff --git a/lightningd/opening_control.c b/lightningd/opening_control.c index 905800f2fca5..9a1b986202fb 100644 --- a/lightningd/opening_control.c +++ b/lightningd/opening_control.c @@ -98,14 +98,14 @@ wallet_commit_channel(struct lightningd *ld, struct channel_info *channel_info, u32 feerate, const u8 *our_upfront_shutdown_script, - const u8 *remote_upfront_shutdown_script) + const u8 *remote_upfront_shutdown_script, + const struct channel_type *type) { struct channel *channel; struct amount_msat our_msat; struct amount_sat local_funding; s64 final_key_idx; u64 static_remotekey_start; - bool option_anchor_outputs; u32 lease_start_blockheight = 0; /* No leases on v1 */ /* We cannot both be the fundee *and* have a `fundchannel_start` @@ -161,18 +161,11 @@ wallet_commit_channel(struct lightningd *ld, * - MUST use that `channel_type` for all commitment transactions. */ /* i.e. We set it now for the channel permanently. */ - if (feature_negotiated(ld->our_features, - uc->peer->their_features, - OPT_STATIC_REMOTEKEY)) + if (channel_type_has(type, OPT_STATIC_REMOTEKEY)) static_remotekey_start = 0; else static_remotekey_start = 0x7FFFFFFFFFFFFFFF; - option_anchor_outputs - = feature_negotiated(ld->our_features, - uc->peer->their_features, - OPT_ANCHOR_OUTPUTS); - channel = new_channel(uc->peer, uc->dbid, NULL, /* No shachain yet */ CHANNELD_AWAITING_LOCKIN, @@ -221,7 +214,7 @@ wallet_commit_channel(struct lightningd *ld, ld->config.fee_per_satoshi, remote_upfront_shutdown_script, static_remotekey_start, static_remotekey_start, - option_anchor_outputs, + type, NUM_SIDES, /* closer not yet known */ uc->fc ? REASON_USER : REASON_REMOTE, NULL, @@ -310,12 +303,12 @@ static void opening_funder_start_replied(struct subd *openingd, const u8 *resp, const int *fds, struct funding_channel *fc) { - u8 *funding_scriptPubkey; bool supports_shutdown_script; - if (!fromwire_openingd_funder_start_reply(resp, resp, - &funding_scriptPubkey, - &supports_shutdown_script)) { + if (!fromwire_openingd_funder_start_reply(fc, resp, + &fc->funding_scriptpubkey, + &supports_shutdown_script, + &fc->channel_type)) { log_broken(fc->uc->log, "bad OPENING_FUNDER_REPLY %s", tal_hex(resp, resp)); @@ -330,8 +323,6 @@ static void opening_funder_start_replied(struct subd *openingd, const u8 *resp, fc->our_upfront_shutdown_script = tal_free(fc->our_upfront_shutdown_script); - /* Save this so we can indentify output for scriptpubkey */ - fc->funding_scriptpubkey = tal_steal(fc, funding_scriptPubkey); funding_started_success(fc); /* Mark that we're in-flight */ @@ -361,6 +352,7 @@ static void opening_funder_finished(struct subd *openingd, const u8 *resp, u8 *remote_upfront_shutdown_script; struct per_peer_state *pps; struct penalty_base *pbase; + struct channel_type *type; /* This is a new channel_info.their_config so set its ID to 0 */ channel_info.their_config.id = 0; @@ -382,7 +374,8 @@ static void opening_funder_finished(struct subd *openingd, const u8 *resp, &funding_txout, &feerate, &fc->uc->our_config.channel_reserve, - &remote_upfront_shutdown_script)) { + &remote_upfront_shutdown_script, + &type)) { log_broken(fc->uc->log, "bad OPENING_FUNDER_REPLY %s", tal_hex(resp, resp)); @@ -417,7 +410,8 @@ static void opening_funder_finished(struct subd *openingd, const u8 *resp, &channel_info, feerate, fc->our_upfront_shutdown_script, - remote_upfront_shutdown_script); + remote_upfront_shutdown_script, + type); if (!channel) { was_pending(command_fail(fc->cmd, LIGHTNINGD, "Key generation failure")); @@ -461,6 +455,7 @@ static void opening_fundee_finished(struct subd *openingd, u8 *remote_upfront_shutdown_script, *local_upfront_shutdown_script; struct per_peer_state *pps; struct penalty_base *pbase; + struct channel_type *type; log_debug(uc->log, "Got opening_fundee_finish_response"); @@ -488,7 +483,8 @@ static void opening_fundee_finished(struct subd *openingd, cast_const2(u8 **, &fwd_msg), &uc->our_config.channel_reserve, &local_upfront_shutdown_script, - &remote_upfront_shutdown_script)) { + &remote_upfront_shutdown_script, + &type)) { log_broken(uc->log, "bad OPENING_FUNDEE_REPLY %s", tal_hex(reply, reply)); uncommitted_channel_disconnect(uc, LOG_BROKEN, @@ -525,7 +521,8 @@ static void opening_fundee_finished(struct subd *openingd, &channel_info, feerate, local_upfront_shutdown_script, - remote_upfront_shutdown_script); + remote_upfront_shutdown_script, + type); if (!channel) { uncommitted_channel_disconnect(uc, LOG_BROKEN, "Commit channel failed"); @@ -968,6 +965,7 @@ void peer_start_openingd(struct peer *peer, struct per_peer_state *pps) msg = towire_openingd_init(NULL, chainparams, peer->ld->our_features, + peer->their_features, &uc->our_config, max_to_self_delay, min_effective_htlc_capacity, @@ -976,13 +974,6 @@ void peer_start_openingd(struct peer *peer, struct per_peer_state *pps) uc->minimum_depth, feerate_min(peer->ld, NULL), feerate_max(peer->ld, NULL), - peer->their_features, - feature_negotiated(peer->ld->our_features, - peer->their_features, - OPT_STATIC_REMOTEKEY), - feature_negotiated(peer->ld->our_features, - peer->their_features, - OPT_ANCHOR_OUTPUTS), IFDEV(peer->ld->dev_force_tmp_channel_id, NULL), IFDEV(peer->ld->dev_fast_gossip, false)); subd_send_msg(uc->open_daemon, take(msg)); @@ -1096,8 +1087,9 @@ static struct command_result *json_fundchannel_complete(struct command *cmd, /* Set the cmd to this new cmd */ peer->uncommitted_channel->fc->cmd = cmd; msg = towire_openingd_funder_complete(NULL, - funding_txid, - *funding_txout_num); + funding_txid, + *funding_txout_num, + peer->uncommitted_channel->fc->channel_type); subd_send_msg(peer->uncommitted_channel->open_daemon, take(msg)); return command_still_pending(cmd); } diff --git a/lightningd/options.c b/lightningd/options.c index aff8b090b414..a6fae5f6245a 100644 --- a/lightningd/options.c +++ b/lightningd/options.c @@ -806,6 +806,9 @@ static char *list_features_and_exit(struct lightningd *ld) const char **features = list_supported_features(tmpctx, ld->our_features); for (size_t i = 0; i < tal_count(features); i++) printf("%s\n", features[i]); +#if EXPERIMENTAL_FEATURES + printf("supports_open_accept_channel_type\n"); +#endif exit(0); } diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 98b79493f8c8..fd6e49b25267 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -504,7 +504,7 @@ static void json_add_htlcs(struct lightningd *ld, htlc_state_name(hin->hstate)); if (htlc_is_trimmed(REMOTE, hin->msat, local_feerate, channel->our_config.dust_limit, LOCAL, - channel->option_anchor_outputs)) + channel_has(channel, OPT_ANCHOR_OUTPUTS))) json_add_bool(response, "local_trimmed", true); if (hin->status != NULL) json_add_string(response, "status", hin->status); @@ -528,7 +528,7 @@ static void json_add_htlcs(struct lightningd *ld, htlc_state_name(hout->hstate)); if (htlc_is_trimmed(LOCAL, hout->msat, local_feerate, channel->our_config.dust_limit, LOCAL, - channel->option_anchor_outputs)) + channel_has(channel, OPT_ANCHOR_OUTPUTS))) json_add_bool(response, "local_trimmed", true); json_object_end(response); } @@ -563,6 +563,7 @@ static struct amount_sat commit_txfee(const struct channel *channel, channel->opener, side); struct amount_sat dust_limit; struct amount_sat fee; + bool option_anchor_outputs = channel_has(channel, OPT_ANCHOR_OUTPUTS); if (side == LOCAL) dust_limit = channel->our_config.dust_limit; @@ -571,7 +572,7 @@ static struct amount_sat commit_txfee(const struct channel *channel, /* Assume we tried to add "amount" */ if (!htlc_is_trimmed(side, amount, feerate, dust_limit, side, - channel->option_anchor_outputs)) + option_anchor_outputs)) num_untrimmed_htlcs++; for (hin = htlc_in_map_first(&ld->htlcs_in, &ini); @@ -580,8 +581,7 @@ static struct amount_sat commit_txfee(const struct channel *channel, if (hin->key.channel != channel) continue; if (!htlc_is_trimmed(!side, hin->msat, feerate, dust_limit, - side, - channel->option_anchor_outputs)) + side, option_anchor_outputs)) num_untrimmed_htlcs++; } for (hout = htlc_out_map_first(&ld->htlcs_out, &outi); @@ -590,8 +590,7 @@ static struct amount_sat commit_txfee(const struct channel *channel, if (hout->key.channel != channel) continue; if (!htlc_is_trimmed(side, hout->msat, feerate, dust_limit, - side, - channel->option_anchor_outputs)) + side, option_anchor_outputs)) num_untrimmed_htlcs++; } @@ -608,9 +607,9 @@ static struct amount_sat commit_txfee(const struct channel *channel, * predictability between implementations. */ fee = commit_tx_base_fee(2 * feerate, num_untrimmed_htlcs + 1, - channel->option_anchor_outputs); + option_anchor_outputs); - if (channel->option_anchor_outputs) { + if (option_anchor_outputs) { /* BOLT #3: * If `option_anchors` applies to the commitment * transaction, also subtract two times the fixed anchor size @@ -854,9 +853,9 @@ static void json_add_channel(struct lightningd *ld, json_add_null(response, "closer"); json_array_start(response, "features"); - if (channel->static_remotekey_start[LOCAL] != 0x7FFFFFFFFFFFFFFF) + if (channel_has(channel, OPT_STATIC_REMOTEKEY)) json_add_string(response, NULL, "option_static_remotekey"); - if (channel->option_anchor_outputs) + if (channel_has(channel, OPT_ANCHOR_OUTPUTS)) json_add_string(response, NULL, "option_anchor_outputs"); json_array_end(response); diff --git a/lightningd/peer_htlcs.c b/lightningd/peer_htlcs.c index 3ae970d44832..518c7f87f1a5 100644 --- a/lightningd/peer_htlcs.c +++ b/lightningd/peer_htlcs.c @@ -1127,7 +1127,6 @@ static bool ecdh_maybe_blinding(const struct pubkey *ephemeral_key, return true; } -/* AUTODATA wants a different line number */ REGISTER_PLUGIN_HOOK(htlc_accepted, htlc_accepted_hook_deserialize, htlc_accepted_hook_final, diff --git a/lightningd/test/run-invoice-select-inchan.c b/lightningd/test/run-invoice-select-inchan.c index 5a44a0db457d..9e36d9e1992c 100644 --- a/lightningd/test/run-invoice-select-inchan.c +++ b/lightningd/test/run-invoice-select-inchan.c @@ -121,6 +121,9 @@ bool channel_tell_depth(struct lightningd *ld UNNEEDED, const struct bitcoin_txid *txid UNNEEDED, u32 depth UNNEEDED) { fprintf(stderr, "channel_tell_depth called!\n"); abort(); } +/* Generated stub for channel_type_has */ +bool channel_type_has(const struct channel_type *type UNNEEDED, int feature UNNEEDED) +{ fprintf(stderr, "channel_type_has called!\n"); abort(); } /* Generated stub for channel_unsaved_close_conn */ void channel_unsaved_close_conn(struct channel *channel UNNEEDED, const char *why UNNEEDED) { fprintf(stderr, "channel_unsaved_close_conn called!\n"); abort(); } diff --git a/onchaind/onchaind_wiregen.c b/onchaind/onchaind_wiregen.c index 1b1b1d81e82e..f129790b29fe 100644 --- a/onchaind/onchaind_wiregen.c +++ b/onchaind/onchaind_wiregen.c @@ -639,4 +639,4 @@ bool fromwire_onchaind_notify_coin_mvt(const void *p, struct chain_coin_mvt *mvt fromwire_chain_coin_mvt(&cursor, &plen, mvt); return cursor != NULL; } -// SHA256STAMP:f226dc95c62a951ec3fa958313783f65daff69034a06ef4188b81ca80fe7b53a +// SHA256STAMP:bc0704404825187064ec3c7721098bdf5f2ccf07e9b7c3262474f3c8275f5a40 diff --git a/onchaind/onchaind_wiregen.h b/onchaind/onchaind_wiregen.h index 8b7afbb44ab3..1eeab41baae0 100644 --- a/onchaind/onchaind_wiregen.h +++ b/onchaind/onchaind_wiregen.h @@ -161,4 +161,4 @@ bool fromwire_onchaind_notify_coin_mvt(const void *p, struct chain_coin_mvt *mvt #endif /* LIGHTNING_ONCHAIND_ONCHAIND_WIREGEN_H */ -// SHA256STAMP:f226dc95c62a951ec3fa958313783f65daff69034a06ef4188b81ca80fe7b53a +// SHA256STAMP:bc0704404825187064ec3c7721098bdf5f2ccf07e9b7c3262474f3c8275f5a40 diff --git a/openingd/Makefile b/openingd/Makefile index 655119611f5c..e0d77e6122a2 100644 --- a/openingd/Makefile +++ b/openingd/Makefile @@ -39,6 +39,7 @@ OPENINGD_COMMON_OBJS := \ common/blockheight_states.o \ common/channel_config.o \ common/channel_id.o \ + common/channel_type.o \ common/crypto_state.o \ common/crypto_sync.o \ common/cryptomsg.o \ diff --git a/openingd/dualopend.c b/openingd/dualopend.c index 342eacbd862b..f939cd44e0db 100644 --- a/openingd/dualopend.c +++ b/openingd/dualopend.c @@ -27,8 +27,8 @@ #include #include #include +#include #include -#include #include #include #include @@ -1692,6 +1692,7 @@ static void revert_channel_state(struct state *state) struct amount_sat total; struct amount_msat our_msats; enum side opener = state->our_role == TX_INITIATOR ? LOCAL : REMOTE; + const struct channel_type *type; /* We've already checked this */ if (!amount_sat_add(&total, tx_state->opener_funding, @@ -1706,6 +1707,8 @@ static void revert_channel_state(struct state *state) abort(); tal_free(state->channel); + type = default_channel_type(NULL, + state->our_features, state->their_features); state->channel = new_initial_channel(state, &state->channel_id, &tx_state->funding_txid, @@ -1725,7 +1728,7 @@ static void revert_channel_state(struct state *state) &state->their_points, &state->our_funding_pubkey, &state->their_funding_pubkey, - true, true, + take(type), feature_offered(state->their_features, OPT_LARGE_CHANNELS), opener); @@ -1749,6 +1752,7 @@ static u8 *accepter_commits(struct state *state, const u8 *wscript; u8 *msg; char *error; + const struct channel_type *type; /* Find the funding transaction txid */ psbt_txid(NULL, tx_state->psbt, &tx_state->funding_txid, NULL); @@ -1809,6 +1813,8 @@ static u8 *accepter_commits(struct state *state, if (state->channel) state->channel = tal_free(state->channel); + type = default_channel_type(NULL, + state->our_features, state->their_features); state->channel = new_initial_channel(state, &state->channel_id, &tx_state->funding_txid, @@ -1829,7 +1835,7 @@ static u8 *accepter_commits(struct state *state, &state->their_points, &state->our_funding_pubkey, &state->their_funding_pubkey, - true, true, + take(type), feature_offered(state->their_features, OPT_LARGE_CHANNELS), REMOTE); @@ -2379,6 +2385,7 @@ static u8 *opener_commits(struct state *state, const u8 *wscript; u8 *msg; char *error; + const struct channel_type *type; wscript = bitcoin_redeem_2of2(tmpctx, &state->our_funding_pubkey, &state->their_funding_pubkey); @@ -2421,6 +2428,8 @@ static u8 *opener_commits(struct state *state, } /* Ok, we're mostly good now? Let's do this */ + type = default_channel_type(NULL, + state->our_features, state->their_features); state->channel = new_initial_channel(state, &cid, &tx_state->funding_txid, @@ -2439,7 +2448,7 @@ static u8 *opener_commits(struct state *state, &state->their_points, &state->our_funding_pubkey, &state->their_funding_pubkey, - true, true, + take(type), feature_offered(state->their_features, OPT_LARGE_CHANNELS), /* Opener is local */ @@ -3765,6 +3774,7 @@ int main(int argc, char *argv[]) u8 *msg; struct amount_sat total_funding; struct amount_msat our_msat; + const struct channel_type *type; subdaemon_setup(argc, argv); @@ -3847,6 +3857,9 @@ int main(int argc, char *argv[]) /*~ We only reconnect on channels that the * saved the the database (exchanged commitment sigs) */ + type = default_channel_type(NULL, + state->our_features, + state->their_features); state->channel = new_initial_channel(state, &state->channel_id, &state->tx_state->funding_txid, @@ -3864,7 +3877,7 @@ int main(int argc, char *argv[]) &state->their_points, &state->our_funding_pubkey, &state->their_funding_pubkey, - true, true, + take(type), feature_offered(state->their_features, OPT_LARGE_CHANNELS), opener); diff --git a/openingd/dualopend_wiregen.c b/openingd/dualopend_wiregen.c index 89457320f779..9c2f01562ab7 100644 --- a/openingd/dualopend_wiregen.c +++ b/openingd/dualopend_wiregen.c @@ -1051,4 +1051,4 @@ bool fromwire_dualopend_validate_lease_reply(const tal_t *ctx, const void *p, wi } return cursor != NULL; } -// SHA256STAMP:bedb1217727e81cbd377567f3db8348b524bd79ccc7030f338c800e84c47b368 +// SHA256STAMP:4f00f3d34c3e8137837cf975ff52c868901b17ce0bc72efa61a561b0bb29fb07 diff --git a/openingd/dualopend_wiregen.h b/openingd/dualopend_wiregen.h index c8485108b500..76e9ba059460 100644 --- a/openingd/dualopend_wiregen.h +++ b/openingd/dualopend_wiregen.h @@ -225,4 +225,4 @@ bool fromwire_dualopend_validate_lease_reply(const tal_t *ctx, const void *p, wi #endif /* LIGHTNING_OPENINGD_DUALOPEND_WIREGEN_H */ -// SHA256STAMP:bedb1217727e81cbd377567f3db8348b524bd79ccc7030f338c800e84c47b368 +// SHA256STAMP:4f00f3d34c3e8137837cf975ff52c868901b17ce0bc72efa61a561b0bb29fb07 diff --git a/openingd/openingd.c b/openingd/openingd.c index 5d03b6153ecf..ecaa02aed7ba 100644 --- a/openingd/openingd.c +++ b/openingd/openingd.c @@ -18,9 +18,9 @@ #include #include #include +#include #include #include -#include #include #include #include @@ -114,8 +114,8 @@ struct state { * as initial channels never have HTLCs. */ struct channel *channel; - bool option_static_remotekey; - bool option_anchor_outputs; + /* Channel type we agreed on (even before channel populated) */ + struct channel_type *channel_type; struct feature_set *our_features; }; @@ -150,6 +150,8 @@ static void negotiation_aborted(struct state *state, bool am_opener, * failed. */ memset(&state->channel_id, 0, sizeof(state->channel_id)); state->channel = tal_free(state->channel); + + state->channel_type = tal_free(state->channel_type); } /*~ For negotiation failures: we tell them the parameter we didn't like. */ @@ -370,10 +372,24 @@ static u8 *funder_channel_start(struct state *state, u8 channel_flags) state->our_features, state->their_features); + state->channel_type = default_channel_type(state, + state->our_features, + state->their_features); + open_tlvs = tlv_open_channel_tlvs_new(tmpctx); open_tlvs->upfront_shutdown_script = state->upfront_shutdown_script[LOCAL]; + /* BOLT #2: + * - if it includes `channel_type`: + * - MUST set it to a defined type representing the type it wants. + * - MUST use the smallest bitmap possible to represent the channel + * type. + * - SHOULD NOT set it to a type containing a feature which was not + * negotiated. + */ + open_tlvs->channel_type = state->channel_type->features; + msg = towire_open_channel(NULL, &chainparams->genesis_blockhash, &state->channel_id, @@ -435,6 +451,21 @@ static u8 *funder_channel_start(struct state *state, u8 channel_flags) } set_remote_upfront_shutdown(state, accept_tlvs->upfront_shutdown_script); + /* BOLT #2: + * - if `channel_type` is set, and `channel_type` was set in + * `open_channel`, and they are not equal types: + * - MUST reject the channel. + */ + if (accept_tlvs->channel_type + && !featurebits_eq(accept_tlvs->channel_type, + state->channel_type->features)) { + negotiation_failed(state, true, + "Return unoffered channel_type: %s", + fmt_featurebits(tmpctx, + accept_tlvs->channel_type)); + return NULL; + } + /* BOLT #2: * * The `temporary_channel_id` MUST be the same as the @@ -466,7 +497,9 @@ static u8 *funder_channel_start(struct state *state, u8 channel_flags) &state->remoteconf, &state->localconf, true, - state->option_anchor_outputs, + feature_negotiated(state->our_features, + state->their_features, + OPT_ANCHOR_OUTPUTS), &err_reason)) { negotiation_failed(state, true, "%s", err_reason); return NULL; @@ -484,11 +517,12 @@ static u8 *funder_channel_start(struct state *state, u8 channel_flags) tal_hex(tmpctx, funding_output_script)); return towire_openingd_funder_start_reply(state, - funding_output_script, - feature_negotiated( - state->our_features, - state->their_features, - OPT_UPFRONT_SHUTDOWN_SCRIPT)); + funding_output_script, + feature_negotiated( + state->our_features, + state->their_features, + OPT_UPFRONT_SHUTDOWN_SCRIPT), + state->channel_type); } static bool funder_finalize_channel_setup(struct state *state, @@ -531,8 +565,7 @@ static bool funder_finalize_channel_setup(struct state *state, &state->their_points, &state->our_funding_pubkey, &state->their_funding_pubkey, - state->option_static_remotekey, - state->option_anchor_outputs, + state->channel_type, feature_offered(state->their_features, OPT_LARGE_CHANNELS), /* Opener is local */ @@ -579,7 +612,8 @@ static bool funder_finalize_channel_setup(struct state *state, *tx, &state->channel->funding_pubkey[REMOTE], &state->first_per_commitment_point[REMOTE], - state->channel->option_static_remotekey); + channel_has(state->channel, + OPT_STATIC_REMOTEKEY)); wire_sync_write(HSM_FD, take(msg)); msg = wire_sync_read(tmpctx, HSM_FD); @@ -675,12 +709,14 @@ static bool funder_finalize_channel_setup(struct state *state, if (!check_tx_sig(*tx, 0, NULL, wscript, &state->their_funding_pubkey, sig)) { peer_failed_err(state->pps, &state->channel_id, - "Bad signature %s on tx %s using key %s", + "Bad signature %s on tx %s using key %s (channel_type=%s)", type_to_string(tmpctx, struct bitcoin_signature, sig), type_to_string(tmpctx, struct bitcoin_tx, *tx), type_to_string(tmpctx, struct pubkey, - &state->their_funding_pubkey)); + &state->their_funding_pubkey), + fmt_featurebits(tmpctx, + state->channel->type->features)); } /* We save their sig to our first commitment tx */ @@ -743,7 +779,8 @@ static u8 *funder_channel_complete(struct state *state) state->funding_txout, state->feerate_per_kw, state->localconf.channel_reserve, - state->upfront_shutdown_script[REMOTE]); + state->upfront_shutdown_script[REMOTE], + state->channel_type); } /*~ The peer sent us an `open_channel`, that means we're the fundee. */ @@ -797,6 +834,31 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg) "Parsing open_channel %s", tal_hex(tmpctx, open_channel_msg)); set_remote_upfront_shutdown(state, open_tlvs->upfront_shutdown_script); + /* BOLT #2: + * The receiving node MUST fail the channel if: + *... + * - It supports `channel_type`, `channel_type` was set, and the + * `type` is not suitable. + */ + if (open_tlvs->channel_type) { + state->channel_type = + channel_type_accept(state, + open_tlvs->channel_type, + state->our_features, + state->their_features); + if (!state->channel_type) { + negotiation_failed(state, false, + "Did not support channel_type %s", + fmt_featurebits(tmpctx, + open_tlvs->channel_type)); + return NULL; + } + } else + state->channel_type + = default_channel_type(state, + state->our_features, + state->their_features); + /* BOLT #2: * * The receiving node MUST fail the channel if: @@ -910,7 +972,9 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg) &state->remoteconf, &state->localconf, false, - state->option_anchor_outputs, + feature_negotiated(state->our_features, + state->their_features, + OPT_ANCHOR_OUTPUTS), &err_reason)) { negotiation_failed(state, false, "%s", err_reason); return NULL; @@ -941,9 +1005,7 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg) /* If they give us a reason to reject, do so. */ if (err_reason) { - u8 *errmsg = towire_errorfmt(NULL, &state->channel_id, - "%s", err_reason); - sync_crypto_write(state->pps, take(errmsg)); + negotiation_failed(state, false, "%s", err_reason); tal_free(err_reason); return NULL; } @@ -958,6 +1020,11 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg) accept_tlvs = tlv_accept_channel_tlvs_new(tmpctx); accept_tlvs->upfront_shutdown_script = state->upfront_shutdown_script[LOCAL]; + /* BOLT #2: + * - if it sets `channel_type`: + * - MUST set it to the `channel_type` from `open_channel` + */ + accept_tlvs->channel_type = state->channel_type->features; msg = towire_accept_channel(NULL, &state->channel_id, state->localconf.dust_limit, @@ -1023,8 +1090,7 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg) &state->our_points, &theirs, &state->our_funding_pubkey, &their_funding_pubkey, - state->option_static_remotekey, - state->option_anchor_outputs, + state->channel_type, feature_offered(state->their_features, OPT_LARGE_CHANNELS), REMOTE); @@ -1114,7 +1180,8 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg) remote_commit, &state->channel->funding_pubkey[REMOTE], &state->first_per_commitment_point[REMOTE], - state->channel->option_static_remotekey); + channel_has(state->channel, + OPT_STATIC_REMOTEKEY)); wire_sync_write(HSM_FD, take(msg)); msg = wire_sync_read(tmpctx, HSM_FD); @@ -1154,7 +1221,8 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg) msg, state->localconf.channel_reserve, state->upfront_shutdown_script[LOCAL], - state->upfront_shutdown_script[REMOTE]); + state->upfront_shutdown_script[REMOTE], + state->channel_type); } /*~ Standard "peer sent a message, handle it" demuxer. Though it really only @@ -1281,9 +1349,10 @@ static u8 *handle_master_in(struct state *state) wire_sync_write(REQ_FD, take(msg)); return NULL; case WIRE_OPENINGD_FUNDER_COMPLETE: - if (!fromwire_openingd_funder_complete(msg, - &funding_txid, - &funding_txout)) + if (!fromwire_openingd_funder_complete(state, msg, + &funding_txid, + &funding_txout, + &state->channel_type)) master_badmsg(WIRE_OPENINGD_FUNDER_COMPLETE, msg); state->funding_txid = funding_txid; state->funding_txout = funding_txout; @@ -1357,6 +1426,7 @@ int main(int argc, char *argv[]) if (!fromwire_openingd_init(state, msg, &chainparams, &state->our_features, + &state->their_features, &state->localconf, &state->max_to_self_delay, &state->min_effective_htlc_capacity, @@ -1365,9 +1435,6 @@ int main(int argc, char *argv[]) &state->our_funding_pubkey, &state->minimum_depth, &state->min_feerate, &state->max_feerate, - &state->their_features, - &state->option_static_remotekey, - &state->option_anchor_outputs, &force_tmp_channel_id, &dev_fast_gossip)) master_badmsg(WIRE_OPENINGD_INIT, msg); diff --git a/openingd/openingd_wire.csv b/openingd/openingd_wire.csv index 84f51bccfbc6..26451bf675d7 100644 --- a/openingd/openingd_wire.csv +++ b/openingd/openingd_wire.csv @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -10,6 +11,8 @@ msgtype,openingd_init,6000 # Which network are we configured for? msgdata,openingd_init,chainparams,chainparams, msgdata,openingd_init,our_features,feature_set, +msgdata,openingd_init,their_init_features_len,u16, +msgdata,openingd_init,their_init_features,u8,their_init_features_len # Base configuration we'll offer (channel reserve will vary with amount) msgdata,openingd_init,our_config,channel_config, # Minimum/maximum configuration values we'll accept @@ -22,10 +25,6 @@ msgdata,openingd_init,our_funding_pubkey,pubkey, msgdata,openingd_init,minimum_depth,u32, msgdata,openingd_init,min_feerate,u32, msgdata,openingd_init,max_feerate,u32, -msgdata,openingd_init,lfeatures_len,u16, -msgdata,openingd_init,lfeatures,u8,lfeatures_len -msgdata,openingd_init,option_static_remotekey,bool, -msgdata,openingd_init,option_anchor_outputs,bool, msgdata,openingd_init,dev_temporary_channel_id,?byte,32 msgdata,openingd_init,dev_fast_gossip,bool, @@ -50,6 +49,7 @@ msgdata,openingd_got_offer,max_accepted_htlcs,u16, msgdata,openingd_got_offer,channel_flags,u8, msgdata,openingd_got_offer,shutdown_len,u16, msgdata,openingd_got_offer,shutdown_scriptpubkey,u8,shutdown_len + # master->openingd: optional rejection message msgtype,openingd_got_offer_reply,6105 msgdata,openingd_got_offer_reply,rejection,?wirestring, @@ -78,6 +78,7 @@ msgdata,openingd_funder_reply,feerate_per_kw,u32, msgdata,openingd_funder_reply,our_channel_reserve_satoshis,amount_sat, msgdata,openingd_funder_reply,shutdown_len,u16, msgdata,openingd_funder_reply,shutdown_scriptpubkey,u8,shutdown_len +msgdata,openingd_funder_reply,channel_type,channel_type, # master->openingd: start channel establishment for a funding tx msgtype,openingd_funder_start,6002 @@ -93,6 +94,7 @@ msgtype,openingd_funder_start_reply,6102 msgdata,openingd_funder_start_reply,script_len,u8, msgdata,openingd_funder_start_reply,scriptpubkey,u8,script_len msgdata,openingd_funder_start_reply,upfront_shutdown_negotiated,bool, +msgdata,openingd_funder_start_reply,channel_type,channel_type, # master->openingd: complete channel establishment for a funding # tx that will be paid for by an external wallet @@ -100,6 +102,7 @@ msgdata,openingd_funder_start_reply,upfront_shutdown_negotiated,bool, msgtype,openingd_funder_complete,6012 msgdata,openingd_funder_complete,funding_txid,bitcoin_txid, msgdata,openingd_funder_complete,funding_txout,u16, +msgdata,openingd_funder_complete,channel_type,channel_type, #master->openingd: cancel channel establishment for a funding msgtype,openingd_funder_cancel,6013 @@ -136,6 +139,7 @@ msgdata,openingd_fundee,local_shutdown_len,u16, msgdata,openingd_fundee,local_shutdown_scriptpubkey,u8,local_shutdown_len msgdata,openingd_fundee,remote_shutdown_len,u16, msgdata,openingd_fundee,remote_shutdown_scriptpubkey,u8,remote_shutdown_len +msgdata,openingd_fundee,channel_type,channel_type, # master -> openingd: do you have a memleak? msgtype,openingd_dev_memleak,6033 diff --git a/openingd/openingd_wiregen.c b/openingd/openingd_wiregen.c index 07aa2d2fae5f..9a4eafa85d5d 100644 --- a/openingd/openingd_wiregen.c +++ b/openingd/openingd_wiregen.c @@ -65,15 +65,17 @@ bool openingd_wire_is_defined(u16 type) /* WIRE: OPENINGD_INIT */ -u8 *towire_openingd_init(const tal_t *ctx, const struct chainparams *chainparams, const struct feature_set *our_features, const struct channel_config *our_config, u32 max_to_self_delay, struct amount_msat min_effective_htlc_capacity_msat, const struct per_peer_state *pps, const struct basepoints *our_basepoints, const struct pubkey *our_funding_pubkey, u32 minimum_depth, u32 min_feerate, u32 max_feerate, const u8 *lfeatures, bool option_static_remotekey, bool option_anchor_outputs, const struct channel_id *dev_temporary_channel_id, bool dev_fast_gossip) +u8 *towire_openingd_init(const tal_t *ctx, const struct chainparams *chainparams, const struct feature_set *our_features, const u8 *their_init_features, const struct channel_config *our_config, u32 max_to_self_delay, struct amount_msat min_effective_htlc_capacity_msat, const struct per_peer_state *pps, const struct basepoints *our_basepoints, const struct pubkey *our_funding_pubkey, u32 minimum_depth, u32 min_feerate, u32 max_feerate, const struct channel_id *dev_temporary_channel_id, bool dev_fast_gossip) { - u16 lfeatures_len = tal_count(lfeatures); + u16 their_init_features_len = tal_count(their_init_features); u8 *p = tal_arr(ctx, u8, 0); towire_u16(&p, WIRE_OPENINGD_INIT); /* Which network are we configured for? */ towire_chainparams(&p, chainparams); towire_feature_set(&p, our_features); + towire_u16(&p, their_init_features_len); + towire_u8_array(&p, their_init_features, their_init_features_len); /* Base configuration we'll offer (channel reserve will vary with amount) */ towire_channel_config(&p, our_config); /* Minimum/maximum configuration values we'll accept */ @@ -86,10 +88,6 @@ u8 *towire_openingd_init(const tal_t *ctx, const struct chainparams *chainparams towire_u32(&p, minimum_depth); towire_u32(&p, min_feerate); towire_u32(&p, max_feerate); - towire_u16(&p, lfeatures_len); - towire_u8_array(&p, lfeatures, lfeatures_len); - towire_bool(&p, option_static_remotekey); - towire_bool(&p, option_anchor_outputs); if (!dev_temporary_channel_id) towire_bool(&p, false); else { @@ -100,9 +98,9 @@ u8 *towire_openingd_init(const tal_t *ctx, const struct chainparams *chainparams return memcheck(p, tal_count(p)); } -bool fromwire_openingd_init(const tal_t *ctx, const void *p, const struct chainparams **chainparams, struct feature_set **our_features, struct channel_config *our_config, u32 *max_to_self_delay, struct amount_msat *min_effective_htlc_capacity_msat, struct per_peer_state **pps, struct basepoints *our_basepoints, struct pubkey *our_funding_pubkey, u32 *minimum_depth, u32 *min_feerate, u32 *max_feerate, u8 **lfeatures, bool *option_static_remotekey, bool *option_anchor_outputs, struct channel_id **dev_temporary_channel_id, bool *dev_fast_gossip) +bool fromwire_openingd_init(const tal_t *ctx, const void *p, const struct chainparams **chainparams, struct feature_set **our_features, u8 **their_init_features, struct channel_config *our_config, u32 *max_to_self_delay, struct amount_msat *min_effective_htlc_capacity_msat, struct per_peer_state **pps, struct basepoints *our_basepoints, struct pubkey *our_funding_pubkey, u32 *minimum_depth, u32 *min_feerate, u32 *max_feerate, struct channel_id **dev_temporary_channel_id, bool *dev_fast_gossip) { - u16 lfeatures_len; + u16 their_init_features_len; const u8 *cursor = p; size_t plen = tal_count(p); @@ -112,6 +110,10 @@ bool fromwire_openingd_init(const tal_t *ctx, const void *p, const struct chainp /* Which network are we configured for? */ fromwire_chainparams(&cursor, &plen, chainparams); *our_features = fromwire_feature_set(ctx, &cursor, &plen); + their_init_features_len = fromwire_u16(&cursor, &plen); + // 2nd case their_init_features + *their_init_features = their_init_features_len ? tal_arr(ctx, u8, their_init_features_len) : NULL; + fromwire_u8_array(&cursor, &plen, *their_init_features, their_init_features_len); /* Base configuration we'll offer (channel reserve will vary with amount) */ fromwire_channel_config(&cursor, &plen, our_config); /* Minimum/maximum configuration values we'll accept */ @@ -124,12 +126,6 @@ bool fromwire_openingd_init(const tal_t *ctx, const void *p, const struct chainp *minimum_depth = fromwire_u32(&cursor, &plen); *min_feerate = fromwire_u32(&cursor, &plen); *max_feerate = fromwire_u32(&cursor, &plen); - lfeatures_len = fromwire_u16(&cursor, &plen); - // 2nd case lfeatures - *lfeatures = lfeatures_len ? tal_arr(ctx, u8, lfeatures_len) : NULL; - fromwire_u8_array(&cursor, &plen, *lfeatures, lfeatures_len); - *option_static_remotekey = fromwire_bool(&cursor, &plen); - *option_anchor_outputs = fromwire_bool(&cursor, &plen); if (!fromwire_bool(&cursor, &plen)) *dev_temporary_channel_id = NULL; else { @@ -265,7 +261,7 @@ bool fromwire_openingd_got_offer_reply(const tal_t *ctx, const void *p, wirestri /* WIRE: OPENINGD_FUNDER_REPLY */ /* Openingd->master: we've successfully offered channel. */ /* This gives their sig */ -u8 *towire_openingd_funder_reply(const tal_t *ctx, const struct channel_config *their_config, const struct bitcoin_tx *first_commit, const struct penalty_base *pbase, const struct bitcoin_signature *first_commit_sig, const struct per_peer_state *pps, const struct pubkey *revocation_basepoint, const struct pubkey *payment_basepoint, const struct pubkey *htlc_basepoint, const struct pubkey *delayed_payment_basepoint, const struct pubkey *their_per_commit_point, u32 minimum_depth, const struct pubkey *remote_fundingkey, const struct bitcoin_txid *funding_txid, u16 funding_txout, u32 feerate_per_kw, struct amount_sat our_channel_reserve_satoshis, const u8 *shutdown_scriptpubkey) +u8 *towire_openingd_funder_reply(const tal_t *ctx, const struct channel_config *their_config, const struct bitcoin_tx *first_commit, const struct penalty_base *pbase, const struct bitcoin_signature *first_commit_sig, const struct per_peer_state *pps, const struct pubkey *revocation_basepoint, const struct pubkey *payment_basepoint, const struct pubkey *htlc_basepoint, const struct pubkey *delayed_payment_basepoint, const struct pubkey *their_per_commit_point, u32 minimum_depth, const struct pubkey *remote_fundingkey, const struct bitcoin_txid *funding_txid, u16 funding_txout, u32 feerate_per_kw, struct amount_sat our_channel_reserve_satoshis, const u8 *shutdown_scriptpubkey, const struct channel_type *channel_type) { u16 shutdown_len = tal_count(shutdown_scriptpubkey); u8 *p = tal_arr(ctx, u8, 0); @@ -294,10 +290,11 @@ u8 *towire_openingd_funder_reply(const tal_t *ctx, const struct channel_config * towire_amount_sat(&p, our_channel_reserve_satoshis); towire_u16(&p, shutdown_len); towire_u8_array(&p, shutdown_scriptpubkey, shutdown_len); + towire_channel_type(&p, channel_type); return memcheck(p, tal_count(p)); } -bool fromwire_openingd_funder_reply(const tal_t *ctx, const void *p, struct channel_config *their_config, struct bitcoin_tx **first_commit, struct penalty_base **pbase, struct bitcoin_signature *first_commit_sig, struct per_peer_state **pps, struct pubkey *revocation_basepoint, struct pubkey *payment_basepoint, struct pubkey *htlc_basepoint, struct pubkey *delayed_payment_basepoint, struct pubkey *their_per_commit_point, u32 *minimum_depth, struct pubkey *remote_fundingkey, struct bitcoin_txid *funding_txid, u16 *funding_txout, u32 *feerate_per_kw, struct amount_sat *our_channel_reserve_satoshis, u8 **shutdown_scriptpubkey) +bool fromwire_openingd_funder_reply(const tal_t *ctx, const void *p, struct channel_config *their_config, struct bitcoin_tx **first_commit, struct penalty_base **pbase, struct bitcoin_signature *first_commit_sig, struct per_peer_state **pps, struct pubkey *revocation_basepoint, struct pubkey *payment_basepoint, struct pubkey *htlc_basepoint, struct pubkey *delayed_payment_basepoint, struct pubkey *their_per_commit_point, u32 *minimum_depth, struct pubkey *remote_fundingkey, struct bitcoin_txid *funding_txid, u16 *funding_txout, u32 *feerate_per_kw, struct amount_sat *our_channel_reserve_satoshis, u8 **shutdown_scriptpubkey, struct channel_type **channel_type) { u16 shutdown_len; @@ -331,6 +328,7 @@ bool fromwire_openingd_funder_reply(const tal_t *ctx, const void *p, struct chan // 2nd case shutdown_scriptpubkey *shutdown_scriptpubkey = shutdown_len ? tal_arr(ctx, u8, shutdown_len) : NULL; fromwire_u8_array(&cursor, &plen, *shutdown_scriptpubkey, shutdown_len); + *channel_type = fromwire_channel_type(ctx, &cursor, &plen); return cursor != NULL; } @@ -373,7 +371,7 @@ bool fromwire_openingd_funder_start(const tal_t *ctx, const void *p, struct amou /* WIRE: OPENINGD_FUNDER_START_REPLY */ /* openingd->master: send back output script for 2-of-2 funding output */ -u8 *towire_openingd_funder_start_reply(const tal_t *ctx, const u8 *scriptpubkey, bool upfront_shutdown_negotiated) +u8 *towire_openingd_funder_start_reply(const tal_t *ctx, const u8 *scriptpubkey, bool upfront_shutdown_negotiated, const struct channel_type *channel_type) { u8 script_len = tal_count(scriptpubkey); u8 *p = tal_arr(ctx, u8, 0); @@ -382,10 +380,11 @@ u8 *towire_openingd_funder_start_reply(const tal_t *ctx, const u8 *scriptpubkey, towire_u8(&p, script_len); towire_u8_array(&p, scriptpubkey, script_len); towire_bool(&p, upfront_shutdown_negotiated); + towire_channel_type(&p, channel_type); return memcheck(p, tal_count(p)); } -bool fromwire_openingd_funder_start_reply(const tal_t *ctx, const void *p, u8 **scriptpubkey, bool *upfront_shutdown_negotiated) +bool fromwire_openingd_funder_start_reply(const tal_t *ctx, const void *p, u8 **scriptpubkey, bool *upfront_shutdown_negotiated, struct channel_type **channel_type) { u8 script_len; @@ -399,6 +398,7 @@ bool fromwire_openingd_funder_start_reply(const tal_t *ctx, const void *p, u8 ** *scriptpubkey = script_len ? tal_arr(ctx, u8, script_len) : NULL; fromwire_u8_array(&cursor, &plen, *scriptpubkey, script_len); *upfront_shutdown_negotiated = fromwire_bool(&cursor, &plen); + *channel_type = fromwire_channel_type(ctx, &cursor, &plen); return cursor != NULL; } @@ -406,17 +406,18 @@ bool fromwire_openingd_funder_start_reply(const tal_t *ctx, const void *p, u8 ** /* master->openingd: complete channel establishment for a funding */ /* tx that will be paid for by an external wallet */ /* response to this is a normal `openingd_funder_reply` ?? */ -u8 *towire_openingd_funder_complete(const tal_t *ctx, const struct bitcoin_txid *funding_txid, u16 funding_txout) +u8 *towire_openingd_funder_complete(const tal_t *ctx, const struct bitcoin_txid *funding_txid, u16 funding_txout, const struct channel_type *channel_type) { u8 *p = tal_arr(ctx, u8, 0); towire_u16(&p, WIRE_OPENINGD_FUNDER_COMPLETE); towire_bitcoin_txid(&p, funding_txid); towire_u16(&p, funding_txout); + towire_channel_type(&p, channel_type); return memcheck(p, tal_count(p)); } -bool fromwire_openingd_funder_complete(const void *p, struct bitcoin_txid *funding_txid, u16 *funding_txout) +bool fromwire_openingd_funder_complete(const tal_t *ctx, const void *p, struct bitcoin_txid *funding_txid, u16 *funding_txout, struct channel_type **channel_type) { const u8 *cursor = p; size_t plen = tal_count(p); @@ -425,6 +426,7 @@ bool fromwire_openingd_funder_complete(const void *p, struct bitcoin_txid *fundi return false; fromwire_bitcoin_txid(&cursor, &plen, funding_txid); *funding_txout = fromwire_u16(&cursor, &plen); + *channel_type = fromwire_channel_type(ctx, &cursor, &plen); return cursor != NULL; } @@ -473,7 +475,7 @@ bool fromwire_openingd_funder_failed(const tal_t *ctx, const void *p, wirestring /* WIRE: OPENINGD_FUNDEE */ /* Openingd->master: they offered channel. */ /* This gives their txid and info */ -u8 *towire_openingd_fundee(const tal_t *ctx, const struct channel_config *their_config, const struct bitcoin_tx *first_commit, const struct penalty_base *pbase, const struct bitcoin_signature *first_commit_sig, const struct per_peer_state *pps, const struct pubkey *revocation_basepoint, const struct pubkey *payment_basepoint, const struct pubkey *htlc_basepoint, const struct pubkey *delayed_payment_basepoint, const struct pubkey *their_per_commit_point, const struct pubkey *remote_fundingkey, const struct bitcoin_txid *funding_txid, u16 funding_txout, struct amount_sat funding_satoshis, struct amount_msat push_msat, u8 channel_flags, u32 feerate_per_kw, const u8 *funding_signed_msg, struct amount_sat our_channel_reserve_satoshis, const u8 *local_shutdown_scriptpubkey, const u8 *remote_shutdown_scriptpubkey) +u8 *towire_openingd_fundee(const tal_t *ctx, const struct channel_config *their_config, const struct bitcoin_tx *first_commit, const struct penalty_base *pbase, const struct bitcoin_signature *first_commit_sig, const struct per_peer_state *pps, const struct pubkey *revocation_basepoint, const struct pubkey *payment_basepoint, const struct pubkey *htlc_basepoint, const struct pubkey *delayed_payment_basepoint, const struct pubkey *their_per_commit_point, const struct pubkey *remote_fundingkey, const struct bitcoin_txid *funding_txid, u16 funding_txout, struct amount_sat funding_satoshis, struct amount_msat push_msat, u8 channel_flags, u32 feerate_per_kw, const u8 *funding_signed_msg, struct amount_sat our_channel_reserve_satoshis, const u8 *local_shutdown_scriptpubkey, const u8 *remote_shutdown_scriptpubkey, const struct channel_type *channel_type) { u16 msglen = tal_count(funding_signed_msg); u16 local_shutdown_len = tal_count(local_shutdown_scriptpubkey); @@ -511,10 +513,11 @@ u8 *towire_openingd_fundee(const tal_t *ctx, const struct channel_config *their_ towire_u8_array(&p, local_shutdown_scriptpubkey, local_shutdown_len); towire_u16(&p, remote_shutdown_len); towire_u8_array(&p, remote_shutdown_scriptpubkey, remote_shutdown_len); + towire_channel_type(&p, channel_type); return memcheck(p, tal_count(p)); } -bool fromwire_openingd_fundee(const tal_t *ctx, const void *p, struct channel_config *their_config, struct bitcoin_tx **first_commit, struct penalty_base **pbase, struct bitcoin_signature *first_commit_sig, struct per_peer_state **pps, struct pubkey *revocation_basepoint, struct pubkey *payment_basepoint, struct pubkey *htlc_basepoint, struct pubkey *delayed_payment_basepoint, struct pubkey *their_per_commit_point, struct pubkey *remote_fundingkey, struct bitcoin_txid *funding_txid, u16 *funding_txout, struct amount_sat *funding_satoshis, struct amount_msat *push_msat, u8 *channel_flags, u32 *feerate_per_kw, u8 **funding_signed_msg, struct amount_sat *our_channel_reserve_satoshis, u8 **local_shutdown_scriptpubkey, u8 **remote_shutdown_scriptpubkey) +bool fromwire_openingd_fundee(const tal_t *ctx, const void *p, struct channel_config *their_config, struct bitcoin_tx **first_commit, struct penalty_base **pbase, struct bitcoin_signature *first_commit_sig, struct per_peer_state **pps, struct pubkey *revocation_basepoint, struct pubkey *payment_basepoint, struct pubkey *htlc_basepoint, struct pubkey *delayed_payment_basepoint, struct pubkey *their_per_commit_point, struct pubkey *remote_fundingkey, struct bitcoin_txid *funding_txid, u16 *funding_txout, struct amount_sat *funding_satoshis, struct amount_msat *push_msat, u8 *channel_flags, u32 *feerate_per_kw, u8 **funding_signed_msg, struct amount_sat *our_channel_reserve_satoshis, u8 **local_shutdown_scriptpubkey, u8 **remote_shutdown_scriptpubkey, struct channel_type **channel_type) { u16 msglen; u16 local_shutdown_len; @@ -561,6 +564,7 @@ bool fromwire_openingd_fundee(const tal_t *ctx, const void *p, struct channel_co // 2nd case remote_shutdown_scriptpubkey *remote_shutdown_scriptpubkey = remote_shutdown_len ? tal_arr(ctx, u8, remote_shutdown_len) : NULL; fromwire_u8_array(&cursor, &plen, *remote_shutdown_scriptpubkey, remote_shutdown_len); + *channel_type = fromwire_channel_type(ctx, &cursor, &plen); return cursor != NULL; } @@ -604,4 +608,4 @@ bool fromwire_openingd_dev_memleak_reply(const void *p, bool *leak) *leak = fromwire_bool(&cursor, &plen); return cursor != NULL; } -// SHA256STAMP:e01a9f3e8b3c9962c9b35502d3b74977e289e61ebebf28627276e97d06bc4b35 +// SHA256STAMP:f1728e2b3e5e2001e7620e23b0d1c1d359569684fd7d585b6f4471d1abeb332c diff --git a/openingd/openingd_wiregen.h b/openingd/openingd_wiregen.h index 91d752e57d2d..600530001a57 100644 --- a/openingd/openingd_wiregen.h +++ b/openingd/openingd_wiregen.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -60,8 +61,8 @@ bool openingd_wire_is_defined(u16 type); /* WIRE: OPENINGD_INIT */ -u8 *towire_openingd_init(const tal_t *ctx, const struct chainparams *chainparams, const struct feature_set *our_features, const struct channel_config *our_config, u32 max_to_self_delay, struct amount_msat min_effective_htlc_capacity_msat, const struct per_peer_state *pps, const struct basepoints *our_basepoints, const struct pubkey *our_funding_pubkey, u32 minimum_depth, u32 min_feerate, u32 max_feerate, const u8 *lfeatures, bool option_static_remotekey, bool option_anchor_outputs, const struct channel_id *dev_temporary_channel_id, bool dev_fast_gossip); -bool fromwire_openingd_init(const tal_t *ctx, const void *p, const struct chainparams **chainparams, struct feature_set **our_features, struct channel_config *our_config, u32 *max_to_self_delay, struct amount_msat *min_effective_htlc_capacity_msat, struct per_peer_state **pps, struct basepoints *our_basepoints, struct pubkey *our_funding_pubkey, u32 *minimum_depth, u32 *min_feerate, u32 *max_feerate, u8 **lfeatures, bool *option_static_remotekey, bool *option_anchor_outputs, struct channel_id **dev_temporary_channel_id, bool *dev_fast_gossip); +u8 *towire_openingd_init(const tal_t *ctx, const struct chainparams *chainparams, const struct feature_set *our_features, const u8 *their_init_features, const struct channel_config *our_config, u32 max_to_self_delay, struct amount_msat min_effective_htlc_capacity_msat, const struct per_peer_state *pps, const struct basepoints *our_basepoints, const struct pubkey *our_funding_pubkey, u32 minimum_depth, u32 min_feerate, u32 max_feerate, const struct channel_id *dev_temporary_channel_id, bool dev_fast_gossip); +bool fromwire_openingd_init(const tal_t *ctx, const void *p, const struct chainparams **chainparams, struct feature_set **our_features, u8 **their_init_features, struct channel_config *our_config, u32 *max_to_self_delay, struct amount_msat *min_effective_htlc_capacity_msat, struct per_peer_state **pps, struct basepoints *our_basepoints, struct pubkey *our_funding_pubkey, u32 *minimum_depth, u32 *min_feerate, u32 *max_feerate, struct channel_id **dev_temporary_channel_id, bool *dev_fast_gossip); /* WIRE: OPENINGD_GOT_REESTABLISH */ /* Openingd->master: they tried to reestablish a channel. */ @@ -81,8 +82,8 @@ bool fromwire_openingd_got_offer_reply(const tal_t *ctx, const void *p, wirestri /* WIRE: OPENINGD_FUNDER_REPLY */ /* Openingd->master: we've successfully offered channel. */ /* This gives their sig */ -u8 *towire_openingd_funder_reply(const tal_t *ctx, const struct channel_config *their_config, const struct bitcoin_tx *first_commit, const struct penalty_base *pbase, const struct bitcoin_signature *first_commit_sig, const struct per_peer_state *pps, const struct pubkey *revocation_basepoint, const struct pubkey *payment_basepoint, const struct pubkey *htlc_basepoint, const struct pubkey *delayed_payment_basepoint, const struct pubkey *their_per_commit_point, u32 minimum_depth, const struct pubkey *remote_fundingkey, const struct bitcoin_txid *funding_txid, u16 funding_txout, u32 feerate_per_kw, struct amount_sat our_channel_reserve_satoshis, const u8 *shutdown_scriptpubkey); -bool fromwire_openingd_funder_reply(const tal_t *ctx, const void *p, struct channel_config *their_config, struct bitcoin_tx **first_commit, struct penalty_base **pbase, struct bitcoin_signature *first_commit_sig, struct per_peer_state **pps, struct pubkey *revocation_basepoint, struct pubkey *payment_basepoint, struct pubkey *htlc_basepoint, struct pubkey *delayed_payment_basepoint, struct pubkey *their_per_commit_point, u32 *minimum_depth, struct pubkey *remote_fundingkey, struct bitcoin_txid *funding_txid, u16 *funding_txout, u32 *feerate_per_kw, struct amount_sat *our_channel_reserve_satoshis, u8 **shutdown_scriptpubkey); +u8 *towire_openingd_funder_reply(const tal_t *ctx, const struct channel_config *their_config, const struct bitcoin_tx *first_commit, const struct penalty_base *pbase, const struct bitcoin_signature *first_commit_sig, const struct per_peer_state *pps, const struct pubkey *revocation_basepoint, const struct pubkey *payment_basepoint, const struct pubkey *htlc_basepoint, const struct pubkey *delayed_payment_basepoint, const struct pubkey *their_per_commit_point, u32 minimum_depth, const struct pubkey *remote_fundingkey, const struct bitcoin_txid *funding_txid, u16 funding_txout, u32 feerate_per_kw, struct amount_sat our_channel_reserve_satoshis, const u8 *shutdown_scriptpubkey, const struct channel_type *channel_type); +bool fromwire_openingd_funder_reply(const tal_t *ctx, const void *p, struct channel_config *their_config, struct bitcoin_tx **first_commit, struct penalty_base **pbase, struct bitcoin_signature *first_commit_sig, struct per_peer_state **pps, struct pubkey *revocation_basepoint, struct pubkey *payment_basepoint, struct pubkey *htlc_basepoint, struct pubkey *delayed_payment_basepoint, struct pubkey *their_per_commit_point, u32 *minimum_depth, struct pubkey *remote_fundingkey, struct bitcoin_txid *funding_txid, u16 *funding_txout, u32 *feerate_per_kw, struct amount_sat *our_channel_reserve_satoshis, u8 **shutdown_scriptpubkey, struct channel_type **channel_type); /* WIRE: OPENINGD_FUNDER_START */ /* master->openingd: start channel establishment for a funding tx */ @@ -91,15 +92,15 @@ bool fromwire_openingd_funder_start(const tal_t *ctx, const void *p, struct amou /* WIRE: OPENINGD_FUNDER_START_REPLY */ /* openingd->master: send back output script for 2-of-2 funding output */ -u8 *towire_openingd_funder_start_reply(const tal_t *ctx, const u8 *scriptpubkey, bool upfront_shutdown_negotiated); -bool fromwire_openingd_funder_start_reply(const tal_t *ctx, const void *p, u8 **scriptpubkey, bool *upfront_shutdown_negotiated); +u8 *towire_openingd_funder_start_reply(const tal_t *ctx, const u8 *scriptpubkey, bool upfront_shutdown_negotiated, const struct channel_type *channel_type); +bool fromwire_openingd_funder_start_reply(const tal_t *ctx, const void *p, u8 **scriptpubkey, bool *upfront_shutdown_negotiated, struct channel_type **channel_type); /* WIRE: OPENINGD_FUNDER_COMPLETE */ /* master->openingd: complete channel establishment for a funding */ /* tx that will be paid for by an external wallet */ /* response to this is a normal `openingd_funder_reply` ?? */ -u8 *towire_openingd_funder_complete(const tal_t *ctx, const struct bitcoin_txid *funding_txid, u16 funding_txout); -bool fromwire_openingd_funder_complete(const void *p, struct bitcoin_txid *funding_txid, u16 *funding_txout); +u8 *towire_openingd_funder_complete(const tal_t *ctx, const struct bitcoin_txid *funding_txid, u16 funding_txout, const struct channel_type *channel_type); +bool fromwire_openingd_funder_complete(const tal_t *ctx, const void *p, struct bitcoin_txid *funding_txid, u16 *funding_txout, struct channel_type **channel_type); /* WIRE: OPENINGD_FUNDER_CANCEL */ /* master->openingd: cancel channel establishment for a funding */ @@ -114,8 +115,8 @@ bool fromwire_openingd_funder_failed(const tal_t *ctx, const void *p, wirestring /* WIRE: OPENINGD_FUNDEE */ /* Openingd->master: they offered channel. */ /* This gives their txid and info */ -u8 *towire_openingd_fundee(const tal_t *ctx, const struct channel_config *their_config, const struct bitcoin_tx *first_commit, const struct penalty_base *pbase, const struct bitcoin_signature *first_commit_sig, const struct per_peer_state *pps, const struct pubkey *revocation_basepoint, const struct pubkey *payment_basepoint, const struct pubkey *htlc_basepoint, const struct pubkey *delayed_payment_basepoint, const struct pubkey *their_per_commit_point, const struct pubkey *remote_fundingkey, const struct bitcoin_txid *funding_txid, u16 funding_txout, struct amount_sat funding_satoshis, struct amount_msat push_msat, u8 channel_flags, u32 feerate_per_kw, const u8 *funding_signed_msg, struct amount_sat our_channel_reserve_satoshis, const u8 *local_shutdown_scriptpubkey, const u8 *remote_shutdown_scriptpubkey); -bool fromwire_openingd_fundee(const tal_t *ctx, const void *p, struct channel_config *their_config, struct bitcoin_tx **first_commit, struct penalty_base **pbase, struct bitcoin_signature *first_commit_sig, struct per_peer_state **pps, struct pubkey *revocation_basepoint, struct pubkey *payment_basepoint, struct pubkey *htlc_basepoint, struct pubkey *delayed_payment_basepoint, struct pubkey *their_per_commit_point, struct pubkey *remote_fundingkey, struct bitcoin_txid *funding_txid, u16 *funding_txout, struct amount_sat *funding_satoshis, struct amount_msat *push_msat, u8 *channel_flags, u32 *feerate_per_kw, u8 **funding_signed_msg, struct amount_sat *our_channel_reserve_satoshis, u8 **local_shutdown_scriptpubkey, u8 **remote_shutdown_scriptpubkey); +u8 *towire_openingd_fundee(const tal_t *ctx, const struct channel_config *their_config, const struct bitcoin_tx *first_commit, const struct penalty_base *pbase, const struct bitcoin_signature *first_commit_sig, const struct per_peer_state *pps, const struct pubkey *revocation_basepoint, const struct pubkey *payment_basepoint, const struct pubkey *htlc_basepoint, const struct pubkey *delayed_payment_basepoint, const struct pubkey *their_per_commit_point, const struct pubkey *remote_fundingkey, const struct bitcoin_txid *funding_txid, u16 funding_txout, struct amount_sat funding_satoshis, struct amount_msat push_msat, u8 channel_flags, u32 feerate_per_kw, const u8 *funding_signed_msg, struct amount_sat our_channel_reserve_satoshis, const u8 *local_shutdown_scriptpubkey, const u8 *remote_shutdown_scriptpubkey, const struct channel_type *channel_type); +bool fromwire_openingd_fundee(const tal_t *ctx, const void *p, struct channel_config *their_config, struct bitcoin_tx **first_commit, struct penalty_base **pbase, struct bitcoin_signature *first_commit_sig, struct per_peer_state **pps, struct pubkey *revocation_basepoint, struct pubkey *payment_basepoint, struct pubkey *htlc_basepoint, struct pubkey *delayed_payment_basepoint, struct pubkey *their_per_commit_point, struct pubkey *remote_fundingkey, struct bitcoin_txid *funding_txid, u16 *funding_txout, struct amount_sat *funding_satoshis, struct amount_msat *push_msat, u8 *channel_flags, u32 *feerate_per_kw, u8 **funding_signed_msg, struct amount_sat *our_channel_reserve_satoshis, u8 **local_shutdown_scriptpubkey, u8 **remote_shutdown_scriptpubkey, struct channel_type **channel_type); /* WIRE: OPENINGD_DEV_MEMLEAK */ /* master -> openingd: do you have a memleak? */ @@ -128,4 +129,4 @@ bool fromwire_openingd_dev_memleak_reply(const void *p, bool *leak); #endif /* LIGHTNING_OPENINGD_OPENINGD_WIREGEN_H */ -// SHA256STAMP:e01a9f3e8b3c9962c9b35502d3b74977e289e61ebebf28627276e97d06bc4b35 +// SHA256STAMP:f1728e2b3e5e2001e7620e23b0d1c1d359569684fd7d585b6f4471d1abeb332c diff --git a/plugins/Makefile b/plugins/Makefile index f9ec59a4045b..b54c0fcea75c 100644 --- a/plugins/Makefile +++ b/plugins/Makefile @@ -133,6 +133,7 @@ PLUGIN_COMMON_OBJS := \ common/utils.o \ common/version.o \ common/wireaddr.o \ + wire/channel_type_wiregen.o \ wire/fromwire.o \ wire/onion$(EXP)_wiregen.o \ wire/peer$(EXP)_wiregen.o \ @@ -146,7 +147,7 @@ plugins/autoclean: bitcoin/chainparams.o $(PLUGIN_AUTOCLEAN_OBJS) $(PLUGIN_LIB_O # Topology wants to decode node_announcement, and peer_wiregen which # pulls in some of bitcoin/. -plugins/topology: common/route.o common/dijkstra.o common/gossmap.o common/fp16.o bitcoin/chainparams.o wire/peer$(EXP)_wiregen.o bitcoin/block.o bitcoin/preimage.o $(PLUGIN_TOPOLOGY_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_COMMON_OBJS) $(JSMN_OBJS) $(CCAN_OBJS) +plugins/topology: common/route.o common/dijkstra.o common/gossmap.o common/fp16.o bitcoin/chainparams.o wire/peer$(EXP)_wiregen.o wire/channel_type_wiregen.o bitcoin/block.o bitcoin/preimage.o $(PLUGIN_TOPOLOGY_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_COMMON_OBJS) $(JSMN_OBJS) $(CCAN_OBJS) plugins/txprepare: bitcoin/chainparams.o $(PLUGIN_TXPREPARE_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_COMMON_OBJS) $(JSMN_OBJS) $(CCAN_OBJS) diff --git a/tests/test_connection.py b/tests/test_connection.py index a3ba2fd379d5..2082b49f4bd4 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -3500,8 +3500,8 @@ def test_upgrade_statickey(node_factory, executor): l1.rpc.connect(l2.info['id'], 'localhost', l2.port) l1.daemon.wait_for_logs([r"They sent current_type \[\]", - r"They offered upgrade to \[13\]"]) - l2.daemon.wait_for_log(r"They sent desired_type \[13\]") + r"They offered upgrade to \[12\]"]) + l2.daemon.wait_for_log(r"They sent desired_type \[12\]") l1.daemon.wait_for_log('option_static_remotekey enabled at 1/1') l2.daemon.wait_for_log('option_static_remotekey enabled at 1/1') @@ -3514,8 +3514,8 @@ def test_upgrade_statickey(node_factory, executor): # They won't offer upgrade! assert not l1.daemon.is_in_log("They offered upgrade", start=l1.daemon.logsearch_start) - l1.daemon.wait_for_log(r"They sent current_type \[13\]") - l2.daemon.wait_for_log(r"They sent desired_type \[13\]") + l1.daemon.wait_for_log(r"They sent current_type \[12\]") + l2.daemon.wait_for_log(r"They sent desired_type \[12\]") @unittest.skipIf(not EXPERIMENTAL_FEATURES, "upgrade protocol not available") diff --git a/tests/test_misc.py b/tests/test_misc.py index 94282291eaca..ec274dc8ebd9 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -1924,6 +1924,7 @@ def test_list_features_only(node_factory): expected += ['option_anchor_outputs/odd'] expected += ['option_shutdown_anysegwit/odd'] expected += ['option_onion_messages/odd'] + expected += ['supports_open_accept_channel_type'] else: expected += ['option_shutdown_anysegwit/odd'] assert features == expected diff --git a/tools/gen/print_impl_template b/tools/gen/print_impl_template index b3f10c4f6e6a..4922e4e9ee4e 100644 --- a/tools/gen/print_impl_template +++ b/tools/gen/print_impl_template @@ -9,6 +9,7 @@ #include #include +% if enum_sets: void print${options.enum_name}_message(const u8 *msg) { switch ((enum ${options.enum_name})fromwire_peektype(msg)) { @@ -22,6 +23,7 @@ void print${options.enum_name}_message(const u8 *msg) printf("UNKNOWN: %s\\n", tal_hex(msg, msg)); } +% endif ## 'component' for 'truncate check <%def name="truncate_check(nested=False)"> @@ -54,7 +56,7 @@ void print${options.enum_name}_message(const u8 *msg) % else: for (size_t i = 0; i < ${f.size()}; i++) { % endif - % if f.type_obj.is_subtype(): + % if f.type_obj.is_subtype() or f.type_obj.is_varsize(): printf("{\n"); printwire_${f.type_obj.name}(tal_fmt(NULL, "%s.${f.name}", fieldname), ${cursor}, ${plen}); printf("}\n"); @@ -76,7 +78,7 @@ void print${options.enum_name}_message(const u8 *msg) printf("]"); % endif ${truncate_check(nested)} \ - % elif f.type_obj.is_subtype(): + % elif f.type_obj.is_subtype() or f.type_obj.is_varsize(): printf("{\n"); printwire_${f.type_obj.name}(tal_fmt(NULL, "%s.${f.name}", fieldname), ${cursor}, ${plen}); printf("}\n"); @@ -136,15 +138,13 @@ ${print_fieldset(msg.fields.values(), False, '&cursor', '&plen')} } % endfor -void print${options.enum_name}_tlv_message(const char *tlv_name, const u8 *msg) { % if bool(tlvs): +void print${options.enum_name}_tlv_message(const char *tlv_name, const u8 *msg) { size_t plen = tal_count(msg); % for tlv_name in tlvs: if (strcmp(tlv_name, "${tlv_name}") == 0) { printwire_tlvs(tlv_name, &msg, &plen, print_tlvs_${tlv_name}, ARRAY_SIZE(print_tlvs_${tlv_name})); } % endfor -% else: - printf("ERR: No TLV definition found for %s\n", tlv_name); -% endif } +% endif diff --git a/tools/generate-wire.py b/tools/generate-wire.py index 9845c9a0bfce..9698eb09c3ae 100755 --- a/tools/generate-wire.py +++ b/tools/generate-wire.py @@ -220,6 +220,7 @@ class Type(FieldSet): # Externally defined variable size types (require a context) varsize_types = [ 'peer_features', + 'channel_type', 'gossip_getnodes_entry', 'gossip_getchannels_entry', 'failed_htlc', @@ -239,6 +240,7 @@ class Type(FieldSet): 'tx_parts', 'wally_psbt', 'wally_tx', + 'channel_type', ] # Some BOLT types are re-typed based on their field name diff --git a/wallet/db_postgres_sqlgen.c b/wallet/db_postgres_sqlgen.c index 6ca03f26a771..ce2e74609f58 100644 --- a/wallet/db_postgres_sqlgen.c +++ b/wallet/db_postgres_sqlgen.c @@ -2074,4 +2074,4 @@ struct db_query db_postgres_queries[] = { #endif /* LIGHTNINGD_WALLET_GEN_DB_POSTGRES */ -// SHA256STAMP:f929ee6db13bdf55b5e0cdf54840091948b664a61c63a4aaaef403dc7e6f23ad +// SHA256STAMP:a70af01d3b2f3a7003703b7feb0b2ef12359e0d2850bde1697a53780e2f5dbae diff --git a/wallet/db_sqlite3_sqlgen.c b/wallet/db_sqlite3_sqlgen.c index fa71450da8e6..c0ff233169ca 100644 --- a/wallet/db_sqlite3_sqlgen.c +++ b/wallet/db_sqlite3_sqlgen.c @@ -2074,4 +2074,4 @@ struct db_query db_sqlite3_queries[] = { #endif /* LIGHTNINGD_WALLET_GEN_DB_SQLITE3 */ -// SHA256STAMP:f929ee6db13bdf55b5e0cdf54840091948b664a61c63a4aaaef403dc7e6f23ad +// SHA256STAMP:a70af01d3b2f3a7003703b7feb0b2ef12359e0d2850bde1697a53780e2f5dbae diff --git a/wallet/statements_gettextgen.po b/wallet/statements_gettextgen.po index a0bff95df0f5..570d63d84216 100644 --- a/wallet/statements_gettextgen.po +++ b/wallet/statements_gettextgen.po @@ -938,419 +938,419 @@ msgstr "" msgid "SELECT funding_tx_id, funding_tx_outnum, funding_feerate, funding_satoshi, our_funding_satoshi, funding_psbt, last_tx, last_sig, funding_tx_remote_sigs_received, lease_expiry, lease_commit_sig, lease_chan_max_msat, lease_chan_max_ppt, lease_blockheight_start FROM channel_funding_inflights WHERE channel_id = ? ORDER BY funding_feerate" msgstr "" -#: wallet/wallet.c:1453 +#: wallet/wallet.c:1461 msgid "SELECT id FROM channels ORDER BY id DESC LIMIT 1;" msgstr "" -#: wallet/wallet.c:1470 +#: wallet/wallet.c:1478 msgid "SELECT id, peer_id, short_channel_id, full_channel_id, channel_config_local, channel_config_remote, state, funder, channel_flags, minimum_depth, next_index_local, next_index_remote, next_htlc_id, funding_tx_id, funding_tx_outnum, funding_satoshi, our_funding_satoshi, funding_locked_remote, push_msatoshi, msatoshi_local, fundingkey_remote, revocation_basepoint_remote, payment_basepoint_remote, htlc_basepoint_remote, delayed_payment_basepoint_remote, per_commit_remote, old_per_commit_remote, local_feerate_per_kw, remote_feerate_per_kw, shachain_remote_id, shutdown_scriptpubkey_remote, shutdown_keyidx_local, last_sent_commit_state, last_sent_commit_id, last_tx, last_sig, last_was_revoke, first_blocknum, min_possible_feerate, max_possible_feerate, msatoshi_to_us_min, msatoshi_to_us_max, future_per_commitment_point, last_sent_commit, feerate_base, feerate_ppm, remote_upfront_shutdown_script, local_static_remotekey_start, remote_static_remotekey_start, option_anchor_outputs, shutdown_scriptpubkey_local, closer, state_change_reason, revocation_basepoint_local, payment_basepoint_local, htlc_basepoint_local, delayed_payment_basepoint_local, funding_pubkey_local, shutdown_wrong_txid, shutdown_wrong_outnum, lease_expiry, lease_commit_sig, lease_chan_max_msat, lease_chan_max_ppt FROM channels WHERE state != ?;" msgstr "" -#: wallet/wallet.c:1582 +#: wallet/wallet.c:1590 msgid "UPDATE channels SET in_payments_offered = COALESCE(in_payments_offered, 0) + 1 , in_msatoshi_offered = COALESCE(in_msatoshi_offered, 0) + ? WHERE id = ?;" msgstr "" -#: wallet/wallet.c:1588 +#: wallet/wallet.c:1596 msgid "UPDATE channels SET in_payments_fulfilled = COALESCE(in_payments_fulfilled, 0) + 1 , in_msatoshi_fulfilled = COALESCE(in_msatoshi_fulfilled, 0) + ? WHERE id = ?;" msgstr "" -#: wallet/wallet.c:1594 +#: wallet/wallet.c:1602 msgid "UPDATE channels SET out_payments_offered = COALESCE(out_payments_offered, 0) + 1 , out_msatoshi_offered = COALESCE(out_msatoshi_offered, 0) + ? WHERE id = ?;" msgstr "" -#: wallet/wallet.c:1600 +#: wallet/wallet.c:1608 msgid "UPDATE channels SET out_payments_fulfilled = COALESCE(out_payments_fulfilled, 0) + 1 , out_msatoshi_fulfilled = COALESCE(out_msatoshi_fulfilled, 0) + ? WHERE id = ?;" msgstr "" -#: wallet/wallet.c:1645 +#: wallet/wallet.c:1653 msgid "SELECT in_payments_offered, in_payments_fulfilled, in_msatoshi_offered, in_msatoshi_fulfilled, out_payments_offered, out_payments_fulfilled, out_msatoshi_offered, out_msatoshi_fulfilled FROM channels WHERE id = ?" msgstr "" -#: wallet/wallet.c:1674 +#: wallet/wallet.c:1682 msgid "SELECT MIN(height), MAX(height) FROM blocks;" msgstr "" -#: wallet/wallet.c:1696 +#: wallet/wallet.c:1704 msgid "INSERT INTO channel_configs DEFAULT VALUES;" msgstr "" -#: wallet/wallet.c:1708 +#: wallet/wallet.c:1716 msgid "UPDATE channel_configs SET dust_limit_satoshis=?, max_htlc_value_in_flight_msat=?, channel_reserve_satoshis=?, htlc_minimum_msat=?, to_self_delay=?, max_accepted_htlcs=? WHERE id=?;" msgstr "" -#: wallet/wallet.c:1732 +#: wallet/wallet.c:1740 msgid "SELECT id, dust_limit_satoshis, max_htlc_value_in_flight_msat, channel_reserve_satoshis, htlc_minimum_msat, to_self_delay, max_accepted_htlcs FROM channel_configs WHERE id= ? ;" msgstr "" -#: wallet/wallet.c:1766 +#: wallet/wallet.c:1774 msgid "UPDATE channels SET remote_ann_node_sig=?, remote_ann_bitcoin_sig=? WHERE id=?" msgstr "" -#: wallet/wallet.c:1785 +#: wallet/wallet.c:1793 msgid "UPDATE channels SET shachain_remote_id=?, short_channel_id=?, full_channel_id=?, state=?, funder=?, channel_flags=?, minimum_depth=?, next_index_local=?, next_index_remote=?, next_htlc_id=?, funding_tx_id=?, funding_tx_outnum=?, funding_satoshi=?, our_funding_satoshi=?, funding_locked_remote=?, push_msatoshi=?, msatoshi_local=?, shutdown_scriptpubkey_remote=?, shutdown_keyidx_local=?, channel_config_local=?, last_tx=?, last_sig=?, last_was_revoke=?, min_possible_feerate=?, max_possible_feerate=?, msatoshi_to_us_min=?, msatoshi_to_us_max=?, feerate_base=?, feerate_ppm=?, remote_upfront_shutdown_script=?, local_static_remotekey_start=?, remote_static_remotekey_start=?, option_anchor_outputs=?, shutdown_scriptpubkey_local=?, closer=?, state_change_reason=?, shutdown_wrong_txid=?, shutdown_wrong_outnum=?, lease_expiry=?, lease_commit_sig=?, lease_chan_max_msat=?, lease_chan_max_ppt=? WHERE id=?" msgstr "" -#: wallet/wallet.c:1894 +#: wallet/wallet.c:1902 msgid "UPDATE channels SET fundingkey_remote=?, revocation_basepoint_remote=?, payment_basepoint_remote=?, htlc_basepoint_remote=?, delayed_payment_basepoint_remote=?, per_commit_remote=?, old_per_commit_remote=?, channel_config_remote=?, future_per_commitment_point=? WHERE id=?" msgstr "" -#: wallet/wallet.c:1921 +#: wallet/wallet.c:1929 msgid "DELETE FROM channel_feerates WHERE channel_id=?" msgstr "" -#: wallet/wallet.c:1931 +#: wallet/wallet.c:1939 msgid "INSERT INTO channel_feerates VALUES(?, ?, ?)" msgstr "" -#: wallet/wallet.c:1940 +#: wallet/wallet.c:1948 msgid "DELETE FROM channel_blockheights WHERE channel_id=?" msgstr "" -#: wallet/wallet.c:1950 +#: wallet/wallet.c:1958 msgid "INSERT INTO channel_blockheights VALUES(?, ?, ?)" msgstr "" -#: wallet/wallet.c:1967 +#: wallet/wallet.c:1975 msgid "UPDATE channels SET last_sent_commit=? WHERE id=?" msgstr "" -#: wallet/wallet.c:1990 +#: wallet/wallet.c:1998 msgid "INSERT INTO channel_state_changes ( channel_id, timestamp, old_state, new_state, cause, message) VALUES (?, ?, ?, ?, ?, ?);" msgstr "" -#: wallet/wallet.c:2018 +#: wallet/wallet.c:2026 msgid "SELECT timestamp, old_state, new_state, cause, message FROM channel_state_changes WHERE channel_id = ? ORDER BY timestamp ASC;" msgstr "" -#: wallet/wallet.c:2047 +#: wallet/wallet.c:2055 msgid "SELECT id FROM peers WHERE node_id = ?" msgstr "" -#: wallet/wallet.c:2059 +#: wallet/wallet.c:2067 msgid "UPDATE peers SET address = ? WHERE id = ?" msgstr "" -#: wallet/wallet.c:2068 +#: wallet/wallet.c:2076 msgid "INSERT INTO peers (node_id, address) VALUES (?, ?);" msgstr "" -#: wallet/wallet.c:2089 +#: wallet/wallet.c:2097 msgid "INSERT INTO channels ( peer_id, first_blocknum, id, revocation_basepoint_local, payment_basepoint_local, htlc_basepoint_local, delayed_payment_basepoint_local, funding_pubkey_local) VALUES (?, ?, ?, ?, ?, ?, ?, ?);" msgstr "" -#: wallet/wallet.c:2130 +#: wallet/wallet.c:2138 msgid "DELETE FROM channel_htlcs WHERE channel_id=?" msgstr "" -#: wallet/wallet.c:2136 +#: wallet/wallet.c:2144 msgid "DELETE FROM htlc_sigs WHERE channelid=?" msgstr "" -#: wallet/wallet.c:2142 +#: wallet/wallet.c:2150 msgid "DELETE FROM channeltxs WHERE channel_id=?" msgstr "" -#: wallet/wallet.c:2149 +#: wallet/wallet.c:2157 msgid "DELETE FROM channel_funding_inflights WHERE channel_id=?" msgstr "" -#: wallet/wallet.c:2155 +#: wallet/wallet.c:2163 msgid "DELETE FROM shachains WHERE id IN ( SELECT shachain_remote_id FROM channels WHERE channels.id=?)" msgstr "" -#: wallet/wallet.c:2165 +#: wallet/wallet.c:2173 msgid "UPDATE channels SET state=?, peer_id=? WHERE channels.id=?" msgstr "" -#: wallet/wallet.c:2179 +#: wallet/wallet.c:2187 msgid "SELECT * FROM channels WHERE peer_id = ?;" msgstr "" -#: wallet/wallet.c:2187 +#: wallet/wallet.c:2195 msgid "DELETE FROM peers WHERE id=?" msgstr "" -#: wallet/wallet.c:2198 +#: wallet/wallet.c:2206 msgid "UPDATE outputs SET confirmation_height = ? WHERE prev_out_tx = ?" msgstr "" -#: wallet/wallet.c:2301 +#: wallet/wallet.c:2309 msgid "INSERT INTO channel_htlcs ( channel_id, channel_htlc_id, direction, msatoshi, cltv_expiry, payment_hash, payment_key, hstate, shared_secret, routing_onion, received_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);" msgstr "" -#: wallet/wallet.c:2354 +#: wallet/wallet.c:2362 msgid "INSERT INTO channel_htlcs ( channel_id, channel_htlc_id, direction, origin_htlc, msatoshi, cltv_expiry, payment_hash, payment_key, hstate, routing_onion, malformed_onion, partid) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, ?);" msgstr "" -#: wallet/wallet.c:2415 +#: wallet/wallet.c:2423 msgid "UPDATE channel_htlcs SET hstate=?, payment_key=?, malformed_onion=?, failuremsg=?, localfailmsg=?, we_filled=? WHERE id=?" msgstr "" -#: wallet/wallet.c:2632 +#: wallet/wallet.c:2640 msgid "SELECT id, channel_htlc_id, msatoshi, cltv_expiry, hstate, payment_hash, payment_key, routing_onion, failuremsg, malformed_onion, origin_htlc, shared_secret, received_time, we_filled FROM channel_htlcs WHERE direction= ? AND channel_id= ? AND hstate != ?" msgstr "" -#: wallet/wallet.c:2679 +#: wallet/wallet.c:2687 msgid "SELECT id, channel_htlc_id, msatoshi, cltv_expiry, hstate, payment_hash, payment_key, routing_onion, failuremsg, malformed_onion, origin_htlc, shared_secret, received_time, partid, localfailmsg FROM channel_htlcs WHERE direction = ? AND channel_id = ? AND hstate != ?" msgstr "" -#: wallet/wallet.c:2810 +#: wallet/wallet.c:2818 msgid "SELECT channel_id, direction, cltv_expiry, channel_htlc_id, payment_hash FROM channel_htlcs WHERE channel_id = ?;" msgstr "" -#: wallet/wallet.c:2844 +#: wallet/wallet.c:2852 msgid "DELETE FROM channel_htlcs WHERE direction = ? AND origin_htlc = ? AND payment_hash = ? AND partid = ?;" msgstr "" -#: wallet/wallet.c:2897 +#: wallet/wallet.c:2905 msgid "SELECT status FROM payments WHERE payment_hash=? AND partid = ?;" msgstr "" -#: wallet/wallet.c:2915 +#: wallet/wallet.c:2923 msgid "INSERT INTO payments ( status, payment_hash, destination, msatoshi, timestamp, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, total_msat, partid, local_offer_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);" msgstr "" -#: wallet/wallet.c:3004 +#: wallet/wallet.c:3012 msgid "DELETE FROM payments WHERE payment_hash = ? AND partid = ?" msgstr "" -#: wallet/wallet.c:3018 +#: wallet/wallet.c:3026 msgid "DELETE FROM payments WHERE payment_hash = ?" msgstr "" -#: wallet/wallet.c:3119 +#: wallet/wallet.c:3127 msgid "SELECT id, status, destination, msatoshi, payment_hash, timestamp, payment_preimage, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, failonionreply, total_msat, partid, local_offer_id FROM payments WHERE payment_hash = ? AND partid = ?" msgstr "" -#: wallet/wallet.c:3169 +#: wallet/wallet.c:3177 msgid "UPDATE payments SET status=? WHERE payment_hash=? AND partid=?" msgstr "" -#: wallet/wallet.c:3179 +#: wallet/wallet.c:3187 msgid "UPDATE payments SET payment_preimage=? WHERE payment_hash=? AND partid=?" msgstr "" -#: wallet/wallet.c:3189 +#: wallet/wallet.c:3197 msgid "UPDATE payments SET path_secrets = NULL , route_nodes = NULL , route_channels = NULL WHERE payment_hash = ? AND partid = ?;" msgstr "" -#: wallet/wallet.c:3221 +#: wallet/wallet.c:3229 msgid "SELECT failonionreply, faildestperm, failindex, failcode, failnode, failchannel, failupdate, faildetail, faildirection FROM payments WHERE payment_hash=? AND partid=?;" msgstr "" -#: wallet/wallet.c:3288 +#: wallet/wallet.c:3296 msgid "UPDATE payments SET failonionreply=? , faildestperm=? , failindex=? , failcode=? , failnode=? , failchannel=? , failupdate=? , faildetail=? , faildirection=? WHERE payment_hash=? AND partid=?;" msgstr "" -#: wallet/wallet.c:3347 +#: wallet/wallet.c:3355 msgid "SELECT id, status, destination, msatoshi, payment_hash, timestamp, payment_preimage, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, failonionreply, total_msat, partid, local_offer_id FROM payments WHERE payment_hash = ? ORDER BY id;" msgstr "" -#: wallet/wallet.c:3370 +#: wallet/wallet.c:3378 msgid "SELECT id, status, destination, msatoshi, payment_hash, timestamp, payment_preimage, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, failonionreply, total_msat, partid, local_offer_id FROM payments ORDER BY id;" msgstr "" -#: wallet/wallet.c:3421 +#: wallet/wallet.c:3429 msgid "SELECT id, status, destination, msatoshi, payment_hash, timestamp, payment_preimage, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, failonionreply, total_msat, partid, local_offer_id FROM payments WHERE local_offer_id = ?;" msgstr "" -#: wallet/wallet.c:3466 +#: wallet/wallet.c:3474 msgid "DELETE FROM htlc_sigs WHERE channelid = ?" msgstr "" -#: wallet/wallet.c:3473 +#: wallet/wallet.c:3481 msgid "INSERT INTO htlc_sigs (channelid, signature) VALUES (?, ?)" msgstr "" -#: wallet/wallet.c:3485 +#: wallet/wallet.c:3493 msgid "SELECT blobval FROM vars WHERE name='genesis_hash'" msgstr "" -#: wallet/wallet.c:3509 +#: wallet/wallet.c:3517 msgid "INSERT INTO vars (name, blobval) VALUES ('genesis_hash', ?);" msgstr "" -#: wallet/wallet.c:3527 +#: wallet/wallet.c:3535 msgid "SELECT txid, outnum FROM utxoset WHERE spendheight < ?" msgstr "" -#: wallet/wallet.c:3539 +#: wallet/wallet.c:3547 msgid "DELETE FROM utxoset WHERE spendheight < ?" msgstr "" -#: wallet/wallet.c:3547 wallet/wallet.c:3661 +#: wallet/wallet.c:3555 wallet/wallet.c:3669 msgid "INSERT INTO blocks (height, hash, prev_hash) VALUES (?, ?, ?);" msgstr "" -#: wallet/wallet.c:3566 +#: wallet/wallet.c:3574 msgid "DELETE FROM blocks WHERE hash = ?" msgstr "" -#: wallet/wallet.c:3572 +#: wallet/wallet.c:3580 msgid "SELECT * FROM blocks WHERE height >= ?;" msgstr "" -#: wallet/wallet.c:3581 +#: wallet/wallet.c:3589 msgid "DELETE FROM blocks WHERE height > ?" msgstr "" -#: wallet/wallet.c:3593 +#: wallet/wallet.c:3601 msgid "UPDATE outputs SET spend_height = ?, status = ? WHERE prev_out_tx = ? AND prev_out_index = ?" msgstr "" -#: wallet/wallet.c:3611 +#: wallet/wallet.c:3619 msgid "UPDATE utxoset SET spendheight = ? WHERE txid = ? AND outnum = ?" msgstr "" -#: wallet/wallet.c:3634 wallet/wallet.c:3672 +#: wallet/wallet.c:3642 wallet/wallet.c:3680 msgid "INSERT INTO utxoset ( txid, outnum, blockheight, spendheight, txindex, scriptpubkey, satoshis) VALUES(?, ?, ?, ?, ?, ?, ?);" msgstr "" -#: wallet/wallet.c:3698 +#: wallet/wallet.c:3706 msgid "SELECT height FROM blocks WHERE height = ?" msgstr "" -#: wallet/wallet.c:3711 +#: wallet/wallet.c:3719 msgid "SELECT txid, spendheight, scriptpubkey, satoshis FROM utxoset WHERE blockheight = ? AND txindex = ? AND outnum = ? AND spendheight IS NULL" msgstr "" -#: wallet/wallet.c:3775 +#: wallet/wallet.c:3783 msgid "SELECT blockheight, txindex, outnum FROM utxoset WHERE spendheight = ?" msgstr "" -#: wallet/wallet.c:3792 +#: wallet/wallet.c:3800 msgid "SELECT blockheight, txindex, outnum FROM utxoset WHERE blockheight = ?" msgstr "" -#: wallet/wallet.c:3809 wallet/wallet.c:3969 +#: wallet/wallet.c:3817 wallet/wallet.c:3977 msgid "SELECT blockheight FROM transactions WHERE id=?" msgstr "" -#: wallet/wallet.c:3819 +#: wallet/wallet.c:3827 msgid "INSERT INTO transactions ( id, blockheight, txindex, rawtx) VALUES (?, ?, ?, ?);" msgstr "" -#: wallet/wallet.c:3840 +#: wallet/wallet.c:3848 msgid "UPDATE transactions SET blockheight = ?, txindex = ? WHERE id = ?" msgstr "" -#: wallet/wallet.c:3857 +#: wallet/wallet.c:3865 msgid "INSERT INTO transaction_annotations (txid, idx, location, type, channel) VALUES (?, ?, ?, ?, ?) ON CONFLICT(txid,idx) DO NOTHING;" msgstr "" -#: wallet/wallet.c:3889 +#: wallet/wallet.c:3897 msgid "SELECT type, channel_id FROM transactions WHERE id=?" msgstr "" -#: wallet/wallet.c:3905 +#: wallet/wallet.c:3913 msgid "UPDATE transactions SET type = ?, channel_id = ? WHERE id = ?" msgstr "" -#: wallet/wallet.c:3924 +#: wallet/wallet.c:3932 msgid "SELECT type FROM transactions WHERE id=?" msgstr "" -#: wallet/wallet.c:3947 +#: wallet/wallet.c:3955 msgid "SELECT rawtx FROM transactions WHERE id=?" msgstr "" -#: wallet/wallet.c:3993 +#: wallet/wallet.c:4001 msgid "SELECT blockheight, txindex FROM transactions WHERE id=?" msgstr "" -#: wallet/wallet.c:4021 +#: wallet/wallet.c:4029 msgid "SELECT id FROM transactions WHERE blockheight=?" msgstr "" -#: wallet/wallet.c:4040 +#: wallet/wallet.c:4048 msgid "INSERT INTO channeltxs ( channel_id, type, transaction_id, input_num, blockheight) VALUES (?, ?, ?, ?, ?);" msgstr "" -#: wallet/wallet.c:4064 +#: wallet/wallet.c:4072 msgid "SELECT DISTINCT(channel_id) FROM channeltxs WHERE type = ?;" msgstr "" -#: wallet/wallet.c:4085 +#: wallet/wallet.c:4093 msgid "SELECT c.type, c.blockheight, t.rawtx, c.input_num, c.blockheight - t.blockheight + 1 AS depth, t.id as txid FROM channeltxs c JOIN transactions t ON t.id = c.transaction_id WHERE c.channel_id = ? ORDER BY c.id ASC;" msgstr "" -#: wallet/wallet.c:4130 +#: wallet/wallet.c:4138 msgid "UPDATE forwarded_payments SET in_msatoshi=?, out_msatoshi=?, state=?, resolved_time=?, failcode=? WHERE in_htlc_id=?" msgstr "" -#: wallet/wallet.c:4188 +#: wallet/wallet.c:4196 msgid "INSERT INTO forwarded_payments ( in_htlc_id, out_htlc_id, in_channel_scid, out_channel_scid, in_msatoshi, out_msatoshi, state, received_time, resolved_time, failcode) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);" msgstr "" -#: wallet/wallet.c:4247 +#: wallet/wallet.c:4255 msgid "SELECT CAST(COALESCE(SUM(in_msatoshi - out_msatoshi), 0) AS BIGINT)FROM forwarded_payments WHERE state = ?;" msgstr "" -#: wallet/wallet.c:4296 +#: wallet/wallet.c:4304 msgid "SELECT f.state, in_msatoshi, out_msatoshi, hin.payment_hash as payment_hash, in_channel_scid, out_channel_scid, f.received_time, f.resolved_time, f.failcode FROM forwarded_payments f LEFT JOIN channel_htlcs hin ON (f.in_htlc_id = hin.id) WHERE (1 = ? OR f.state = ?) AND (1 = ? OR f.in_channel_scid = ?) AND (1 = ? OR f.out_channel_scid = ?)" msgstr "" -#: wallet/wallet.c:4418 +#: wallet/wallet.c:4426 msgid "SELECT t.id, t.rawtx, t.blockheight, t.txindex, t.type as txtype, c2.short_channel_id as txchan, a.location, a.idx as ann_idx, a.type as annotation_type, c.short_channel_id FROM transactions t LEFT JOIN transaction_annotations a ON (a.txid = t.id) LEFT JOIN channels c ON (a.channel = c.id) LEFT JOIN channels c2 ON (t.channel_id = c2.id) ORDER BY t.blockheight, t.txindex ASC" msgstr "" -#: wallet/wallet.c:4512 +#: wallet/wallet.c:4520 msgid "INSERT INTO penalty_bases ( channel_id, commitnum, txid, outnum, amount) VALUES (?, ?, ?, ?, ?);" msgstr "" -#: wallet/wallet.c:4537 +#: wallet/wallet.c:4545 msgid "SELECT commitnum, txid, outnum, amount FROM penalty_bases WHERE channel_id = ?" msgstr "" -#: wallet/wallet.c:4561 +#: wallet/wallet.c:4569 msgid "DELETE FROM penalty_bases WHERE channel_id = ? AND commitnum = ?" msgstr "" -#: wallet/wallet.c:4579 +#: wallet/wallet.c:4587 msgid "SELECT 1 FROM offers WHERE offer_id = ?;" msgstr "" -#: wallet/wallet.c:4592 +#: wallet/wallet.c:4600 msgid "INSERT INTO offers ( offer_id, bolt12, label, status) VALUES (?, ?, ?, ?);" msgstr "" -#: wallet/wallet.c:4619 +#: wallet/wallet.c:4627 msgid "SELECT bolt12, label, status FROM offers WHERE offer_id = ?;" msgstr "" -#: wallet/wallet.c:4647 +#: wallet/wallet.c:4655 msgid "SELECT offer_id FROM offers;" msgstr "" -#: wallet/wallet.c:4673 +#: wallet/wallet.c:4681 msgid "UPDATE offers SET status=? WHERE offer_id = ?;" msgstr "" -#: wallet/wallet.c:4684 +#: wallet/wallet.c:4692 msgid "UPDATE invoices SET state=? WHERE state=? AND local_offer_id = ?;" msgstr "" -#: wallet/wallet.c:4712 +#: wallet/wallet.c:4720 msgid "SELECT status FROM offers WHERE offer_id = ?;" msgstr "" -#: wallet/wallet.c:4797 +#: wallet/wallet.c:4805 msgid "UPDATE datastore SET data=?, generation=generation+1 WHERE key=?;" msgstr "" -#: wallet/wallet.c:4808 +#: wallet/wallet.c:4816 msgid "INSERT INTO datastore VALUES (?, ?, 0);" msgstr "" -#: wallet/wallet.c:4819 +#: wallet/wallet.c:4827 msgid "DELETE FROM datastore WHERE key = ?" msgstr "" -#: wallet/wallet.c:4836 +#: wallet/wallet.c:4844 msgid "SELECT key, data, generation FROM datastore WHERE key >= ? ORDER BY key;" msgstr "" -#: wallet/wallet.c:4843 +#: wallet/wallet.c:4851 msgid "SELECT key, data, generation FROM datastore ORDER BY key;" msgstr "" @@ -1362,11 +1362,11 @@ msgstr "" msgid "not a valid SQL statement" msgstr "" -#: wallet/test/run-wallet.c:1545 +#: wallet/test/run-wallet.c:1541 msgid "SELECT COUNT(1) FROM channel_funding_inflights WHERE channel_id = ?;" msgstr "" -#: wallet/test/run-wallet.c:1758 +#: wallet/test/run-wallet.c:1754 msgid "INSERT INTO channels (id) VALUES (1);" msgstr "" -# SHA256STAMP:35e10cb3ec34af54b6d78d9eea1aefa0861ef9acbfe0e78745d24b8e49e50b05 +# SHA256STAMP:651a6c15e8780351cd32a4e6dc3011b1c5fc2af6308b0e65a442dda2a3874e19 diff --git a/wallet/test/Makefile b/wallet/test/Makefile index 7526ec2321e6..6ea28e140169 100644 --- a/wallet/test/Makefile +++ b/wallet/test/Makefile @@ -9,7 +9,9 @@ WALLET_TEST_COMMON_OBJS := \ common/amount.o \ common/base32.o \ common/blockheight_states.o \ + common/channel_type.o \ common/derive_basepoints.o \ + common/features.o \ common/htlc_state.o \ common/htlc_wire.o \ common/fee_states.o \ diff --git a/wallet/test/run-wallet.c b/wallet/test/run-wallet.c index 666068099d33..dc1417a5e756 100644 --- a/wallet/test/run-wallet.c +++ b/wallet/test/run-wallet.c @@ -121,13 +121,6 @@ char *encode_scriptpubkey_to_addr(const tal_t *ctx UNNEEDED, /* Generated stub for fatal */ void fatal(const char *fmt UNNEEDED, ...) { fprintf(stderr, "fatal called!\n"); abort(); } -/* Generated stub for feature_negotiated */ -bool feature_negotiated(const struct feature_set *our_features UNNEEDED, - const u8 *their_features UNNEEDED, size_t f UNNEEDED) -{ fprintf(stderr, "feature_negotiated called!\n"); abort(); } -/* Generated stub for feature_offered */ -bool feature_offered(const u8 *features UNNEEDED, size_t f UNNEEDED) -{ fprintf(stderr, "feature_offered called!\n"); abort(); } /* Generated stub for fromwire_channeld_dev_memleak_reply */ bool fromwire_channeld_dev_memleak_reply(const void *p UNNEEDED, bool *leak UNNEEDED) { fprintf(stderr, "fromwire_channeld_dev_memleak_reply called!\n"); abort(); } @@ -1122,7 +1115,7 @@ static bool test_wallet_outputs(struct lightningd *ld, const tal_t *ctx) true, NULL); channel.peer = new_peer(ld, 0, &id, &addr, false); channel.dbid = 1; - channel.option_anchor_outputs = true; + channel.type = channel_type_anchor_outputs(tmpctx); memset(&u.txid, 3, sizeof(u.txid)); CHECK_MSG(wallet_add_onchaind_utxo(w, &u.txid, u.outnum, @@ -1359,6 +1352,7 @@ static bool channelseq(struct channel *c1, struct channel *c2) } /* c2 should also be out of inflights */ CHECK(list_next(&c2->inflights, i2, list) == NULL); + CHECK(channel_type_eq(c1->type, c2->type)); return true; } @@ -1398,6 +1392,7 @@ static bool test_channel_crud(struct lightningd *ld, const tal_t *ctx) secp256k1_ecdsa_signature *node_sig2, *bitcoin_sig2; u32 feerate, blockheight; bool load; + const struct channel_type *type = channel_type_static_remotekey(w); memset(&c1, 0, sizeof(c1)); memset(c2, 0, sizeof(*c2)); @@ -1446,6 +1441,7 @@ static bool test_channel_crud(struct lightningd *ld, const tal_t *ctx) c1.unsaved_dbid = 0; /* Init channel inflights */ list_head_init(&c1.inflights); + c1.type = type; db_begin_transaction(w->db); CHECK(!wallet_err); @@ -1640,7 +1636,7 @@ static bool test_channel_inflight_crud(struct lightningd *ld, const tal_t *ctx) &basepoints, &pk, NULL, 1000, 100, - NULL, 0, 0, true, + NULL, 0, 0, channel_type_static_remotekey(NULL), LOCAL, REASON_UNKNOWN, NULL, new_height_states(w, LOCAL, diff --git a/wallet/wallet.c b/wallet/wallet.c index fc85bd982572..23a7648b6530 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -652,7 +652,7 @@ bool wallet_add_onchaind_utxo(struct wallet *w, else db_bind_null(stmt, 8); - db_bind_int(stmt, 9, channel->option_anchor_outputs); + db_bind_int(stmt, 9, channel_has(channel, OPT_ANCHOR_OUTPUTS)); db_bind_int(stmt, 10, blockheight); /* spendheight */ @@ -1245,6 +1245,7 @@ static struct channel *wallet_stmt2channel(struct wallet *w, struct db_stmt *stm struct pubkey *future_per_commitment_point; struct amount_sat funding_sat, our_funding_sat; struct amount_msat push_msat, our_msat, msat_to_us_min, msat_to_us_max; + struct channel_type *type; secp256k1_ecdsa_signature *lease_commit_sig; u32 lease_chan_max_msat; u16 lease_chan_max_ppt; @@ -1381,6 +1382,13 @@ static struct channel *wallet_stmt2channel(struct wallet *w, struct db_stmt *stm lease_chan_max_ppt = 0; } + if (db_column_int(stmt, 49)) + type = channel_type_anchor_outputs(NULL); + else if (db_column_u64(stmt, 47) != 0x7FFFFFFFFFFFFFFFULL) + type = channel_type_static_remotekey(NULL); + else + type = channel_type_none(NULL); + chan = new_channel(peer, db_column_u64(stmt, 0), &wshachain, db_column_int(stmt, 6), @@ -1428,7 +1436,7 @@ static struct channel *wallet_stmt2channel(struct wallet *w, struct db_stmt *stm db_column_arr(tmpctx, stmt, 46, u8), db_column_u64(stmt, 47), db_column_u64(stmt, 48), - db_column_int(stmt, 49), + type, db_column_int(stmt, 51), db_column_int(stmt, 52), shutdown_wrong_funding, @@ -1865,7 +1873,7 @@ void wallet_channel_save(struct wallet *w, struct channel *chan) db_bind_talarr(stmt, 29, chan->remote_upfront_shutdown_script); db_bind_u64(stmt, 30, chan->static_remotekey_start[LOCAL]); db_bind_u64(stmt, 31, chan->static_remotekey_start[REMOTE]); - db_bind_int(stmt, 32, chan->option_anchor_outputs); + db_bind_int(stmt, 32, channel_has(chan, OPT_ANCHOR_OUTPUTS)); db_bind_talarr(stmt, 33, chan->shutdown_scriptpubkey[LOCAL]); db_bind_int(stmt, 34, chan->closer); db_bind_int(stmt, 35, chan->state_change_cause); diff --git a/wire/Makefile b/wire/Makefile index b822b97401a2..345fa83263db 100644 --- a/wire/Makefile +++ b/wire/Makefile @@ -11,6 +11,7 @@ WIRE_HEADERS := wire/onion_defs.h \ wire/onion$(EXP)_wiregen.h \ wire/bolt12$(EXP)_wiregen.h \ wire/common_wiregen.h \ + wire/channel_type_wiregen.h \ wire/peer$(EXP)_printgen.h \ wire/onion$(EXP)_printgen.h @@ -24,11 +25,13 @@ WIRE_SRC := wire/wire_sync.c \ wire/common_wiregen.c \ wire/bolt12$(EXP)_wiregen.c \ wire/peer$(EXP)_wiregen.c \ + wire/channel_type_wiregen.c \ wire/onion$(EXP)_wiregen.c WIRE_PRINT_SRC := \ wire/onion$(EXP)_printgen.c \ - wire/peer$(EXP)_printgen.c + wire/peer$(EXP)_printgen.c \ + wire/channel_type_printgen.c WIRE_OBJS := $(WIRE_SRC:.c=.o) WIRE_PRINT_OBJS := $(WIRE_PRINT_SRC:.c=.o) @@ -45,7 +48,8 @@ WIRE_NONEXP_HEADERS := wire/peer_wiregen.h \ wire/onion_wiregen.h \ wire/bolt12_wiregen.h \ wire/peer_printgen.h \ - wire/onion_printgen.h + wire/onion_printgen.h \ + wire/channel_type_printgen.h ALL_C_SOURCES += $(WIRE_SRC) $(WIRE_PRINT_SRC) $(WIRE_NONEXP_SRC) @@ -125,8 +129,9 @@ wire/onion_wiregen.h_args := --include='bitcoin/short_channel_id.h' --include='b wire/onion_wiregen.c_args := -s --expose-tlv-type=tlv_payload # Same for _exp versions -wire/peer_exp_wiregen.h_args := $(wire/peer_wiregen.h_args) +wire/peer_exp_wiregen.h_args := $(wire/peer_wiregen.h_args) --include='wire/channel_type_wiregen.h' wire/peer_exp_wiregen.c_args := $(wire/peer_wiregen.c_args) +wire/peer_exp_printgen.h_args := --include='wire/channel_type_printgen.h' wire/onion_exp_wiregen.h_args := $(wire/onion_wiregen.h_args) wire/onion_exp_wiregen.c_args := $(wire/onion_wiregen.c_args) @@ -138,6 +143,9 @@ wire/bolt12_exp_wiregen.c_args := $(wire/bolt12_wiregen.c_args) wire/peer_wiregen.h_args := --include='common/channel_id.h' --include='bitcoin/tx.h' --include='bitcoin/preimage.h' --include='bitcoin/short_channel_id.h' --include='common/node_id.h' --include='common/bigsize.h' --include='bitcoin/block.h' --include='bitcoin/privkey.h' -s --expose-tlv-type=n1 --expose-tlv-type=n2 +wire/channel_type_wiregen.h_args := -s +wire/channel_type_wiregen.c_args := $(wire/channel_type_wiregen.h_args) + # All generated wire/ files depend on this Makefile $(filter %printgen.h %printgen.c %wiregen.h %wiregen.c, $(WIRE_SRC) $(WIRE_PRINT_SRC) $(WIRE_NONEXP_SRC) $(WIRE_HEADERS) $(WIRE_NONEXP_HEADERS)): wire/Makefile diff --git a/wire/bolt12_wiregen.c b/wire/bolt12_wiregen.c index 171cd8c7e6ad..5a74d7f64960 100644 --- a/wire/bolt12_wiregen.c +++ b/wire/bolt12_wiregen.c @@ -1684,4 +1684,4 @@ bool invoice_error_is_valid(const struct tlv_invoice_error *record, size_t *err_ return tlv_fields_valid(record->fields, NULL, err_index); } -// SHA256STAMP:f29bdf0cc1fd0cce9362c88e3b8681781e11c203cc3026fe13e6c52a845154ba +// SHA256STAMP:148a2f3fb6e0148409b1a86d22febab73d290e33b697b803f2d46ddcb61290ac diff --git a/wire/bolt12_wiregen.h b/wire/bolt12_wiregen.h index a07edec15367..8a5ba2b5ff92 100644 --- a/wire/bolt12_wiregen.h +++ b/wire/bolt12_wiregen.h @@ -323,4 +323,4 @@ struct fallback_address *fromwire_fallback_address(const tal_t *ctx, const u8 ** #endif /* LIGHTNING_WIRE_BOLT12_WIREGEN_H */ -// SHA256STAMP:f29bdf0cc1fd0cce9362c88e3b8681781e11c203cc3026fe13e6c52a845154ba +// SHA256STAMP:148a2f3fb6e0148409b1a86d22febab73d290e33b697b803f2d46ddcb61290ac diff --git a/wire/channel_type_wire.csv b/wire/channel_type_wire.csv new file mode 100644 index 000000000000..ac072f0c0fbd --- /dev/null +++ b/wire/channel_type_wire.csv @@ -0,0 +1,4 @@ +# Why not let our generator generate this too? +subtype,channel_type +subtypedata,channel_type,len,u16, +subtypedata,channel_type,features,byte,len diff --git a/wire/common_wiregen.c b/wire/common_wiregen.c index 4c4d39178f28..59bb028e39e5 100644 --- a/wire/common_wiregen.c +++ b/wire/common_wiregen.c @@ -100,4 +100,4 @@ bool fromwire_custommsg_out(const tal_t *ctx, const void *p, u8 **msg) fromwire_u8_array(&cursor, &plen, *msg, msg_len); return cursor != NULL; } -// SHA256STAMP:5e31b6f1281965e31e28ce8a6d1a7e54635170b877bbd11b6ec09cba60f317aa +// SHA256STAMP:fbe11d774ac183c6d77a14e451214f167d0d7205f656ddff1d6a96c40bfd0326 diff --git a/wire/common_wiregen.h b/wire/common_wiregen.h index d6a013dc2d92..1f9aeabb419f 100644 --- a/wire/common_wiregen.h +++ b/wire/common_wiregen.h @@ -41,4 +41,4 @@ bool fromwire_custommsg_out(const tal_t *ctx, const void *p, u8 **msg); #endif /* LIGHTNING_WIRE_COMMON_WIREGEN_H */ -// SHA256STAMP:5e31b6f1281965e31e28ce8a6d1a7e54635170b877bbd11b6ec09cba60f317aa +// SHA256STAMP:fbe11d774ac183c6d77a14e451214f167d0d7205f656ddff1d6a96c40bfd0326 diff --git a/wire/extracted_peer_exp_upgradable.patch b/wire/extracted_peer_exp_upgradable.patch index db26af74680e..2f85d96acde3 100644 --- a/wire/extracted_peer_exp_upgradable.patch +++ b/wire/extracted_peer_exp_upgradable.patch @@ -1,6 +1,6 @@ --- wire/peer_wire.csv 2021-05-09 15:44:59.166135652 +0930 +++ wire/peer_wire.csv.raw 2021-05-11 09:59:31.695459756 +0930 -@@ -221,6 +131,18 @@ +@@ -221,6 +131,15 @@ msgdata,channel_reestablish,next_revocation_number,u64, msgdata,channel_reestablish,your_last_per_commitment_secret,byte,32 msgdata,channel_reestablish,my_current_per_commitment_point,point, @@ -13,9 +13,6 @@ +tlvdata,channel_reestablish_tlvs,current_type,type,channel_type, +tlvtype,channel_reestablish_tlvs,upgradable,7 +tlvdata,channel_reestablish_tlvs,upgradable,upgrades,channel_type,... -+subtype,channel_type -+subtypedata,channel_type,len,u16, -+subtypedata,channel_type,features,byte,len msgtype,announcement_signatures,259 msgdata,announcement_signatures,channel_id,channel_id, msgdata,announcement_signatures,short_channel_id,short_channel_id, diff --git a/wire/onion_printgen.c b/wire/onion_printgen.c index b0a7b81c85e8..b222a5d00cf9 100644 --- a/wire/onion_printgen.c +++ b/wire/onion_printgen.c @@ -859,4 +859,4 @@ void printonion_wire_tlv_message(const char *tlv_name, const u8 *msg) { printwire_tlvs(tlv_name, &msg, &plen, print_tlvs_encmsg_tlvs, ARRAY_SIZE(print_tlvs_encmsg_tlvs)); } } -// SHA256STAMP:79946dd94a6cd6e0af297d3676c688228c7098e6b874469cd49b63fee97ac8cf +// SHA256STAMP:fd460361e76105eb612f69f2a3f27e70115c0ebdad82785f2c852c13f9c08c8d diff --git a/wire/onion_printgen.h b/wire/onion_printgen.h index 7acaf3be8446..c803ce3056fb 100644 --- a/wire/onion_printgen.h +++ b/wire/onion_printgen.h @@ -58,4 +58,4 @@ void printwire_mpp_timeout(const char *fieldname, const u8 *cursor); void printwire_onionmsg_path(const char *fieldname, const u8 **cursor, size_t *plen); #endif /* LIGHTNING_WIRE_ONION_PRINTGEN_H */ -// SHA256STAMP:79946dd94a6cd6e0af297d3676c688228c7098e6b874469cd49b63fee97ac8cf +// SHA256STAMP:fd460361e76105eb612f69f2a3f27e70115c0ebdad82785f2c852c13f9c08c8d diff --git a/wire/onion_wiregen.c b/wire/onion_wiregen.c index 9272b70966a5..c8493d56edd2 100644 --- a/wire/onion_wiregen.c +++ b/wire/onion_wiregen.c @@ -1026,4 +1026,4 @@ bool fromwire_mpp_timeout(const void *p) return false; return cursor != NULL; } -// SHA256STAMP:79946dd94a6cd6e0af297d3676c688228c7098e6b874469cd49b63fee97ac8cf +// SHA256STAMP:fd460361e76105eb612f69f2a3f27e70115c0ebdad82785f2c852c13f9c08c8d diff --git a/wire/onion_wiregen.h b/wire/onion_wiregen.h index d5c9a0ac876a..58c0d83f8797 100644 --- a/wire/onion_wiregen.h +++ b/wire/onion_wiregen.h @@ -317,4 +317,4 @@ bool fromwire_mpp_timeout(const void *p); #endif /* LIGHTNING_WIRE_ONION_WIREGEN_H */ -// SHA256STAMP:79946dd94a6cd6e0af297d3676c688228c7098e6b874469cd49b63fee97ac8cf +// SHA256STAMP:fd460361e76105eb612f69f2a3f27e70115c0ebdad82785f2c852c13f9c08c8d diff --git a/wire/peer_printgen.c b/wire/peer_printgen.c index 4e689ea40240..92725c19383c 100644 --- a/wire/peer_printgen.c +++ b/wire/peer_printgen.c @@ -3139,4 +3139,4 @@ void printpeer_wire_tlv_message(const char *tlv_name, const u8 *msg) { printwire_tlvs(tlv_name, &msg, &plen, print_tlvs_onion_message_tlvs, ARRAY_SIZE(print_tlvs_onion_message_tlvs)); } } -// SHA256STAMP:c55c98a2d8cac53c9f0db9ca4eb5ef1caac507e2f7cf4d1988cfc548efe40bbf +// SHA256STAMP:d2dbf0b5768a6a6c940a353621f8a0521f49104c99d7f5d350c500587a7d54c4 diff --git a/wire/peer_printgen.h b/wire/peer_printgen.h index b6bc64290ca2..e23e2d9cdb6d 100644 --- a/wire/peer_printgen.h +++ b/wire/peer_printgen.h @@ -99,4 +99,4 @@ void printwire_channel_update_checksums(const char *fieldname, const u8 **cursor void printwire_channel_update_timestamps(const char *fieldname, const u8 **cursor, size_t *plen); void printwire_witness_stack(const char *fieldname, const u8 **cursor, size_t *plen); #endif /* LIGHTNING_WIRE_PEER_PRINTGEN_H */ -// SHA256STAMP:c55c98a2d8cac53c9f0db9ca4eb5ef1caac507e2f7cf4d1988cfc548efe40bbf +// SHA256STAMP:d2dbf0b5768a6a6c940a353621f8a0521f49104c99d7f5d350c500587a7d54c4 diff --git a/wire/peer_wiregen.c b/wire/peer_wiregen.c index 7e7f95cef6b5..573d42bd35c7 100644 --- a/wire/peer_wiregen.c +++ b/wire/peer_wiregen.c @@ -2589,4 +2589,4 @@ bool fromwire_channel_update_option_channel_htlc_max(const void *p, secp256k1_ec *htlc_maximum_msat = fromwire_amount_msat(&cursor, &plen); return cursor != NULL; } -// SHA256STAMP:c55c98a2d8cac53c9f0db9ca4eb5ef1caac507e2f7cf4d1988cfc548efe40bbf +// SHA256STAMP:d2dbf0b5768a6a6c940a353621f8a0521f49104c99d7f5d350c500587a7d54c4 diff --git a/wire/peer_wiregen.h b/wire/peer_wiregen.h index 2deb9d052677..bfbc713a21cf 100644 --- a/wire/peer_wiregen.h +++ b/wire/peer_wiregen.h @@ -981,4 +981,4 @@ bool fromwire_channel_update_option_channel_htlc_max(const void *p, secp256k1_ec #endif /* LIGHTNING_WIRE_PEER_WIREGEN_H */ -// SHA256STAMP:c55c98a2d8cac53c9f0db9ca4eb5ef1caac507e2f7cf4d1988cfc548efe40bbf +// SHA256STAMP:d2dbf0b5768a6a6c940a353621f8a0521f49104c99d7f5d350c500587a7d54c4 diff --git a/wire/test/run-peer-wire.c b/wire/test/run-peer-wire.c index 4c74c3314491..b624df16102a 100644 --- a/wire/test/run-peer-wire.c +++ b/wire/test/run-peer-wire.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -21,6 +22,12 @@ extern secp256k1_context *secp256k1_ctx; /* AUTOGENERATED MOCKS START */ +/* Generated stub for fromwire_channel_type */ +struct channel_type *fromwire_channel_type(const tal_t *ctx UNNEEDED, const u8 **cursor UNNEEDED, size_t *plen UNNEEDED) +{ fprintf(stderr, "fromwire_channel_type called!\n"); abort(); } +/* Generated stub for towire_channel_type */ +void towire_channel_type(u8 **p UNNEEDED, const struct channel_type *channel_type UNNEEDED) +{ fprintf(stderr, "towire_channel_type called!\n"); abort(); } /* AUTOGENERATED MOCKS END */ /* memsetting pubkeys doesn't work */ diff --git a/wire/test/run-tlvstream.c b/wire/test/run-tlvstream.c index 6821f3d5beb9..2cf00405bcba 100644 --- a/wire/test/run-tlvstream.c +++ b/wire/test/run-tlvstream.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -28,9 +29,15 @@ static const char *reason; void fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct channel_id *channel_id UNNEEDED) { fprintf(stderr, "fromwire_channel_id called!\n"); abort(); } +/* Generated stub for fromwire_channel_type */ +struct channel_type *fromwire_channel_type(const tal_t *ctx UNNEEDED, const u8 **cursor UNNEEDED, size_t *plen UNNEEDED) +{ fprintf(stderr, "fromwire_channel_type called!\n"); abort(); } /* Generated stub for towire_channel_id */ void towire_channel_id(u8 **pptr UNNEEDED, const struct channel_id *channel_id UNNEEDED) { fprintf(stderr, "towire_channel_id called!\n"); abort(); } +/* Generated stub for towire_channel_type */ +void towire_channel_type(u8 **p UNNEEDED, const struct channel_type *channel_type UNNEEDED) +{ fprintf(stderr, "towire_channel_type called!\n"); abort(); } /* AUTOGENERATED MOCKS END */