calcCacheSize¶
| Source (upstream pre-purge) | Current | |
|---|---|---|
| File | consensus/ethash/algorithm.go |
algorithm.go |
| Symbol | calcCacheSize |
calcCacheSize |
| Ref | dde2da0ef~1 |
etc/v1.17.3-full-node |
epoch param kept as int (matching upstream). core-geth changed to uint64 for consistency with calcEpoch, but we prioritize minimal diff. The uint64→int cast happens in cacheSize() caller.
3-way merge — purge → getc ← upstream¶
pre-purge
↗// calcCacheSize calculates the cache size for epoch. The cache size grows linearly,
// however, we always take the highest prime below the linearly growing threshold in order
// to reduce the risk of accidental regularities leading to cyclic behavior.
func calcCacheSize(epoch int) uint64 {
size := cacheInitBytes + cacheGrowthBytes*uint64(epoch) - hashBytes
for !new(big.Int).SetUint64(size / hashBytes).ProbablyPrime(1) { // Always accurate for n < 2^64
size -= 2 * hashBytes
}
return size
}
core-geth validation — +2 -2
| | | |---|---| | File | [`algorithm.go`](https://github.com/etclabscore/core-geth/blob/v1.12.20/consensus/ethash/algorithm.go) | | Symbol | `calcCacheSize` | | Ref | `v1.12.20` |--- a/core-geth/consensus/ethash/algorithm.go
+++ b/etc/consensus/ethash/algorithm.go
@@ -1,8 +1,8 @@
// calcCacheSize calculates the cache size for epoch. The cache size grows linearly,
// however, we always take the highest prime below the linearly growing threshold in order
// to reduce the risk of accidental regularities leading to cyclic behavior.
-func calcCacheSize(epoch uint64) uint64 {
- size := cacheInitBytes + cacheGrowthBytes*epoch - hashBytes
+func calcCacheSize(epoch int) uint64 {
+ size := cacheInitBytes + cacheGrowthBytes*uint64(epoch) - hashBytes
for !new(big.Int).SetUint64(size / hashBytes).ProbablyPrime(1) { // Always accurate for n < 2^64
size -= 2 * hashBytes
}