FuelLabs / fuel-core

Rust full node implementation of the Fuel v2 protocol.
Other
57.95k stars 2.79k forks source link

Zeroing of our reward and costs doesn't work with Simulation #2264

Closed MitchTurner closed 1 month ago

MitchTurner commented 1 month ago

Since adding the finalization period for the DA blocks in our gas price algorithm analyzer here https://github.com/FuelLabs/fuel-core/pull/2240 , the way our simulation tallies the actual_cost doesn't work anymore.

The problem is with the _normalize_rewards_and_costs function, which regularly trims the rewards and costs in the algorithm to avoid overflow. This simulation doesn't work with that because now the actual_cost is recorded much later now.

We can either

  1. Remove the function. It is currently unused to avoid this issue. We should evaluate whether overflow is ever possible or if we should increase them from u128 to something beefier
  2. Fix the simulation to work with the function included
rafal-ch commented 1 month ago

Notes from the huddle:

  1. there's a 3rd way we can apply - do not call the normalization function on every DA block update, but only occasionally, when we see that the accumulated numbers go close to the u128::MAX limit
  2. there's also another issue - normalization is called for every DA block update, but the overflow of total_da_rewards_excess can already happen when we're updating the L2 blocks

Anyway, after analyzing the numbers, the conclusion is that we don't need the normalization function as the chances of the overflow are close to non-existent:

  1. u128::MAX = 340,282,366,920,938,463,463,374,607,431,768,211,455
  2. we do calculation in wei, hence the above is equal to ~340,282,366,920,938,463,463 ether
  3. even if we'd assume 1 eth of rewards per block (each second), this gives us ~10,790,283,070,806 years before we overflow

Hence, the way to go is to remove the normalization step.

cc: @MitchTurner

rafal-ch commented 1 month ago

Closed with https://github.com/FuelLabs/fuel-core/pull/2293