forked from consensus-shipyard/ref-fvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement FIP-0032 gas parameters and charges (filecoin-project#534)
* exec gas: apply only on non-structural instructions. * pricelist: add new gas fees. * gas: fully switch to milligas as canonical unit. * price list: update gas cost formulae. * price list: vertical spacing. * kernel: apply extern gas. * syscalls: charge for gas; small refactors. * remove Kernel#charge_milligas(). Canonical unit is now milligas everywhere. * fix tests. * fix param. * clippy. * add comment. * fix gas instrumentation. * rename GasTracker#{charge_gas=>apply_charge} to disambiguate. * add Gas and Milligas unit types to disambiguate. * convert public gas charges to milligas. * inclusion cost: adapt to milligas. * charge_gas: move conversion to milligas to syscall handler. * {to_milligas=>static_milligas}; make private. * clippy. * price list: remove compute_gas_multiplier (unused). * polish comment. * use saturation arithmetics for mem costs. * price list: use Milligas type for cost fields. * rename Kernel#charge_{=>milli}gas. * add extern cost in syscall pricing formulae. * charge for syscall gas at the right place.
- Loading branch information
Showing
13 changed files
with
351 additions
and
239 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,30 @@ | ||
// Copyright 2019-2022 ChainSafe Systems | ||
// SPDX-License-Identifier: Apache-2.0, MIT | ||
|
||
use crate::gas::Milligas; | ||
|
||
/// Single gas charge in the VM. Contains information about what gas was for, as well | ||
/// as the amount of gas needed for computation and storage respectively. | ||
pub struct GasCharge<'a> { | ||
pub name: &'a str, | ||
pub compute_gas: i64, | ||
pub storage_gas: i64, | ||
/// Compute costs in milligas. | ||
pub compute_gas: Milligas, | ||
/// Storage costs in milligas. | ||
pub storage_gas: Milligas, | ||
} | ||
|
||
impl<'a> GasCharge<'a> { | ||
pub fn new(name: &'a str, compute_gas: i64, storage_gas: i64) -> Self { | ||
pub fn new(name: &'a str, compute_gas: Milligas, storage_gas: Milligas) -> Self { | ||
Self { | ||
name, | ||
compute_gas, | ||
storage_gas, | ||
} | ||
} | ||
|
||
/// Calculates total gas charge based on compute and storage multipliers. | ||
pub fn total(&self) -> i64 { | ||
/// Calculates total gas charge (in milligas) by summing compute and | ||
/// storage gas associated with this charge. | ||
pub fn total(&self) -> Milligas { | ||
self.compute_gas + self.storage_gas | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.