Skip to content

Commit

Permalink
rosetta: fix account value below zero crash (#6165)
Browse files Browse the repository at this point in the history
  • Loading branch information
666lcz authored and ebmifa committed Nov 17, 2022
1 parent ec5b7de commit 6c001d0
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions crates/sui-rosetta/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,15 @@ impl PseudoBlockProvider {
.map(|HistoricBalance { balance, .. }| *balance)
.unwrap_or_default();
let new_balance = if value.is_negative() {
assert!(
current_balance >= value.abs(),
"Account gas value fall below 0 at block {}, address: [{}]",
block_height,
addr
);
if current_balance < value.abs() {
// This can happen due to missing transactions data due to unstable validators, causing balance to
// fall below zero temporarily. The problem should go away when we start using checkpoints for event and indexing
return Err(anyhow!(
"Account gas value fall below 0 at block {}, address: [{}]",
block_height,
addr
));
}
current_balance - value.abs()
} else {
current_balance + value.abs()
Expand Down

0 comments on commit 6c001d0

Please sign in to comment.