diff --git a/Makefile b/Makefile index 962055e4eedf..9b7ad463d3cb 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,7 @@ CCANDIR := ccan # Where we keep the BOLT RFCs BOLTDIR := ../bolts/ -DEFAULT_BOLTVERSION := fc687e8c7638a65c9120777025ae5ae53e4e622f +DEFAULT_BOLTVERSION := 57ce4b1e05c996fa649f00dc13521f6d496a288f # Can be overridden on cmdline. BOLTVERSION := $(DEFAULT_BOLTVERSION) diff --git a/lightningd/onchain_control.c b/lightningd/onchain_control.c index f40e7898d466..662b3bc55491 100644 --- a/lightningd/onchain_control.c +++ b/lightningd/onchain_control.c @@ -1624,8 +1624,6 @@ enum watch_result onchaind_funding_spent(struct channel *channel, channel->last_htlc_sigs, channel->min_possible_feerate, channel->max_possible_feerate, - /* FIXME: remove support from onchaind */ - NULL, &channel->local_funding_pubkey, &channel->channel_info.remote_fundingkey, channel->static_remotekey_start[LOCAL], diff --git a/onchaind/onchaind.c b/onchaind/onchaind.c index fe821596f99b..537ff976b068 100644 --- a/onchaind/onchaind.c +++ b/onchaind/onchaind.c @@ -3280,78 +3280,41 @@ static void handle_their_unilateral(const struct tx_parts *tx, static void handle_unknown_commitment(const struct tx_parts *tx, u32 tx_blockheight, - const struct pubkey *possible_remote_per_commitment_point, const struct basepoints basepoints[NUM_SIDES], struct tracked_output **outs) { int to_us_output = -1; - /* We have two possible local scripts, depending on options */ - u8 *local_scripts[2]; struct htlcs_info *htlcs_info; onchain_annotate_txin(&tx->txid, 0, TX_CHANNEL_UNILATERAL | TX_THEIRS); resolved_by_other(outs[0], &tx->txid, UNKNOWN_UNILATERAL); - /* This is the not-option_static_remotekey case, if we got a hint - * from them about the per-commitment point */ - if (possible_remote_per_commitment_point) { - struct keyset *ks = tal(tmpctx, struct keyset); - if (!derive_keyset(possible_remote_per_commitment_point, - &basepoints[REMOTE], - &basepoints[LOCAL], - false, - ks)) - status_failed(STATUS_FAIL_INTERNAL_ERROR, - "Deriving keyset for possible_remote_per_commitment_point %s", - fmt_pubkey(tmpctx, - possible_remote_per_commitment_point)); - - local_scripts[0] = scriptpubkey_p2wpkh(tmpctx, - &ks->other_payment_key); - } else { - local_scripts[0] = NULL; - } - - /* For option_will_fund, we need to figure out what CSV lock was used */ + /* Normally, csv is 1, but for option_will_fund, we need to + * figure out what CSV lock was used */ for (size_t csv = 1; csv <= LEASE_RATE_DURATION; csv++) { - - /* Other possible local script is for option_static_remotekey */ - local_scripts[1] = scriptpubkey_to_remote(tmpctx, - &basepoints[LOCAL].payment, - csv); + const u8 *local_script; + local_script = scriptpubkey_to_remote(tmpctx, + &basepoints[LOCAL].payment, + csv); for (size_t i = 0; i < tal_count(tx->outputs); i++) { - struct tracked_output *out; - struct amount_asset asset = wally_tx_output_get_amount(tx->outputs[i]); + struct amount_asset asset; struct amount_sat amt; - int which_script; struct bitcoin_outpoint outpoint; + struct tracked_output *out; + + if (!wally_tx_output_scripteq(tx->outputs[i], + local_script)) + continue; + asset = wally_tx_output_get_amount(tx->outputs[i]); assert(amount_asset_is_main(&asset)); amt = amount_asset_to_sat(&asset); outpoint.txid = tx->txid; outpoint.n = i; - /* Elements can have empty output scripts (fee output) */ - if (local_scripts[0] - && wally_tx_output_scripteq(tx->outputs[i], local_scripts[0])) - which_script = 0; - else if (local_scripts[1] - && wally_tx_output_scripteq(tx->outputs[i], - local_scripts[1])) - which_script = 1; - else { - /* Record every output on this tx as an - * external 'penalty' */ - record_external_output(&outpoint, amt, - tx_blockheight, - PENALTY); - - continue; - } - /* BOLT #5: * * - MAY take no action in regard to the associated @@ -3369,17 +3332,38 @@ static void handle_unknown_commitment(const struct tx_parts *tx, tell_wallet_to_remote(tx, &outpoint, tx_blockheight, - local_scripts[which_script], - possible_remote_per_commitment_point, - which_script == 1, + local_script, + NULL, + true, csv); - local_scripts[0] = local_scripts[1] = NULL; to_us_output = i; - /* Even though we're finished, we keep rolling - * so we log all the outputs */ + goto found; } } +found: + /* Record every unidentified output on this tx as an external + * 'penalty' */ + for (size_t i = 0; i < tal_count(tx->outputs); i++) { + struct amount_asset asset; + struct amount_sat amt; + struct bitcoin_outpoint outpoint; + + if (i == to_us_output) + continue; + + asset = wally_tx_output_get_amount(tx->outputs[i]); + assert(amount_asset_is_main(&asset)); + amt = amount_asset_to_sat(&asset); + + outpoint.txid = tx->txid; + outpoint.n = i; + + record_external_output(&outpoint, amt, + tx_blockheight, + PENALTY); + } + if (to_us_output == -1) { status_broken("FUNDS LOST. Unknown commitment #%"PRIu64"!", commit_num); @@ -3425,7 +3409,6 @@ int main(int argc, char *argv[]) struct amount_sat funding_sats; u8 *scriptpubkey[NUM_SIDES]; u32 locktime, tx_blockheight; - struct pubkey *possible_remote_per_commitment_point; subdaemon_setup(argc, argv); @@ -3461,7 +3444,6 @@ int main(int argc, char *argv[]) &remote_htlc_sigs, &min_possible_feerate, &max_possible_feerate, - &possible_remote_per_commitment_point, &funding_pubkey[LOCAL], &funding_pubkey[REMOTE], &static_remotekey_start[LOCAL], @@ -3578,7 +3560,6 @@ int main(int argc, char *argv[]) outs); } else { handle_unknown_commitment(tx, tx_blockheight, - possible_remote_per_commitment_point, basepoints, outs); } diff --git a/onchaind/onchaind_wire.csv b/onchaind/onchaind_wire.csv index a320c6381dad..32d5d37d2c96 100644 --- a/onchaind/onchaind_wire.csv +++ b/onchaind/onchaind_wire.csv @@ -42,7 +42,6 @@ msgdata,onchaind_init,num_htlc_sigs,u16, msgdata,onchaind_init,htlc_signature,bitcoin_signature,num_htlc_sigs msgdata,onchaind_init,min_possible_feerate,u32, 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,local_static_remotekey_start,u64, diff --git a/onchaind/test/run-grind_feerate.c b/onchaind/test/run-grind_feerate.c index 4ac501957f8b..06485657dc12 100644 --- a/onchaind/test/run-grind_feerate.c +++ b/onchaind/test/run-grind_feerate.c @@ -56,7 +56,7 @@ bool fromwire_onchaind_dev_memleak(const void *p UNNEEDED) bool fromwire_onchaind_htlcs(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct htlc_stub **htlc UNNEEDED, bool **tell_if_missing UNNEEDED, bool **tell_immediately UNNEEDED) { fprintf(stderr, "fromwire_onchaind_htlcs 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, struct amount_sat *local_dust_limit_satoshi UNNEEDED, struct bitcoin_txid *our_broadcast_txid UNNEEDED, u8 **local_scriptpubkey UNNEEDED, u8 **remote_scriptpubkey UNNEEDED, u32 *ourwallet_index UNNEEDED, struct ext_key *ourwallet_ext_key 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, 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 *option_anchors_zero_fee_htlc_tx 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, struct amount_sat *local_dust_limit_satoshi UNNEEDED, struct bitcoin_txid *our_broadcast_txid UNNEEDED, u8 **local_scriptpubkey UNNEEDED, u8 **remote_scriptpubkey UNNEEDED, u32 *ourwallet_index UNNEEDED, struct ext_key *ourwallet_ext_key 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, u32 *min_possible_feerate UNNEEDED, u32 *max_possible_feerate 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 *option_anchors_zero_fee_htlc_tx 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)