From b2b85100d73eb5bd5b0ea76fd4660a68ef05e380 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 9 Jul 2018 20:47:59 +0930 Subject: [PATCH] common/derive_basepoints: add routines for marshal/unmarshal. Signed-off-by: Rusty Russell --- channeld/channel.c | 5 +---- channeld/channel_wire.csv | 6 ++--- common/derive_basepoints.c | 18 +++++++++++++++ common/derive_basepoints.h | 5 +++++ lightningd/channel_control.c | 5 +---- lightningd/onchain_control.c | 5 +---- onchaind/onchain.c | 37 +++++++++++++------------------ onchaind/onchain_wire.csv | 7 +++--- onchaind/test/run-grind_feerate.c | 2 +- 9 files changed, 48 insertions(+), 42 deletions(-) diff --git a/channeld/channel.c b/channeld/channel.c index 888215bd2..d0eb0534d 100644 --- a/channeld/channel.c +++ b/channeld/channel.c @@ -2432,10 +2432,7 @@ static void init_channel(struct peer *peer) &peer->their_commit_sig, &peer->cs, &funding_pubkey[REMOTE], - &points[REMOTE].revocation, - &points[REMOTE].payment, - &points[REMOTE].htlc, - &points[REMOTE].delayed_payment, + &points[REMOTE], &peer->remote_per_commit, &peer->old_remote_per_commit, &funder, diff --git a/channeld/channel_wire.csv b/channeld/channel_wire.csv index 681cba28a..8cc505cd2 100644 --- a/channeld/channel_wire.csv +++ b/channeld/channel_wire.csv @@ -1,5 +1,6 @@ #include #include +#include # Begin! (passes gossipd-client fd) channel_init,1000 @@ -16,10 +17,7 @@ channel_init,,feerate_max,u32 channel_init,,first_commit_sig,secp256k1_ecdsa_signature channel_init,,crypto_state,struct crypto_state channel_init,,remote_fundingkey,struct pubkey -channel_init,,remote_revocation_basepoint,struct pubkey -channel_init,,remote_payment_basepoint,struct pubkey -channel_init,,remote_htlc_basepoint,struct pubkey -channel_init,,remote_delayed_payment_basepoint,struct pubkey +channel_init,,remote_basepoints,struct basepoints channel_init,,remote_per_commit,struct pubkey channel_init,,old_remote_per_commit,struct pubkey channel_init,,funder,enum side diff --git a/common/derive_basepoints.c b/common/derive_basepoints.c index 92c4806e9..a2dccc6f1 100644 --- a/common/derive_basepoints.c +++ b/common/derive_basepoints.c @@ -2,6 +2,7 @@ #include #include #include +#include bool derive_basepoints(const struct secret *seed, struct pubkey *funding_pubkey, @@ -85,3 +86,20 @@ bool per_commit_point(const struct sha256 *shaseed, return true; } + +void towire_basepoints(u8 **pptr, const struct basepoints *b) +{ + towire_pubkey(pptr, &b->revocation); + towire_pubkey(pptr, &b->payment); + towire_pubkey(pptr, &b->htlc); + towire_pubkey(pptr, &b->delayed_payment); +} + +void fromwire_basepoints(const u8 **ptr, size_t *max, + struct basepoints *b) +{ + fromwire_pubkey(ptr, max, &b->revocation); + fromwire_pubkey(ptr, max, &b->payment); + fromwire_pubkey(ptr, max, &b->htlc); + fromwire_pubkey(ptr, max, &b->delayed_payment); +} diff --git a/common/derive_basepoints.h b/common/derive_basepoints.h index 7e119cf13..433d56b6d 100644 --- a/common/derive_basepoints.h +++ b/common/derive_basepoints.h @@ -75,4 +75,9 @@ static inline u64 revocations_received(const struct shachain *shachain) { return (1ULL << SHACHAIN_BITS) - (shachain_next_index(shachain) + 1); } + +void towire_basepoints(u8 **pptr, const struct basepoints *b); +void fromwire_basepoints(const u8 **ptr, size_t *max, + struct basepoints *b); + #endif /* LIGHTNING_COMMON_DERIVE_BASEPOINTS_H */ diff --git a/lightningd/channel_control.c b/lightningd/channel_control.c index 6176687ea..2b55ed1ab 100644 --- a/lightningd/channel_control.c +++ b/lightningd/channel_control.c @@ -260,10 +260,7 @@ bool peer_start_channeld(struct channel *channel, &channel->last_sig, cs, &channel->channel_info.remote_fundingkey, - &channel->channel_info.theirbase.revocation, - &channel->channel_info.theirbase.payment, - &channel->channel_info.theirbase.htlc, - &channel->channel_info.theirbase.delayed_payment, + &channel->channel_info.theirbase, &channel->channel_info.remote_per_commit, &channel->channel_info.old_remote_per_commit, channel->funder, diff --git a/lightningd/onchain_control.c b/lightningd/onchain_control.c index 4f4beff6f..887c25de4 100644 --- a/lightningd/onchain_control.c +++ b/lightningd/onchain_control.c @@ -440,16 +440,13 @@ enum watch_result onchaind_funding_spent(struct channel *channel, channel->our_config.to_self_delay, get_feerate(ld->topology, FEERATE_NORMAL), channel->our_config.dust_limit_satoshis, - &channel->channel_info.theirbase.revocation, &our_last_txid, p2wpkh_for_keyidx(tmpctx, ld, channel->final_key_idx), channel->remote_shutdown_scriptpubkey, &final_key, channel->funder, - &channel->channel_info.theirbase.payment, - &channel->channel_info.theirbase.htlc, - &channel->channel_info.theirbase.delayed_payment, + &channel->channel_info.theirbase, tx, blockheight, /* FIXME: config for 'reasonable depth' */ diff --git a/onchaind/onchain.c b/onchaind/onchain.c index 510890de3..2e0373037 100644 --- a/onchaind/onchain.c +++ b/onchaind/onchain.c @@ -2136,11 +2136,9 @@ int main(int argc, char *argv[]) const tal_t *ctx = tal(NULL, char); u8 *msg; struct secret seed; - struct pubkey remote_payment_basepoint, remote_htlc_basepoint, - remote_per_commit_point, old_remote_per_commit_point, - remote_revocation_basepoint, remote_delayed_payment_basepoint; + struct pubkey remote_per_commit_point, old_remote_per_commit_point; enum side funder; - struct basepoints basepoints; + struct basepoints basepoints, remote_basepoints; struct shachain shachain; struct bitcoin_tx *tx; struct secrets secrets; @@ -2170,15 +2168,12 @@ int main(int argc, char *argv[]) &to_self_delay[REMOTE], &feerate_per_kw, &dust_limit_satoshis, - &remote_revocation_basepoint, &our_broadcast_txid, &scriptpubkey[LOCAL], &scriptpubkey[REMOTE], &our_wallet_pubkey, &funder, - &remote_payment_basepoint, - &remote_htlc_basepoint, - &remote_delayed_payment_basepoint, + &remote_basepoints, &tx, &tx_blockheight, &reasonable_depth, @@ -2246,7 +2241,7 @@ int main(int argc, char *argv[]) struct sha256 revocation_preimage; u64 commit_num = unmask_commit_number(tx, funder, &basepoints.payment, - &remote_payment_basepoint); + &remote_basepoints.payment); status_trace("commitnum = %"PRIu64 ", revocations_received = %"PRIu64, @@ -2256,10 +2251,10 @@ int main(int argc, char *argv[]) handle_our_unilateral(tx, tx_blockheight, &txid, &secrets, &shaseed, - &remote_revocation_basepoint, - &remote_payment_basepoint, + &remote_basepoints.revocation, + &remote_basepoints.payment, &basepoints.payment, - &remote_htlc_basepoint, + &remote_basepoints.htlc, &basepoints.htlc, &basepoints.delayed_payment, commit_num, @@ -2283,10 +2278,10 @@ int main(int argc, char *argv[]) &secrets, &basepoints.revocation, &basepoints.payment, - &remote_payment_basepoint, + &remote_basepoints.payment, &basepoints.htlc, - &remote_htlc_basepoint, - &remote_delayed_payment_basepoint, + &remote_basepoints.htlc, + &remote_basepoints.delayed_payment, commit_num, htlcs, tell_if_missing, tell_immediately, @@ -2307,10 +2302,10 @@ int main(int argc, char *argv[]) &old_remote_per_commit_point, &basepoints.revocation, &basepoints.payment, - &remote_payment_basepoint, - &remote_htlc_basepoint, + &remote_basepoints.payment, + &remote_basepoints.htlc, &basepoints.htlc, - &remote_delayed_payment_basepoint, + &remote_basepoints.delayed_payment, commit_num, htlcs, tell_if_missing, @@ -2323,10 +2318,10 @@ int main(int argc, char *argv[]) &remote_per_commit_point, &basepoints.revocation, &basepoints.payment, - &remote_payment_basepoint, - &remote_htlc_basepoint, + &remote_basepoints.payment, + &remote_basepoints.htlc, &basepoints.htlc, - &remote_delayed_payment_basepoint, + &remote_basepoints.delayed_payment, commit_num, htlcs, tell_if_missing, diff --git a/onchaind/onchain_wire.csv b/onchaind/onchain_wire.csv index 37f80ed79..7eb2a2ca5 100644 --- a/onchaind/onchain_wire.csv +++ b/onchaind/onchain_wire.csv @@ -1,4 +1,6 @@ +#include #include + # Begin! Here's the onchain tx which spends funding tx, followed by all HTLCs. onchain_init,5001 onchain_init,,seed,struct secret @@ -12,7 +14,6 @@ onchain_init,,local_to_self_delay,u32 onchain_init,,remote_to_self_delay,u32 onchain_init,,feerate_per_kw,u32 onchain_init,,local_dust_limit_satoshi,u64 -onchain_init,,remote_revocation_basepoint,struct pubkey # Gives an easy way to tell if it's our unilateral close or theirs... onchain_init,,our_broadcast_txid,struct bitcoin_txid onchain_init,,local_scriptpubkey_len,u16 @@ -22,9 +23,7 @@ onchain_init,,remote_scriptpubkey,remote_scriptpubkey_len*u8 onchain_init,,ourwallet_pubkey,struct pubkey # We need these two for commit number obscurer onchain_init,,funder,enum side -onchain_init,,remote_payment_basepoint,struct pubkey -onchain_init,,remote_htlc_basepoint,struct pubkey -onchain_init,,remote_delayed_payment_basepoint,struct pubkey +onchain_init,,remote_basepoints,struct basepoints onchain_init,,tx,struct bitcoin_tx onchain_init,,tx_blockheight,u32 onchain_init,,reasonable_depth,u32 diff --git a/onchaind/test/run-grind_feerate.c b/onchaind/test/run-grind_feerate.c index 627d9253b..4f224b96c 100644 --- a/onchaind/test/run-grind_feerate.c +++ b/onchaind/test/run-grind_feerate.c @@ -55,7 +55,7 @@ bool fromwire_onchain_depth(const void *p UNNEEDED, struct bitcoin_txid *txid UN 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 secret *seed UNNEEDED, struct shachain *shachain UNNEEDED, u64 *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, u64 *local_dust_limit_satoshi UNNEEDED, struct pubkey *remote_revocation_basepoint 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 pubkey *remote_payment_basepoint UNNEEDED, struct pubkey *remote_htlc_basepoint UNNEEDED, struct pubkey *remote_delayed_payment_basepoint 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) +bool fromwire_onchain_init(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct secret *seed UNNEEDED, struct shachain *shachain UNNEEDED, u64 *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, u64 *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 *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) { 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)