Skip to content

Commit 55beb12

Browse files
committed
gossip: Add local channels when channeld tells us to
This adds the channel from us to the remote node and activates it with our local parameters. Signed-off-by: Christian Decker <[email protected]>
1 parent 90b79c6 commit 55beb12

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

gossipd/gossip.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <ccan/mem/mem.h>
1010
#include <ccan/noerr/noerr.h>
1111
#include <ccan/read_write_all/read_write_all.h>
12+
#include <ccan/structeq/structeq.h>
1213
#include <ccan/take/take.h>
1314
#include <ccan/tal/str/str.h>
1415
#include <ccan/timer/timer.h>
@@ -737,6 +738,48 @@ static void handle_get_update(struct peer *peer, const u8 *msg)
737738
daemon_conn_send(peer->remote, take(msg));
738739
}
739740

741+
static void handle_local_add_channel(struct peer *peer, u8 *msg)
742+
{
743+
struct routing_state *rstate = peer->daemon->rstate;
744+
struct short_channel_id scid;
745+
struct sha256_double chain_hash;
746+
struct pubkey remote_node_id;
747+
u16 flags, cltv_expiry_delta, direction;
748+
u32 fee_base_msat, fee_proportional_millionths;
749+
u64 htlc_minimum_msat;
750+
struct node_connection *c;
751+
752+
if (!fromwire_gossip_local_add_channel(
753+
msg, NULL, &scid, &chain_hash, &remote_node_id, &flags,
754+
&cltv_expiry_delta, &htlc_minimum_msat, &fee_base_msat,
755+
&fee_proportional_millionths)) {
756+
status_trace("Unable to parse local_add_channel message: %s", tal_hex(msg, msg));
757+
return;
758+
}
759+
760+
if (!structeq(&chain_hash, &rstate->chain_hash)) {
761+
status_trace("Received channel_announcement for unknown chain %s",
762+
type_to_string(msg, struct sha256_double,&chain_hash));
763+
return;
764+
}
765+
766+
if (get_connection_by_scid(rstate, &scid, 0) || get_connection_by_scid(rstate, &scid, 0)) {
767+
status_trace("Attempted to local_add_channel a know channel");
768+
return;
769+
}
770+
771+
direction = get_channel_direction(&rstate->local_id, &remote_node_id);
772+
c = half_add_connection(rstate, &rstate->local_id, &remote_node_id, &scid, direction);
773+
774+
c->active = true;
775+
c->last_timestamp = 0;
776+
c->delay = cltv_expiry_delta;
777+
c->htlc_minimum_msat = htlc_minimum_msat;
778+
c->base_fee = fee_base_msat;
779+
c->proportional_fee = fee_proportional_millionths;
780+
status_trace("Added and updated local channel %s/%d", type_to_string(msg, struct short_channel_id, &scid), direction);
781+
}
782+
740783
/**
741784
* owner_msg_in - Called by the `peer->owner_conn` upon receiving a
742785
* message
@@ -753,7 +796,15 @@ static struct io_plan *owner_msg_in(struct io_conn *conn,
753796
handle_gossip_msg(peer->daemon, dc->msg_in);
754797
} else if (type == WIRE_GOSSIP_GET_UPDATE) {
755798
handle_get_update(peer, dc->msg_in);
799+
} else if (type == WIRE_GOSSIP_LOCAL_ADD_CHANNEL) {
800+
handle_local_add_channel(peer, dc->msg_in);
801+
} else {
802+
status_failed(
803+
STATUS_FAIL_INTERNAL_ERROR,
804+
"Gossip received unknown message of type %s from owner",
805+
gossip_wire_type_name(type));
756806
}
807+
757808
return daemon_conn_read_next(conn, dc);
758809
}
759810

0 commit comments

Comments
 (0)