Skip to content

fix: reduce update_fee target for anchor channels - #9826

Merged
SomberNight merged 1 commit into
spesmilo:masterfrom
f321x:fix_fee_disagreement_ln
May 15, 2025
Merged

SomberNight merged 1 commit into
spesmilo:masterfrom
f321x:fix_fee_disagreement_ln

Conversation

@f321x

@f321x f321x commented May 14, 2025 •

Copy link
Copy Markdown
Member

the update_fee logic for lightning channels is not adapted to anchor channels causing us to send update_fee with a eta target of 2 blocks, while for anchor channels it is enough to just get into the mempool as the fee can be bumped later. This causes force closes when there are mempool spikes as the fees we try to update to are a lot higher than e.g. eclair uses. Eclair will send errors if our attempted fee update is 10x > than their fee.
This now uses the 1008 block estimate + 25% buffer as the anchor channel fee target. This is the lowest value available to fetch from electrum servers / bitcoin core estimatesmartfee limit, which also guarantees acceptance into the mempool.

As side effect of adding 1008 blocks to the FEE_ETA_TARGETS to be fetched, these values are also shown in the gui. So i added 144 (1 day) too and tooltips for them, as they seem useful anyways and introducing logic to not show all eta's in the gui would make things more complex.

Potentially an addition to the electrum protocol allowing to explicitly fetch the minimal mempool acceptance fee would be useful for the future.

Example of such a force close:

20250512T153015.040871Z |     INFO | network | fee_estimates {25: 1000, 10: 1198, 5: 1624, 2: 25239}
20250512T153015.042300Z |     INFO | lnpeer.Peer.[LNWallet, 03ecef675b-1efa36c8] | (889664x860x1) oncha  
in fees have changed considerably. updating fee.  
20250512T153015.042453Z |     INFO | lnpeer.Peer.[LNWallet, 03ecef675b-1efa36c8] | (chan: 889664x860x1)  
current pending feerate 353. new feerate 6309  
20250512T153015.042765Z |    DEBUG | lnpeer.Peer.[LNWallet, 03ecef675b-1efa36c8] | Sending UPDATE_FEE  
20250512T153015.043246Z |     INFO | lnpeer.Peer.[LNWallet, 03ecef675b-1efa36c8] | send_commitment. cha  
n 889664x860x1. ctn: 608.  
20250512T153015.043339Z |     INFO | lnchannel.Channel.[889664x860x1] | sign_next_commitment. ctn=608  
20250512T153015.046253Z |     INFO | transaction | adding signature for 02cbc2ce4bb807bed254258422d2318  
76862e92280d5aa1c1ec71bc11a51ab702c. spending utxo 954703ec4d6044a4d38e98b44116d062c64b8c2798b5be3c186f  
d73df4fe146d:1  
20250512T153015.046905Z |    DEBUG | transaction | tx.sign() finished. is_complete=False  
20250512T153015.047170Z |    DEBUG | lnchannel.Channel.[889664x860x1] | sign_next_commitment. pending_r  
emote_commitment.serialize()='cHNidP8BAN8CAAAAAW0U/vQ9128YPL61mCeMS8Zi0BZBtJiO06REYE3sA0eVAQAAAADe5EOAB  
EoBAAAAAAAAIgAgBNYj6SGWhmgpLuy5t+wOZydMd5w9AXtiFi5/iphcFPZKAQAAAAAAACIAIAl4sd/cEJ0F9Ur3FDu2cCqPwXWVjoNU  
83mwx198Q8EXMzwBAAAAAAAiACAjfV4QIrbAk3IE9shrBvDwAlsIxMBcN5XI8fBpf2FXTBWrDgAAAAAAIgAgm4c18e0wfwPFI+1yRCH  
dpg2u13HOZ+ZULvH2jtMZ75HHn0MgACICAsvCzku4B77SVCWEItIxh2hi6SKA1aocHscbwRpRq3AsRzBEAiBHtguWPqa6Szgo/zlpNV  
YHt5+gT8xX4AoVhqOYqSyxrwIgBIRmrm7As0uI+FgcEfPwJ5UU6D7zylhUxmFrvZTyRTABAQVHUiECy8LOS7gHvtJUJYQi0jGHaGLpI  
oDVqhwexxvBGlGrcCwhA1j1uhAUjVhQUHpjY8/CnYWFYqui22k0nNevgSMfFtcTUq4AAAAAAA=='. sig_64.hex()='47b60b963ea  
6ba4b3828ff3969355607b79fa04fcc57e00a1586a398a92cb1af048466ae6ec0b34b88f8581c11f3f0279514e83ef3ca5854c6  
616bbd94f24530'  
20250512T153015.047759Z |    DEBUG | lnpeer.Peer.[LNWallet, 03ecef675b-1efa36c8] | Sending COMMITMENT_S  
IGNED  
20250512T153015.048056Z |     INFO | wallet_db.WalletDB | appending 83 pending changes  
20250512T153015.049813Z |    DEBUG | lnpeer.Peer.[LNWallet, 03ecef675b-1efa36c8] | Received ERROR  
20250512T153015.050042Z |     INFO | lnpeer.Peer.[LNWallet, 03ecef675b-1efa36c8] | remote peer sent err  
or [DO NOT TRUST THIS MESSAGE]: 'local/remote feerates are too different: remoteFeeratePerKw=6309 local  
FeeratePerKw=562'. chan_id=6d14fef43dd76f183cbeb598278c4bc662d01641b4988ed3a444604dec034794. is_known_c  
han_id=True  
20250512T153015.053411Z |     INFO | transaction | adding signature for 02cbc2ce4bb807bed254258422d2318  
76862e92280d5aa1c1ec71bc11a51ab702c. spending utxo 954703ec4d6044a4d38e98b44116d062c64b8c2798b5be3c186f  
d73df4fe146d:1  
20250512T153015.053948Z |    DEBUG | transaction | tx.sign() finished. is_complete=False  
20250512T153015.054171Z |    DEBUG | lnchannel.Channel.[889664x860x1] | Setting channel state: OPEN ->  
FORCE_CLOSING  

Comment thread electrum/lnpeer.py Outdated
Comment on lines +2661 to +2662
self.logger.info(f"({chan.get_id_for_log()}) current pending feerate {chan_fee}. "
f"new feerate {feerate_per_kw}")
chan.update_fee(feerate_per_kw, True)
f"new feerate {current_feerate_per_kw}")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find the current_feerate_per_kw / update_feerate_per_kw split somewhat confusing.
For example, here, we should probably log the value we are actually updating the fee to.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah missed that log, changed it.
I found it useful to have these two variables as it is hard to do the calculations otherwise, would you suggest different naming or do you see any cleaner approach?

Comment thread electrum/lnpeer.py Outdated
Comment on lines +2641 to +2648
ratio = chan_feerate / current_feerate_per_kw
if ratio < 0.5:
# Note that we trust the Electrum server about fee rates
# Thus, automated force-closing might not be a good idea
# Maybe we should display something in the GUI instead
self.logger.warning(
f"({chan.get_id_for_log()}) feerate is {chan_feerate} sat/kw, "
f"current recommended feerate is {feerate_per_kw} sat/kw, consider force closing!")
f"current recommended feerate is {current_feerate_per_kw} sat/kw, consider force closing!")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here also, we probably want update_feerate_per_kw instead.
(what we "recommend" should be what we would want to update the fee to, no? :P)

@f321x f321x May 14, 2025 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched to update_feerate_per_kw, i thought it may is better to be "less aggressive" here but it's just a warning, so using update_feerate_per_kw for the ratio and the log seems more consistent yes.

Comment thread electrum/lnpeer.py Outdated
return
# add some buffer to anchor chan fees as we always act at the lower end and don't
# want to get kicked out of the mempool immediately if it grows
fee_buffer = current_feerate_per_kw * 0.25 if chan.has_anchors() else 0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: the +25% comes from eclair: https://github.com/ACINQ/eclair/blob/f14b92d7df8727d6362d86251d717a93f37df251/eclair-core/src/main/scala/fr/acinq/eclair/blockchain/fee/OnChainFeeConf.scala#L127
but they have additional logic giving it more buffer

I think we could just use +50%, to be safer, but not have said additional logic.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on second thought, let's just add a 5 sat/vbyte floor, to reduce the chance of not getting into the mempool after coming back from a long offline period

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have added a floor in current_target_feerate_per_kw() and increased the buffer to 50%

@f321x
f321x force-pushed the fix_fee_disagreement_ln branch from d2b7941 to c6b376e Compare May 14, 2025 14:59
the update_fee logic for lightning channels was not adapted to anchor
channels causing us to send update_fee with a eta target of 2 blocks.
This causes force closes when there are mempool spikes as the fees we
try to update to are a lot higher than e.g. eclair uses. Eclair will
force close if our fee is 10x > than their fee.
@f321x
f321x force-pushed the fix_fee_disagreement_ln branch from c6b376e to 61874e9 Compare May 14, 2025 16:02
@ecdsa ecdsa added this to the 4.6.0 milestone May 15, 2025
@SomberNight
SomberNight merged commit 79a54c1 into spesmilo:master May 15, 2025
Comment thread electrum/lnworker.py
if has_anchors:
# set a floor of 5 sat/vb to have some safety margin in case the mempool
# grows quickly
feerate_per_kvbyte = max(feerate_per_kvbyte, 5000)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self-note: we add the +50% buffer on top of this later, so the effective floor is 7.5 s/b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants