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

Bitcoin backend: batch fee estimation requests #3570

Merged

Conversation

darosior
Copy link
Collaborator

@darosior darosior commented Mar 5, 2020

EDIT: the scope changed from just batching feerate requests, cf #3570 (comment)

fixes #3508

@darosior darosior requested a review from cdecker as a code owner March 5, 2020 14:03
@darosior darosior force-pushed the bitcoind_getfeerate_batch branch 2 times, most recently from 506703c to 79ace3e Compare March 5, 2020 17:06
Copy link
Collaborator

@niftynei niftynei left a comment

Choose a reason for hiding this comment

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

something to think about: this PR locks us into the 3 definitions of "urgent, normal, slow" in a harder to change way than the previous method of calling getfeerate 3 times. i can see how this is preferable for a plugin API.

further it canonicalizes 'urgent, normal and slow', while removing the bitcoind standard that we adhered to previously of CONSERVATIVE/2 , ECONOMICAL/100 etc. what guarantees do these new standards require? i.e. if a plugin reports back an urgent feerate, how fast does that mean it'll be mined on average? bitcoind lays these out for their feerate API, and by moving away from them we're opening up some possibility for interpretation. we should add some strong guidelines around the meaning of them in any bitcoin-plugin documentation, and perhaps annotate them in this commit series as well.

lightningd/bitcoind.c Outdated Show resolved Hide resolved
lightningd/bitcoind.c Outdated Show resolved Hide resolved
lightningd/bitcoind.c Outdated Show resolved Hide resolved
plugins/bcli.c Show resolved Hide resolved
lightningd/bitcoind.c Show resolved Hide resolved
@darosior darosior force-pushed the bitcoind_getfeerate_batch branch 2 times, most recently from d02b8bb to 256cffb Compare March 6, 2020 09:36
@darosior
Copy link
Collaborator Author

darosior commented Mar 9, 2020

something to think about: this PR locks us into the 3 definitions of "urgent, normal, slow" in a harder to change way than the previous method of calling getfeerate 3 times. i can see how this is preferable for a plugin API.

imho it's an improvement, this classification is clearer, not backend-specific, and closer to what we use internally.

further it canonicalizes 'urgent, normal and slow', while removing the bitcoind standard that we adhered to previously of CONSERVATIVE/2 , ECONOMICAL/100 etc. what guarantees do these new standards require?

That's not a complete removal, bcli does use the same standards as before. But it gives more flexibility to the plugin if it tries to be smart.

if a plugin reports back an urgent feerate, how fast does that mean it'll be mined on average?

We completely trust the plugin for providing an urgent feerate when asked, and it doesn't change default behaviour at all as we still use CONSERVATIVE/2 for urgent feerate in bcli.

by moving away from them we're opening up some possibility for interpretation. we should add some strong guidelines around the meaning of them in any bitcoin-plugin documentation

Yep, the doc is ready and yet to come once we have the final API.
Of course I shall add that if one wants to write an exotic fee-estimation plugin, it shouldn't take the urgent feerate too lightly as it's crucial...

@rustyrussell
Copy link
Contributor

Agree with @niftynei that these differentiations suck. We should expose them by usage.

Currently we use the following:

  • Mutual close (NORMAL)
  • Opening (NORMAL)
  • Unilateral (URGENT)
  • Minimum acceptable (SLOW / 2)
  • Maximum acceptable (URGENT * config.max_fee_multiplier)
  • onchaind: HTLC to wallet, penalty txs, returning our unilateral spend to us (NORMAL).

Perhaps we should expose these directly via the API? Frankly, returning HTLC to wallet (if timed out) should probably be more urgent, whereas the other onchaind cases should be slower.

An even better API would allow an amount and a timeout (in number of blocks), where the amount says how much we'd lose, and the timeout says how many blocks we have.

@darosior
Copy link
Collaborator Author

darosior commented Mar 10, 2020

Ok.

I've looked into it and propose the following feerates :

  • opening
  • mutual_close
  • unilateral_close
  • minimum
  • maximum
  • delayed_to_us
  • htlc
  • penalty

I propose to also bump the penalty and htlc feerates to URGENT bcli-side.

@darosior
Copy link
Collaborator Author

darosior commented Mar 11, 2020

Ok so now the patchset is bigger and breaks some APIs but it's really better this way, I think :).

So, this now changes our feerate tracking from urgent, normal and slow feerates to a "type-based" feerate tracking.
This also batch the fee estimation requests to the Bitcoin backend which will answer with the same estimates as before, so the estimations themselves aren't actually changed.

I propose to also bump the penalty and htlc feerates to URGENT bcli-side.

I'll propose this as an other PR, what do you think of CONSERVATIVE/3 ?
I'll also propose a PR to be able to tweak the mutual close transaction fees since it's part of the types, iirc it was a feature request ?

Copy link
Contributor

@vasild vasild left a comment

Choose a reason for hiding this comment

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

Code review about OK. Notice that I am missing some pieces of the big picture.

Some comments follow, feel free to ignore them (except the one about feerate[3]).

lightningd/bitcoind.c Outdated Show resolved Hide resolved
lightningd/bitcoind.c Show resolved Hide resolved
lightningd/bitcoind.c Outdated Show resolved Hide resolved
lightningd/bitcoind.c Outdated Show resolved Hide resolved
lightningd/chaintopology.c Outdated Show resolved Hide resolved
lightningd/chaintopology.c Outdated Show resolved Hide resolved
lightningd/onchain_control.c Outdated Show resolved Hide resolved
plugins/bcli.c Show resolved Hide resolved
plugins/bcli.c Outdated Show resolved Hide resolved
tests/test_misc.py Outdated Show resolved Hide resolved
@darosior
Copy link
Collaborator Author

Thanks for the review @vasild ! Sorry for the obvious fails I was too eager so push that I didn't review the cherry-picked commits of the old version :/

@darosior
Copy link
Collaborator Author

Added two commits for handling the max_fee multiplier bcli-side.

@darosior darosior force-pushed the bitcoind_getfeerate_batch branch 4 times, most recently from c7c25c4 to 6dcf600 Compare March 11, 2020 21:42
@niftynei
Copy link
Collaborator

#3542 is related to this; see comment regarding desired API for specifying a default feerate policy for fundchannel

lightningd/bitcoind.c Outdated Show resolved Hide resolved
@darosior
Copy link
Collaborator Author

Corrected the wrong comments (BTC/kVB => sat/kVB)

Copy link
Contributor

@rustyrussell rustyrussell left a comment

Choose a reason for hiding this comment

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

Minor comments only.

Ack b712a6f

lightningd/chaintopology.c Show resolved Hide resolved
lightningd/chaintopology.c Outdated Show resolved Hide resolved
plugins/libplugin.c Outdated Show resolved Hide resolved
plugins/libplugin.c Show resolved Hide resolved
@darosior
Copy link
Collaborator Author

Corrected, and rebased.

@vasild
Copy link
Contributor

vasild commented Mar 24, 2020

ACK dcaf75f, light code review

This allows us to set more fine-grained feerate for onchain resolution.

We still give it the same feerate for all types, but this will change as
we move feerates to bcli.
We kept track of an URGENT, a NORMAL, and a SLOW feerate. They were used
for opening (NORMAL), mutual (NORMAL), UNILATERAL (URGENT) transactions
as well as minimum and maximum estimations, and onchain resolution.

We now keep track of more fine-grained feerates:
- `opening` used for funding and also misc transactions
- `mutual_close` used for the mutual close transaction
- `unilateral_close` used for unilateral close (commitment transactions)
- `delayed_to_us` used for resolving our output from our unilateral close
- `htlc_resolution` used for resolving onchain HTLCs
- `penalty` used for resolving revoked transactions

We don't modify our requests to our Bitcoin backend, as the next commit
will batch them !

Changelog-deprecated: The "urgent", "slow", and "normal" field of the `feerates` command are now deprecated.
Changelog-added: The fields "opening", "mutual_close", "unilateral_close", "delayed_to_us", "htlc_resolution" and "penalty" have been added to the `feerates` command.
This adapts our fee estimations requests to the Bitcoin backend to the
new semantic, and batch the requests.

This makes our request for fees much simpler, and leaves some more
flexibility for a plugin to do something smart (it could still lie before
but now it's explicit, at least.) as we don't explicitly request
estimation for a specific mode and a target.

Changelog-Changed: We now batch the requests for fee estimation to our Bitcoin backend.
Changelog-Changed: We now get more fine-grained fee estimation from our Bitcoin backend.
We keep the same behaviour as lightningd before.
Changelog-Changed: "htlc_timeout_satoshis" and "htlc_success_satoshis" fields have been added to the `feerates` command.
That way we pass the real min_acceptable (SLOW/2) and max_acceptable
(URGENT * 10) feerates to lightningd.
@darosior
Copy link
Collaborator Author

Re-rebased after #3572 was merged.

@rustyrussell
Copy link
Contributor

Ack eff7241

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Batching feerate requests for our plugin backend
4 participants