Skip to content

Commit

Permalink
fix(collator): fix gas_used overflow on large blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexagon committed Jul 17, 2024
1 parent 340df5b commit 27e2bd2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion collator/src/collator/do_collate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,9 @@ fn new_transaction(
);

collation_data.execute_count_all += 1;
collation_data.block_limit.gas_used += executor_output.gas_used as u32;

let gas_used = &mut collation_data.block_limit.gas_used;
*gas_used = gas_used.saturating_add(executor_output.gas_used.try_into().unwrap_or(u32::MAX));

let import_fees;
let in_msg_hash = *in_msg.cell.repr_hash();
Expand Down
3 changes: 2 additions & 1 deletion collator/src/collator/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ pub(super) struct BlockCollationData {
// TODO: set from anchor
pub created_by: HashBytes,
}

#[derive(Debug)]
pub struct BlockLimitStats {
pub gas_used: u32,
Expand Down Expand Up @@ -485,7 +486,7 @@ impl BlockLimitStats {
..
} = lt_delta;

let delta_lt = (self.lt_current - self.lt_start) as u32;
let delta_lt = u32::try_from(self.lt_current - self.lt_start).unwrap_or(u32::MAX);
if delta_lt >= *hard_limit {
return true;
}
Expand Down

0 comments on commit 27e2bd2

Please sign in to comment.