Browse Source

lightningd/peer_control: save funder side in struct peer.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 8 years ago
parent
commit
93849b1e02
  1. 17
      lightningd/peer_control.c
  2. 4
      lightningd/peer_control.h

17
lightningd/peer_control.c

@ -1414,7 +1414,7 @@ static bool peer_start_channeld_hsmfd(struct subd *hsm, const u8 *resp,
} }
/* opening is done, start lightningd_channel for peer. */ /* opening is done, start lightningd_channel for peer. */
static void peer_start_channeld(struct peer *peer, enum side funder, static void peer_start_channeld(struct peer *peer,
const struct channel_config *their_config, const struct channel_config *their_config,
const struct crypto_state *crypto_state, const struct crypto_state *crypto_state,
const secp256k1_ecdsa_signature *commit_sig, const secp256k1_ecdsa_signature *commit_sig,
@ -1432,8 +1432,8 @@ static void peer_start_channeld(struct peer *peer, enum side funder,
/* Now we can consider balance set. */ /* Now we can consider balance set. */
peer->balance = tal_arr(peer, u64, NUM_SIDES); peer->balance = tal_arr(peer, u64, NUM_SIDES);
peer->balance[funder] = peer->funding_satoshi * 1000 - peer->push_msat; peer->balance[peer->funder] = peer->funding_satoshi * 1000 - peer->push_msat;
peer->balance[!funder] = peer->push_msat; peer->balance[!peer->funder] = peer->push_msat;
cds->peer = peer; cds->peer = peer;
/* Prepare init message now while we have access to all the data. */ /* Prepare init message now while we have access to all the data. */
@ -1449,7 +1449,7 @@ static void peer_start_channeld(struct peer *peer, enum side funder,
&theirbase->payment, &theirbase->payment,
&theirbase->delayed_payment, &theirbase->delayed_payment,
their_per_commit_point, their_per_commit_point,
funder == LOCAL, peer->funder == LOCAL,
cfg->fee_base, cfg->fee_base,
cfg->fee_per_satoshi, cfg->fee_per_satoshi,
peer->funding_satoshi, peer->funding_satoshi,
@ -1514,7 +1514,7 @@ static bool opening_release_tx(struct subd *opening, const u8 *resp,
opening_got_hsm_funding_sig, fc); opening_got_hsm_funding_sig, fc);
/* Start normal channel daemon. */ /* Start normal channel daemon. */
peer_start_channeld(fc->peer, LOCAL, peer_start_channeld(fc->peer,
&their_config, &crypto_state, &commit_sig, &their_config, &crypto_state, &commit_sig,
&fc->remote_fundingkey, &theirbase, &fc->remote_fundingkey, &theirbase,
&their_per_commit_point); &their_per_commit_point);
@ -1592,7 +1592,7 @@ static bool opening_accept_finish_response(struct subd *opening,
} }
/* On to normal operation! */ /* On to normal operation! */
peer_start_channeld(peer, REMOTE, &their_config, &crypto_state, peer_start_channeld(peer, &their_config, &crypto_state,
&first_commit_sig, &remote_fundingkey, &theirbase, &first_commit_sig, &remote_fundingkey, &theirbase,
&their_per_commit_point); &their_per_commit_point);
@ -1699,6 +1699,9 @@ void peer_accept_open(struct peer *peer,
/* We handed off peer fd */ /* We handed off peer fd */
peer->fd = -1; peer->fd = -1;
/* They will open channel. */
peer->funder = REMOTE;
/* BOLT #2: /* BOLT #2:
* *
* The sender SHOULD set `minimum-depth` to an amount where * The sender SHOULD set `minimum-depth` to an amount where
@ -1771,6 +1774,8 @@ static bool gossip_peer_released(struct subd *gossip,
/* They took our fd. */ /* They took our fd. */
fc->peer->fd = -1; fc->peer->fd = -1;
/* We will fund channel */
fc->peer->funder = LOCAL;
channel_config(ld, &fc->peer->our_config, channel_config(ld, &fc->peer->our_config,
&max_to_self_delay, &max_minimum_depth, &max_to_self_delay, &max_minimum_depth,
&min_effective_htlc_capacity_msat); &min_effective_htlc_capacity_msat);

4
lightningd/peer_control.h

@ -3,6 +3,7 @@
#include "config.h" #include "config.h"
#include <ccan/compiler/compiler.h> #include <ccan/compiler/compiler.h>
#include <ccan/list/list.h> #include <ccan/list/list.h>
#include <daemon/htlc.h>
#include <daemon/json.h> #include <daemon/json.h>
#include <daemon/netaddr.h> #include <daemon/netaddr.h>
#include <lightningd/channel_config.h> #include <lightningd/channel_config.h>
@ -18,6 +19,9 @@ struct peer {
/* Unique ID (works before we know their pubkey) */ /* Unique ID (works before we know their pubkey) */
u64 unique_id; u64 unique_id;
/* Which side offered channel? */
enum side funder;
/* Inside ld->peers. */ /* Inside ld->peers. */
struct list_node list; struct list_node list;

Loading…
Cancel
Save