Browse Source

channeld: set option_static_remotekey when negotiated.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
travis-debug
Rusty Russell 5 years ago
committed by neil saitug
parent
commit
87f0ee6351
  1. 1
      channeld/channel_wire.csv
  2. 5
      channeld/channeld.c
  3. 2
      channeld/full_channel.c
  4. 2
      channeld/full_channel.h
  5. 4
      channeld/test/run-full_channel.c
  6. 2
      common/initial_channel.c
  7. 4
      common/initial_channel.h
  8. 59
      devtools/mkcommit.c
  9. 6
      lightningd/channel_control.c
  10. 3
      lightningd/onchain_control.c
  11. 27
      lightningd/opening_control.c
  12. 1
      onchaind/onchain_wire.csv
  13. 6
      onchaind/onchaind.c
  14. 2
      onchaind/test/run-grind_feerate-bug.c
  15. 2
      onchaind/test/run-grind_feerate.c
  16. 1
      openingd/opening_wire.csv
  17. 4
      openingd/openingd.c

1
channeld/channel_wire.csv

@ -69,6 +69,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,announce_delay,u32,
msgdata,channel_init,option_static_remotekey,bool,
# master->channeld funding hit new depth(funding locked if >= lock depth)
msgtype,channel_funding_depth,1002

Can't render this file because it has a wrong number of fields in line 7.

5
channeld/channeld.c

@ -2866,6 +2866,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;
assert(!(fcntl(MASTER_FD, F_GETFL) & O_NONBLOCK));
@ -2924,7 +2925,8 @@ static void init_channel(struct peer *peer)
&peer->remote_upfront_shutdown_script,
&remote_ann_node_sig,
&remote_ann_bitcoin_sig,
&peer->announce_delay)) {
&peer->announce_delay,
&option_static_remotekey)) {
master_badmsg(WIRE_CHANNEL_INIT, msg);
}
/* stdin == requests, 3 == peer, 4 = gossip, 5 = gossip_store, 6 = HSM */
@ -2980,6 +2982,7 @@ static void init_channel(struct peer *peer)
&points[LOCAL], &points[REMOTE],
&funding_pubkey[LOCAL],
&funding_pubkey[REMOTE],
option_static_remotekey,
funder);
if (!channel_force_htlcs(peer->channel, htlcs, hstates,

2
channeld/full_channel.c

@ -46,6 +46,7 @@ struct channel *new_full_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,
enum side funder)
{
struct channel *channel = new_initial_channel(ctx,
@ -61,6 +62,7 @@ struct channel *new_full_channel(const tal_t *ctx,
remote_basepoints,
local_funding_pubkey,
remote_funding_pubkey,
option_static_remotekey,
funder);
if (channel) {

2
channeld/full_channel.h

@ -24,6 +24,7 @@
* @remote_basepoints: remote basepoints.
* @local_fundingkey: local funding key
* @remote_fundingkey: remote funding key
* @option_static_remotekey: use `option_static_remotekey`.
* @funder: which side initiated it.
*
* Returns state, or NULL if malformed.
@ -42,6 +43,7 @@ struct channel *new_full_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,
enum side funder);
/**

4
channeld/test/run-full_channel.c

@ -473,7 +473,7 @@ int main(void)
&localbase, &remotebase,
&local_funding_pubkey,
&remote_funding_pubkey,
LOCAL);
false, LOCAL);
rchannel = new_full_channel(tmpctx,
&chainparams->genesis_blockhash,
&funding_txid, funding_output_index, 0,
@ -484,7 +484,7 @@ int main(void)
&remotebase, &localbase,
&remote_funding_pubkey,
&local_funding_pubkey,
REMOTE);
false, REMOTE);
/* BOLT #3:
*

2
common/initial_channel.c

@ -22,6 +22,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,
enum side funder)
{
struct channel *channel = tal(ctx, struct channel);
@ -65,6 +66,7 @@ struct channel *new_initial_channel(const tal_t *ctx,
if (channel->chainparams == NULL)
return tal_free(channel);
channel->option_static_remotekey = option_static_remotekey;
return channel;
}

4
common/initial_channel.h

@ -64,6 +64,9 @@ struct channel {
/* Chain params to check against */
const struct chainparams *chainparams;
/* Is this using option_static_remotekey? */
bool option_static_remotekey;
};
/**
@ -101,6 +104,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,
enum side funder);

59
devtools/mkcommit.c

@ -10,6 +10,7 @@
*/
#include <bitcoin/script.h>
#include <bitcoin/tx.h>
#include <ccan/opt/opt.h>
#include <ccan/err/err.h>
#include <ccan/str/hex/hex.h>
#include <channeld/full_channel.h>
@ -20,6 +21,7 @@
#include <common/keyset.h>
#include <common/status.h>
#include <common/type_to_string.h>
#include <common/version.h>
#include <inttypes.h>
#include <stdarg.h>
#include <stdio.h>
@ -247,6 +249,7 @@ int main(int argc, char *argv[])
const struct htlc **htlcmap;
struct privkey local_htlc_privkey, remote_htlc_privkey;
struct pubkey local_htlc_pubkey, remote_htlc_pubkey;
bool option_static_remotekey = false;
const struct chainparams *chainparams = chainparams_for_network("bitcoin");
setup_locale();
@ -254,30 +257,36 @@ int main(int argc, char *argv[])
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY |
SECP256K1_CONTEXT_SIGN);
if (argv[1] && streq(argv[1], "-v")) {
verbose = true;
argv++;
argc--;
}
opt_register_noarg("--help|-h", opt_usage_and_exit,
"<commitnum> <funding-txid> <funding-txout> <funding-amount> <feerate-per-kw> <local-msat> <fee-payer> <localconfig> <remoteconfig> <localsecrets> <remotesecrets> [<htlc>...]\n"
"Where <config> are:\n"
" <to-self-delay>\n"
" <dustlimit>\n"
" <reserve-sat>\n"
"Where <secrets> are:\n"
" <funding-privkey>\n"
" <shachain-seed>\n"
" <revocation-base-secret>\n"
" <payment-base-secret>\n"
" <delayed-payment-base-secret>\n"
" <htlc-base-secret>\n"
"Where <htlc>s are:\n"
" <offer-side>\n"
" <payment-preimage>\n"
" <amount-msat>\n"
" <cltv-expiry>\n",
"Show this message");
opt_register_noarg("-v|--verbose", opt_set_bool, &verbose,
"Increase verbosity");
opt_register_noarg("--option-static-remotekey", opt_set_bool,
&option_static_remotekey,
"Use option_static_remotekey generation rules");
opt_register_version();
opt_parse(&argc, argv, opt_log_stderr_exit);
if (argc < 1 + 7 + 3*2 + 6*2)
errx(1, "Usage: mkcommit [-v] <commitnum> <funding-txid> <funding-txout> <funding-amount> <feerate-per-kw> <local-msat> <fee-payer> <localconfig> <remoteconfig> <localsecrets> <remotesecrets> [<htlc>...]\n"
"Where <config> are:\n"
" <to-self-delay>\n"
" <dustlimit>\n"
" <reserve-sat>\n"
"Where <secrets> are:\n"
" <funding-privkey>\n"
" <shachain-seed>\n"
" <revocation-base-secret>\n"
" <payment-base-secret>\n"
" <delayed-payment-base-secret>\n"
" <htlc-base-secret>\n"
"Where <htlc>s are:\n"
" <offer-side>\n"
" <payment-preimage>\n"
" <amount-msat>\n"
" <cltv-expiry>\n");
opt_usage_exit_fail("Too few arguments");
argnum = 1;
commitnum = atol(argv[argnum++]);
@ -312,8 +321,11 @@ int main(int argc, char *argv[])
errx(1, "Can't afford local_msat");
printf("## HTLCs\n");
while (argnum < argc)
while (argnum < argc) {
if (argnum + 4 > argc)
opt_usage_exit_fail("Too few arguments for htlc");
argnum += parse_htlc(argv + argnum, &htlcs, &hstates, &preimages);
}
printf("\n");
if (!pubkey_from_privkey(&local.funding_privkey, &funding_localkey)
@ -355,6 +367,7 @@ int main(int argc, char *argv[])
&localconfig, &remoteconfig,
&localbase, &remotebase,
&funding_localkey, &funding_remotekey,
option_static_remotekey,
fee_payer);
if (!channel_force_htlcs(channel, htlcs, hstates, NULL, NULL, NULL, NULL,

6
lightningd/channel_control.c

@ -1,6 +1,7 @@
#include <bitcoin/pubkey.h>
#include <bitcoin/script.h>
#include <channeld/gen_channel_wire.h>
#include <common/features.h>
#include <common/memleak.h>
#include <common/per_peer_state.h>
#include <common/timeout.h>
@ -431,7 +432,10 @@ void peer_start_channeld(struct channel *channel,
remote_ann_bitcoin_sig,
/* Delay announce by 60 seconds after
* seeing block (adjustable if dev) */
ld->topology->poll_seconds * 2);
ld->topology->poll_seconds * 2,
/* Set at channel open, even if not
* negotiated now! */
channel->option_static_remotekey);
/* We don't expect a response: we are triggered by funding_depth_cb. */
subd_send_msg(channel->owner, take(initmsg));

3
lightningd/onchain_control.c

@ -543,7 +543,8 @@ enum watch_result onchaind_funding_spent(struct channel *channel,
tal_count(stubs),
channel->min_possible_feerate,
channel->max_possible_feerate,
channel->future_per_commitment_point);
channel->future_per_commitment_point,
channel->option_static_remotekey);
subd_send_msg(channel->owner, take(msg));
/* FIXME: Don't queue all at once, use an empty cb... */

27
lightningd/opening_control.c

@ -4,6 +4,7 @@
#include <ccan/tal/str/str.h>
#include <common/addr.h>
#include <common/channel_config.h>
#include <common/features.h>
#include <common/funding_tx.h>
#include <common/json_command.h>
#include <common/jsonrpc_errors.h>
@ -168,6 +169,7 @@ wallet_commit_channel(struct lightningd *ld,
struct channel *channel;
struct amount_msat our_msat;
s64 final_key_idx;
bool option_static_remotekey;
/* Get a key to use for closing outputs from this tx */
final_key_idx = wallet_get_newindex(ld);
@ -196,6 +198,27 @@ 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-930a9b44076a8f25a8626b31b3d5a55c0888308c #2:
* 1. type: 35 (`funding_signed`)
* 2. data:
* * [`channel_id`:`channel_id`]
* * [`signature`:`signature`]
*
* #### Requirements
*
* Both peers:
* - if `option_static_remotekey` was negotiated:
* - `option_static_remotekey` applies to all commitment
* transactions
* - otherwise:
* - `option_static_remotekey` does not apply to any commitment
* transactions
*/
/* i.e. We set it now for the channel permanently. */
option_static_remotekey
= local_feature_negotiated(uc->peer->localfeatures,
LOCAL_STATIC_REMOTEKEY);
channel = new_channel(uc->peer, uc->dbid,
NULL, /* No shachain yet */
CHANNELD_AWAITING_LOCKIN,
@ -238,7 +261,7 @@ wallet_commit_channel(struct lightningd *ld,
ld->config.fee_base,
ld->config.fee_per_satoshi,
remote_upfront_shutdown_script,
false);
option_static_remotekey);
/* Now we finally put it in the database. */
wallet_channel_insert(ld->wallet, channel);
@ -1106,6 +1129,8 @@ void peer_start_openingd(struct peer *peer,
feerate_min(peer->ld, NULL),
feerate_max(peer->ld, NULL),
peer->localfeatures,
local_feature_negotiated(peer->localfeatures,
LOCAL_STATIC_REMOTEKEY),
send_msg);
subd_send_msg(uc->openingd, take(msg));
}

1
onchaind/onchain_wire.csv

@ -35,6 +35,7 @@ msgdata,onchain_init,num_htlcs,u64,
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,
#include <onchaind/onchain_wire.h>
# This is all the HTLCs: one per message

Can't render this file because it has a wrong number of fields in line 5.

6
onchaind/onchaind.c

@ -67,6 +67,9 @@ static u32 reasonable_depth;
/* The messages to send at that depth. */
static u8 **missing_htlc_msgs;
/* Does option_static_remotekey apply to this commitment tx? */
bool option_static_remotekey;
/* If we broadcast a tx, or need a delay to resolve the output. */
struct proposed_resolution {
/* This can be NULL if our proposal is to simply ignore it after depth */
@ -2567,7 +2570,8 @@ int main(int argc, char *argv[])
&num_htlcs,
&min_possible_feerate,
&max_possible_feerate,
&possible_remote_per_commitment_point)) {
&possible_remote_per_commitment_point,
&option_static_remotekey)) {
master_badmsg(WIRE_ONCHAIN_INIT, msg);
}

2
onchaind/test/run-grind_feerate-bug.c

@ -42,7 +42,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, struct bitcoin_blkid *chain_hash UNNEEDED, struct amount_sat *funding_amount_satoshi 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 *feerate_per_kw 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 *funder UNNEEDED, struct basepoints *local_basepoints UNNEEDED, struct basepoints *remote_basepoints UNNEEDED, struct bitcoin_tx **tx 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 fromwire_onchain_init(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct shachain *shachain UNNEEDED, struct bitcoin_blkid *chain_hash UNNEEDED, struct amount_sat *funding_amount_satoshi 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 *feerate_per_kw 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 *funder UNNEEDED, struct basepoints *local_basepoints UNNEEDED, struct basepoints *remote_basepoints UNNEEDED, struct bitcoin_tx **tx 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)
{ 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)

2
onchaind/test/run-grind_feerate.c

@ -46,7 +46,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, struct bitcoin_blkid *chain_hash UNNEEDED, struct amount_sat *funding_amount_satoshi 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 *feerate_per_kw 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 *funder UNNEEDED, struct basepoints *local_basepoints UNNEEDED, struct basepoints *remote_basepoints UNNEEDED, struct bitcoin_tx **tx 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 fromwire_onchain_init(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct shachain *shachain UNNEEDED, struct bitcoin_blkid *chain_hash UNNEEDED, struct amount_sat *funding_amount_satoshi 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 *feerate_per_kw 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 *funder UNNEEDED, struct basepoints *local_basepoints UNNEEDED, struct basepoints *remote_basepoints UNNEEDED, struct bitcoin_tx **tx 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)
{ 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)

1
openingd/opening_wire.csv

@ -20,6 +20,7 @@ msgdata,opening_init,min_feerate,u32,
msgdata,opening_init,max_feerate,u32,
msgdata,opening_init,lfeatures_len,u16,
msgdata,opening_init,lfeatures,u8,lfeatures_len
msgdata,opening_init,option_static_remotekey,bool,
# Optional msg to send.
msgdata,opening_init,len,u16,
msgdata,opening_init,msg,u8,len

Can't render this file because it has a wrong number of fields in line 6.

4
openingd/openingd.c

@ -105,6 +105,7 @@ struct state {
/* Which chain we're on, so we can check/set `chain_hash` fields */
const struct chainparams *chainparams;
bool option_static_remotekey;
};
static const u8 *dev_upfront_shutdown_script(const tal_t *ctx)
@ -660,6 +661,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,
/* Funder is local */
LOCAL);
/* We were supposed to do enough checks above, but just in case,
@ -1378,6 +1380,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,
REMOTE);
/* We don't expect this to fail, but it does do some additional
* internal sanity checks. */
@ -1703,6 +1706,7 @@ int main(int argc, char *argv[])
&state->minimum_depth,
&state->min_feerate, &state->max_feerate,
&state->localfeatures,
&state->option_static_remotekey,
&inner))
master_badmsg(WIRE_OPENING_INIT, msg);

Loading…
Cancel
Save