Skip to content

Commit

Permalink
gas counter scale up fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dvush committed Mar 19, 2021
1 parent 2eba975 commit 64b4d0e
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions core/lib/types/src/gas_counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,22 +209,26 @@ impl GasCounter {
}

pub fn commit_gas_limit_aggregated(blocks: &[Block]) -> U256 {
U256::from(Self::BASE_COMMIT_BLOCKS_TX_COST)
let approx_limit = U256::from(Self::BASE_COMMIT_BLOCKS_TX_COST)
+ blocks
.iter()
.fold(U256::zero(), |acc, block| acc + block.commit_gas_limit)
.fold(U256::zero(), |acc, block| acc + block.commit_gas_limit);

Self::scale_up(approx_limit)
}

pub fn execute_gas_limit_aggregated(blocks: &[Block]) -> U256 {
U256::from(Self::BASE_EXECUTE_BLOCKS_TX_COST)
let approx_limit = U256::from(Self::BASE_EXECUTE_BLOCKS_TX_COST)
+ blocks
.iter()
.fold(U256::zero(), |acc, block| acc + block.verify_gas_limit)
.fold(U256::zero(), |acc, block| acc + block.verify_gas_limit);

Self::scale_up(approx_limit)
}

/// Increases the value by 30%.
/// Increases the value by 35%.
fn scale_up(value: U256) -> U256 {
value * U256::from(130) / U256::from(100)
value * U256::from(135) / U256::from(100)
}
}

Expand Down

0 comments on commit 64b4d0e

Please sign in to comment.