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

Function create_open_channel_msg

tests/fuzz/fuzz-open_channel.c:364–424  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

362}
363
364static 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,

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