~ This is the key function that checks that their configuration is reasonable: * it applied for both the case where they're trying to open a channel, and when * they've accepted our open. */
| 13 | * it applied for both the case where they're trying to open a channel, and when |
| 14 | * they've accepted our open. */ |
| 15 | bool check_config_bounds(const tal_t *ctx, |
| 16 | struct amount_sat funding, |
| 17 | u32 feerate_per_kw, |
| 18 | u32 max_to_self_delay, |
| 19 | struct amount_msat min_effective_htlc_capacity, |
| 20 | const struct channel_config *remoteconf, |
| 21 | const struct channel_config *localconf, |
| 22 | bool option_anchor_outputs, |
| 23 | char **err_reason) |
| 24 | { |
| 25 | struct amount_sat capacity; |
| 26 | struct amount_sat reserve; |
| 27 | struct amount_sat fee; |
| 28 | |
| 29 | /* BOLT #2: |
| 30 | * |
| 31 | * The receiving node MUST fail the channel if: |
| 32 | *... |
| 33 | * - `to_self_delay` is unreasonably large. |
| 34 | */ |
| 35 | if (remoteconf->to_self_delay > max_to_self_delay) { |
| 36 | *err_reason = tal_fmt(ctx, |
| 37 | "to_self_delay %u larger than %u", |
| 38 | remoteconf->to_self_delay, |
| 39 | max_to_self_delay); |
| 40 | return false; |
| 41 | } |
| 42 | |
| 43 | /* BOLT #2: |
| 44 | * |
| 45 | * The receiving node MAY fail the channel if: |
| 46 | *... |
| 47 | * - `funding_satoshis` is too small. |
| 48 | * - it considers `htlc_minimum_msat` too large. |
| 49 | * - it considers `max_htlc_value_in_flight_msat` too small. |
| 50 | * - it considers `channel_reserve_satoshis` too large. |
| 51 | * - it considers `max_accepted_htlcs` too small. |
| 52 | */ |
| 53 | /* We accumulate this into an effective bandwidth minimum. */ |
| 54 | |
| 55 | /* Add both reserves to deduct from capacity. */ |
| 56 | if (!amount_sat_add(&reserve, |
| 57 | remoteconf->channel_reserve, |
| 58 | localconf->channel_reserve)) { |
| 59 | *err_reason = tal_fmt(ctx, |
| 60 | "channel_reserve_satoshis %s" |
| 61 | " too large", |
| 62 | type_to_string(ctx, struct amount_sat, |
| 63 | &remoteconf->channel_reserve)); |
| 64 | return false; |
| 65 | } |
| 66 | |
| 67 | /* BOLT #2: |
| 68 | * - if `option_anchors` applies to this commitment |
| 69 | * transaction and the sending node is the funder: |
| 70 | * - MUST be able to additionally pay for `to_local_anchor` and |
| 71 | * `to_remote_anchor` above its reserve. |
| 72 | */ |
no test coverage detected