Skip to content

Commit

Permalink
core, ethdb/leveldb: use min/max/clear
Browse files Browse the repository at this point in the history
  • Loading branch information
gitglorythegreat authored Dec 26, 2024
1 parent 341647f commit d26fd9b
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 27 deletions.
5 changes: 1 addition & 4 deletions core/rawdb/chain_freezer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions core/txpool/blobpool/priority.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions core/vm/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 3 additions & 12 deletions core/vm/memory_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
4 changes: 1 addition & 3 deletions ethdb/leveldb/leveldb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit d26fd9b

Please sign in to comment.