Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework of fee estimation #102

Merged
merged 13 commits into from
Jul 18, 2022
Merged

Rework of fee estimation #102

merged 13 commits into from
Jul 18, 2022

Conversation

nepet
Copy link
Contributor

@nepet nepet commented Jul 13, 2022

This is a complete rework of the fee estimation. This pr introduces an Estimator interface to allow for lnds internal and bitcoind fee estimation. The following two estimator implementations are provided:

  • LndEstimator: Uses lnds internal fee estimation.
  • GBitcoindEstimator: This estimator uses the gbitcoin api from glightning to access the bitcoind backend. The estimator mimics the behavior that lnd is using to provide a common way for fee estimation. We can set a fallback fee rate and have a constant floor fee rate of 253 sat/kw

The BitcoinOnchain service uses the new estimators that return the fee rate in sat/kw. Also a fallbackFeeRateSatPerKw and a floorFeeRateSatPerKw are provided while the former can be set on service creation, the later is a constant fixed to 275 sat/kw which equals 1.1 sat/vb.
If the fee rate returned by the estimator is below the floor, the floor will be used for estimation. The fallback is used if the estimator does return an error or an 0 fee rate.

This PR includes PRs #100 and #79

Please do not merge this PR until ElementsProject/glightning#1 got merged as it depends on my fork nepet/glightning@gbitcoin/add-public-request right now

@nepet nepet added this to the v0.3.0 milestone Jul 13, 2022
@kornpow
Copy link
Contributor

kornpow commented Jul 13, 2022

Im still running into the fee agreement issue while running this PR:
2022/07/13 14:19:14 rpc error: code = Unknown desc = Fee is too damn high. Max expected: 717 Received 6403
Im running LND.
Though from the discord I think this is being actively worked on.

@kornpow
Copy link
Contributor

kornpow commented Jul 14, 2022

maybe more useful logs

2022/07/14 11:29:21 [INFO] Could not fetch on-chain fee from lnd: rpc error: code = DeadlineExceeded desc = context deadline exceeded
2022/07/14 11:29:21 [DEBUG] Estimated fee is 0, using fallback fee 0
2022/07/14 11:29:21 [INFO] Estimated fee rate is below floor of 275 sat/kw, take floor instead
2022/07/14 11:29:21 [DEBUG] Using a fee rate of 1.10 sat/vb for a total fee of 239
2022/07/14 11:29:21 [INFO] [FSM] Action failure Fee is too damn high. Max expected: 717 Received 6180
2022/07/14 11:29:21 [DEBUG] [FSM] event:id: dae7620ca9b5d18d89fa6f49aa872c1dd760f68bacd738b6dfb3b187bad57863, Event_ActionFailed on State_SwapOutSender_PayFeeInvoice
2022/07/14 11:29:21 [DEBUG] [FSM] Canceling because of Fee is too damn high. Max expected: 717 Received 6180

@kornpow
Copy link
Contributor

kornpow commented Jul 14, 2022

I was able to perform a swap out on btc chain using this PR, and didnt hit the fee too high bug this time around

@wtogami
Copy link
Contributor

wtogami commented Jul 14, 2022

This test error is a timeout that I suspect might be harmless? Not sure. In any case this is an improvement for LND which earlier today had broken fee estimation so it's worth testing for LND users.

@nepet
Copy link
Contributor Author

nepet commented Jul 14, 2022

Nono, I kicked ci a few times with the same error. Give me some time to understand and fix it! It now failed in the other direction concerning cln and lnd.

@wtogami
Copy link
Contributor

wtogami commented Jul 15, 2022

Maybe the timeouts are not new? Between CLN and LND with #102 yesterday I saw some timeouts.

There's also a known bug with CLN v0.11.2 where payments can break entirely while the channel works for custommessage and ping. If we figure out a way to reproduce THAT it would be helpful.

huilder and others added 3 commits July 17, 2022 20:54
We want to have an estimator interface that allows for multiple
backend implementations to provide the same fee estimation for
the cln plugin as for the lnd daemon.
@nepet
Copy link
Contributor Author

nepet commented Jul 17, 2022

If this is tested on signet/mainnet I squash the commit to make it ready to be merged

@nepet nepet changed the title draft: Rework of fee estimation Rework of fee estimation Jul 17, 2022
@nepet
Copy link
Contributor Author

nepet commented Jul 17, 2022

Squashed the fixups and removed the draft status.

@wtogami
Copy link
Contributor

wtogami commented Jul 17, 2022

Visually inspecting the changes today may be confusing due to the subsequent rebase on top of master.

https://github.com/ElementsProject/peerswap/compare/test-83-97-102..test-102-jul17
https://github.com/ElementsProject/peerswap/compare/795c23a4999be67252b3d2ad227a7ae0ae757cbe..3f9864b9c49c99d2b19c87274be10f2f73c2a743
795c23a was #102 as of July 14th.
3f9864b is master with #102 of July 17th. This allows you to more easily see the changes since we last tested this.

Copy link
Contributor

@wtogami wtogami left a comment

Choose a reason for hiding this comment

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

$ grep -r 'CONSERVATIVE'
onchain/estimator.go:	// must be one of "UNSET", "ECONOMICAL" or "CONSERVATIVE" and defaults to
onchain/estimator.go:	// "CONSERVATIVE".
onchain/estimator_test.go:		"CONSERVATIVE",

Should these be changed to ECONOMICAL as well?

@wtogami
Copy link
Contributor

wtogami commented Jul 18, 2022

04dee90
This commit is the main change since yesterday that needs testing and review.

@wtogami
Copy link
Contributor

wtogami commented Jul 18, 2022

If you test be sure you merge #102 into master or use 3f9864b which did so.

@wtogami
Copy link
Contributor

wtogami commented Jul 18, 2022

ACK 04dee90

Please add one more trivial commit to get rid of the last CONSERVATIVE and merge. This is certainly a needed improvement. It would be easier for everyone to test merged.

nepet added 4 commits July 18, 2022 11:10
…nterface.

We use gbitcoin as our RPC proxy for bitcoind connection and calls.
This estimator mimics lnds bitcoind estimator such that we will get
reliable and same results for Peerswap on lnd and Peerswap on cln.
The LndEstimator uses lnds walletkit RPC EstimateFee call to fetch
the fee estimation from lnds internal estimator.
We now use the Estimator interface in BitcoinOnchain to estimate
the fees. The GetFee command now also has a fallback and floor
fee rate where the floor is set to 1.1 sat/vb.
nepet added 6 commits July 18, 2022 11:10
This uses the current head of master that includes a PR that
enables the use of the "getmempoolinfo" call.
We had no documentation on how the stubs were built. Now we can use
the Makefile for stub generation.
The lnd fee estimator returns a static fee rate if lnd is used
on the regtest network. In order to match this behavior for
integration tests. We add the static RegtestFeeEstimator to the
cln plugin that is used if bitcoind is configured to use regtest.
@nepet
Copy link
Contributor Author

nepet commented Jul 18, 2022

$ grep -r 'CONSERVATIVE'
onchain/estimator.go:	// must be one of "UNSET", "ECONOMICAL" or "CONSERVATIVE" and defaults to
onchain/estimator.go:	// "CONSERVATIVE".
onchain/estimator_test.go:		"CONSERVATIVE",

Should these be changed to ECONOMICAL as well?

Changed commits: f1fafe3, 6075df5, to address the change from "CONSERVATIVE" to "ECONOMICAL" in tests and to remove the default part in the comment.

@nepet nepet merged commit e563b00 into ElementsProject:master Jul 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants