@ -101,7 +101,7 @@ struct channel *new_full_channel(const tal_t *ctx,
const struct pubkey * local_funding_pubkey ,
const struct pubkey * remote_funding_pubkey ,
bool option_static_remotekey ,
enum side fund er)
enum side open er)
{
struct channel * channel = new_initial_channel ( ctx ,
funding_txid ,
@ -116,7 +116,7 @@ struct channel *new_full_channel(const tal_t *ctx,
local_funding_pubkey ,
remote_funding_pubkey ,
option_static_remotekey ,
fund er) ;
open er) ;
if ( channel ) {
channel - > htlcs = tal ( channel , struct htlc_map ) ;
@ -295,7 +295,7 @@ struct bitcoin_tx **channel_txs(const tal_t *ctx,
txs = tal_arr ( ctx , struct bitcoin_tx * , 1 ) ;
txs [ 0 ] = commit_tx (
ctx , & channel - > funding_txid , channel - > funding_txout ,
channel - > funding , channel - > fund er,
channel - > funding , channel - > open er,
channel - > config [ ! side ] . to_self_delay , & keyset ,
channel_feerate ( channel , side ) ,
channel - > config [ side ] . dust_limit , channel - > view [ side ] . owed [ side ] ,
@ -384,8 +384,8 @@ static struct amount_sat fee_for_htlcs(const struct channel *channel,
}
/*
* There is a corner case where the fund er can spend so much that the
* non - fund er can ' t add any non - dust HTLCs ( since the fund er would
* There is a corner case where the open er can spend so much that the
* non - open er can ' t add any non - dust HTLCs ( since the open er would
* have to pay the additional fee , but it can ' t afford to ) . This
* leads to the channel starving at the feast ! This was reported by
* ACINQ ' s @ t - bast
@ -394,7 +394,7 @@ static struct amount_sat fee_for_htlcs(const struct channel *channel,
* ( https : //github.com/ElementsProject/lightning/pull/3498).
*
* To mostly avoid this situation , at least from our side , we apply an
* additional constraint when we ' re fund er trying to add an HTLC : make
* additional constraint when we ' re open er trying to add an HTLC : make
* sure we can afford one more HTLC , even if fees increase by 100 % .
*
* We could do this for the peer , as well , by rejecting their HTLC
@ -408,7 +408,7 @@ static struct amount_sat fee_for_htlcs(const struct channel *channel,
* This mitigation will become BOLT # 2 standard by :
* https : //github.com/lightningnetwork/lightning-rfc/issues/740
*/
static bool local_fund er_has_fee_headroom ( const struct channel * channel ,
static bool local_open er_has_fee_headroom ( const struct channel * channel ,
struct amount_msat remainder ,
const struct htlc * * committed ,
const struct htlc * * adding ,
@ -418,7 +418,7 @@ static bool local_funder_has_fee_headroom(const struct channel *channel,
size_t untrimmed ;
struct amount_sat fee ;
assert ( channel - > fund er = = LOCAL ) ;
assert ( channel - > open er = = LOCAL ) ;
/* How many untrimmed at current feerate? Increasing feerate can
* only * reduce * this number , so use current feerate here ! */
@ -540,7 +540,7 @@ static enum channel_add_err add_htlc(struct channel *channel,
*/
/* Also we should not add more htlc's than sender or recipient
* configured . This mitigates attacks in which a peer can force the
* fund er of the channel to pay unnecessary onchain fees during a fee
* open er of the channel to pay unnecessary onchain fees during a fee
* spike with large commitment transactions .
*/
min_concurrent_htlcs = channel - > config [ recipient ] . max_accepted_htlcs ;
@ -614,7 +614,7 @@ static enum channel_add_err add_htlc(struct channel *channel,
& remainder ) )
return CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED ;
if ( channel - > funder = = sender ) {
if ( channel - > opener = = sender ) {
if ( amount_msat_less_sat ( remainder , fee ) ) {
status_debug ( " Cannot afford fee %s with %s above reserve " ,
type_to_string ( tmpctx , struct amount_sat ,
@ -625,7 +625,7 @@ static enum channel_add_err add_htlc(struct channel *channel,
}
if ( sender = = LOCAL
& & ! local_fund er_has_fee_headroom ( channel ,
& & ! local_open er_has_fee_headroom ( channel ,
remainder ,
committed ,
adding ,
@ -634,12 +634,12 @@ static enum channel_add_err add_htlc(struct channel *channel,
}
}
/* Try not to add a payment which will take fund er into fees
/* Try not to add a payment which will take open er into fees
* on either our side or theirs . */
if ( sender = = LOCAL ) {
if ( ! get_room_above_reserve ( channel , view ,
adding , removing ,
channel - > fund er,
channel - > open er,
& remainder ) )
return CHANNEL_ERR_CHANNEL_CAPACITY_EXCEEDED ;
/* Should be able to afford both their own commit tx
@ -649,7 +649,7 @@ static enum channel_add_err add_htlc(struct channel *channel,
committed ,
adding ,
removing ,
channel - > fund er) ;
channel - > open er) ;
/* set fee output pointer if given */
if ( htlc_fee & & amount_sat_greater ( fee , * htlc_fee ) )
* htlc_fee = fee ;
@ -667,7 +667,7 @@ static enum channel_add_err add_htlc(struct channel *channel,
committed ,
adding ,
removing ,
! channel - > fund er) ;
! channel - > open er) ;
/* set fee output pointer if given */
if ( htlc_fee & & amount_sat_greater ( fee , * htlc_fee ) )
* htlc_fee = fee ;
@ -970,7 +970,7 @@ u32 approx_max_feerate(const struct channel *channel)
struct amount_sat avail ;
const struct htlc * * committed , * * adding , * * removing ;
gather_htlcs ( tmpctx , channel , ! channel - > fund er,
gather_htlcs ( tmpctx , channel , ! channel - > open er,
& committed , & removing , & adding ) ;
/* Assume none are trimmed; this gives lower bound on feerate. */
@ -1001,28 +1001,28 @@ u32 approx_max_feerate(const struct channel *channel)
/* We should never go below reserve. */
if ( ! amount_sat_sub ( & avail ,
amount_msat_to_sat_round_down ( channel - > view [ ! channel - > fund er] . owed [ channel - > fund er] ) ,
channel - > config [ ! channel - > fund er] . channel_reserve ) )
amount_msat_to_sat_round_down ( channel - > view [ ! channel - > open er] . owed [ channel - > open er] ) ,
channel - > config [ ! channel - > open er] . channel_reserve ) )
avail = AMOUNT_SAT ( 0 ) ;
return avail . satoshis / weight * 1000 ; /* Raw: once-off reverse feerate*/
}
bool can_fund er_afford_feerate ( const struct channel * channel , u32 feerate_per_kw )
bool can_open er_afford_feerate ( const struct channel * channel , u32 feerate_per_kw )
{
struct amount_sat needed , fee ;
struct amount_sat dust_limit = channel - > config [ ! channel - > fund er] . dust_limit ;
struct amount_sat dust_limit = channel - > config [ ! channel - > open er] . dust_limit ;
size_t untrimmed ;
const struct htlc * * committed , * * adding , * * removing ;
gather_htlcs ( tmpctx , channel , ! channel - > fund er,
gather_htlcs ( tmpctx , channel , ! channel - > open er,
& committed , & removing , & adding ) ;
untrimmed = commit_tx_num_untrimmed ( committed , feerate_per_kw , dust_limit ,
! channel - > fund er)
! channel - > open er)
+ commit_tx_num_untrimmed ( adding , feerate_per_kw , dust_limit ,
! channel - > fund er)
! channel - > open er)
- commit_tx_num_untrimmed ( removing , feerate_per_kw , dust_limit ,
! channel - > fund er) ;
! channel - > open er) ;
fee = commit_tx_base_fee ( feerate_per_kw , untrimmed ) ;
@ -1032,38 +1032,38 @@ bool can_funder_afford_feerate(const struct channel *channel, u32 feerate_per_kw
* node ' s current commitment transaction :
* - SHOULD fail the channel
*/
/* Note: sender == fund er */
/* Note: sender == open er */
/* How much does it think it has? Must be >= reserve + fee */
if ( ! amount_sat_add ( & needed , fee ,
channel - > config [ ! channel - > fund er] . channel_reserve ) )
channel - > config [ ! channel - > open er] . channel_reserve ) )
status_failed ( STATUS_FAIL_INTERNAL_ERROR ,
" Cannot add fee %s and reserve %s " ,
type_to_string ( tmpctx , struct amount_sat ,
& fee ) ,
type_to_string ( tmpctx , struct amount_sat ,
& channel - > config [ ! channel - > fund er] . channel_reserve ) ) ;
& channel - > config [ ! channel - > open er] . channel_reserve ) ) ;
status_debug ( " We need %s at feerate %u for %zu untrimmed htlcs: we have %s/%s " ,
type_to_string ( tmpctx , struct amount_sat , & needed ) ,
feerate_per_kw , untrimmed ,
type_to_string ( tmpctx , struct amount_msat ,
& channel - > view [ LOCAL ] . owed [ channel - > fund er] ) ,
& channel - > view [ LOCAL ] . owed [ channel - > open er] ) ,
type_to_string ( tmpctx , struct amount_msat ,
& channel - > view [ REMOTE ] . owed [ channel - > fund er] ) ) ;
return amount_msat_greater_eq_sat ( channel - > view [ ! channel - > fund er] . owed [ channel - > fund er] ,
& channel - > view [ REMOTE ] . owed [ channel - > open er] ) ) ;
return amount_msat_greater_eq_sat ( channel - > view [ ! channel - > open er] . owed [ channel - > open er] ,
needed ) ;
}
bool channel_update_feerate ( struct channel * channel , u32 feerate_per_kw )
{
if ( ! can_fund er_afford_feerate ( channel , feerate_per_kw ) )
if ( ! can_open er_afford_feerate ( channel , feerate_per_kw ) )
return false ;
status_debug ( " Setting %s feerate to %u " ,
side_to_str ( ! channel - > fund er) , feerate_per_kw ) ;
side_to_str ( ! channel - > open er) , feerate_per_kw ) ;
start_fee_update ( channel - > fee_states , channel - > fund er, feerate_per_kw ) ;
start_fee_update ( channel - > fee_states , channel - > open er, feerate_per_kw ) ;
return true ;
}