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

Function get_agreed_channelfeatures

common/features.c:302–326  ·  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

300 * it sets.
301 */
302u8 *get_agreed_channelfeatures(const tal_t *ctx,
303 const struct feature_set *our_features,
304 const u8 *their_features)
305{
306 u8 *f = tal_dup_talarr(ctx, u8, our_features->bits[CHANNEL_FEATURE]);
307 size_t max_len = 0;
308
309 /* Clear any features which they didn't offer too */
310 for (size_t i = 0; i < 8 * tal_count(f); i += 2) {
311 if (!feature_offered(f, i))
312 continue;
313 if (!feature_offered(their_features, i)) {
314 clear_feature_bit(f, COMPULSORY_FEATURE(i));
315 clear_feature_bit(f, OPTIONAL_FEATURE(i));
316 trim_features(&f);
317 continue;
318 }
319 max_len = (i / 8) + 1;
320 }
321
322 /* Trim to length (unless it's already NULL). */
323 if (f)
324 tal_resize(&f, max_len);
325 return f;
326}
327
328bool feature_is_set(const u8 *features, size_t bit)
329{

Callers 1

Calls 3

feature_offeredFunction · 0.85
clear_feature_bitFunction · 0.85
trim_featuresFunction · 0.85

Tested by

no test coverage detected