diff --git a/channeld/channel_wire.csv b/channeld/channel_wire.csv index 9a25cc5e0..cc055904e 100644 --- a/channeld/channel_wire.csv +++ b/channeld/channel_wire.csv @@ -64,6 +64,7 @@ msgdata,channel_init,upfront_shutdown_script,u8,upfront_shutdown_script_len msgdata,channel_init,remote_ann_node_sig,?secp256k1_ecdsa_signature, msgdata,channel_init,remote_ann_bitcoin_sig,?secp256k1_ecdsa_signature, msgdata,channel_init,option_static_remotekey,bool, +msgdata,channel_init,option_anchor_outputs,bool, msgdata,channel_init,dev_fast_gossip,bool, msgdata,channel_init,dev_fail_process_onionpacket,bool, msgdata,channel_init,num_penalty_bases,u32, diff --git a/channeld/channeld.c b/channeld/channeld.c index 895e691f7..2c27e4f0e 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -3108,7 +3108,7 @@ 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; + bool option_static_remotekey, option_anchor_outputs; struct penalty_base *pbases; #if !DEVELOPER bool dev_fail_process_onionpacket; /* Ignored */ @@ -3169,6 +3169,7 @@ static void init_channel(struct peer *peer) &remote_ann_node_sig, &remote_ann_bitcoin_sig, &option_static_remotekey, + &option_anchor_outputs, &dev_fast_gossip, &dev_fail_process_onionpacket, &pbases)) { diff --git a/lightningd/channel.c b/lightningd/channel.c index 4e00bbc17..0e04efbb6 100644 --- a/lightningd/channel.c +++ b/lightningd/channel.c @@ -189,7 +189,8 @@ struct channel *new_channel(struct peer *peer, u64 dbid, u32 feerate_base, u32 feerate_ppm, const u8 *remote_upfront_shutdown_script, - bool option_static_remotekey) + bool option_static_remotekey, + bool option_anchor_outputs) { struct channel *channel = tal(peer->ld, struct channel); @@ -270,6 +271,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid, channel->remote_upfront_shutdown_script = tal_steal(channel, remote_upfront_shutdown_script); channel->option_static_remotekey = option_static_remotekey; + channel->option_anchor_outputs = option_anchor_outputs; channel->forgets = tal_arr(channel, struct command *, 0); list_add_tail(&peer->channels, &channel->list); diff --git a/lightningd/channel.h b/lightningd/channel.h index fbd30e010..b605d6b4a 100644 --- a/lightningd/channel.h +++ b/lightningd/channel.h @@ -131,6 +131,9 @@ struct channel { /* Was this negotiated with `option_static_remotekey? */ bool option_static_remotekey; + /* Was this negotiated with `option_anchor_outputs? */ + bool option_anchor_outputs; + /* Any commands trying to forget us. */ struct command **forgets; }; @@ -183,7 +186,8 @@ struct channel *new_channel(struct peer *peer, u64 dbid, u32 feerate_ppm, /* NULL or stolen */ const u8 *remote_upfront_shutdown_script STEALS, - bool option_static_remotekey); + bool option_static_remotekey, + bool option_anchor_outputs); void delete_channel(struct channel *channel STEALS); diff --git a/lightningd/channel_control.c b/lightningd/channel_control.c index c6b7cade4..a0dc5e743 100644 --- a/lightningd/channel_control.c +++ b/lightningd/channel_control.c @@ -575,6 +575,7 @@ void peer_start_channeld(struct channel *channel, /* Set at channel open, even if not * negotiated now! */ channel->option_static_remotekey, + channel->option_anchor_outputs, IFDEV(ld->dev_fast_gossip, false), IFDEV(dev_fail_process_onionpacket, false), pbases); diff --git a/lightningd/onchain_control.c b/lightningd/onchain_control.c index 8632667dc..936e8a338 100644 --- a/lightningd/onchain_control.c +++ b/lightningd/onchain_control.c @@ -625,6 +625,7 @@ enum watch_result onchaind_funding_spent(struct channel *channel, channel->max_possible_feerate, channel->future_per_commitment_point, channel->option_static_remotekey, + channel->option_anchor_outputs, is_replay); subd_send_msg(channel->owner, take(msg)); diff --git a/lightningd/opening_control.c b/lightningd/opening_control.c index 86a2729ba..64867999f 100644 --- a/lightningd/opening_control.c +++ b/lightningd/opening_control.c @@ -180,6 +180,7 @@ wallet_commit_channel(struct lightningd *ld, struct amount_sat local_funding; s64 final_key_idx; bool option_static_remotekey; + bool option_anchor_outputs; /* Get a key to use for closing outputs from this tx */ final_key_idx = wallet_get_newindex(ld); @@ -209,7 +210,7 @@ wallet_commit_channel(struct lightningd *ld, /* old_remote_per_commit not valid yet, copy valid one. */ channel_info->old_remote_per_commit = channel_info->remote_per_commit; - /* BOLT #2: + /* BOLT-a12da24dd0102c170365124782b46d9710950ac1 #2: * 1. type: 35 (`funding_signed`) * 2. data: * * [`channel_id`:`channel_id`] @@ -218,11 +219,11 @@ wallet_commit_channel(struct lightningd *ld, * #### Requirements * * Both peers: - * - if `option_static_remotekey` was negotiated: - * - `option_static_remotekey` applies to all commitment + * - if `option_static_remotekey` or `option_anchor_outputs` was negotiated: + * - `option_static_remotekey` or `option_anchor_outputs` applies to all commitment * transactions * - otherwise: - * - `option_static_remotekey` does not apply to any commitment + * - `option_static_remotekey` or `option_anchor_outputs` does not apply to any commitment * transactions */ /* i.e. We set it now for the channel permanently. */ @@ -230,6 +231,10 @@ wallet_commit_channel(struct lightningd *ld, = feature_negotiated(ld->our_features, uc->peer->their_features, OPT_STATIC_REMOTEKEY); + 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 */ @@ -275,7 +280,8 @@ wallet_commit_channel(struct lightningd *ld, ld->config.fee_base, ld->config.fee_per_satoshi, remote_upfront_shutdown_script, - option_static_remotekey); + option_static_remotekey, + option_anchor_outputs); /* Now we finally put it in the database. */ wallet_channel_insert(ld->wallet, channel); diff --git a/onchaind/onchain_wire.csv b/onchaind/onchain_wire.csv index 1190a8c17..1921fb0a1 100644 --- a/onchaind/onchain_wire.csv +++ b/onchaind/onchain_wire.csv @@ -45,6 +45,7 @@ msgdata,onchain_init,min_possible_feerate,u32, msgdata,onchain_init,max_possible_feerate,u32, msgdata,onchain_init,possible_remote_per_commit_point,?pubkey, msgdata,onchain_init,option_static_remotekey,bool, +msgdata,onchain_init,option_anchor_outputs,bool, msgdata,onchain_init,is_replay,bool, #include diff --git a/onchaind/onchaind.c b/onchaind/onchaind.c index 177475ed0..d6162065b 100644 --- a/onchaind/onchaind.c +++ b/onchaind/onchaind.c @@ -80,7 +80,10 @@ static u8 **missing_htlc_msgs; static struct amount_msat our_msat; /* Does option_static_remotekey apply to this commitment tx? */ -bool option_static_remotekey; +static bool option_static_remotekey; + +/* Does option_anchor_outputs apply to this commitment tx? */ +static bool option_anchor_outputs; /* If we broadcast a tx, or need a delay to resolve the output. */ struct proposed_resolution { @@ -3225,6 +3228,7 @@ int main(int argc, char *argv[]) &max_possible_feerate, &possible_remote_per_commitment_point, &option_static_remotekey, + &option_anchor_outputs, &open_is_replay)) { master_badmsg(WIRE_ONCHAIN_INIT, msg); } diff --git a/onchaind/test/run-grind_feerate-bug.c b/onchaind/test/run-grind_feerate-bug.c index 633a15a62..2a59292f9 100644 --- a/onchaind/test/run-grind_feerate-bug.c +++ b/onchaind/test/run-grind_feerate-bug.c @@ -50,7 +50,7 @@ bool fromwire_onchain_dev_memleak(const void *p UNNEEDED) bool fromwire_onchain_htlc(const void *p UNNEEDED, struct htlc_stub *htlc UNNEEDED, bool *tell_if_missing UNNEEDED, bool *tell_immediately UNNEEDED) { fprintf(stderr, "fromwire_onchain_htlc called!\n"); abort(); } /* Generated stub for fromwire_onchain_init */ -bool fromwire_onchain_init(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct shachain *shachain UNNEEDED, const struct chainparams **chainparams UNNEEDED, struct amount_sat *funding_amount_satoshi UNNEEDED, struct amount_msat *our_msat UNNEEDED, struct pubkey *old_remote_per_commitment_point UNNEEDED, struct pubkey *remote_per_commitment_point UNNEEDED, u32 *local_to_self_delay UNNEEDED, u32 *remote_to_self_delay UNNEEDED, u32 *delayed_to_us_feerate UNNEEDED, u32 *htlc_feerate UNNEEDED, u32 *penalty_feerate UNNEEDED, struct amount_sat *local_dust_limit_satoshi UNNEEDED, struct bitcoin_txid *our_broadcast_txid UNNEEDED, u8 **local_scriptpubkey UNNEEDED, u8 **remote_scriptpubkey UNNEEDED, struct pubkey *ourwallet_pubkey UNNEEDED, enum side *opener UNNEEDED, struct basepoints *local_basepoints UNNEEDED, struct basepoints *remote_basepoints UNNEEDED, struct tx_parts **tx_parts UNNEEDED, u32 *locktime UNNEEDED, u32 *tx_blockheight UNNEEDED, u32 *reasonable_depth UNNEEDED, secp256k1_ecdsa_signature **htlc_signature UNNEEDED, u64 *num_htlcs UNNEEDED, u32 *min_possible_feerate UNNEEDED, u32 *max_possible_feerate UNNEEDED, struct pubkey **possible_remote_per_commit_point UNNEEDED, bool *option_static_remotekey UNNEEDED, bool *is_replay UNNEEDED) +bool fromwire_onchain_init(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct shachain *shachain UNNEEDED, const struct chainparams **chainparams UNNEEDED, struct amount_sat *funding_amount_satoshi UNNEEDED, struct amount_msat *our_msat UNNEEDED, struct pubkey *old_remote_per_commitment_point UNNEEDED, struct pubkey *remote_per_commitment_point UNNEEDED, u32 *local_to_self_delay UNNEEDED, u32 *remote_to_self_delay UNNEEDED, u32 *delayed_to_us_feerate UNNEEDED, u32 *htlc_feerate UNNEEDED, u32 *penalty_feerate UNNEEDED, struct amount_sat *local_dust_limit_satoshi UNNEEDED, struct bitcoin_txid *our_broadcast_txid UNNEEDED, u8 **local_scriptpubkey UNNEEDED, u8 **remote_scriptpubkey UNNEEDED, struct pubkey *ourwallet_pubkey UNNEEDED, enum side *opener UNNEEDED, struct basepoints *local_basepoints UNNEEDED, struct basepoints *remote_basepoints UNNEEDED, struct tx_parts **tx_parts UNNEEDED, u32 *locktime UNNEEDED, u32 *tx_blockheight UNNEEDED, u32 *reasonable_depth UNNEEDED, secp256k1_ecdsa_signature **htlc_signature UNNEEDED, u64 *num_htlcs UNNEEDED, u32 *min_possible_feerate UNNEEDED, u32 *max_possible_feerate UNNEEDED, struct pubkey **possible_remote_per_commit_point UNNEEDED, bool *option_static_remotekey UNNEEDED, bool *option_anchor_outputs UNNEEDED, bool *is_replay UNNEEDED) { fprintf(stderr, "fromwire_onchain_init called!\n"); abort(); } /* Generated stub for fromwire_onchain_known_preimage */ bool fromwire_onchain_known_preimage(const void *p UNNEEDED, struct preimage *preimage UNNEEDED, bool *is_replay UNNEEDED) diff --git a/onchaind/test/run-grind_feerate.c b/onchaind/test/run-grind_feerate.c index 3dbe8ce48..b00e167fd 100644 --- a/onchaind/test/run-grind_feerate.c +++ b/onchaind/test/run-grind_feerate.c @@ -54,7 +54,7 @@ bool fromwire_onchain_dev_memleak(const void *p UNNEEDED) bool fromwire_onchain_htlc(const void *p UNNEEDED, struct htlc_stub *htlc UNNEEDED, bool *tell_if_missing UNNEEDED, bool *tell_immediately UNNEEDED) { fprintf(stderr, "fromwire_onchain_htlc called!\n"); abort(); } /* Generated stub for fromwire_onchain_init */ -bool fromwire_onchain_init(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct shachain *shachain UNNEEDED, const struct chainparams **chainparams UNNEEDED, struct amount_sat *funding_amount_satoshi UNNEEDED, struct amount_msat *our_msat UNNEEDED, struct pubkey *old_remote_per_commitment_point UNNEEDED, struct pubkey *remote_per_commitment_point UNNEEDED, u32 *local_to_self_delay UNNEEDED, u32 *remote_to_self_delay UNNEEDED, u32 *delayed_to_us_feerate UNNEEDED, u32 *htlc_feerate UNNEEDED, u32 *penalty_feerate UNNEEDED, struct amount_sat *local_dust_limit_satoshi UNNEEDED, struct bitcoin_txid *our_broadcast_txid UNNEEDED, u8 **local_scriptpubkey UNNEEDED, u8 **remote_scriptpubkey UNNEEDED, struct pubkey *ourwallet_pubkey UNNEEDED, enum side *opener UNNEEDED, struct basepoints *local_basepoints UNNEEDED, struct basepoints *remote_basepoints UNNEEDED, struct tx_parts **tx_parts UNNEEDED, u32 *locktime UNNEEDED, u32 *tx_blockheight UNNEEDED, u32 *reasonable_depth UNNEEDED, secp256k1_ecdsa_signature **htlc_signature UNNEEDED, u64 *num_htlcs UNNEEDED, u32 *min_possible_feerate UNNEEDED, u32 *max_possible_feerate UNNEEDED, struct pubkey **possible_remote_per_commit_point UNNEEDED, bool *option_static_remotekey UNNEEDED, bool *is_replay UNNEEDED) +bool fromwire_onchain_init(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct shachain *shachain UNNEEDED, const struct chainparams **chainparams UNNEEDED, struct amount_sat *funding_amount_satoshi UNNEEDED, struct amount_msat *our_msat UNNEEDED, struct pubkey *old_remote_per_commitment_point UNNEEDED, struct pubkey *remote_per_commitment_point UNNEEDED, u32 *local_to_self_delay UNNEEDED, u32 *remote_to_self_delay UNNEEDED, u32 *delayed_to_us_feerate UNNEEDED, u32 *htlc_feerate UNNEEDED, u32 *penalty_feerate UNNEEDED, struct amount_sat *local_dust_limit_satoshi UNNEEDED, struct bitcoin_txid *our_broadcast_txid UNNEEDED, u8 **local_scriptpubkey UNNEEDED, u8 **remote_scriptpubkey UNNEEDED, struct pubkey *ourwallet_pubkey UNNEEDED, enum side *opener UNNEEDED, struct basepoints *local_basepoints UNNEEDED, struct basepoints *remote_basepoints UNNEEDED, struct tx_parts **tx_parts UNNEEDED, u32 *locktime UNNEEDED, u32 *tx_blockheight UNNEEDED, u32 *reasonable_depth UNNEEDED, secp256k1_ecdsa_signature **htlc_signature UNNEEDED, u64 *num_htlcs UNNEEDED, u32 *min_possible_feerate UNNEEDED, u32 *max_possible_feerate UNNEEDED, struct pubkey **possible_remote_per_commit_point UNNEEDED, bool *option_static_remotekey UNNEEDED, bool *option_anchor_outputs UNNEEDED, bool *is_replay UNNEEDED) { fprintf(stderr, "fromwire_onchain_init called!\n"); abort(); } /* Generated stub for fromwire_onchain_known_preimage */ bool fromwire_onchain_known_preimage(const void *p UNNEEDED, struct preimage *preimage UNNEEDED, bool *is_replay UNNEEDED) diff --git a/wallet/wallet.c b/wallet/wallet.c index 7578715dc..7f9d7d909 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -1281,7 +1281,8 @@ static struct channel *wallet_stmt2channel(struct wallet *w, struct db_stmt *stm db_column_int(stmt, 43), db_column_int(stmt, 44), db_column_arr(tmpctx, stmt, 45, u8), - db_column_int(stmt, 46)); + db_column_int(stmt, 46), + db_column_int(stmt, 47)); return chan; } @@ -1673,8 +1674,7 @@ void wallet_channel_save(struct wallet *w, struct channel *chan) db_bind_null(stmt, 28); db_bind_int(stmt, 29, chan->option_static_remotekey); - /* FIXME: option_anchor_outputs */ - db_bind_int(stmt, 30, false); + db_bind_int(stmt, 30, chan->option_anchor_outputs); db_bind_blob(stmt, 31, chan->shutdown_scriptpubkey[LOCAL], tal_count(chan->shutdown_scriptpubkey[LOCAL])); db_bind_u64(stmt, 32, chan->dbid);