mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
daemon: encapsulate each side's state in a struct.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
0376e08fea
commit
b04392609a
@ -64,6 +64,9 @@ static struct peer *new_peer(struct lightningd_state *state,
|
||||
{
|
||||
struct peer *peer = tal(state, struct peer);
|
||||
|
||||
assert(offer_anchor == CMD_OPEN_WITH_ANCHOR
|
||||
|| offer_anchor == CMD_OPEN_WITHOUT_ANCHOR);
|
||||
|
||||
/* FIXME: Stop listening if too many peers? */
|
||||
list_add(&state->peers, &peer->list);
|
||||
|
||||
@ -72,11 +75,14 @@ static struct peer *new_peer(struct lightningd_state *state,
|
||||
peer->addr.protocol = addr_protocol;
|
||||
peer->io_data = NULL;
|
||||
peer->secrets = NULL;
|
||||
peer->offer_anchor = offer_anchor;
|
||||
assert(offer_anchor == CMD_OPEN_WITH_ANCHOR
|
||||
|| offer_anchor == CMD_OPEN_WITHOUT_ANCHOR);
|
||||
list_head_init(&peer->watches);
|
||||
|
||||
peer->us.offer_anchor = offer_anchor;
|
||||
peer->us.locktime = state->config.rel_locktime;
|
||||
peer->us.mindepth = state->config.anchor_confirms;
|
||||
/* FIXME: Make this dynamic. */
|
||||
peer->us.commit_fee = state->config.commitment_fee;
|
||||
|
||||
/* FIXME: Attach IO logging for this peer. */
|
||||
tal_add_destructor(peer, destroy_peer);
|
||||
|
||||
|
@ -7,6 +7,19 @@
|
||||
#include "state_types.h"
|
||||
#include <ccan/list/list.h>
|
||||
|
||||
struct peer_visible_state {
|
||||
/* CMD_OPEN_WITH_ANCHOR or CMD_OPEN_WITHOUT_ANCHOR */
|
||||
enum state_input offer_anchor;
|
||||
/* Key for commitment tx inputs, then key for commitment tx outputs */
|
||||
struct pubkey commitkey, finalkey;
|
||||
/* How long to they want the other's outputs locked (seconds) */
|
||||
unsigned int locktime;
|
||||
/* Minimum depth of anchor before channel usable. */
|
||||
unsigned int mindepth;
|
||||
/* Commitment fee they're offering (satoshi). */
|
||||
u64 commit_fee;
|
||||
};
|
||||
|
||||
struct peer {
|
||||
/* state->peers list */
|
||||
struct list_node list;
|
||||
@ -32,13 +45,11 @@ struct peer {
|
||||
/* Things we're watching for (see watches.c) */
|
||||
struct list_head watches;
|
||||
|
||||
/* Did we offer an anchor? */
|
||||
enum state_input offer_anchor;
|
||||
|
||||
/* Keys for transactions with this peer. */
|
||||
struct pubkey their_commitkey, their_finalkey;
|
||||
struct pubkey our_commitkey, our_finalkey;
|
||||
/* Private keys for dealing with this peer. */
|
||||
struct peer_secrets *secrets;
|
||||
|
||||
/* Stuff we have in common. */
|
||||
struct peer_visible_state us, them;
|
||||
};
|
||||
|
||||
void setup_listeners(struct lightningd_state *state, unsigned int portnum);
|
||||
|
@ -55,8 +55,8 @@ void peer_secrets_init(struct peer *peer)
|
||||
{
|
||||
peer->secrets = tal(peer, struct peer_secrets);
|
||||
|
||||
new_keypair(peer->state, &peer->secrets->commit, &peer->our_commitkey);
|
||||
new_keypair(peer->state, &peer->secrets->final, &peer->our_finalkey);
|
||||
new_keypair(peer->state, &peer->secrets->commit, &peer->us.commitkey);
|
||||
new_keypair(peer->state, &peer->secrets->final, &peer->us.finalkey);
|
||||
if (RAND_bytes(peer->secrets->revocation_seed.u.u8,
|
||||
sizeof(peer->secrets->revocation_seed.u.u8)) != 1)
|
||||
fatal("Could not get random bytes for revocation seed");
|
||||
|
@ -144,8 +144,8 @@ void add_anchor_watch_(struct peer *peer,
|
||||
insert_txwatch(peer, peer->state, peer, txid, anchor_cb, cbdata);
|
||||
insert_txo_watch(peer, txid, out, spend_cb, cbdata);
|
||||
|
||||
redeemscript = bitcoin_redeem_2of2(peer, &peer->their_commitkey,
|
||||
&peer->our_commitkey);
|
||||
redeemscript = bitcoin_redeem_2of2(peer, &peer->them.commitkey,
|
||||
&peer->us.commitkey);
|
||||
sha256(&h, redeemscript, tal_count(redeemscript));
|
||||
ripemd160(&redeemhash, h.u.u8, sizeof(h));
|
||||
tal_free(redeemscript);
|
||||
|
Loading…
Reference in New Issue
Block a user