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

Fix fees in WASM planner #3693

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions crates/wasm/src/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,23 @@ impl<R: RngCore + CryptoRng> Planner<R> {
///
/// This function should be called once.
pub fn add_gas_fees(&mut self) -> &mut Self {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes copied from

pub fn add_gas_fees(&mut self) -> &mut Self {
// Add a single Spend + Output to the minimum fee to cover paying the fee
let minimum_fee = self
.gas_prices
.fee(&(self.plan.gas_cost() + gas::output_gas_cost() + gas::spend_gas_cost()));
// Since paying the fee possibly requires adding additional Spends and Outputs
// to the transaction, which would then change the fee calculation, we multiply
// the fee here by a factor of 128 and then recalculate and capture the excess as
// change outputs.
//
// TODO: this is gross and depending on gas costs could make the gas overpayment
// ridiculously large (so large that the account may not have notes available to cover it)
// or too small. We may need a cyclical calculation of fees on the transaction plan,
// or a "simulated" transaction plan with infinite assets to calculate fees on before
// copying the exact fees to the real transaction.
let fee = Fee::from_staking_token_amount(minimum_fee * Amount::from(128u32));
self.balance -= fee.0;
self.plan.transaction_parameters.fee = fee.clone();
self
}

let minimum_fee = self.gas_prices.fee(&self.plan.gas_cost());
let minimum_fee = self
.gas_prices
.fee(&(self.plan.gas_cost() + gas::output_gas_cost() + gas::spend_gas_cost()));

// Since paying the fee possibly requires adding an additional Spend to the
// transaction, which would then change the fee calculation, we multiply the
// fee here by a factor of 2 and then recalculate and capture the excess as
// Since paying the fee possibly requires adding additional Spends and Outputs
// to the transaction, which would then change the fee calculation, we multiply
// the fee here by a factor of 128 and then recalculate and capture the excess as
// change outputs.
let fee = Fee::from_staking_token_amount(minimum_fee * Amount::from(2u32));
self.balance += fee.0;
self.plan.transaction_parameters.fee = fee;
//
// TODO: this is gross and depending on gas costs could make the gas overpayment
// ridiculously large (so large that the account may not have notes available to cover it)
// or too small. We may need a cyclical calculation of fees on the transaction plan,
// or a "simulated" transaction plan with infinite assets to calculate fees on before
// copying the exact fees to the real transaction.
let fee = Fee::from_staking_token_amount(minimum_fee * Amount::from(128u32));
self.balance -= fee.0;
self.plan.transaction_parameters.fee = fee.clone();
self
}

Expand Down
Loading