From 15e73e3dc333f0fa6a742f21cb81ad3dc91c57c1 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Tue, 30 Jul 2019 16:24:13 +0200 Subject: [PATCH] onchaind: Pass genesis hash to onchaind so it knows the chainparams It'll be creating quite a few transactions and we will have to know which params to use. Signed-off-by: Christian Decker --- lightningd/onchain_control.c | 4 ++++ onchaind/onchain_wire.csv | 1 + onchaind/onchaind.c | 2 ++ onchaind/test/run-grind_feerate.c | 2 +- 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lightningd/onchain_control.c b/lightningd/onchain_control.c index 0c9765ce9..7c35d6be9 100644 --- a/lightningd/onchain_control.c +++ b/lightningd/onchain_control.c @@ -438,6 +438,7 @@ enum watch_result onchaind_funding_spent(struct channel *channel, struct pubkey final_key; int hsmfd; u32 feerate; + const struct chainparams *chainparams; channel_fail_permanent(channel, "Funding transaction spent"); @@ -507,8 +508,11 @@ enum watch_result onchaind_funding_spent(struct channel *channel, feerate = feerate_floor(); } + chainparams = get_chainparams(channel->peer->ld); + msg = towire_onchain_init(channel, &channel->their_shachain.chain, + &chainparams->genesis_blockhash, channel->funding, &channel->channel_info.old_remote_per_commit, &channel->channel_info.remote_per_commit, diff --git a/onchaind/onchain_wire.csv b/onchaind/onchain_wire.csv index eef640480..08f7d362f 100644 --- a/onchaind/onchain_wire.csv +++ b/onchaind/onchain_wire.csv @@ -5,6 +5,7 @@ # Begin! Here's the onchain tx which spends funding tx, followed by all HTLCs. msgtype,onchain_init,5001 msgdata,onchain_init,shachain,shachain, +msgdata,onchain_init,chain_hash,bitcoin_blkid, msgdata,onchain_init,funding_amount_satoshi,amount_sat, # Remote per commit point for committed tx. msgdata,onchain_init,old_remote_per_commitment_point,pubkey, diff --git a/onchaind/onchaind.c b/onchaind/onchaind.c index 4297ede3d..8e4344314 100644 --- a/onchaind/onchaind.c +++ b/onchaind/onchaind.c @@ -2501,6 +2501,7 @@ int main(int argc, char *argv[]) bool *tell_if_missing, *tell_immediately; u32 tx_blockheight; struct pubkey *possible_remote_per_commitment_point; + struct bitcoin_blkid chain_hash; subdaemon_setup(argc, argv); @@ -2511,6 +2512,7 @@ int main(int argc, char *argv[]) msg = wire_sync_read(tmpctx, REQ_FD); if (!fromwire_onchain_init(tmpctx, msg, &shachain, + &chain_hash, &funding, &old_remote_per_commit_point, &remote_per_commit_point, diff --git a/onchaind/test/run-grind_feerate.c b/onchaind/test/run-grind_feerate.c index 83c4e8780..af99dfb17 100644 --- a/onchaind/test/run-grind_feerate.c +++ b/onchaind/test/run-grind_feerate.c @@ -43,7 +43,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 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) { 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)