feat(wallet): Use mempool histogram for fee estimation (#358)

* feat(wallet): Use mempool.space as a secondary fee estimation source

* fix: warn if mempool client cannot be instantiated

* make clippy happy

* nitpick: rename clippy_check to clippy in justfile

* rename `estimate_fee_rate_from_mempool` to `estimate_fee_rate_from_histogram` for clarity

* dprint fmt

* make clippy happy

* change teacing level back to debug!

* change log levels

* refactors

* refactor: estimate_fee and min_relay_fee

* serde camel case

Co-authored-by: Byron Hambly <byron@hambly.dev>

* refactors

* Add comments, use Weight struct where possible

* fmt, fix testrs

* dont fallback to bitcoin::MAX, fail instead

* make mempool space optional

* fmt

* refactor: use estimate_fee(...) in max_giveable(...)

* refactor max_giveable(...)

* refactor max_giveeable to return fee as well, remove safety margin for fee

* fix compile

* fmtr

* fix(integration test): Use pre-calculated cancel / punish fees for assert_alice_punished

* fix(integration test): Use real fees for asserts

* sync wallet before transaction_fee call

* split send_to_address into sweep_balance_to_address_dynamic_fee

---------

Co-authored-by: Byron Hambly <byron@hambly.dev>
This commit is contained in:
Mohan 2025-05-27 15:41:24 +02:00 committed by GitHub
parent 854b14939e
commit 091ba57547
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 995 additions and 358 deletions

View file

@ -574,6 +574,11 @@ mod tests {
.estimate_fee(TxPunish::weight(), btc_amount)
.await
.unwrap();
let tx_lock_fee = alice_wallet
.estimate_fee(TxLock::weight(), btc_amount)
.await
.unwrap();
let redeem_address = alice_wallet.new_address().await.unwrap();
let punish_address = alice_wallet.new_address().await.unwrap();
@ -600,6 +605,7 @@ mod tests {
config.monero_finality_confirmations,
spending_fee,
spending_fee,
tx_lock_fee,
);
let message0 = bob_state0.next_message();
@ -633,10 +639,10 @@ mod tests {
.unwrap();
let refund_transaction = bob_state6.signed_refund_transaction().unwrap();
assert_weight(redeem_transaction, TxRedeem::weight() as u64, "TxRedeem");
assert_weight(cancel_transaction, TxCancel::weight() as u64, "TxCancel");
assert_weight(punish_transaction, TxPunish::weight() as u64, "TxPunish");
assert_weight(refund_transaction, TxRefund::weight() as u64, "TxRefund");
assert_weight(redeem_transaction, TxRedeem::weight().to_wu(), "TxRedeem");
assert_weight(cancel_transaction, TxCancel::weight().to_wu(), "TxCancel");
assert_weight(punish_transaction, TxPunish::weight().to_wu(), "TxPunish");
assert_weight(refund_transaction, TxRefund::weight().to_wu(), "TxRefund");
}
// Weights fluctuate because of the length of the signatures. Valid ecdsa