mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 09:54:16 +01:00
common/keyset: use struct basepoints rather than open-coding fields.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
76cc428923
commit
dd2773dfc0
@ -248,12 +248,8 @@ struct bitcoin_tx **channel_txs(const tal_t *ctx,
|
||||
struct keyset keyset;
|
||||
|
||||
if (!derive_keyset(per_commitment_point,
|
||||
&channel->basepoints[side].payment,
|
||||
&channel->basepoints[!side].payment,
|
||||
&channel->basepoints[side].htlc,
|
||||
&channel->basepoints[!side].htlc,
|
||||
&channel->basepoints[side].delayed_payment,
|
||||
&channel->basepoints[!side].revocation,
|
||||
&channel->basepoints[side],
|
||||
&channel->basepoints[!side],
|
||||
&keyset))
|
||||
return NULL;
|
||||
|
||||
|
@ -75,12 +75,8 @@ struct bitcoin_tx *initial_channel_tx(const tal_t *ctx,
|
||||
assert(!channel->htlcs);
|
||||
|
||||
if (!derive_keyset(per_commitment_point,
|
||||
&channel->basepoints[side].payment,
|
||||
&channel->basepoints[!side].payment,
|
||||
&channel->basepoints[side].htlc,
|
||||
&channel->basepoints[!side].htlc,
|
||||
&channel->basepoints[side].delayed_payment,
|
||||
&channel->basepoints[!side].revocation,
|
||||
&channel->basepoints[side],
|
||||
&channel->basepoints[!side],
|
||||
&keyset))
|
||||
return NULL;
|
||||
|
||||
|
@ -1,13 +1,10 @@
|
||||
#include <common/derive_basepoints.h>
|
||||
#include <common/key_derive.h>
|
||||
#include <common/keyset.h>
|
||||
|
||||
bool derive_keyset(const struct pubkey *per_commitment_point,
|
||||
const struct pubkey *self_payment_basepoint,
|
||||
const struct pubkey *other_payment_basepoint,
|
||||
const struct pubkey *self_htlc_basepoint,
|
||||
const struct pubkey *other_htlc_basepoint,
|
||||
const struct pubkey *self_delayed_basepoint,
|
||||
const struct pubkey *other_revocation_basepoint,
|
||||
const struct basepoints *self,
|
||||
const struct basepoints *other,
|
||||
struct keyset *keyset)
|
||||
{
|
||||
/* BOLT #3:
|
||||
@ -27,27 +24,27 @@ bool derive_keyset(const struct pubkey *per_commitment_point,
|
||||
* node's `htlc_basepoint`; and the `remote_delayedpubkey` uses the
|
||||
* remote node's `delayed_payment_basepoint`.
|
||||
*/
|
||||
if (!derive_simple_key(self_payment_basepoint,
|
||||
if (!derive_simple_key(&self->payment,
|
||||
per_commitment_point,
|
||||
&keyset->self_payment_key))
|
||||
return false;
|
||||
|
||||
if (!derive_simple_key(other_payment_basepoint,
|
||||
if (!derive_simple_key(&other->payment,
|
||||
per_commitment_point,
|
||||
&keyset->other_payment_key))
|
||||
return false;
|
||||
|
||||
if (!derive_simple_key(self_htlc_basepoint,
|
||||
if (!derive_simple_key(&self->htlc,
|
||||
per_commitment_point,
|
||||
&keyset->self_htlc_key))
|
||||
return false;
|
||||
|
||||
if (!derive_simple_key(other_htlc_basepoint,
|
||||
if (!derive_simple_key(&other->htlc,
|
||||
per_commitment_point,
|
||||
&keyset->other_htlc_key))
|
||||
return false;
|
||||
|
||||
if (!derive_simple_key(self_delayed_basepoint,
|
||||
if (!derive_simple_key(&self->delayed_payment,
|
||||
per_commitment_point,
|
||||
&keyset->self_delayed_payment_key))
|
||||
return false;
|
||||
@ -61,7 +58,7 @@ bool derive_keyset(const struct pubkey *per_commitment_point,
|
||||
* `revocation_basepoint` and the remote node's `per_commitment_point`
|
||||
* to derive a new `revocationpubkey` for the commitment.
|
||||
*/
|
||||
if (!derive_revocation_key(other_revocation_basepoint,
|
||||
if (!derive_revocation_key(&other->revocation,
|
||||
per_commitment_point,
|
||||
&keyset->self_revocation_key))
|
||||
return false;
|
||||
|
@ -4,6 +4,8 @@
|
||||
#include <bitcoin/pubkey.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
struct basepoints;
|
||||
|
||||
/* Keys needed to derive a particular commitment tx. */
|
||||
struct keyset {
|
||||
struct pubkey self_revocation_key;
|
||||
@ -12,12 +14,9 @@ struct keyset {
|
||||
struct pubkey self_payment_key, other_payment_key;
|
||||
};
|
||||
|
||||
/* Self == owner of commitment tx, other == non-owner. */
|
||||
bool derive_keyset(const struct pubkey *per_commitment_point,
|
||||
const struct pubkey *self_payment_basepoint,
|
||||
const struct pubkey *other_payment_basepoint,
|
||||
const struct pubkey *self_htlc_basepoint,
|
||||
const struct pubkey *other_htlc_basepoint,
|
||||
const struct pubkey *self_delayed_basepoint,
|
||||
const struct pubkey *other_revocation_basepoint,
|
||||
const struct basepoints *self,
|
||||
const struct basepoints *other,
|
||||
struct keyset *keyset);
|
||||
#endif /* LIGHTNING_COMMON_KEYSET_H */
|
||||
|
@ -1369,12 +1369,7 @@ static void handle_our_unilateral(const struct bitcoin_tx *tx,
|
||||
const struct bitcoin_txid *txid,
|
||||
const struct secrets *secrets,
|
||||
const struct sha256 *shaseed,
|
||||
const struct pubkey *remote_revocation_basepoint,
|
||||
const struct pubkey *remote_payment_basepoint,
|
||||
const struct pubkey *local_payment_basepoint,
|
||||
const struct pubkey *remote_htlc_basepoint,
|
||||
const struct pubkey *local_htlc_basepoint,
|
||||
const struct pubkey *local_delayed_payment_basepoint,
|
||||
const struct basepoints basepoints[NUM_SIDES],
|
||||
const struct htlc_stub *htlcs,
|
||||
const bool *tell_if_missing,
|
||||
const bool *tell_immediately,
|
||||
@ -1405,12 +1400,8 @@ static void handle_our_unilateral(const struct bitcoin_tx *tx,
|
||||
/* keyset is const, we need a non-const ptr to set it up */
|
||||
keyset = ks = tal(tx, struct keyset);
|
||||
if (!derive_keyset(&local_per_commitment_point,
|
||||
local_payment_basepoint,
|
||||
remote_payment_basepoint,
|
||||
local_htlc_basepoint,
|
||||
remote_htlc_basepoint,
|
||||
local_delayed_payment_basepoint,
|
||||
remote_revocation_basepoint,
|
||||
&basepoints[LOCAL],
|
||||
&basepoints[REMOTE],
|
||||
ks))
|
||||
status_failed(STATUS_FAIL_INTERNAL_ERROR,
|
||||
"Deriving keyset for %"PRIu64, commit_num);
|
||||
@ -1438,7 +1429,7 @@ static void handle_our_unilateral(const struct bitcoin_tx *tx,
|
||||
&keyset->other_htlc_key));
|
||||
|
||||
if (!derive_simple_privkey(&secrets->delayed_payment_basepoint_secret,
|
||||
local_delayed_payment_basepoint,
|
||||
&basepoints[LOCAL].delayed_payment,
|
||||
&local_per_commitment_point,
|
||||
&delayed_payment_privkey))
|
||||
status_failed(STATUS_FAIL_INTERNAL_ERROR,
|
||||
@ -1446,7 +1437,7 @@ static void handle_our_unilateral(const struct bitcoin_tx *tx,
|
||||
commit_num);
|
||||
|
||||
if (!derive_simple_privkey(&secrets->payment_basepoint_secret,
|
||||
local_payment_basepoint,
|
||||
&basepoints[LOCAL].payment,
|
||||
&local_per_commitment_point,
|
||||
&payment_privkey))
|
||||
status_failed(STATUS_FAIL_INTERNAL_ERROR,
|
||||
@ -1454,7 +1445,7 @@ static void handle_our_unilateral(const struct bitcoin_tx *tx,
|
||||
commit_num);
|
||||
|
||||
if (!derive_simple_privkey(&secrets->htlc_basepoint_secret,
|
||||
local_htlc_basepoint,
|
||||
&basepoints[LOCAL].htlc,
|
||||
&local_per_commitment_point,
|
||||
&htlc_privkey))
|
||||
status_failed(STATUS_FAIL_INTERNAL_ERROR,
|
||||
@ -1674,12 +1665,7 @@ static void handle_their_cheat(const struct bitcoin_tx *tx,
|
||||
u32 tx_blockheight,
|
||||
const struct sha256 *revocation_preimage,
|
||||
const struct secrets *secrets,
|
||||
const struct pubkey *local_revocation_basepoint,
|
||||
const struct pubkey *local_payment_basepoint,
|
||||
const struct pubkey *remote_payment_basepoint,
|
||||
const struct pubkey *remote_htlc_basepoint,
|
||||
const struct pubkey *local_htlc_basepoint,
|
||||
const struct pubkey *remote_delayed_payment_basepoint,
|
||||
const struct basepoints basepoints[NUM_SIDES],
|
||||
const struct htlc_stub *htlcs,
|
||||
const bool *tell_if_missing,
|
||||
const bool *tell_immediately,
|
||||
@ -1729,27 +1715,23 @@ static void handle_their_cheat(const struct bitcoin_tx *tx,
|
||||
type_to_string(tmpctx, struct pubkey,
|
||||
&per_commitment_point),
|
||||
type_to_string(tmpctx, struct pubkey,
|
||||
remote_payment_basepoint),
|
||||
&basepoints[REMOTE].payment),
|
||||
type_to_string(tmpctx, struct pubkey,
|
||||
local_payment_basepoint),
|
||||
&basepoints[LOCAL].payment),
|
||||
type_to_string(tmpctx, struct pubkey,
|
||||
remote_htlc_basepoint),
|
||||
&basepoints[REMOTE].htlc),
|
||||
type_to_string(tmpctx, struct pubkey,
|
||||
local_htlc_basepoint),
|
||||
&basepoints[LOCAL].htlc),
|
||||
type_to_string(tmpctx, struct pubkey,
|
||||
remote_delayed_payment_basepoint),
|
||||
&basepoints[REMOTE].delayed_payment),
|
||||
type_to_string(tmpctx, struct pubkey,
|
||||
local_revocation_basepoint));
|
||||
&basepoints[LOCAL].revocation));
|
||||
|
||||
/* keyset is const, we need a non-const ptr to set it up */
|
||||
keyset = ks = tal(tx, struct keyset);
|
||||
if (!derive_keyset(&per_commitment_point,
|
||||
remote_payment_basepoint,
|
||||
local_payment_basepoint,
|
||||
local_htlc_basepoint,
|
||||
remote_htlc_basepoint,
|
||||
remote_delayed_payment_basepoint,
|
||||
local_revocation_basepoint,
|
||||
&basepoints[REMOTE],
|
||||
&basepoints[LOCAL],
|
||||
ks))
|
||||
status_failed(STATUS_FAIL_INTERNAL_ERROR,
|
||||
"Deriving keyset for %"PRIu64, commit_num);
|
||||
@ -1779,7 +1761,7 @@ static void handle_their_cheat(const struct bitcoin_tx *tx,
|
||||
revocation_privkey = tal(tx, struct privkey);
|
||||
if (!derive_revocation_privkey(&secrets->revocation_basepoint_secret,
|
||||
&per_commitment_secret,
|
||||
local_revocation_basepoint,
|
||||
&basepoints[LOCAL].revocation,
|
||||
&per_commitment_point,
|
||||
revocation_privkey))
|
||||
status_failed(STATUS_FAIL_INTERNAL_ERROR,
|
||||
@ -1906,12 +1888,7 @@ static void handle_their_unilateral(const struct bitcoin_tx *tx,
|
||||
const struct bitcoin_txid *txid,
|
||||
const struct secrets *secrets,
|
||||
const struct pubkey *remote_per_commitment_point,
|
||||
const struct pubkey *local_revocation_basepoint,
|
||||
const struct pubkey *local_payment_basepoint,
|
||||
const struct pubkey *remote_payment_basepoint,
|
||||
const struct pubkey *remote_htlc_basepoint,
|
||||
const struct pubkey *local_htlc_basepoint,
|
||||
const struct pubkey *remote_delayed_payment_basepoint,
|
||||
const struct basepoints basepoints[NUM_SIDES],
|
||||
const struct htlc_stub *htlcs,
|
||||
const bool *tell_if_missing,
|
||||
const bool *tell_immediately,
|
||||
@ -1950,27 +1927,23 @@ static void handle_their_unilateral(const struct bitcoin_tx *tx,
|
||||
type_to_string(tmpctx, struct pubkey,
|
||||
remote_per_commitment_point),
|
||||
type_to_string(tmpctx, struct pubkey,
|
||||
remote_payment_basepoint),
|
||||
&basepoints[REMOTE].payment),
|
||||
type_to_string(tmpctx, struct pubkey,
|
||||
local_payment_basepoint),
|
||||
&basepoints[LOCAL].payment),
|
||||
type_to_string(tmpctx, struct pubkey,
|
||||
remote_htlc_basepoint),
|
||||
&basepoints[REMOTE].htlc),
|
||||
type_to_string(tmpctx, struct pubkey,
|
||||
local_htlc_basepoint),
|
||||
&basepoints[LOCAL].htlc),
|
||||
type_to_string(tmpctx, struct pubkey,
|
||||
remote_delayed_payment_basepoint),
|
||||
&basepoints[REMOTE].delayed_payment),
|
||||
type_to_string(tmpctx, struct pubkey,
|
||||
local_revocation_basepoint));
|
||||
&basepoints[LOCAL].revocation));
|
||||
|
||||
/* keyset is const, we need a non-const ptr to set it up */
|
||||
keyset = ks = tal(tx, struct keyset);
|
||||
if (!derive_keyset(remote_per_commitment_point,
|
||||
remote_payment_basepoint,
|
||||
local_payment_basepoint,
|
||||
remote_htlc_basepoint,
|
||||
local_htlc_basepoint,
|
||||
remote_delayed_payment_basepoint,
|
||||
local_revocation_basepoint,
|
||||
&basepoints[REMOTE],
|
||||
&basepoints[LOCAL],
|
||||
ks))
|
||||
status_failed(STATUS_FAIL_INTERNAL_ERROR,
|
||||
"Deriving keyset for %"PRIu64, commit_num);
|
||||
@ -1998,7 +1971,7 @@ static void handle_their_unilateral(const struct bitcoin_tx *tx,
|
||||
&keyset->other_htlc_key));
|
||||
|
||||
if (!derive_simple_privkey(&secrets->payment_basepoint_secret,
|
||||
local_payment_basepoint,
|
||||
&basepoints[LOCAL].payment,
|
||||
remote_per_commitment_point,
|
||||
&payment_privkey))
|
||||
status_failed(STATUS_FAIL_INTERNAL_ERROR,
|
||||
@ -2006,7 +1979,7 @@ static void handle_their_unilateral(const struct bitcoin_tx *tx,
|
||||
commit_num);
|
||||
|
||||
if (!derive_simple_privkey(&secrets->htlc_basepoint_secret,
|
||||
local_htlc_basepoint,
|
||||
&basepoints[LOCAL].htlc,
|
||||
remote_per_commitment_point,
|
||||
&htlc_privkey))
|
||||
status_failed(STATUS_FAIL_INTERNAL_ERROR,
|
||||
@ -2138,7 +2111,7 @@ int main(int argc, char *argv[])
|
||||
struct secret seed;
|
||||
struct pubkey remote_per_commit_point, old_remote_per_commit_point;
|
||||
enum side funder;
|
||||
struct basepoints basepoints, remote_basepoints;
|
||||
struct basepoints basepoints[NUM_SIDES];
|
||||
struct shachain shachain;
|
||||
struct bitcoin_tx *tx;
|
||||
struct secrets secrets;
|
||||
@ -2173,7 +2146,7 @@ int main(int argc, char *argv[])
|
||||
&scriptpubkey[REMOTE],
|
||||
&our_wallet_pubkey,
|
||||
&funder,
|
||||
&remote_basepoints,
|
||||
&basepoints[REMOTE],
|
||||
&tx,
|
||||
&tx_blockheight,
|
||||
&reasonable_depth,
|
||||
@ -2184,7 +2157,7 @@ int main(int argc, char *argv[])
|
||||
master_badmsg(WIRE_ONCHAIN_INIT, msg);
|
||||
}
|
||||
|
||||
derive_basepoints(&seed, NULL, &basepoints, &secrets, &shaseed);
|
||||
derive_basepoints(&seed, NULL, &basepoints[LOCAL], &secrets, &shaseed);
|
||||
bitcoin_txid(tx, &txid);
|
||||
|
||||
/* FIXME: Filter as we go, don't load them all into mem! */
|
||||
@ -2240,8 +2213,8 @@ int main(int argc, char *argv[])
|
||||
*/
|
||||
struct sha256 revocation_preimage;
|
||||
commit_num = unmask_commit_number(tx, funder,
|
||||
&basepoints.payment,
|
||||
&remote_basepoints.payment);
|
||||
&basepoints[LOCAL].payment,
|
||||
&basepoints[REMOTE].payment);
|
||||
|
||||
status_trace("commitnum = %"PRIu64
|
||||
", revocations_received = %"PRIu64,
|
||||
@ -2251,12 +2224,7 @@ int main(int argc, char *argv[])
|
||||
handle_our_unilateral(tx, tx_blockheight, &txid,
|
||||
&secrets,
|
||||
&shaseed,
|
||||
&remote_basepoints.revocation,
|
||||
&remote_basepoints.payment,
|
||||
&basepoints.payment,
|
||||
&remote_basepoints.htlc,
|
||||
&basepoints.htlc,
|
||||
&basepoints.delayed_payment,
|
||||
basepoints,
|
||||
htlcs,
|
||||
tell_if_missing, tell_immediately,
|
||||
remote_htlc_sigs,
|
||||
@ -2275,12 +2243,7 @@ int main(int argc, char *argv[])
|
||||
tx_blockheight,
|
||||
&revocation_preimage,
|
||||
&secrets,
|
||||
&basepoints.revocation,
|
||||
&basepoints.payment,
|
||||
&remote_basepoints.payment,
|
||||
&basepoints.htlc,
|
||||
&remote_basepoints.htlc,
|
||||
&remote_basepoints.delayed_payment,
|
||||
basepoints,
|
||||
htlcs,
|
||||
tell_if_missing, tell_immediately,
|
||||
outs);
|
||||
@ -2298,12 +2261,7 @@ int main(int argc, char *argv[])
|
||||
handle_their_unilateral(tx, tx_blockheight,
|
||||
&txid, &secrets,
|
||||
&old_remote_per_commit_point,
|
||||
&basepoints.revocation,
|
||||
&basepoints.payment,
|
||||
&remote_basepoints.payment,
|
||||
&remote_basepoints.htlc,
|
||||
&basepoints.htlc,
|
||||
&remote_basepoints.delayed_payment,
|
||||
basepoints,
|
||||
htlcs,
|
||||
tell_if_missing,
|
||||
tell_immediately,
|
||||
@ -2313,12 +2271,7 @@ int main(int argc, char *argv[])
|
||||
handle_their_unilateral(tx, tx_blockheight,
|
||||
&txid, &secrets,
|
||||
&remote_per_commit_point,
|
||||
&basepoints.revocation,
|
||||
&basepoints.payment,
|
||||
&remote_basepoints.payment,
|
||||
&remote_basepoints.htlc,
|
||||
&basepoints.htlc,
|
||||
&remote_basepoints.delayed_payment,
|
||||
basepoints,
|
||||
htlcs,
|
||||
tell_if_missing,
|
||||
tell_immediately,
|
||||
|
@ -27,12 +27,8 @@ bool derive_basepoints(const struct secret *seed UNNEEDED,
|
||||
{ fprintf(stderr, "derive_basepoints called!\n"); abort(); }
|
||||
/* Generated stub for derive_keyset */
|
||||
bool derive_keyset(const struct pubkey *per_commitment_point UNNEEDED,
|
||||
const struct pubkey *self_payment_basepoint UNNEEDED,
|
||||
const struct pubkey *other_payment_basepoint UNNEEDED,
|
||||
const struct pubkey *self_htlc_basepoint UNNEEDED,
|
||||
const struct pubkey *other_htlc_basepoint UNNEEDED,
|
||||
const struct pubkey *self_delayed_basepoint UNNEEDED,
|
||||
const struct pubkey *other_revocation_basepoint UNNEEDED,
|
||||
const struct basepoints *self UNNEEDED,
|
||||
const struct basepoints *other UNNEEDED,
|
||||
struct keyset *keyset UNNEEDED)
|
||||
{ fprintf(stderr, "derive_keyset called!\n"); abort(); }
|
||||
/* Generated stub for derive_revocation_privkey */
|
||||
|
Loading…
Reference in New Issue
Block a user