Skip to content

Commit 250fcf7

Browse files
rustyrussellcdecker
authored andcommitted
onchaind: handle static_remotekey thresholds.
No longer a global "on" or "off", it depends on the commitment number. Signed-off-by: Rusty Russell <[email protected]>
1 parent cb8fe55 commit 250fcf7

File tree

8 files changed

+35
-27
lines changed

8 files changed

+35
-27
lines changed

lightningd/onchain_control.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -694,8 +694,8 @@ enum watch_result onchaind_funding_spent(struct channel *channel,
694694
channel->future_per_commitment_point,
695695
&channel->local_funding_pubkey,
696696
&channel->channel_info.remote_fundingkey,
697-
/* FIXME! onchaind needs start numbers! */
698-
channel->static_remotekey_start[LOCAL] == 0,
697+
channel->static_remotekey_start[LOCAL],
698+
channel->static_remotekey_start[REMOTE],
699699
channel->option_anchor_outputs,
700700
is_replay,
701701
feerate_min(ld, NULL));

onchaind/onchaind.c

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ static struct amount_msat our_msat;
8484
/* Needed for anchor outputs */
8585
static struct pubkey funding_pubkey[NUM_SIDES];
8686

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

9090
/* Does option_anchor_outputs apply to this commitment tx? */
9191
static bool option_anchor_outputs;
@@ -2615,7 +2615,7 @@ static void handle_our_unilateral(const struct tx_parts *tx,
26152615
if (!derive_keyset(&local_per_commitment_point,
26162616
&basepoints[LOCAL],
26172617
&basepoints[REMOTE],
2618-
option_static_remotekey,
2618+
commit_num >= static_remotekey_start[LOCAL],
26192619
ks))
26202620
status_failed(STATUS_FAIL_INTERNAL_ERROR,
26212621
"Deriving keyset for %"PRIu64, commit_num);
@@ -3050,7 +3050,7 @@ static void handle_their_cheat(const struct tx_parts *tx,
30503050
if (!derive_keyset(remote_per_commitment_point,
30513051
&basepoints[REMOTE],
30523052
&basepoints[LOCAL],
3053-
option_static_remotekey,
3053+
commit_num >= static_remotekey_start[REMOTE],
30543054
ks))
30553055
status_failed(STATUS_FAIL_INTERNAL_ERROR,
30563056
"Deriving keyset for %"PRIu64, commit_num);
@@ -3063,7 +3063,7 @@ static void handle_their_cheat(const struct tx_parts *tx,
30633063
" other_payment_key: %s"
30643064
" self_htlc_key: %s"
30653065
" other_htlc_key: %s"
3066-
" (option_static_remotekey = %i)",
3066+
" (static_remotekey = %"PRIu64"/%"PRIu64")",
30673067
commit_num,
30683068
type_to_string(tmpctx, struct pubkey,
30693069
&keyset->self_revocation_key),
@@ -3077,7 +3077,8 @@ static void handle_their_cheat(const struct tx_parts *tx,
30773077
&keyset->self_htlc_key),
30783078
type_to_string(tmpctx, struct pubkey,
30793079
&keyset->other_htlc_key),
3080-
option_static_remotekey);
3080+
static_remotekey_start[LOCAL],
3081+
static_remotekey_start[REMOTE]);
30813082

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

@@ -3154,7 +3155,7 @@ static void handle_their_cheat(const struct tx_parts *tx,
31543155
tx_blockheight,
31553156
script[LOCAL],
31563157
remote_per_commitment_point,
3157-
option_static_remotekey);
3158+
commit_num >= static_remotekey_start[REMOTE]);
31583159
script[LOCAL] = NULL;
31593160
add_amt(&total_outs, amt);
31603161
continue;
@@ -3334,7 +3335,7 @@ static void handle_their_unilateral(const struct tx_parts *tx,
33343335
if (!derive_keyset(remote_per_commitment_point,
33353336
&basepoints[REMOTE],
33363337
&basepoints[LOCAL],
3337-
option_static_remotekey,
3338+
commit_num >= static_remotekey_start[REMOTE],
33383339
ks))
33393340
status_failed(STATUS_FAIL_INTERNAL_ERROR,
33403341
"Deriving keyset for %"PRIu64, commit_num);
@@ -3434,7 +3435,7 @@ static void handle_their_unilateral(const struct tx_parts *tx,
34343435
tx_blockheight,
34353436
script[LOCAL],
34363437
remote_per_commitment_point,
3437-
option_static_remotekey);
3438+
commit_num >= static_remotekey_start[REMOTE]);
34383439
script[LOCAL] = NULL;
34393440
add_amt(&our_outs, amt);
34403441
continue;
@@ -3634,10 +3635,13 @@ static void handle_unknown_commitment(const struct tx_parts *tx,
36343635
assert(amount_asset_is_main(&asset));
36353636
amt = amount_asset_to_sat(&asset);
36363637

3637-
if (wally_tx_output_scripteq(tx->outputs[i], local_scripts[0]))
3638+
/* Elements can have empty output scripts it seems. */
3639+
if (local_scripts[0]
3640+
&& wally_tx_output_scripteq(tx->outputs[i], local_scripts[0]))
36383641
which_script = 0;
3639-
else if (wally_tx_output_scripteq(tx->outputs[i],
3640-
local_scripts[1]))
3642+
else if (local_scripts[1]
3643+
&& wally_tx_output_scripteq(tx->outputs[i],
3644+
local_scripts[1]))
36413645
which_script = 1;
36423646
else
36433647
continue;
@@ -3666,8 +3670,8 @@ static void handle_unknown_commitment(const struct tx_parts *tx,
36663670
local_scripts[which_script],
36673671
possible_remote_per_commitment_point,
36683672
which_script == 1);
3669-
local_scripts[0] = local_scripts[1] = NULL;
36703673
to_us_output = i;
3674+
break;
36713675
}
36723676

36733677
if (to_us_output == -1) {
@@ -3772,7 +3776,8 @@ int main(int argc, char *argv[])
37723776
&possible_remote_per_commitment_point,
37733777
&funding_pubkey[LOCAL],
37743778
&funding_pubkey[REMOTE],
3775-
&option_static_remotekey,
3779+
&static_remotekey_start[LOCAL],
3780+
&static_remotekey_start[REMOTE],
37763781
&option_anchor_outputs,
37773782
&open_is_replay,
37783783
&min_relay_feerate)) {

onchaind/onchaind_wire.csv

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ msgdata,onchaind_init,max_possible_feerate,u32,
4646
msgdata,onchaind_init,possible_remote_per_commit_point,?pubkey,
4747
msgdata,onchaind_init,local_funding_pubkey,pubkey,
4848
msgdata,onchaind_init,remote_funding_pubkey,pubkey,
49-
msgdata,onchaind_init,option_static_remotekey,bool,
49+
msgdata,onchaind_init,local_static_remotekey_start,u64,
50+
msgdata,onchaind_init,remote_static_remotekey_start,u64,
5051
msgdata,onchaind_init,option_anchor_outputs,bool,
5152
msgdata,onchaind_init,is_replay,bool,
5253
# We need this for BIP125 rule 4

onchaind/onchaind_wiregen.c

Lines changed: 7 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

onchaind/onchaind_wiregen.h

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

onchaind/test/onchainstress-data.gz

1.56 KB
Binary file not shown.

onchaind/test/run-grind_feerate-bug.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ bool fromwire_onchaind_dev_memleak(const void *p UNNEEDED)
5050
bool fromwire_onchaind_htlc(const void *p UNNEEDED, struct htlc_stub *htlc UNNEEDED, bool *tell_if_missing UNNEEDED, bool *tell_immediately UNNEEDED)
5151
{ fprintf(stderr, "fromwire_onchaind_htlc called!\n"); abort(); }
5252
/* Generated stub for fromwire_onchaind_init */
53-
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)
53+
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)
5454
{ fprintf(stderr, "fromwire_onchaind_init called!\n"); abort(); }
5555
/* Generated stub for fromwire_onchaind_known_preimage */
5656
bool fromwire_onchaind_known_preimage(const void *p UNNEEDED, struct preimage *preimage UNNEEDED, bool *is_replay UNNEEDED)

0 commit comments

Comments
 (0)