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

Function get_agreed_channelfeatures

common/features.c:316–340  ·  view source on GitHub ↗

BOLT #7: * * - MUST set `features` based on what features were negotiated for this channel, according to [BOLT #9](09-features.md#assigned-features-flags) * - MUST set `len` to the minimum length required to hold the `features` bits * it sets. */

Source from the content-addressed store, hash-verified

314 * it sets.
315 */
316u8 *get_agreed_channelfeatures(const tal_t *ctx,
317 const struct feature_set *our_features,
318 const u8 *their_features)
319{
320 u8 *f = tal_dup_talarr(ctx, u8, our_features->bits[CHANNEL_FEATURE]);
321 size_t max_len = 0;
322
323 /* Clear any features which they didn't offer too */
324 for (size_t i = 0; i < 8 * tal_count(f); i += 2) {
325 if (!feature_offered(f, i))
326 continue;
327 if (!feature_offered(their_features, i)) {
328 clear_feature_bit(f, COMPULSORY_FEATURE(i));
329 clear_feature_bit(f, OPTIONAL_FEATURE(i));
330 trim_features(&f);
331 continue;
332 }
333 max_len = (i / 8) + 1;
334 }
335
336 /* Trim to length (unless it's already NULL). */
337 if (f)
338 tal_resize(&f, max_len);
339 return f;
340}
341
342bool feature_is_set(const u8 *features, size_t bit)
343{

Callers 3

tell_gossipd_new_channelFunction · 0.85

Calls 3

clear_feature_bitFunction · 0.85
trim_featuresFunction · 0.85
feature_offeredFunction · 0.70

Tested by

no test coverage detected