Remove Fee from the Network API

The only benefit to having it would be the ability to cache it across
prepare_send, which can be done internally to the Network.
This commit is contained in:
Luke Parker
2023-10-20 16:12:26 -04:00
parent 5977121c48
commit c056b751fe
7 changed files with 39 additions and 81 deletions

View File

@@ -36,9 +36,7 @@ use scheduler::Scheduler;
use crate::{
Get, Db, Payment, Plan,
networks::{
OutputType, Output, Transaction, SignableTransaction, Block, PreparedSend, Network, get_block,
},
networks::{OutputType, Output, Transaction, SignableTransaction, Block, PreparedSend, Network},
};
// InInstructionWithBalance from an external output
@@ -80,20 +78,14 @@ enum RotationStep {
ClosingExisting,
}
async fn get_fee_rate<N: Network>(network: &N, block_number: usize) -> N::Fee {
// TODO2: Use an fee representative of several blocks
get_block(network, block_number).await.median_fee()
}
async fn prepare_send<N: Network>(
network: &N,
block_number: usize,
fee_rate: N::Fee,
plan: Plan<N>,
operating_costs: u64,
) -> PreparedSend<N> {
loop {
match network.prepare_send(block_number, plan.clone(), fee_rate, operating_costs).await {
match network.prepare_send(block_number, plan.clone(), operating_costs).await {
Ok(prepared) => {
return prepared;
}
@@ -157,15 +149,13 @@ impl<D: Db, N: Network> MultisigManager<D, N> {
{
let block_number = block_number.try_into().unwrap();
let fee_rate = get_fee_rate(network, block_number).await;
let id = plan.id();
info!("reloading plan {}: {:?}", hex::encode(id), plan);
let key_bytes = plan.key.to_bytes();
let Some((tx, eventuality)) =
prepare_send(network, block_number, fee_rate, plan.clone(), operating_costs).await.tx
prepare_send(network, block_number, plan.clone(), operating_costs).await.tx
else {
panic!("previously created transaction is no longer being created")
};
@@ -675,7 +665,6 @@ impl<D: Db, N: Network> MultisigManager<D, N> {
let res = {
let mut res = Vec::with_capacity(plans.len());
let fee_rate = get_fee_rate(network, block_number).await;
for plan in plans {
let id = plan.id();
@@ -699,7 +688,7 @@ impl<D: Db, N: Network> MultisigManager<D, N> {
assert_eq!(plan.inputs.len(), 1);
}
let PreparedSend { tx, post_fee_branches, operating_costs } =
prepare_send(network, block_number, fee_rate, plan, running_operating_costs).await;
prepare_send(network, block_number, plan, running_operating_costs).await;
// 'Drop' running_operating_costs to ensure only operating_costs is used from here on out
#[allow(unused, clippy::let_unit_value)]
let running_operating_costs: () = ();