-
Notifications
You must be signed in to change notification settings - Fork 465
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Controller for statelimit adjustment
- Loading branch information
1 parent
2636960
commit 1f33c90
Showing
5 changed files
with
47 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,43 @@ | ||
package misc | ||
|
||
func CalcStateLimit() uint64 { | ||
return 0 | ||
import ( | ||
"github.com/dominant-strategies/go-quai/common" | ||
"github.com/dominant-strategies/go-quai/core/types" | ||
"github.com/dominant-strategies/go-quai/params" | ||
) | ||
|
||
func CalcStateLimit(parent *types.WorkObject, stateCeil uint64) uint64 { | ||
// No Gas for TimeToStartTx days worth of zone blocks, this gives enough time to | ||
// onboard new miners into the slice | ||
if parent.NumberU64(common.ZONE_CTX) < params.TimeToStartTx { | ||
return 0 | ||
} | ||
|
||
// If parent gas is zero and we have passed the 5 day threshold, we can set the first block gas limit to min gas limit | ||
if parent.StateLimit() == 0 { | ||
return params.MinGasLimit | ||
} | ||
|
||
parentStateLimit := parent.StateLimit() | ||
|
||
delta := parentStateLimit/params.StateLimitBoundDivisor - 1 | ||
limit := parentStateLimit | ||
|
||
var desiredLimit uint64 | ||
percentStateUsed := parent.StateUsed() * 100 / parent.StateLimit() | ||
if percentStateUsed > params.PercentStateUsedThreshold { | ||
desiredLimit = stateCeil | ||
if limit+delta > desiredLimit { | ||
return desiredLimit | ||
} else { | ||
return limit + delta | ||
} | ||
} else { | ||
desiredLimit = params.MinGasLimit | ||
if limit-delta/2 < desiredLimit { | ||
return desiredLimit | ||
} else { | ||
return limit - delta/2 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters