Skip to content

Commit

Permalink
onchaind: handle static_remotekey thresholds.
Browse files Browse the repository at this point in the history
No longer a global "on" or "off", it depends on the commitment number.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell committed Jun 3, 2021
1 parent 2e347b1 commit 4be8254
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 23 deletions.
4 changes: 2 additions & 2 deletions lightningd/onchain_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -694,8 +694,8 @@ enum watch_result onchaind_funding_spent(struct channel *channel,
channel->future_per_commitment_point,
&channel->local_funding_pubkey,
&channel->channel_info.remote_fundingkey,
/* FIXME! onchaind needs start numbers! */
channel->static_remotekey_start[LOCAL] == 0,
channel->static_remotekey_start[LOCAL],
channel->static_remotekey_start[REMOTE],
channel->option_anchor_outputs,
is_replay,
feerate_min(ld, NULL));
Expand Down
22 changes: 12 additions & 10 deletions onchaind/onchaind.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ static struct amount_msat our_msat;
/* Needed for anchor outputs */
static struct pubkey funding_pubkey[NUM_SIDES];

/* Does option_static_remotekey apply to this commitment tx? */
static bool option_static_remotekey;
/* At what commit number does option_static_remotekey apply? */
static u64 static_remotekey_start[NUM_SIDES];

/* Does option_anchor_outputs apply to this commitment tx? */
static bool option_anchor_outputs;
Expand Down Expand Up @@ -2615,7 +2615,7 @@ static void handle_our_unilateral(const struct tx_parts *tx,
if (!derive_keyset(&local_per_commitment_point,
&basepoints[LOCAL],
&basepoints[REMOTE],
option_static_remotekey,
commit_num >= static_remotekey_start[LOCAL],
ks))
status_failed(STATUS_FAIL_INTERNAL_ERROR,
"Deriving keyset for %"PRIu64, commit_num);
Expand Down Expand Up @@ -3050,7 +3050,7 @@ static void handle_their_cheat(const struct tx_parts *tx,
if (!derive_keyset(remote_per_commitment_point,
&basepoints[REMOTE],
&basepoints[LOCAL],
option_static_remotekey,
commit_num >= static_remotekey_start[REMOTE],
ks))
status_failed(STATUS_FAIL_INTERNAL_ERROR,
"Deriving keyset for %"PRIu64, commit_num);
Expand All @@ -3063,7 +3063,7 @@ static void handle_their_cheat(const struct tx_parts *tx,
" other_payment_key: %s"
" self_htlc_key: %s"
" other_htlc_key: %s"
" (option_static_remotekey = %i)",
" (static_remotekey = %"PRIu64"/%"PRIu64")",
commit_num,
type_to_string(tmpctx, struct pubkey,
&keyset->self_revocation_key),
Expand All @@ -3077,7 +3077,8 @@ static void handle_their_cheat(const struct tx_parts *tx,
&keyset->self_htlc_key),
type_to_string(tmpctx, struct pubkey,
&keyset->other_htlc_key),
option_static_remotekey);
static_remotekey_start[LOCAL],
static_remotekey_start[REMOTE]);

remote_wscript = to_self_wscript(tmpctx, to_self_delay[REMOTE], keyset);

Expand Down Expand Up @@ -3154,7 +3155,7 @@ static void handle_their_cheat(const struct tx_parts *tx,
tx_blockheight,
script[LOCAL],
remote_per_commitment_point,
option_static_remotekey);
commit_num >= static_remotekey_start[REMOTE]);
script[LOCAL] = NULL;
add_amt(&total_outs, amt);
continue;
Expand Down Expand Up @@ -3334,7 +3335,7 @@ static void handle_their_unilateral(const struct tx_parts *tx,
if (!derive_keyset(remote_per_commitment_point,
&basepoints[REMOTE],
&basepoints[LOCAL],
option_static_remotekey,
commit_num >= static_remotekey_start[REMOTE],
ks))
status_failed(STATUS_FAIL_INTERNAL_ERROR,
"Deriving keyset for %"PRIu64, commit_num);
Expand Down Expand Up @@ -3434,7 +3435,7 @@ static void handle_their_unilateral(const struct tx_parts *tx,
tx_blockheight,
script[LOCAL],
remote_per_commitment_point,
option_static_remotekey);
commit_num >= static_remotekey_start[REMOTE]);
script[LOCAL] = NULL;
add_amt(&our_outs, amt);
continue;
Expand Down Expand Up @@ -3772,7 +3773,8 @@ int main(int argc, char *argv[])
&possible_remote_per_commitment_point,
&funding_pubkey[LOCAL],
&funding_pubkey[REMOTE],
&option_static_remotekey,
&static_remotekey_start[LOCAL],
&static_remotekey_start[REMOTE],
&option_anchor_outputs,
&open_is_replay,
&min_relay_feerate)) {
Expand Down
3 changes: 2 additions & 1 deletion onchaind/onchaind_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ msgdata,onchaind_init,max_possible_feerate,u32,
msgdata,onchaind_init,possible_remote_per_commit_point,?pubkey,
msgdata,onchaind_init,local_funding_pubkey,pubkey,
msgdata,onchaind_init,remote_funding_pubkey,pubkey,
msgdata,onchaind_init,option_static_remotekey,bool,
msgdata,onchaind_init,local_static_remotekey_start,u64,
msgdata,onchaind_init,remote_static_remotekey_start,u64,
msgdata,onchaind_init,option_anchor_outputs,bool,
msgdata,onchaind_init,is_replay,bool,
# We need this for BIP125 rule 4
Expand Down
12 changes: 7 additions & 5 deletions onchaind/onchaind_wiregen.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions onchaind/onchaind_wiregen.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified onchaind/test/onchainstress-data.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion onchaind/test/run-grind_feerate-bug.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ bool fromwire_onchaind_dev_memleak(const void *p UNNEEDED)
bool fromwire_onchaind_htlc(const void *p UNNEEDED, struct htlc_stub *htlc UNNEEDED, bool *tell_if_missing UNNEEDED, bool *tell_immediately UNNEEDED)
{ fprintf(stderr, "fromwire_onchaind_htlc called!\n"); abort(); }
/* Generated stub for fromwire_onchaind_init */
bool fromwire_onchaind_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, struct bitcoin_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, struct pubkey *local_funding_pubkey UNNEEDED, struct pubkey *remote_funding_pubkey UNNEEDED, bool *option_static_remotekey UNNEEDED, bool *option_anchor_outputs UNNEEDED, bool *is_replay UNNEEDED, u32 *min_relay_feerate UNNEEDED)
bool fromwire_onchaind_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, struct bitcoin_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, struct pubkey *local_funding_pubkey UNNEEDED, struct pubkey *remote_funding_pubkey UNNEEDED, u64 *local_static_remotekey_start UNNEEDED, u64 *remote_static_remotekey_start UNNEEDED, bool *option_anchor_outputs UNNEEDED, bool *is_replay UNNEEDED, u32 *min_relay_feerate UNNEEDED)
{ fprintf(stderr, "fromwire_onchaind_init called!\n"); abort(); }
/* Generated stub for fromwire_onchaind_known_preimage */
bool fromwire_onchaind_known_preimage(const void *p UNNEEDED, struct preimage *preimage UNNEEDED, bool *is_replay UNNEEDED)
Expand Down

0 comments on commit 4be8254

Please sign in to comment.