Skip to content

Commit

Permalink
Enable rounding for gas (MystenLabs#12467)
Browse files Browse the repository at this point in the history
## Description 

Actually enable rounding

## Test Plan 

current tests

---
If your changes are not user-facing and not a breaking change, you can
skip the following section. Otherwise, please indicate what changed, and
then add to the Release Notes section as highlighted during the release
process.

### Type of Change (Check all that apply)

- [ ] protocol change
- [ ] user-visible impact
- [ ] breaking change for a client SDKs
- [ ] breaking change for FNs (FN binary must upgrade)
- [ ] breaking change for validators or node operators (must upgrade
binaries)
- [ ] breaking change for on-chain data layout
- [ ] necessitate either a data wipe or data migration

### Release notes
  • Loading branch information
dariorussi authored Jun 14, 2023
1 parent d694faa commit 2d3f822
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ gas summary: computation_cost: 10000000, storage_cost: 988000, storage_rebate:

task 4 'run'. lines 42-44:
mutated: object(0,0)
gas summary: computation_cost: 200000000, storage_cost: 988000, storage_rebate: 978120, non_refundable_storage_fee: 9880
gas summary: computation_cost: 96000000, storage_cost: 988000, storage_rebate: 978120, non_refundable_storage_fee: 9880

task 5 'run'. lines 45-47:
Error: Transaction Effects Status: Move Primitive Runtime Error. Location: sui::tx_context::derive_id (function index 6) at offset 0. Arithmetic error, stack overflow, max value depth, etc.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ gas summary: computation_cost: 1000000, storage_cost: 988000, storage_rebate: 9
task 3 'run'. lines 61-63:
events: 50
mutated: 1
gas summary: computation_cost: 20000000, storage_cost: 988000, storage_rebate: 978120, non_refundable_storage_fee: 9880
gas summary: computation_cost: 11000000, storage_cost: 988000, storage_rebate: 978120, non_refundable_storage_fee: 9880

task 4 'run'. lines 64-66:
Error: Transaction Effects Status: Move Primitive Runtime Error. Location: sui::event::emit (function index 0) at offset 0. Arithmetic error, stack overflow, max value depth, etc.
Expand All @@ -26,12 +26,12 @@ Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { k
task 6 'run'. lines 70-72:
events: 1
mutated: 1
gas summary: computation_cost: 5000000000, storage_cost: 988000, storage_rebate: 978120, non_refundable_storage_fee: 9880
gas summary: computation_cost: 1521000000, storage_cost: 988000, storage_rebate: 978120, non_refundable_storage_fee: 9880

task 7 'run'. lines 73-75:
events: 1
mutated: 1
gas summary: computation_cost: 5000000000, storage_cost: 988000, storage_rebate: 978120, non_refundable_storage_fee: 9880
gas summary: computation_cost: 1948000000, storage_cost: 988000, storage_rebate: 978120, non_refundable_storage_fee: 9880

task 8 'run'. lines 76-78:
Error: Transaction Effects Status: Move Primitive Runtime Error. Location: sui::event::emit (function index 0) at offset 0. Arithmetic error, stack overflow, max value depth, etc.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ Execution Error: ExecutionError: ExecutionError { inner: ExecutionErrorInner { k
task 3 'run'. lines 86-88:
created: object(3,0)
mutated: object(0,0)
gas summary: computation_cost: 5000000000, storage_cost: 1947553200, storage_rebate: 978120, non_refundable_storage_fee: 9880
gas summary: computation_cost: 1996000000, storage_cost: 1947553200, storage_rebate: 978120, non_refundable_storage_fee: 9880

task 4 'run'. lines 89-89:
created: object(4,0)
mutated: object(0,0)
gas summary: computation_cost: 5000000000, storage_cost: 1947560800, storage_rebate: 978120, non_refundable_storage_fee: 9880
gas summary: computation_cost: 1996000000, storage_cost: 1947560800, storage_rebate: 978120, non_refundable_storage_fee: 9880
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ gas summary: computation_cost: 10000000, storage_cost: 988000, storage_rebate:

task 4 'run'. lines 43-45:
mutated: object(0,0)
gas summary: computation_cost: 200000000, storage_cost: 988000, storage_rebate: 978120, non_refundable_storage_fee: 9880
gas summary: computation_cost: 96000000, storage_cost: 988000, storage_rebate: 978120, non_refundable_storage_fee: 9880

task 5 'run'. lines 46-48:
Error: Transaction Effects Status: Move Primitive Runtime Error. Location: sui::tx_context::derive_id (function index 6) at offset 0. Arithmetic error, stack overflow, max value depth, etc.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ gas summary: computation_cost: 1000000, storage_cost: 5821600, storage_rebate:
task 2 'run'. lines 30-30:
created: 200
mutated: 1
gas summary: computation_cost: 10000000, storage_cost: 270028000, storage_rebate: 0, non_refundable_storage_fee: 0
gas summary: computation_cost: 9000000, storage_cost: 270028000, storage_rebate: 0, non_refundable_storage_fee: 0

task 3 'run'. lines 32-32:
created: 2000
mutated: 1
gas summary: computation_cost: 200000000, storage_cost: 2691388000, storage_rebate: 978120, non_refundable_storage_fee: 9880
gas summary: computation_cost: 106000000, storage_cost: 2691388000, storage_rebate: 978120, non_refundable_storage_fee: 9880

task 4 'run'. lines 34-34:
Error: Transaction Effects Status: Move Primitive Runtime Error. Location: sui::dynamic_field::has_child_object (function index 14) at offset 0. Arithmetic error, stack overflow, max value depth, etc.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ gas summary: computation_cost: 10000000, storage_cost: 316175200, storage_rebat
task 4 'run'. lines 42-44:
created: 2048
mutated: 1
gas summary: computation_cost: 200000000, storage_cost: 2522485600, storage_rebate: 978120, non_refundable_storage_fee: 9880
gas summary: computation_cost: 94000000, storage_cost: 2522485600, storage_rebate: 978120, non_refundable_storage_fee: 9880

task 5 'run'. lines 45-47:
Error: Transaction Effects Status: Move Primitive Runtime Error. Location: sui::tx_context::derive_id (function index 6) at offset 0. Arithmetic error, stack overflow, max value depth, etc.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ gas summary: computation_cost: 1000000, storage_cost: 988000, storage_rebate: 9

task 3 'run'. lines 36-38:
mutated: object(0,0)
gas summary: computation_cost: 5000000, storage_cost: 988000, storage_rebate: 978120, non_refundable_storage_fee: 9880
gas summary: computation_cost: 2000000, storage_cost: 988000, storage_rebate: 978120, non_refundable_storage_fee: 9880

task 4 'run'. lines 39-41:
mutated: object(0,0)
gas summary: computation_cost: 5000000000, storage_cost: 988000, storage_rebate: 978120, non_refundable_storage_fee: 9880
gas summary: computation_cost: 4196000000, storage_cost: 988000, storage_rebate: 978120, non_refundable_storage_fee: 9880

task 5 'run'. lines 42-42:
Error: Transaction Effects Status: Move Primitive Runtime Error. Location: Test::M1::push_n_items (function index 0) at offset 11. Arithmetic error, stack overflow, max value depth, etc.
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-types/src/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl SuiCostTable {
gas_budget: u64,
gas_price: u64,
storage_price: u64,
gas_rounding_step: u64,
gas_rounding_step: Option<u64>,
) -> SuiGasStatus {
match self {
Self::V1(cost_table) => SuiGasStatus::V1(SuiGasStatusV1::new_for_testing(
Expand Down
18 changes: 9 additions & 9 deletions crates/sui-types/src/gas_model/gas_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ pub struct SuiGasStatus {
/// This allows us to track how much storage rebate we need to retain in system transactions.
unmetered_storage_rebate: u64,
/// Rounding value to round up gas charges.
gas_rounding_step: u64,
gas_rounding_step: Option<u64>,
}

impl SuiGasStatus {
Expand All @@ -218,10 +218,10 @@ impl SuiGasStatus {
gas_price: u64,
storage_gas_price: u64,
rebate_rate: u64,
gas_rounding_step: u64,
gas_rounding_step: Option<u64>,
cost_table: SuiCostTable,
) -> SuiGasStatus {
let gas_rounding_step = gas_rounding_step.max(1);
let gas_rounding_step = gas_rounding_step.map(|val| val.max(1));
SuiGasStatus {
gas_status: move_gas_status,
gas_budget,
Expand Down Expand Up @@ -251,7 +251,7 @@ impl SuiGasStatus {
gas_budget
};
let sui_cost_table = SuiCostTable::new(config);
let gas_rounding_step = config.gas_rounding_step_as_option().unwrap_or(1u64);
let gas_rounding_step = config.gas_rounding_step_as_option();
Self::new(
GasStatus::new_v2(
sui_cost_table.execution_cost_table.clone(),
Expand All @@ -273,7 +273,7 @@ impl SuiGasStatus {
gas_budget: u64,
gas_price: u64,
storage_gas_price: u64,
gas_rounding_step: u64,
gas_rounding_step: Option<u64>,
cost_table: SuiCostTable,
) -> SuiGasStatus {
let protocol_config = ProtocolConfig::get_for_max_version();
Expand Down Expand Up @@ -309,7 +309,7 @@ impl SuiGasStatus {
0,
0,
0,
1, // `gas_rounding_step` used in a division if we ever enter that code
None,
SuiCostTable::unmetered(),
)
}
Expand All @@ -326,11 +326,11 @@ impl SuiGasStatusAPI for SuiGasStatus {

fn bucketize_computation(&mut self) -> Result<(), ExecutionError> {
let gas_used = self.gas_status.gas_used_pre_gas_price();
let gas_used = if self.gas_status.gas_model_version > 5 {
if gas_used > 0 && gas_used % self.gas_rounding_step == 0 {
let gas_used = if let Some(gas_rounding) = self.gas_rounding_step {
if gas_used > 0 && gas_used % gas_rounding == 0 {
gas_used * self.gas_price
} else {
((gas_used / self.gas_rounding_step) + 1) * self.gas_rounding_step * self.gas_price
((gas_used / gas_rounding) + 1) * gas_rounding * self.gas_price
}
} else {
let bucket_cost = get_bucket_cost(&self.cost_table.computation_bucket, gas_used);
Expand Down

0 comments on commit 2d3f822

Please sign in to comment.