From 93849b1e02ffcb901e429163ea384b1ba1c1360b Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 22 May 2017 20:54:47 +0930 Subject: [PATCH] lightningd/peer_control: save funder side in struct peer. Signed-off-by: Rusty Russell --- lightningd/peer_control.c | 17 +++++++++++------ lightningd/peer_control.h | 4 ++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 4ebecc340..4c1a47c79 100644 --- a/lightningd/peer_control.c +++ b/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. */ -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 crypto_state *crypto_state, 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. */ peer->balance = tal_arr(peer, u64, NUM_SIDES); - peer->balance[funder] = peer->funding_satoshi * 1000 - peer->push_msat; - peer->balance[!funder] = peer->push_msat; + peer->balance[peer->funder] = peer->funding_satoshi * 1000 - peer->push_msat; + peer->balance[!peer->funder] = peer->push_msat; cds->peer = peer; /* 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->delayed_payment, their_per_commit_point, - funder == LOCAL, + peer->funder == LOCAL, cfg->fee_base, cfg->fee_per_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); /* Start normal channel daemon. */ - peer_start_channeld(fc->peer, LOCAL, + peer_start_channeld(fc->peer, &their_config, &crypto_state, &commit_sig, &fc->remote_fundingkey, &theirbase, &their_per_commit_point); @@ -1592,7 +1592,7 @@ static bool opening_accept_finish_response(struct subd *opening, } /* 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, &their_per_commit_point); @@ -1699,6 +1699,9 @@ void peer_accept_open(struct peer *peer, /* We handed off peer fd */ peer->fd = -1; + /* They will open channel. */ + peer->funder = REMOTE; + /* BOLT #2: * * 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. */ fc->peer->fd = -1; + /* We will fund channel */ + fc->peer->funder = LOCAL; channel_config(ld, &fc->peer->our_config, &max_to_self_delay, &max_minimum_depth, &min_effective_htlc_capacity_msat); diff --git a/lightningd/peer_control.h b/lightningd/peer_control.h index 5737ff56f..856fd0681 100644 --- a/lightningd/peer_control.h +++ b/lightningd/peer_control.h @@ -3,6 +3,7 @@ #include "config.h" #include #include +#include #include #include #include @@ -18,6 +19,9 @@ struct peer { /* Unique ID (works before we know their pubkey) */ u64 unique_id; + /* Which side offered channel? */ + enum side funder; + /* Inside ld->peers. */ struct list_node list;