core, ethdb/leveldb: use min/max/clear

This commit is contained in:
gitglorythegreat 2024-12-26 13:01:44 +08:00 committed by GitHub
parent 341647f186
commit d26fd9b26e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 7 additions and 27 deletions

View file

@ -132,10 +132,7 @@ func (f *chainFreezer) freezeThreshold(db ethdb.KeyValueReader) (uint64, error)
if final == 0 && headLimit == 0 {
return 0, errors.New("freezing threshold is not available")
}
if final > headLimit {
return final, nil
}
return headLimit, nil
return max(final, headLimit), nil
}
// freeze is a background thread that periodically checks the blockchain for any

View file

@ -36,10 +36,7 @@ func evictionPriority(basefeeJumps float64, txBasefeeJumps, blobfeeJumps, txBlob
basefeePriority = evictionPriority1D(basefeeJumps, txBasefeeJumps)
blobfeePriority = evictionPriority1D(blobfeeJumps, txBlobfeeJumps)
)
if basefeePriority < blobfeePriority {
return basefeePriority
}
return blobfeePriority
return min(basefeePriority, blobfeePriority)
}
// evictionPriority1D calculates the eviction priority based on the algorithm

View file

@ -426,10 +426,7 @@ func (c *bigModExp) RequiredGas(input []byte) uint64 {
return math.MaxUint64
}
// 3. Minimum price of 200 gas
if gas.Uint64() < 200 {
return 200
}
return gas.Uint64()
return max(200, gas.Uint64())
}
gas = modexpMultComplexity(gas)
if adjExpLen.Cmp(big1) > 0 {

View file

@ -73,10 +73,7 @@ func memoryCall(stack *Stack) (uint64, bool) {
if overflow {
return 0, true
}
if x > y {
return x, false
}
return y, false
return max(x, y), false
}
func memoryDelegateCall(stack *Stack) (uint64, bool) {
@ -88,10 +85,7 @@ func memoryDelegateCall(stack *Stack) (uint64, bool) {
if overflow {
return 0, true
}
if x > y {
return x, false
}
return y, false
return max(x, y), false
}
func memoryStaticCall(stack *Stack) (uint64, bool) {
@ -103,10 +97,7 @@ func memoryStaticCall(stack *Stack) (uint64, bool) {
if overflow {
return 0, true
}
if x > y {
return x, false
}
return y, false
return max(x, y), false
}
func memoryReturn(stack *Stack) (uint64, bool) {

View file

@ -358,9 +358,7 @@ func (db *Database) meter(refresh time.Duration, namespace string) {
continue
}
// Iterate over all the leveldbTable rows, and accumulate the entries
for j := 0; j < len(compactions[i%2]); j++ {
compactions[i%2][j] = 0
}
clear(compactions[i%2])
compactions[i%2][0] = stats.LevelSizes.Sum()
for _, t := range stats.LevelDurations {
compactions[i%2][1] += t.Nanoseconds()