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

Function create_open_channel_msg

tests/fuzz/fuzz-open_channel.c:367–427  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

runFunction · 0.85

Calls 10

amount_sat_greaterFunction · 0.85
feature_negotiatedFunction · 0.85
amount_msat_greater_satFunction · 0.85
fromwire_amount_satFunction · 0.50
fromwire_amount_msatFunction · 0.50
fromwire_u32Function · 0.50
fromwire_u16Function · 0.50
fromwire_u8Function · 0.50
amount_sat_to_msatFunction · 0.50
amount_sat_addFunction · 0.50

Tested by

no test coverage detected