| 362 | } |
| 363 | |
| 364 | static u8 *create_open_channel_msg(const tal_t *ctx, struct state *state) |
| 365 | { |
| 366 | struct amount_sat funding_satoshis = fromwire_amount_sat(cursor, max); |
| 367 | struct amount_msat push_msat = fromwire_amount_msat(cursor, max); |
| 368 | struct amount_sat dust_limit_satoshis = fromwire_amount_sat(cursor, max); |
| 369 | struct amount_msat max_htlc_value_in_flight_msat = fromwire_amount_msat(cursor, max); |
| 370 | struct amount_sat channel_reserve_satoshis = fromwire_amount_sat(cursor, max); |
| 371 | struct amount_msat htlc_minimum_msat = fromwire_amount_msat(cursor, max); |
| 372 | u32 feerate_per_kw = fromwire_u32(cursor, max); |
| 373 | u16 to_self_delay = fromwire_u16(cursor, max); |
| 374 | u16 max_accepted_htlcs = fromwire_u16(cursor, max); |
| 375 | u8 channel_flags = fromwire_u8(cursor, max); |
| 376 | |
| 377 | /* These checks get us past check_config_bounds() in fundee_channel(). */ |
| 378 | if (amount_sat_greater(funding_satoshis, chainparams->max_funding) && |
| 379 | !feature_negotiated(state->our_features, state->their_features, OPT_LARGE_CHANNELS)) |
| 380 | funding_satoshis = chainparams->max_funding; |
| 381 | |
| 382 | if (amount_msat_greater_sat(push_msat, funding_satoshis) && |
| 383 | !amount_sat_to_msat(&push_msat, funding_satoshis)) |
| 384 | return NULL; |
| 385 | |
| 386 | if (feerate_per_kw < state->min_feerate) |
| 387 | feerate_per_kw = state->min_feerate; |
| 388 | if (feerate_per_kw > state->max_feerate) |
| 389 | feerate_per_kw = state->max_feerate; |
| 390 | |
| 391 | if (max_accepted_htlcs > 483 || max_accepted_htlcs == 0) |
| 392 | max_accepted_htlcs = 483; |
| 393 | |
| 394 | if (to_self_delay > state->max_to_self_delay) |
| 395 | to_self_delay = state->max_to_self_delay; |
| 396 | |
| 397 | struct amount_sat total_reserve; |
| 398 | if (!amount_sat_add(&total_reserve, |
| 399 | channel_reserve_satoshis, |
| 400 | state->localconf.channel_reserve)) |
| 401 | return NULL; |
| 402 | |
| 403 | if (amount_sat_greater(total_reserve, funding_satoshis)) |
| 404 | return NULL; |
| 405 | |
| 406 | struct tlv_open_channel_tlvs *tlvs = tlv_open_channel_tlvs_new(ctx); |
| 407 | |
| 408 | return towire_open_channel(ctx, |
| 409 | &chainparams->genesis_blockhash, |
| 410 | &state->channel_id, |
| 411 | funding_satoshis, |
| 412 | push_msat, |
| 413 | dust_limit_satoshis, |
| 414 | max_htlc_value_in_flight_msat, |
| 415 | channel_reserve_satoshis, |
| 416 | htlc_minimum_msat, |
| 417 | feerate_per_kw, |
| 418 | to_self_delay, |
| 419 | max_accepted_htlcs, |
| 420 | &dummy_pubkey, &dummy_pubkey, &dummy_pubkey, |
| 421 | &dummy_pubkey, &dummy_pubkey, &dummy_pubkey, |
no test coverage detected