Advertisement
moonion_nashivan

Untitled

Mar 22nd, 2022
1,504
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.78 KB | None | 0 0
  1. // CalcGasLimit computes the gas limit of the next block after parent. It aims
  2. // to keep the baseline gas close to the provided target, and increase it towards
  3. // the target if the baseline gas is lower.
  4. func CalcGasLimit(parentGasLimit, desiredLimit uint64) uint64 {
  5.     delta := parentGasLimit/params.GasLimitBoundDivisor - 1
  6.     limit := parentGasLimit
  7.     if desiredLimit < params.MinGasLimit {
  8.         desiredLimit = params.MinGasLimit
  9.     }
  10.     // If we're outside our allowed gas range, we try to hone towards them
  11.     if limit < desiredLimit {
  12.         limit = parentGasLimit + delta
  13.         if limit > desiredLimit {
  14.             limit = desiredLimit
  15.         }
  16.         return limit
  17.     }
  18.     if limit > desiredLimit {
  19.         limit = parentGasLimit - delta
  20.         if limit < desiredLimit {
  21.             limit = desiredLimit
  22.         }
  23.     }
  24.     return limit
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement