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. */
| 314 | * it sets. |
| 315 | */ |
| 316 | u8 *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 | |
| 342 | bool feature_is_set(const u8 *features, size_t bit) |
| 343 | { |
no test coverage detected