+ let our_dust_limit_satoshis = Channel::derive_our_dust_limit_satoshis(background_feerate);
+ let our_channel_reserve_satoshis = Channel::get_our_channel_reserve_satoshis(msg.funding_satoshis);
+ if our_channel_reserve_satoshis < our_dust_limit_satoshis {
+ return_error_message!("Suitalbe channel reserve not found. aborting");
+ }
+ if msg.channel_reserve_satoshis < our_dust_limit_satoshis {
+ return_error_message!("channel_reserve_satoshis too small");
+ }
+ if our_channel_reserve_satoshis < msg.dust_limit_satoshis {
+ return_error_message!("Dust limit too high for our channel reserve");
+ }
+
+ // check if the funder's amount for the initial commitment tx is sufficient
+ // for full fee payment
+ let funders_amount_msat = msg.funding_satoshis * 1000 - msg.push_msat;
+ if funders_amount_msat < background_feerate * COMMITMENT_TX_BASE_WEIGHT {
+ return_error_message!("Insufficient funding amount for initial commitment");
+ }
+
+ let to_local_msat = msg.push_msat;
+ let to_remote_msat = funders_amount_msat - background_feerate * COMMITMENT_TX_BASE_WEIGHT;
+ if to_local_msat <= msg.channel_reserve_satoshis * 1000 && to_remote_msat <= our_channel_reserve_satoshis * 1000 {
+ return_error_message!("Insufficient funding amount for initial commitment");
+ }
+