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

Function opening_negotiate_msg

openingd/dualopend.c:1177–1310  ·  view source on GitHub ↗

~ Handle random messages we might get during opening negotiation, (eg. gossip) * returning the first non-handled one, or NULL if we aborted negotiation. */

Source from the content-addressed store, hash-verified

1175/*~ Handle random messages we might get during opening negotiation, (eg. gossip)
1176 * returning the first non-handled one, or NULL if we aborted negotiation. */
1177static u8 *opening_negotiate_msg(const tal_t *ctx, struct state *state)
1178{
1179 /* This is an event loop of its own. That's generally considered poor
1180 * form, but we use it in a very limited way. */
1181 for (;;) {
1182 u8 *msg;
1183 char *err;
1184 bool warning;
1185 struct channel_id actual;
1186 enum peer_wire t;
1187
1188 /* The event loop is responsible for freeing tmpctx, so our
1189 * temporary allocations don't grow unbounded. */
1190 clean_tmpctx();
1191
1192 /* This helper routine polls the peer. */
1193 msg = peer_read(ctx, state->pps);
1194
1195 /* BOLT #1:
1196 *
1197 * A receiving node:
1198 * - upon receiving a message of _odd_, unknown type:
1199 * - MUST ignore the received message.
1200 */
1201 if (is_unknown_msg_discardable(msg))
1202 continue;
1203
1204 /* A helper which decodes an error. */
1205 if (is_peer_error(tmpctx, msg, &state->channel_id,
1206 &err, &warning)) {
1207 /* BOLT #1:
1208 *
1209 * - if no existing channel is referred to by `channel_id`:
1210 * - MUST ignore the message.
1211 */
1212 /* In this case, is_peer_error returns true, but sets
1213 * err to NULL */
1214 if (!err) {
1215 tal_free(msg);
1216 continue;
1217 }
1218 negotiation_aborted(state,
1219 tal_fmt(tmpctx, "They sent %s",
1220 err));
1221 /* Return NULL so caller knows to stop negotiating. */
1222 return NULL;
1223 }
1224
1225 /*~ We do not support multiple "live" channels, though the
1226 * protocol has a "channel_id" field in all non-gossip messages
1227 * so it's possible. Our one-process-one-channel mechanism
1228 * keeps things simple: if we wanted to change this, we would
1229 * probably be best with another daemon to de-multiplex them;
1230 * this could be connectd itself, in fact. */
1231 if (is_wrong_channel(msg, &state->channel_id, &actual)) {
1232 status_debug("Rejecting %s for unknown channel_id %s",
1233 peer_wire_name(fromwire_peektype(msg)),
1234 type_to_string(tmpctx, struct channel_id,

Callers 5

run_tx_interactiveFunction · 0.70
accepter_commitsFunction · 0.70
opener_commitsFunction · 0.70
opener_startFunction · 0.70
rbf_local_startFunction · 0.70

Calls 15

clean_tmpctxFunction · 0.85
peer_readFunction · 0.85
is_peer_errorFunction · 0.85
tal_freeFunction · 0.85
is_wrong_channelFunction · 0.85
peer_writeFunction · 0.85
handle_tx_sigsFunction · 0.85
handle_channel_readyFunction · 0.85
dualopen_shutdownFunction · 0.85
negotiation_abortedFunction · 0.70
handle_peer_shutdownFunction · 0.70
shutdown_completeFunction · 0.70

Tested by

no test coverage detected