mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 20:29:23 +00:00
Don't scan outputs which are dust, track dust change as operating costs
Fixes #299.
This commit is contained in:
@@ -562,21 +562,35 @@ impl Network for Bitcoin {
|
||||
return Ok(PreparedSend {
|
||||
tx: None,
|
||||
post_fee_branches: drop_branches(&plan),
|
||||
// We expected a change output of sum(inputs) - sum(outputs)
|
||||
// This plan expects a change output valued at sum(inputs) - sum(outputs)
|
||||
// Since we can no longer create this change output, it becomes an operating cost
|
||||
operating_costs: operating_costs +
|
||||
plan.inputs.iter().map(|input| input.amount()).sum::<u64>() -
|
||||
plan.payments.iter().map(|payment| payment.amount).sum::<u64>(),
|
||||
// TODO: Look at input restoration to reduce this operating cost
|
||||
operating_costs: operating_costs + plan.expected_change(),
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
let AmortizeFeeRes { post_fee_branches, operating_costs } =
|
||||
let AmortizeFeeRes { post_fee_branches, mut operating_costs } =
|
||||
amortize_fee(&mut plan, operating_costs, tx_fee);
|
||||
|
||||
let signable = signable(&plan, Some(tx_fee)).unwrap();
|
||||
|
||||
// TODO: If the change output was dropped by Bitcoin, increase operating costs
|
||||
// Now that we've amortized the fee (which may raise the expected change value), grab it again
|
||||
// Then, subtract the TX fee
|
||||
//
|
||||
// The first `expected_change` call gets the theoretically expected change from the theoretical
|
||||
// Plan object, and accordingly doesn't subtract the fee (expecting the payments to bare it)
|
||||
// This call wants the actual value, and since Plan is unaware of the fee, has to manually
|
||||
// adjust
|
||||
let on_chain_expected_change = plan.expected_change() - tx_fee;
|
||||
// If the change value is less than the dust threshold, it becomes an operating cost
|
||||
// This may be slightly inaccurate as dropping payments may reduce the fee, raising the change
|
||||
// above dust
|
||||
// That's fine since it'd have to be in a very precarious state AND then it's over-eager in
|
||||
// tabulating costs
|
||||
if on_chain_expected_change < Self::DUST {
|
||||
operating_costs += on_chain_expected_change;
|
||||
}
|
||||
|
||||
let plan_binding_input = *plan.inputs[0].output.outpoint();
|
||||
let outputs = signable.outputs().to_vec();
|
||||
|
||||
Reference in New Issue
Block a user