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

Function extract_channel_id

wire/peer_wire.c:148–426  ·  view source on GitHub ↗

Extract channel_id from various packets, return true if possible. */

Source from the content-addressed store, hash-verified

146
147/* Extract channel_id from various packets, return true if possible. */
148bool extract_channel_id(const u8 *in_pkt, struct channel_id *channel_id)
149{
150 const u8 *cursor = in_pkt;
151 size_t max = tal_bytelen(in_pkt);
152 enum peer_wire t;
153
154 t = fromwire_u16(&cursor, &max);
155
156 /* We carefully quote bolts here, in case anything changes! */
157 switch (t) {
158 /* These ones don't have a channel_id */
159 case WIRE_INIT:
160 case WIRE_PING:
161 case WIRE_PONG:
162 case WIRE_CHANNEL_ANNOUNCEMENT:
163 case WIRE_NODE_ANNOUNCEMENT:
164 case WIRE_CHANNEL_UPDATE:
165 case WIRE_QUERY_SHORT_CHANNEL_IDS:
166 case WIRE_REPLY_SHORT_CHANNEL_IDS_END:
167 case WIRE_QUERY_CHANNEL_RANGE:
168 case WIRE_REPLY_CHANNEL_RANGE:
169 case WIRE_GOSSIP_TIMESTAMP_FILTER:
170 case WIRE_ONION_MESSAGE:
171 case WIRE_PEER_STORAGE:
172 case WIRE_PEER_STORAGE_RETRIEVAL:
173 case WIRE_PROTOCOL_BATCH_ELEMENT:
174 return false;
175
176 /* Special cases: */
177 case WIRE_ERROR:
178 /* BOLT #1:
179 * 1. type: 17 (`error`)
180 * 2. data:
181 * * [`channel_id`:`channel_id`]
182 */
183 /* fall thru */
184 case WIRE_WARNING:
185 /* BOLT #1:
186 * 1. type: 1 (`warning`)
187 * 2. data:
188 * * [`channel_id`:`channel_id`]
189 */
190 /* BOLT #1:
191 *
192 * The channel is referred to by `channel_id`, unless
193 * `channel_id` is 0
194 */
195 if (!fromwire_channel_id(&cursor, &max, channel_id))
196 return false;
197 if (memeqzero(channel_id->id, sizeof(channel_id->id)))
198 return false;
199 return true;
200
201 case WIRE_OPEN_CHANNEL:
202 /* BOLT #2:
203 * 1. type: 32 (`open_channel`)
204 * 2. data:
205 * * [`chain_hash`:`chain_hash`]

Callers 4

maybe_update_channelidFunction · 0.85
read_body_from_peer_doneFunction · 0.85
handle_peer_inFunction · 0.85
handle_peer_inFunction · 0.85

Calls 5

tal_bytelenFunction · 0.85
memeqzeroFunction · 0.85
fromwire_u16Function · 0.70
fromwire_padFunction · 0.70
fromwire_channel_idFunction · 0.50

Tested by

no test coverage detected