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);
|
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? */
|
/* FIXME: Stop listening if too many peers? */
|
||||||
list_add(&state->peers, &peer->list);
|
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->addr.protocol = addr_protocol;
|
||||||
peer->io_data = NULL;
|
peer->io_data = NULL;
|
||||||
peer->secrets = 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);
|
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. */
|
/* FIXME: Attach IO logging for this peer. */
|
||||||
tal_add_destructor(peer, destroy_peer);
|
tal_add_destructor(peer, destroy_peer);
|
||||||
|
|
||||||
|
@ -7,6 +7,19 @@
|
|||||||
#include "state_types.h"
|
#include "state_types.h"
|
||||||
#include <ccan/list/list.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 {
|
struct peer {
|
||||||
/* state->peers list */
|
/* state->peers list */
|
||||||
struct list_node list;
|
struct list_node list;
|
||||||
@ -32,13 +45,11 @@ struct peer {
|
|||||||
/* Things we're watching for (see watches.c) */
|
/* Things we're watching for (see watches.c) */
|
||||||
struct list_head watches;
|
struct list_head watches;
|
||||||
|
|
||||||
/* Did we offer an anchor? */
|
/* Private keys for dealing with this peer. */
|
||||||
enum state_input offer_anchor;
|
|
||||||
|
|
||||||
/* Keys for transactions with this peer. */
|
|
||||||
struct pubkey their_commitkey, their_finalkey;
|
|
||||||
struct pubkey our_commitkey, our_finalkey;
|
|
||||||
struct peer_secrets *secrets;
|
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);
|
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);
|
peer->secrets = tal(peer, struct peer_secrets);
|
||||||
|
|
||||||
new_keypair(peer->state, &peer->secrets->commit, &peer->our_commitkey);
|
new_keypair(peer->state, &peer->secrets->commit, &peer->us.commitkey);
|
||||||
new_keypair(peer->state, &peer->secrets->final, &peer->our_finalkey);
|
new_keypair(peer->state, &peer->secrets->final, &peer->us.finalkey);
|
||||||
if (RAND_bytes(peer->secrets->revocation_seed.u.u8,
|
if (RAND_bytes(peer->secrets->revocation_seed.u.u8,
|
||||||
sizeof(peer->secrets->revocation_seed.u.u8)) != 1)
|
sizeof(peer->secrets->revocation_seed.u.u8)) != 1)
|
||||||
fatal("Could not get random bytes for revocation seed");
|
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_txwatch(peer, peer->state, peer, txid, anchor_cb, cbdata);
|
||||||
insert_txo_watch(peer, txid, out, spend_cb, cbdata);
|
insert_txo_watch(peer, txid, out, spend_cb, cbdata);
|
||||||
|
|
||||||
redeemscript = bitcoin_redeem_2of2(peer, &peer->their_commitkey,
|
redeemscript = bitcoin_redeem_2of2(peer, &peer->them.commitkey,
|
||||||
&peer->our_commitkey);
|
&peer->us.commitkey);
|
||||||
sha256(&h, redeemscript, tal_count(redeemscript));
|
sha256(&h, redeemscript, tal_count(redeemscript));
|
||||||
ripemd160(&redeemhash, h.u.u8, sizeof(h));
|
ripemd160(&redeemhash, h.u.u8, sizeof(h));
|
||||||
tal_free(redeemscript);
|
tal_free(redeemscript);
|
||||||
|
Loading…
Reference in New Issue
Block a user