mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 20:29:23 +00:00
Explicitly only adjust operating costs when plan.change.is_some()
The existing code should've mostly handled this fine. Only a single edge case (TX fee reduction on no-change Plans) would cause an improper increase in operating costs.
This commit is contained in:
@@ -565,7 +565,8 @@ impl Network for Bitcoin {
|
|||||||
// This plan expects a change output valued at 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
|
// Since we can no longer create this change output, it becomes an operating cost
|
||||||
// TODO: Look at input restoration to reduce this operating cost
|
// TODO: Look at input restoration to reduce this operating cost
|
||||||
operating_costs: operating_costs + plan.expected_change(),
|
operating_costs: operating_costs +
|
||||||
|
if plan.change.is_some() { plan.expected_change() } else { 0 },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -575,21 +576,25 @@ impl Network for Bitcoin {
|
|||||||
|
|
||||||
let signable = signable(&plan, Some(tx_fee)).unwrap();
|
let signable = signable(&plan, Some(tx_fee)).unwrap();
|
||||||
|
|
||||||
// Now that we've amortized the fee (which may raise the expected change value), grab it again
|
if plan.change.is_some() {
|
||||||
// Then, subtract the TX fee
|
// Now that we've amortized the fee (which may raise the expected change value), grab it
|
||||||
//
|
// again
|
||||||
// The first `expected_change` call gets the theoretically expected change from the theoretical
|
// Then, subtract the TX fee
|
||||||
// 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
|
// The first `expected_change` call gets the theoretically expected change from the
|
||||||
// adjust
|
// theoretical Plan object, and accordingly doesn't subtract the fee (expecting the payments
|
||||||
let on_chain_expected_change = plan.expected_change() - tx_fee;
|
// to bare it)
|
||||||
// If the change value is less than the dust threshold, it becomes an operating cost
|
// This call wants the actual value, post-amortization over outputs, and since Plan is
|
||||||
// This may be slightly inaccurate as dropping payments may reduce the fee, raising the change
|
// unaware of the fee, has to manually adjust
|
||||||
// above dust
|
let on_chain_expected_change = plan.expected_change() - tx_fee;
|
||||||
// That's fine since it'd have to be in a very precarious state AND then it's over-eager in
|
// If the change value is less than the dust threshold, it becomes an operating cost
|
||||||
// tabulating costs
|
// This may be slightly inaccurate as dropping payments may reduce the fee, raising the
|
||||||
if on_chain_expected_change < Self::DUST {
|
// change above dust
|
||||||
operating_costs += on_chain_expected_change;
|
// 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 plan_binding_input = *plan.inputs[0].output.outpoint();
|
||||||
|
|||||||
@@ -530,32 +530,38 @@ impl Network for Monero {
|
|||||||
// This plan expects a change output valued at 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
|
// Since we can no longer create this change output, it becomes an operating cost
|
||||||
// TODO: Look at input restoration to reduce this operating cost
|
// TODO: Look at input restoration to reduce this operating cost
|
||||||
operating_costs: operating_costs + plan.expected_change(),
|
operating_costs: operating_costs +
|
||||||
|
if plan.change.is_some() { plan.expected_change() } else { 0 },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let AmortizeFeeRes { post_fee_branches, mut operating_costs } =
|
let AmortizeFeeRes { post_fee_branches, mut operating_costs } =
|
||||||
amortize_fee(&mut plan, operating_costs, tx_fee);
|
amortize_fee(&mut plan, operating_costs, tx_fee);
|
||||||
|
let plan_change_is_some = plan.change.is_some();
|
||||||
let plan_expected_change = plan.expected_change();
|
let plan_expected_change = plan.expected_change();
|
||||||
|
|
||||||
let signable = signable(plan, Some(tx_fee))?.unwrap();
|
let signable = signable(plan, Some(tx_fee))?.unwrap();
|
||||||
|
|
||||||
// Now that we've amortized the fee (which may raise the expected change value), grab it again
|
if plan_change_is_some {
|
||||||
// Then, subtract the TX fee
|
// Now that we've amortized the fee (which may raise the expected change value), grab it
|
||||||
//
|
// again
|
||||||
// The first `expected_change` call gets the theoretically expected change from the theoretical
|
// Then, subtract the TX fee
|
||||||
// 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
|
// The first `expected_change` call gets the theoretically expected change from the
|
||||||
// adjust
|
// theoretical Plan object, and accordingly doesn't subtract the fee (expecting the payments
|
||||||
let on_chain_expected_change = plan_expected_change - tx_fee;
|
// to bare it)
|
||||||
// If the change value is less than the dust threshold, it becomes an operating cost
|
// This call wants the actual value, post-amortization over outputs, and since Plan is
|
||||||
// This may be slightly inaccurate as dropping payments may reduce the fee, raising the change
|
// unaware of the fee, has to manually adjust
|
||||||
// above dust
|
let on_chain_expected_change = plan_expected_change - tx_fee;
|
||||||
// That's fine since it'd have to be in a very precarious state AND then it's over-eager in
|
// If the change value is less than the dust threshold, it becomes an operating cost
|
||||||
// tabulating costs
|
// This may be slightly inaccurate as dropping payments may reduce the fee, raising the
|
||||||
if on_chain_expected_change < Self::DUST {
|
// change above dust
|
||||||
operating_costs += on_chain_expected_change;
|
// 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 signable = SignableTransaction { transcript, actual: signable };
|
let signable = SignableTransaction { transcript, actual: signable };
|
||||||
|
|||||||
Reference in New Issue
Block a user