MCPcopy Create free account
hub / github.com/ElementsProject/lightning / routing_add_private_channel

Function routing_add_private_channel

gossipd/routing.c:1961–2030  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1959}
1960
1961bool routing_add_private_channel(struct routing_state *rstate,
1962 const struct node_id *id,
1963 struct amount_sat capacity,
1964 const u8 *chan_ann, u64 index)
1965{
1966 struct short_channel_id scid;
1967 struct node_id node_id[2];
1968 struct pubkey ignorekey;
1969 struct chan *chan;
1970 u8 *features;
1971 secp256k1_ecdsa_signature ignoresig;
1972 struct bitcoin_blkid chain_hash;
1973
1974 if (!fromwire_channel_announcement(tmpctx, chan_ann,
1975 &ignoresig,
1976 &ignoresig,
1977 &ignoresig,
1978 &ignoresig,
1979 &features,
1980 &chain_hash,
1981 &scid,
1982 &node_id[0],
1983 &node_id[1],
1984 &ignorekey,
1985 &ignorekey))
1986 return false;
1987
1988 /* Happens on channeld restart. */
1989 if (get_channel(rstate, &scid))
1990 return true;
1991
1992 /* Make sure this id (if any) was allowed to create this */
1993 if (id) {
1994 struct node_id expected[2];
1995 int cmp = node_id_cmp(&rstate->local_id, id);
1996
1997 if (cmp < 0) {
1998 expected[0] = rstate->local_id;
1999 expected[1] = *id;
2000 } else if (cmp > 0) {
2001 expected[0] = *id;
2002 expected[1] = rstate->local_id;
2003 } else {
2004 /* lightningd sets id, so this is fatal */
2005 status_failed(STATUS_FAIL_MASTER_IO,
2006 "private_channel peer was us?");
2007 }
2008
2009 if (!node_id_eq(&node_id[0], &expected[0])
2010 || !node_id_eq(&node_id[1], &expected[1])) {
2011 status_peer_broken(id, "private channel %s<->%s invalid",
2012 type_to_string(tmpctx, struct node_id,
2013 &node_id[0]),
2014 type_to_string(tmpctx, struct node_id,
2015 &node_id[1]));
2016 return false;
2017 }
2018 }

Callers 2

gossip_store_loadFunction · 0.85

Calls 7

get_channelFunction · 0.85
node_id_eqFunction · 0.85
new_chanFunction · 0.85
gossip_store_addFunction · 0.70
node_id_cmpFunction · 0.50
status_failedFunction · 0.50
type_to_stringClass · 0.50

Tested by

no test coverage detected