diff --git a/lightningd/onchain_control.c b/lightningd/onchain_control.c index 242ab495e..d2ee1ab7d 100644 --- a/lightningd/onchain_control.c +++ b/lightningd/onchain_control.c @@ -70,14 +70,79 @@ static void onchaind_tell_fulfill(struct channel *channel) } } -static void handle_onchain_init_reply(struct channel *channel, const u8 *msg UNUSED) +/* If we want to know if this HTLC is missing, return depth. */ +static bool tell_if_missing(const struct channel *channel, + struct htlc_stub *stub, + bool *tell_immediate) { + struct htlc_out *hout; + + /* Keep valgrind happy. */ + *tell_immediate = false; + + /* Don't care about incoming HTLCs, just ones we offered. */ + if (stub->owner == REMOTE) + return false; + + /* Might not be a current HTLC. */ + hout = find_htlc_out(&channel->peer->ld->htlcs_out, channel, stub->id); + if (!hout) + return false; + + /* BOLT #5: + * + * - for any committed HTLC that does NOT have an output in this + * commitment transaction: + * - once the commitment transaction has reached reasonable depth: + * - MUST fail the corresponding incoming HTLC (if any). + * - if no *valid* commitment transaction contains an output + * corresponding to the HTLC. + * - MAY fail the corresponding incoming HTLC sooner. + */ + if (hout->hstate >= RCVD_ADD_REVOCATION + && hout->hstate < SENT_REMOVE_REVOCATION) + *tell_immediate = true; + + log_debug(channel->log, + "We want to know if htlc %"PRIu64" is missing (%s)", + hout->key.id, *tell_immediate ? "immediate" : "later"); + return true; +} + +static void handle_onchain_init_reply(struct channel *channel, const u8 *msg) +{ + struct htlc_stub *stubs; + u64 commit_num; + bool *tell, *tell_immediate; + + if (!fromwire_onchaind_init_reply(msg, &commit_num)) { + channel_internal_error(channel, "Invalid onchaind_init_reply %s", + tal_hex(tmpctx, msg)); + return; + } + /* FIXME: We may already be ONCHAIN state when we implement restart! */ channel_set_state(channel, FUNDING_SPEND_SEEN, ONCHAIN, REASON_UNKNOWN, "Onchain init reply"); + + /* Tell it about any relevant HTLCs */ + /* FIXME: Filter by commitnum! */ + stubs = wallet_htlc_stubs(tmpctx, channel->peer->ld->wallet, channel); + tell = tal_arr(stubs, bool, tal_count(stubs)); + tell_immediate = tal_arr(stubs, bool, tal_count(stubs)); + + for (size_t i = 0; i < tal_count(stubs); i++) { + tell[i] = tell_if_missing(channel, &stubs[i], + &tell_immediate[i]); + } + msg = towire_onchaind_htlcs(channel, stubs, tell, tell_immediate); + subd_send_msg(channel->owner, take(msg)); + + /* Tell it about any preimages we know. */ + onchaind_tell_fulfill(channel); } /** @@ -492,7 +557,7 @@ static unsigned int onchain_msg(struct subd *sd, const u8 *msg, const int *fds U case WIRE_ONCHAIND_INIT: case WIRE_ONCHAIND_SPENT: case WIRE_ONCHAIND_DEPTH: - case WIRE_ONCHAIND_HTLC: + case WIRE_ONCHAIND_HTLCS: case WIRE_ONCHAIND_KNOWN_PREIMAGE: case WIRE_ONCHAIND_DEV_MEMLEAK: case WIRE_ONCHAIND_DEV_MEMLEAK_REPLY: @@ -502,45 +567,6 @@ static unsigned int onchain_msg(struct subd *sd, const u8 *msg, const int *fds U return 0; } -/* If we want to know if this HTLC is missing, return depth. */ -static bool tell_if_missing(const struct channel *channel, - struct htlc_stub *stub, - bool *tell_immediate) -{ - struct htlc_out *hout; - - /* Keep valgrind happy. */ - *tell_immediate = false; - - /* Don't care about incoming HTLCs, just ones we offered. */ - if (stub->owner == REMOTE) - return false; - - /* Might not be a current HTLC. */ - hout = find_htlc_out(&channel->peer->ld->htlcs_out, channel, stub->id); - if (!hout) - return false; - - /* BOLT #5: - * - * - for any committed HTLC that does NOT have an output in this - * commitment transaction: - * - once the commitment transaction has reached reasonable depth: - * - MUST fail the corresponding incoming HTLC (if any). - * - if no *valid* commitment transaction contains an output - * corresponding to the HTLC. - * - MAY fail the corresponding incoming HTLC sooner. - */ - if (hout->hstate >= RCVD_ADD_REVOCATION - && hout->hstate < SENT_REMOVE_REVOCATION) - *tell_immediate = true; - - log_debug(channel->log, - "We want to know if htlc %"PRIu64" is missing (%s)", - hout->key.id, *tell_immediate ? "immediate" : "later"); - return true; -} - /* Only error onchaind can get is if it dies. */ static void onchain_error(struct channel *channel, struct per_peer_state *pps UNUSED, @@ -564,7 +590,6 @@ enum watch_result onchaind_funding_spent(struct channel *channel, { u8 *msg; struct bitcoin_txid our_last_txid; - struct htlc_stub *stubs; struct lightningd *ld = channel->peer->ld; struct pubkey final_key; int hsmfd; @@ -609,12 +634,6 @@ enum watch_result onchaind_funding_spent(struct channel *channel, return KEEP_WATCHING; } - stubs = wallet_htlc_stubs(tmpctx, ld->wallet, channel); - if (!stubs) { - log_broken(channel->log, "Could not load htlc_stubs"); - return KEEP_WATCHING; - } - if (!bip32_pubkey(ld->wallet->bip32_base, &final_key, channel->final_key_idx)) { log_broken(channel->log, "Could not derive onchain key %"PRIu64, @@ -695,7 +714,6 @@ enum watch_result onchaind_funding_spent(struct channel *channel, /* FIXME: config for 'reasonable depth' */ 3, channel->last_htlc_sigs, - tal_count(stubs), channel->min_possible_feerate, channel->max_possible_feerate, channel->future_per_commitment_point, @@ -708,18 +726,6 @@ enum watch_result onchaind_funding_spent(struct channel *channel, feerate_min(ld, NULL)); subd_send_msg(channel->owner, take(msg)); - /* FIXME: Don't queue all at once, use an empty cb... */ - for (size_t i = 0; i < tal_count(stubs); i++) { - bool tell_immediate; - bool tell = tell_if_missing(channel, &stubs[i], &tell_immediate); - msg = towire_onchaind_htlc(channel, &stubs[i], - tell, tell_immediate); - subd_send_msg(channel->owner, take(msg)); - } - - /* Tell it about any preimages we know. */ - onchaind_tell_fulfill(channel); - watch_tx_and_outputs(channel, tx); /* We keep watching until peer finally deleted, for reorgs. */ diff --git a/onchaind/onchaind.c b/onchaind/onchaind.c index b2973a4fe..eafe7b5d0 100644 --- a/onchaind/onchaind.c +++ b/onchaind/onchaind.c @@ -2222,11 +2222,55 @@ static void wait_for_resolved(struct tracked_output **outs) take(towire_onchaind_all_irrevocably_resolved(outs))); } -static void init_reply(const char *what) +static int cmp_htlc_cltv(const struct htlc_stub *a, + const struct htlc_stub *b, void *unused) { + if (a->cltv_expiry < b->cltv_expiry) + return -1; + else if (a->cltv_expiry > b->cltv_expiry) + return 1; + return 0; +} + +struct htlcs_info { + struct htlc_stub *htlcs; + bool *tell_if_missing; + bool *tell_immediately; +}; + +static struct htlcs_info *init_reply(const tal_t *ctx, const char *what) +{ + struct htlcs_info *htlcs_info = tal(ctx, struct htlcs_info); + u8 *msg; + + /* commit_num is 0 for mutual close, but we don't care about HTLCs + * then anyway. */ + /* Send init_reply first, so billboard gets credited to ONCHAIND */ - wire_sync_write(REQ_FD, take(towire_onchaind_init_reply(NULL))); + wire_sync_write(REQ_FD, + take(towire_onchaind_init_reply(NULL, commit_num))); + peer_billboard(true, what); + + /* Read in htlcs */ + /* FIXME: queue other messages! */ + msg = wire_sync_read(tmpctx, REQ_FD); + if (!fromwire_onchaind_htlcs(htlcs_info, msg, + &htlcs_info->htlcs, + &htlcs_info->tell_if_missing, + &htlcs_info->tell_immediately)) + master_badmsg(WIRE_ONCHAIND_HTLCS, msg); + + /* We want htlcs to be a valid tal parent, so make it a zero-length + * array if NULL (fromwire makes it NULL if there are no entries) */ + if (!htlcs_info->htlcs) + htlcs_info->htlcs = tal_arr(htlcs_info, struct htlc_stub, 0); + + /* Sort by CLTV, so matches are in CLTV order (and easy to skip dups) */ + asort(htlcs_info->htlcs, tal_count(htlcs_info->htlcs), + cmp_htlc_cltv, NULL); + + return htlcs_info; } static void handle_mutual_close(struct tracked_output **outs, @@ -2236,7 +2280,9 @@ static void handle_mutual_close(struct tracked_output **outs, bool is_replay) { struct amount_sat our_out; - init_reply("Tracking mutual close transaction"); + + /* In this case, we don't care about htlcs: there are none. */ + init_reply(tmpctx, "Tracking mutual close transaction"); /* Annotate the first input as close. We can currently only have a * single input for these. */ @@ -2526,11 +2572,9 @@ static enum side matches_direction(const size_t *matches, /* Tell master about any we didn't use, if it wants to know. */ static void note_missing_htlcs(u8 **htlc_scripts, - const struct htlc_stub *htlcs, - const bool *tell_if_missing, - const bool *tell_immediately) + const struct htlcs_info *htlcs_info) { - for (size_t i = 0; i < tal_count(htlcs); i++) { + for (size_t i = 0; i < tal_count(htlcs_info->htlcs); i++) { u8 *msg; /* Used. */ @@ -2538,12 +2582,12 @@ static void note_missing_htlcs(u8 **htlc_scripts, continue; /* Doesn't care. */ - if (!tell_if_missing[i]) + if (!htlcs_info->tell_if_missing[i]) continue; msg = towire_onchaind_missing_htlc_output(missing_htlc_msgs, - &htlcs[i]); - if (tell_immediately[i]) + &htlcs_info->htlcs[i]); + if (htlcs_info->tell_immediately[i]) wire_sync_write(REQ_FD, take(msg)); else tal_arr_expand(&missing_htlc_msgs, msg); @@ -2645,9 +2689,6 @@ static void our_unilateral_to_us(struct tracked_output ***outs, static void handle_our_unilateral(const struct tx_parts *tx, u32 tx_blockheight, const struct basepoints basepoints[NUM_SIDES], - const struct htlc_stub *htlcs, - const bool *tell_if_missing, - const bool *tell_immediately, const enum side opener, const struct bitcoin_signature *remote_htlc_sigs, struct tracked_output **outs, @@ -2659,8 +2700,9 @@ static void handle_our_unilateral(const struct tx_parts *tx, struct keyset *ks; size_t i; struct amount_sat their_outs = AMOUNT_SAT(0), our_outs = AMOUNT_SAT(0); + struct htlcs_info *htlcs_info; - init_reply("Tracking our own unilateral close"); + htlcs_info = init_reply(tx, "Tracking our own unilateral close"); onchain_annotate_txin(&tx->txid, 0, TX_CHANNEL_UNILATERAL); /* BOLT #5: @@ -2716,7 +2758,7 @@ static void handle_our_unilateral(const struct tx_parts *tx, &keyset->other_payment_key, 1); /* Calculate all the HTLC scripts so we can match them */ - htlc_scripts = derive_htlc_scripts(htlcs, LOCAL); + htlc_scripts = derive_htlc_scripts(htlcs_info->htlcs, LOCAL); status_debug("Script to-me: %u: %s (%s)", to_self_delay[LOCAL], @@ -2909,7 +2951,7 @@ static void handle_our_unilateral(const struct tx_parts *tx, i); } - if (matches_direction(matches, htlcs) == LOCAL) { + if (matches_direction(matches, htlcs_info->htlcs) == LOCAL) { /* BOLT #5: * * - MUST handle HTLCs offered by itself as specified @@ -2925,7 +2967,7 @@ static void handle_our_unilateral(const struct tx_parts *tx, remote_htlc_sigs); /* Tells us which htlc to use */ which_htlc = resolve_our_htlc_ourcommit(out, matches, - htlcs, + htlcs_info->htlcs, htlc_scripts, is_replay); add_amt(&our_outs, amt); @@ -2944,12 +2986,13 @@ static void handle_our_unilateral(const struct tx_parts *tx, * Commitment, Remote Offers] */ /* Tells us which htlc to use */ - which_htlc = resolve_their_htlc(out, matches, htlcs, + which_htlc = resolve_their_htlc(out, matches, + htlcs_info->htlcs, htlc_scripts, is_replay); add_amt(&their_outs, amt); } - out->htlc = htlcs[which_htlc]; + out->htlc = htlcs_info->htlcs[which_htlc]; out->wscript = tal_steal(out, htlc_scripts[which_htlc]); /* Each of these consumes one HTLC signature */ @@ -2959,13 +3002,13 @@ static void handle_our_unilateral(const struct tx_parts *tx, } - note_missing_htlcs(htlc_scripts, htlcs, - tell_if_missing, tell_immediately); + note_missing_htlcs(htlc_scripts, htlcs_info); + tal_free(htlcs_info); + if (!is_replay) record_chain_fees_unilateral(&tx->txid, tx_blockheight, outs[0]->sat, their_outs, our_outs); - wait_for_resolved(outs); } @@ -3130,9 +3173,6 @@ static void handle_their_cheat(const struct tx_parts *tx, u32 tx_blockheight, const struct secret *revocation_preimage, const struct basepoints basepoints[NUM_SIDES], - const struct htlc_stub *htlcs, - const bool *tell_if_missing, - const bool *tell_immediately, const enum side opener, struct tracked_output **outs, bool is_replay) @@ -3146,8 +3186,10 @@ static void handle_their_cheat(const struct tx_parts *tx, * for this unilateral tx are */ struct amount_sat total_outs = AMOUNT_SAT(0), fee_cost; bool amt_ok; + struct htlcs_info *htlcs_info; - init_reply("Tracking their illegal close: taking all funds"); + htlcs_info = init_reply(tx, + "Tracking their illegal close: taking all funds"); onchain_annotate_txin( &tx->txid, 0, TX_CHANNEL_UNILATERAL | TX_CHANNEL_CHEAT | TX_THEIRS); @@ -3245,7 +3287,7 @@ static void handle_their_cheat(const struct tx_parts *tx, &keyset->other_payment_key, 1); /* Calculate all the HTLC scripts so we can match them */ - htlc_scripts = derive_htlc_scripts(htlcs, REMOTE); + htlc_scripts = derive_htlc_scripts(htlcs_info->htlcs, REMOTE); status_debug("Script to-them: %u: %s (%s)", to_self_delay[REMOTE], @@ -3427,7 +3469,7 @@ static void handle_their_cheat(const struct tx_parts *tx, /* In this case, we don't care which HTLC we choose; so pick first one */ which_htlc = matches[0]; - if (matches_direction(matches, htlcs) == LOCAL) { + if (matches_direction(matches, htlcs_info->htlcs) == LOCAL) { /* BOLT #5: * * - MUST *resolve* the _local node's offered HTLCs_ in one of three ways: @@ -3440,7 +3482,7 @@ static void handle_their_cheat(const struct tx_parts *tx, THEIR_REVOKED_UNILATERAL, amt, OUR_HTLC, - &htlcs[which_htlc], + &htlcs_info->htlcs[which_htlc], htlc_scripts[which_htlc], NULL); steal_htlc(out, is_replay); @@ -3451,7 +3493,7 @@ static void handle_their_cheat(const struct tx_parts *tx, THEIR_REVOKED_UNILATERAL, amt, THEIR_HTLC, - &htlcs[which_htlc], + &htlcs_info->htlcs[which_htlc], htlc_scripts[which_htlc], NULL); /* BOLT #5: @@ -3467,8 +3509,8 @@ static void handle_their_cheat(const struct tx_parts *tx, htlc_scripts[which_htlc] = NULL; } - note_missing_htlcs(htlc_scripts, htlcs, - tell_if_missing, tell_immediately); + note_missing_htlcs(htlc_scripts, htlcs_info); + tal_free(htlcs_info); /* Record the fee cost for this tx, deducting it from channel balance */ amt_ok = amount_sat_sub(&fee_cost, outs[0]->sat, total_outs); @@ -3486,9 +3528,6 @@ static void handle_their_unilateral(const struct tx_parts *tx, u32 tx_blockheight, const struct pubkey *this_remote_per_commitment_point, const struct basepoints basepoints[NUM_SIDES], - const struct htlc_stub *htlcs, - const bool *tell_if_missing, - const bool *tell_immediately, const enum side opener, struct tracked_output **outs, bool is_replay) @@ -3498,8 +3537,9 @@ static void handle_their_unilateral(const struct tx_parts *tx, struct keyset *ks; size_t i; struct amount_sat their_outs = AMOUNT_SAT(0), our_outs = AMOUNT_SAT(0); + struct htlcs_info *htlcs_info; - init_reply("Tracking their unilateral close"); + htlcs_info = init_reply(tx, "Tracking their unilateral close"); onchain_annotate_txin(&tx->txid, 0, TX_CHANNEL_UNILATERAL | TX_THEIRS); /* HSM can't derive this. */ @@ -3576,7 +3616,7 @@ static void handle_their_unilateral(const struct tx_parts *tx, &keyset->other_htlc_key)); /* Calculate all the HTLC scripts so we can match them */ - htlc_scripts = derive_htlc_scripts(htlcs, REMOTE); + htlc_scripts = derive_htlc_scripts(htlcs_info->htlcs, REMOTE); get_anchor_scriptpubkeys(tmpctx, anchor); @@ -3765,7 +3805,7 @@ static void handle_their_unilateral(const struct tx_parts *tx, i); } - if (matches_direction(matches, htlcs) == LOCAL) { + if (matches_direction(matches, htlcs_info->htlcs) == LOCAL) { /* BOLT #5: * * - MUST handle HTLCs offered by itself as specified in @@ -3781,7 +3821,7 @@ static void handle_their_unilateral(const struct tx_parts *tx, NULL); which_htlc = resolve_our_htlc_theircommit(out, matches, - htlcs, + htlcs_info->htlcs, htlc_scripts, is_replay); add_amt(&our_outs, amt); @@ -3799,17 +3839,18 @@ static void handle_their_unilateral(const struct tx_parts *tx, * specified in [HTLC Output Handling: Remote * Commitment, Remote Offers] */ - which_htlc = resolve_their_htlc(out, matches, htlcs, + which_htlc = resolve_their_htlc(out, matches, + htlcs_info->htlcs, htlc_scripts, is_replay); add_amt(&their_outs, amt); } - out->htlc = htlcs[which_htlc]; + out->htlc = htlcs_info->htlcs[which_htlc]; out->wscript = tal_steal(out, htlc_scripts[which_htlc]); htlc_scripts[which_htlc] = NULL; } - note_missing_htlcs(htlc_scripts, htlcs, - tell_if_missing, tell_immediately); + note_missing_htlcs(htlc_scripts, htlcs_info); + tal_free(htlcs_info); if (!is_replay) record_chain_fees_unilateral(&tx->txid, tx_blockheight, @@ -3859,8 +3900,6 @@ 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], - const struct htlc_stub *htlcs, - const bool *tell_if_missing, struct tracked_output **outs, bool is_replay) { @@ -3868,6 +3907,7 @@ static void handle_unknown_commitment(const struct tx_parts *tx, /* We have two possible local scripts, depending on options */ u8 *local_scripts[2]; struct amount_sat amt_salvaged = AMOUNT_SAT(0); + struct htlcs_info *htlcs_info; onchain_annotate_txin(&tx->txid, 0, TX_CHANNEL_UNILATERAL | TX_THEIRS); @@ -3961,12 +4001,12 @@ script_found: if (to_us_output == -1) { status_broken("FUNDS LOST. Unknown commitment #%"PRIu64"!", commit_num); - init_reply("ERROR: FUNDS LOST. Unknown commitment!"); + htlcs_info = init_reply(tx, "ERROR: FUNDS LOST. Unknown commitment!"); } else { status_broken("ERROR: Unknown commitment #%"PRIu64 ", recovering our funds!", commit_num); - init_reply("ERROR: Unknown commitment, recovering our funds!"); + htlcs_info = init_reply(tx, "ERROR: Unknown commitment, recovering our funds!"); } /* update our accounting notions for this channel. @@ -3975,29 +4015,21 @@ script_found: update_ledger_unknown(&tx->txid, tx_blockheight, amt_salvaged); /* Tell master to give up on HTLCs immediately. */ - for (size_t i = 0; i < tal_count(htlcs); i++) { + for (size_t i = 0; i < tal_count(htlcs_info->htlcs); i++) { u8 *msg; - if (!tell_if_missing[i]) + if (!htlcs_info->tell_if_missing[i]) continue; - msg = towire_onchaind_missing_htlc_output(NULL, &htlcs[i]); + msg = towire_onchaind_missing_htlc_output(NULL, + &htlcs_info->htlcs[i]); wire_sync_write(REQ_FD, take(msg)); } + tal_free(htlcs_info); wait_for_resolved(outs); } -static int cmp_htlc_cltv(const struct htlc_stub *a, - const struct htlc_stub *b, void *unused) -{ - if (a->cltv_expiry < b->cltv_expiry) - return -1; - else if (a->cltv_expiry > b->cltv_expiry) - return 1; - return 0; -} - int main(int argc, char *argv[]) { setup_locale(); @@ -4014,10 +4046,7 @@ int main(int argc, char *argv[]) struct bitcoin_txid our_broadcast_txid; struct bitcoin_signature *remote_htlc_sigs; struct amount_sat funding_sats; - u64 num_htlcs; u8 *scriptpubkey[NUM_SIDES]; - struct htlc_stub *htlcs; - bool *tell_if_missing, *tell_immediately; u32 locktime, tx_blockheight; struct pubkey *possible_remote_per_commitment_point; int mutual_outnum; @@ -4055,7 +4084,6 @@ int main(int argc, char *argv[]) &tx_blockheight, &reasonable_depth, &remote_htlc_sigs, - &num_htlcs, &min_possible_feerate, &max_possible_feerate, &possible_remote_per_commitment_point, @@ -4075,25 +4103,6 @@ int main(int argc, char *argv[]) /* We need to keep tx around, but there's only one: not really a leak */ tal_steal(ctx, notleak(tx)); - /* FIXME: Filter as we go, don't load them all into mem! */ - htlcs = tal_arr(tmpctx, struct htlc_stub, num_htlcs); - tell_if_missing = tal_arr(htlcs, bool, num_htlcs); - tell_immediately = tal_arr(htlcs, bool, num_htlcs); - if (!htlcs || !tell_if_missing || !tell_immediately) - status_failed(STATUS_FAIL_INTERNAL_ERROR, - "Can't allocate %"PRIu64" htlcs", num_htlcs); - - for (u64 i = 0; i < num_htlcs; i++) { - msg = wire_sync_read(tmpctx, REQ_FD); - if (!fromwire_onchaind_htlc(msg, &htlcs[i], - &tell_if_missing[i], - &tell_immediately[i])) - master_badmsg(WIRE_ONCHAIND_HTLC, msg); - } - - /* Sort by CLTV, so matches are in CLTV order (and easy to skip dups) */ - asort(htlcs, tal_count(htlcs), cmp_htlc_cltv, NULL); - outs = tal_arr(ctx, struct tracked_output *, 0); wally_tx_input_get_txid(tx->inputs[0], &funding.txid); funding.n = tx->inputs[0]->index; @@ -4145,8 +4154,6 @@ int main(int argc, char *argv[]) if (is_local_commitment(&tx->txid, &our_broadcast_txid)) handle_our_unilateral(tx, tx_blockheight, basepoints, - htlcs, - tell_if_missing, tell_immediately, opener, remote_htlc_sigs, outs, @@ -4164,8 +4171,6 @@ int main(int argc, char *argv[]) tx_blockheight, &revocation_preimage, basepoints, - htlcs, - tell_if_missing, tell_immediately, opener, outs, open_is_replay); @@ -4183,9 +4188,6 @@ int main(int argc, char *argv[]) handle_their_unilateral(tx, tx_blockheight, &old_remote_per_commit_point, basepoints, - htlcs, - tell_if_missing, - tell_immediately, opener, outs, open_is_replay); @@ -4194,9 +4196,6 @@ int main(int argc, char *argv[]) handle_their_unilateral(tx, tx_blockheight, &remote_per_commit_point, basepoints, - htlcs, - tell_if_missing, - tell_immediately, opener, outs, open_is_replay); @@ -4204,8 +4203,6 @@ int main(int argc, char *argv[]) handle_unknown_commitment(tx, tx_blockheight, possible_remote_per_commitment_point, basepoints, - htlcs, - tell_if_missing, outs, open_is_replay); } diff --git a/onchaind/onchaind_wire.csv b/onchaind/onchaind_wire.csv index ee24243af..0193f4fbb 100644 --- a/onchaind/onchaind_wire.csv +++ b/onchaind/onchaind_wire.csv @@ -40,7 +40,6 @@ msgdata,onchaind_init,tx_blockheight,u32, msgdata,onchaind_init,reasonable_depth,u32, msgdata,onchaind_init,num_htlc_sigs,u16, msgdata,onchaind_init,htlc_signature,bitcoin_signature,num_htlc_sigs -msgdata,onchaind_init,num_htlcs,u64, msgdata,onchaind_init,min_possible_feerate,u32, msgdata,onchaind_init,max_possible_feerate,u32, msgdata,onchaind_init,possible_remote_per_commit_point,?pubkey, @@ -53,16 +52,17 @@ msgdata,onchaind_init,is_replay,bool, # We need this for BIP125 rule 4 msgdata,onchaind_init,min_relay_feerate,u32, -#include -# This is all the HTLCs: one per message -msgtype,onchaind_htlc,5002 -msgdata,onchaind_htlc,htlc,htlc_stub, -# If it's not in the commitment tx, tell us (immediately or htlc_missing_depth) -msgdata,onchaind_htlc,tell_if_missing,bool, -msgdata,onchaind_htlc,tell_immediately,bool, - -# This says we're ready; give us preimages. +# This says we're ready; give us htlcs and preimages. msgtype,onchaind_init_reply,5101 +msgdata,onchaind_init_reply,commit_num,u64, + +#include +msgtype,onchaind_htlcs,5002 +msgdata,onchaind_htlcs,num_htlcs,u32, +msgdata,onchaind_htlcs,htlc,htlc_stub,num_htlcs +# If it's not in the commitment tx, tell us (immediately or htlc_missing_depth) +msgdata,onchaind_htlcs,tell_if_missing,bool,num_htlcs +msgdata,onchaind_htlcs,tell_immediately,bool,num_htlcs # onchaind->master: Send out a tx. # If is_rbf is false then master should rebroadcast the tx. diff --git a/onchaind/test/run-grind_feerate-bug.c b/onchaind/test/run-grind_feerate-bug.c index 9d393069b..17b360244 100644 --- a/onchaind/test/run-grind_feerate-bug.c +++ b/onchaind/test/run-grind_feerate-bug.c @@ -44,11 +44,11 @@ bool fromwire_onchaind_depth(const void *p UNNEEDED, struct bitcoin_txid *txid U /* Generated stub for fromwire_onchaind_dev_memleak */ bool fromwire_onchaind_dev_memleak(const void *p UNNEEDED) { fprintf(stderr, "fromwire_onchaind_dev_memleak called!\n"); abort(); } -/* Generated stub for fromwire_onchaind_htlc */ -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_htlcs */ +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, 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) +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, 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) @@ -242,7 +242,7 @@ u8 *towire_onchaind_extracted_preimage(const tal_t *ctx UNNEEDED, const struct p u8 *towire_onchaind_htlc_timeout(const tal_t *ctx UNNEEDED, const struct htlc_stub *htlc UNNEEDED) { fprintf(stderr, "towire_onchaind_htlc_timeout called!\n"); abort(); } /* Generated stub for towire_onchaind_init_reply */ -u8 *towire_onchaind_init_reply(const tal_t *ctx UNNEEDED) +u8 *towire_onchaind_init_reply(const tal_t *ctx UNNEEDED, u64 commit_num UNNEEDED) { fprintf(stderr, "towire_onchaind_init_reply called!\n"); abort(); } /* Generated stub for towire_onchaind_missing_htlc_output */ u8 *towire_onchaind_missing_htlc_output(const tal_t *ctx UNNEEDED, const struct htlc_stub *htlc UNNEEDED) diff --git a/onchaind/test/run-grind_feerate.c b/onchaind/test/run-grind_feerate.c index c89cca79e..5f5f8495a 100644 --- a/onchaind/test/run-grind_feerate.c +++ b/onchaind/test/run-grind_feerate.c @@ -49,11 +49,11 @@ bool fromwire_onchaind_depth(const void *p UNNEEDED, struct bitcoin_txid *txid U /* Generated stub for fromwire_onchaind_dev_memleak */ bool fromwire_onchaind_dev_memleak(const void *p UNNEEDED) { fprintf(stderr, "fromwire_onchaind_dev_memleak called!\n"); abort(); } -/* Generated stub for fromwire_onchaind_htlc */ -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_htlcs */ +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, 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) +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, 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) @@ -271,7 +271,7 @@ u8 *towire_onchaind_extracted_preimage(const tal_t *ctx UNNEEDED, const struct p u8 *towire_onchaind_htlc_timeout(const tal_t *ctx UNNEEDED, const struct htlc_stub *htlc UNNEEDED) { fprintf(stderr, "towire_onchaind_htlc_timeout called!\n"); abort(); } /* Generated stub for towire_onchaind_init_reply */ -u8 *towire_onchaind_init_reply(const tal_t *ctx UNNEEDED) +u8 *towire_onchaind_init_reply(const tal_t *ctx UNNEEDED, u64 commit_num UNNEEDED) { fprintf(stderr, "towire_onchaind_init_reply called!\n"); abort(); } /* Generated stub for towire_onchaind_missing_htlc_output */ u8 *towire_onchaind_missing_htlc_output(const tal_t *ctx UNNEEDED, const struct htlc_stub *htlc UNNEEDED) diff --git a/onchaind/test/run-onchainstress.c b/onchaind/test/run-onchainstress.c deleted file mode 100644 index e79e6d50a..000000000 --- a/onchaind/test/run-onchainstress.c +++ /dev/null @@ -1,223 +0,0 @@ -#include "../onchaind.c" -#include "../onchaind_wiregen.c" -#include "../onchaind_wire.c" -#include "../../hsmd/hsmd_wiregen.c" -#include -#include -#include -#include -#include -#include - -volatile bool logging_io; -struct backtrace_state *backtrace_state; - -/* AUTOGENERATED MOCKS START */ -/* Generated stub for dup_onionreply */ -struct onionreply *dup_onionreply(const tal_t *ctx UNNEEDED, - const struct onionreply *r TAKES UNNEEDED) -{ fprintf(stderr, "dup_onionreply called!\n"); abort(); } -/* Generated stub for fromwire_bip32_key_version */ -void fromwire_bip32_key_version(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, - struct bip32_key_version *version UNNEEDED) -{ fprintf(stderr, "fromwire_bip32_key_version called!\n"); abort(); } -/* Generated stub for fromwire_chain_coin_mvt */ -void fromwire_chain_coin_mvt(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct chain_coin_mvt *mvt UNNEEDED) -{ fprintf(stderr, "fromwire_chain_coin_mvt called!\n"); abort(); } -/* Generated stub for fromwire_ext_key */ -void fromwire_ext_key(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct ext_key *bip32 UNNEEDED) -{ fprintf(stderr, "fromwire_ext_key called!\n"); abort(); } -/* Generated stub for fromwire_node_id */ -void fromwire_node_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct node_id *id UNNEEDED) -{ fprintf(stderr, "fromwire_node_id called!\n"); abort(); } -/* Generated stub for fromwire_onionreply */ -struct onionreply *fromwire_onionreply(const tal_t *ctx UNNEEDED, - const u8 **cursor UNNEEDED, size_t *max UNNEEDED) -{ fprintf(stderr, "fromwire_onionreply called!\n"); abort(); } -/* Generated stub for fromwire_utxo */ -struct utxo *fromwire_utxo(const tal_t *ctx UNNEEDED, const u8 **ptr UNNEEDED, size_t *max UNNEEDED) -{ fprintf(stderr, "fromwire_utxo called!\n"); abort(); } -/* Generated stub for master_badmsg */ -void master_badmsg(u32 type_expected UNNEEDED, const u8 *msg) -{ fprintf(stderr, "master_badmsg called!\n"); abort(); } -/* Generated stub for memleak_find_allocations */ -struct htable *memleak_find_allocations(const tal_t *ctx UNNEEDED, - const void *exclude1 UNNEEDED, - const void *exclude2 UNNEEDED) -{ fprintf(stderr, "memleak_find_allocations called!\n"); abort(); } -/* Generated stub for new_coin_penalty_sat */ -struct chain_coin_mvt *new_coin_penalty_sat(const tal_t *ctx UNNEEDED, - const char *account_name UNNEEDED, - const struct bitcoin_txid *txid UNNEEDED, - const struct bitcoin_outpoint *outpoint UNNEEDED, - u32 blockheight UNNEEDED, - struct amount_sat amount UNNEEDED) -{ fprintf(stderr, "new_coin_penalty_sat called!\n"); abort(); } -/* Generated stub for new_coin_withdrawal */ -struct chain_coin_mvt *new_coin_withdrawal(const tal_t *ctx UNNEEDED, - const char *account_name UNNEEDED, - const struct bitcoin_txid *tx_txid UNNEEDED, - const struct bitcoin_outpoint *outpoint UNNEEDED, - u32 blockheight UNNEEDED, - struct amount_msat amount UNNEEDED) -{ fprintf(stderr, "new_coin_withdrawal called!\n"); abort(); } -/* Generated stub for status_failed */ -void status_failed(enum status_failreason code UNNEEDED, - const char *fmt UNNEEDED, ...) -{ fprintf(stderr, "status_failed called!\n"); abort(); } -/* Generated stub for status_vfmt */ -void status_vfmt(enum log_level level UNNEEDED, - const struct node_id *peer UNNEEDED, - const char *fmt UNNEEDED, va_list ap UNNEEDED) -{ fprintf(stderr, "status_vfmt called!\n"); abort(); } -/* Generated stub for towire_bip32_key_version */ -void towire_bip32_key_version(u8 **cursor UNNEEDED, const struct bip32_key_version *version UNNEEDED) -{ fprintf(stderr, "towire_bip32_key_version called!\n"); abort(); } -/* Generated stub for towire_ext_key */ -void towire_ext_key(u8 **pptr UNNEEDED, const struct ext_key *bip32 UNNEEDED) -{ fprintf(stderr, "towire_ext_key called!\n"); abort(); } -/* Generated stub for towire_node_id */ -void towire_node_id(u8 **pptr UNNEEDED, const struct node_id *id UNNEEDED) -{ fprintf(stderr, "towire_node_id called!\n"); abort(); } -/* Generated stub for towire_onionreply */ -void towire_onionreply(u8 **cursor UNNEEDED, const struct onionreply *r UNNEEDED) -{ fprintf(stderr, "towire_onionreply called!\n"); abort(); } -/* Generated stub for towire_utxo */ -void towire_utxo(u8 **pptr UNNEEDED, const struct utxo *utxo UNNEEDED) -{ fprintf(stderr, "towire_utxo called!\n"); abort(); } -/* Generated stub for version */ -const char *version(void) -{ fprintf(stderr, "version called!\n"); abort(); } -/* AUTOGENERATED MOCKS END */ -#if DEVELOPER -/* Generated stub for dev_disconnect_init */ -void dev_disconnect_init(int fd UNNEEDED) -{ fprintf(stderr, "dev_disconnect_init called!\n"); abort(); } -/* Generated stub for dump_memleak */ -bool dump_memleak(struct htable *memtable UNNEEDED, - void (*print)(const char *fmt UNNEEDED, ...)) -{ fprintf(stderr, "dump_memleak called!\n"); abort(); } -/* Generated stub for memleak_init */ -void memleak_init(void) -{ fprintf(stderr, "memleak_init called!\n"); abort(); } -/* Generated stub for memleak_remove_region */ -void memleak_remove_region(struct htable *memtable UNNEEDED, - const void *p UNNEEDED, size_t bytelen UNNEEDED) -{ fprintf(stderr, "memleak_remove_region called!\n"); abort(); } -/* Generated stub for memleak_status_broken */ -void memleak_status_broken(const char *fmt UNNEEDED, ...) -{ fprintf(stderr, "memleak_status_broken called!\n"); abort(); } -#endif - -/* Noops */ -void status_setup_sync(int fd UNNEEDED) -{ -} -void status_fmt(enum log_level level, - const struct node_id *peer, - const char *fmt, ...) -{ -} -void *notleak_(const void *ptr UNNEEDED, bool plus_children UNNEEDED) -{ - return (void *)ptr; -} -void peer_billboard(bool perm UNNEEDED, const char *fmt UNNEEDED, ...) -{ -} -struct chain_coin_mvt *new_coin_chain_fees(const tal_t *ctx UNNEEDED, - const char *account_name UNNEEDED, - const struct bitcoin_txid *tx_txid UNNEEDED, - u32 blockheight UNNEEDED, - struct amount_msat amount UNNEEDED) -{ - return NULL; -} - -/* Generated stub for new_coin_chain_fees_sat */ -struct chain_coin_mvt *new_coin_chain_fees_sat(const tal_t *ctx UNNEEDED, - const char *account_name UNNEEDED, - const struct bitcoin_txid *tx_txid UNNEEDED, - u32 blockheight UNNEEDED, - struct amount_sat amount UNNEEDED) -{ - return NULL; -} -/* Generated stub for new_coin_journal_entry */ -struct chain_coin_mvt *new_coin_journal_entry(const tal_t *ctx UNNEEDED, - const char *account_name UNNEEDED, - const struct bitcoin_txid *txid UNNEEDED, - const struct bitcoin_outpoint *outpoint UNNEEDED, - u32 blockheight UNNEEDED, - struct amount_msat amount UNNEEDED, - bool is_credit UNNEEDED) -{ - return NULL; -} -struct chain_coin_mvt *new_coin_onchain_htlc_sat(const tal_t *ctx UNNEEDED, - const char *account_name UNNEEDED, - const struct bitcoin_txid *txid UNNEEDED, - const struct bitcoin_outpoint *outpoint UNNEEDED, - struct sha256 payment_hash UNNEEDED, - u32 blockheight UNNEEDED, - struct amount_sat amount UNNEEDED, - bool is_credit UNNEEDED) -{ - return NULL; -} -struct chain_coin_mvt *new_coin_withdrawal_sat(const tal_t *ctx UNNEEDED, - const char *account_name UNNEEDED, - const struct bitcoin_txid *tx_txid UNNEEDED, - const struct bitcoin_outpoint *outpoint UNNEEDED, - u32 blockheight UNNEEDED, - struct amount_sat amount UNNEEDED) -{ - return NULL; -} -void towire_chain_coin_mvt(u8 **pptr UNNEEDED, const struct chain_coin_mvt *mvt UNNEEDED) -{ -} - -bool wire_sync_write(int fd, const void *msg TAKES) -{ - if (taken(msg)) - tal_free(msg); - return true; -} - -u8 *wire_sync_read(const tal_t *ctx, int fd) -{ - char line[5000]; - u8 *ret; - static gzFile stream; - size_t hexlen; - - /* Don't run this under valgrind in CI: takes too long! */ - if (getenv("VALGRIND") && streq(getenv("VALGRIND"), "1")) - goto exit; - - if (!stream) { - stream = gzopen("onchaind/test/onchainstress-data.gz", "rb"); - if (!stream) - err(1, "opening onchaind/test/onchainstress-data.gz"); - } - - do { - if (!gzgets(stream, line, sizeof(line))) - goto exit; - } while (!strstarts(line, "read ")); - - /* Ignore prefix and \n at end */ - hexlen = strlen(line) - strlen("read ") - 1; - ret = tal_arr(ctx, u8, hex_data_size(hexlen)); - if (!hex_decode(line + strlen("read "), hexlen, ret, tal_bytelen(ret))) - errx(1, "Bad hex string '%s'", line); - return ret; - -exit: - daemon_shutdown(); - /* Free top-level ctx pointer! */ - while (tal_first(NULL)) - tal_free(tal_first(NULL)); - exit(0); -}