fixes gasLimitBounds
This commit is contained in:
parent
ed01201233
commit
b189e1604f
|
@ -18,13 +18,13 @@ proc hasUncles*(header: BlockHeader): bool = header.ommersHash != EMPTY_UNCLE_HA
|
|||
proc `$`*(header: BlockHeader): string =
|
||||
result = &"BlockHeader(timestamp: {header.timestamp} difficulty: {header.difficulty} blockNumber: {header.blockNumber} gasLimit: {header.gasLimit})"
|
||||
|
||||
proc gasLimitBounds*(parent: BlockHeader): (Uint256, Uint256) =
|
||||
proc gasLimitBounds*(parent: BlockHeader): (GasInt, GasInt) =
|
||||
## Compute the boundaries for the block gas limit based on the parent block.
|
||||
let
|
||||
gasLimit = parent.gasLimit.u256
|
||||
boundaryRange = (parent.gasLimit div GAS_LIMIT_ADJUSTMENT_FACTOR).u256
|
||||
upperBound = gasLimit + boundaryRange
|
||||
lowerBound = max(GAS_LIMIT_MINIMUM.u256, gasLimit - boundaryRange)
|
||||
boundaryRange = (parent.gasLimit div GAS_LIMIT_ADJUSTMENT_FACTOR)
|
||||
upperBound = if GAS_LIMIT_MAXIMUM - boundaryRange < parent.gasLimit:
|
||||
GAS_LIMIT_MAXIMUM else: parent.gasLimit + boundaryRange
|
||||
lowerBound = max(GAS_LIMIT_MINIMUM, parent.gasLimit - boundaryRange)
|
||||
|
||||
return (lowerBound, upperBound)
|
||||
|
||||
|
|
|
@ -411,9 +411,9 @@ proc validateGasLimit(chainDB: BaseChainDB, header: BlockHeader) =
|
|||
let parentHeader = chainDB.getBlockHeader(header.parentHash)
|
||||
let (lowBound, highBound) = gasLimitBounds(parentHeader)
|
||||
|
||||
if header.gasLimit.u256 < lowBound:
|
||||
if header.gasLimit < lowBound:
|
||||
raise newException(ValidationError, "The gas limit is too low")
|
||||
elif header.gasLimit.u256 > highBound:
|
||||
elif header.gasLimit > highBound:
|
||||
raise newException(ValidationError, "The gas limit is too high")
|
||||
|
||||
proc validateUncles(chainDB: BaseChainDB, currBlock: PlainBlock, checkSeal: bool) =
|
||||
|
|
Loading…
Reference in New Issue