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 { if final == 0 && headLimit == 0 {
return 0, errors.New("freezing threshold is not available") return 0, errors.New("freezing threshold is not available")
} }
if final > headLimit { return max(final, headLimit), nil
return final, nil
}
return headLimit, nil
} }
// freeze is a background thread that periodically checks the blockchain for any // 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) basefeePriority = evictionPriority1D(basefeeJumps, txBasefeeJumps)
blobfeePriority = evictionPriority1D(blobfeeJumps, txBlobfeeJumps) blobfeePriority = evictionPriority1D(blobfeeJumps, txBlobfeeJumps)
) )
if basefeePriority < blobfeePriority { return min(basefeePriority, blobfeePriority)
return basefeePriority
}
return blobfeePriority
} }
// evictionPriority1D calculates the eviction priority based on the algorithm // 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 return math.MaxUint64
} }
// 3. Minimum price of 200 gas // 3. Minimum price of 200 gas
if gas.Uint64() < 200 { return max(200, gas.Uint64())
return 200
}
return gas.Uint64()
} }
gas = modexpMultComplexity(gas) gas = modexpMultComplexity(gas)
if adjExpLen.Cmp(big1) > 0 { if adjExpLen.Cmp(big1) > 0 {

View file

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

View file

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