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

Document example code or add helper code for fee estimation #1053

Open
Tracked by #76
notmandatory opened this issue Aug 2, 2023 · 5 comments
Open
Tracked by #76

Document example code or add helper code for fee estimation #1053

notmandatory opened this issue Aug 2, 2023 · 5 comments
Assignees
Labels
discussion There's still a discussion ongoing documentation Improvements or additions to documentation

Comments

@notmandatory
Copy link
Member

notmandatory commented Aug 2, 2023

Describe the enhancement

In the pre-1.0.0 BDK APIs the Blockchain.estimate_fee API provided a thin wrapper around blockchain clients native calls. Since the Blockchain trait is not needed anymore we need a new way to help users estimate transaction fees.

A couple options are:

  1. Document how to call the native blockchain client's methods for fee estimation.

electrum-client:

FeeRate::from_btc_per_kvb(client.estimate_fee(target)? as f32)

esplora-client BlockingClient:

let estimates = client.get_fee_estimates()?;
FeeRate::from_sat_per_vb(esplora-client::convert_fee_rate(target, estimates,)?)

eplora-client AsyncClient:

let estimates = client.get_fee_estimates().await?;
FeeRate::from_sat_per_vb(esplora-client::convert_fee_rate(target, estimates,)?)

bitcoincore_rpc:

let sat_per_kb = client
      .estimate_smart_fee(target as u16, None)?
      .fee_rate
      .ok_or(Error::FeeRateUnavailable)?
      .to_sat() as f64;
FeeRate::from_sat_per_vb((sat_per_kb / 1000f64) as f32))
  1. Add some sort of new FeeEstimator trait with implementations for each of the above. Could also add implementations for popular providers custom APIs like mempool.space.

Use case

Getting the fee rate is a common operation most bdk based apps will need. It is also something that pre-1.0 BDK provided and if missing could slow down users migrating to the 1.0.

Additional context

This issue was discussed in #1052 by @tnull and in bitcoindevkit/.github#70 and on Discord.

@notmandatory notmandatory added the new feature New feature or request label Aug 2, 2023
@notmandatory notmandatory added this to BDK Aug 2, 2023
@notmandatory notmandatory added discussion There's still a discussion ongoing documentation Improvements or additions to documentation new feature New feature or request and removed new feature New feature or request labels Aug 2, 2023
@vladimirfomene
Copy link
Contributor

Nakamoto has a way of estimating feerate per block. https://docs.rs/nakamoto-client/0.4.0/nakamoto_client/enum.Event.html#variant.FeeEstimated. I don't yet know how we could use that information for feerate calculation in the case of CBF, but I will definitely look into it.

@nondiremanuel nondiremanuel moved this to Todo in BDK Aug 4, 2023
@sebastianmontero
Copy link

In my opinion it would be great to have a trait that abstracts away the implementation details of each of the clients.

@realeinherjar
Copy link
Contributor

I also think that having traits to abstract details is the way to go.
It is also more future-proof as well.

@LLFourn
Copy link
Contributor

LLFourn commented Sep 13, 2023

Before adding a trait can we use the fee estimation in all the examples.

@nondiremanuel nondiremanuel added this to the 1.0.0-beta.0 milestone Sep 26, 2023
@notmandatory notmandatory removed the new feature New feature or request label Sep 18, 2024
@luisschwab
Copy link
Contributor

Picking this up. Is there any opposition to adding a trait that abstracts away different sources, as mentioned by sebastianmontero and realeinherjar?

@notmandatory notmandatory moved this from Todo to In Progress in BDK Oct 8, 2024
@notmandatory notmandatory removed this from the 1.0.0-beta milestone Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion There's still a discussion ongoing documentation Improvements or additions to documentation
Projects
Status: In Progress
Development

No branches or pull requests

7 participants