Skip to content

Commit

Permalink
Expose c_epochLength for stratum to access
Browse files Browse the repository at this point in the history
  • Loading branch information
Djadih committed Aug 12, 2024
1 parent e826e9d commit 371774c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions consensus/progpow/algorithm.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const (
datasetGrowthBytes = 1 << 23 // Dataset growth per epoch
cacheInitBytes = 1 << 24 // Bytes in cache at genesis
cacheGrowthBytes = 1 << 17 // Cache growth per epoch
epochLength = 4320 // Blocks per epoch
C_epochLength = 4320 // Blocks per epoch
mixBytes = 128 // Width of mix
hashBytes = 64 // Hash length in bytes
hashWords = 16 // Number of 32 bit ints in a hash
Expand All @@ -53,7 +53,7 @@ const (
// cacheSize returns the size of the ethash verification cache that belongs to a certain
// block number.
func cacheSize(block uint64) uint64 {
epoch := int(block / epochLength)
epoch := int(block / C_epochLength)
if epoch < maxEpoch {
return cacheSizes[epoch]
}
Expand All @@ -74,7 +74,7 @@ func calcCacheSize(epoch int) uint64 {
// datasetSize returns the size of the ethash mining dataset that belongs to a certain
// block number.
func datasetSize(block uint64) uint64 {
epoch := int(block / epochLength)
epoch := int(block / C_epochLength)
if epoch < maxEpoch {
return datasetSizes[epoch]
}
Expand Down Expand Up @@ -122,11 +122,11 @@ func makeHasher(h hash.Hash) hasher {
// dataset.
func seedHash(block uint64) []byte {
seed := make([]byte, 32)
if block < epochLength {
if block < C_epochLength {
return seed
}
keccak256 := makeHasher(sha3.NewLegacyKeccak256())
for i := 0; i < int(block/epochLength); i++ {
for i := 0; i < int(block/C_epochLength); i++ {
keccak256(seed, seed)
}
return seed
Expand Down
2 changes: 1 addition & 1 deletion consensus/progpow/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ func (progpow *Progpow) ComputePowLight(header *types.WorkObjectHeader) (mixHash
ethashCache := progpow.cache(blockNumber)
if ethashCache.cDag == nil {
cDag := make([]uint32, progpowCacheWords)
generateCDag(cDag, ethashCache.cache, blockNumber/epochLength, progpow.logger)
generateCDag(cDag, ethashCache.cache, blockNumber/C_epochLength, progpow.logger)
ethashCache.cDag = cDag
}
return progpowLight(size, cache, hash.Bytes(), nonce, blockNumber, ethashCache.cDag, progpow.lookupCache)
Expand Down
8 changes: 4 additions & 4 deletions consensus/progpow/progpow.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,8 @@ func (c *cache) generate(dir string, limit int, lock bool, test bool, logger *lo
}
}()
c.once.Do(func() {
size := cacheSize(c.epoch*epochLength + 1)
seed := seedHash(c.epoch*epochLength + 1)
size := cacheSize(c.epoch*C_epochLength + 1)
seed := seedHash(c.epoch*C_epochLength + 1)
if test {
size = 1024
}
Expand Down Expand Up @@ -409,7 +409,7 @@ func (c *cache) generate(dir string, limit int, lock bool, test bool, logger *lo
generateCDag(c.cDag, c.cache, c.epoch, logger)
// Iterate over all previous instances and delete old ones
for ep := int(c.epoch) - limit; ep >= 0; ep-- {
seed := seedHash(uint64(ep)*epochLength + 1)
seed := seedHash(uint64(ep)*C_epochLength + 1)
path := filepath.Join(dir, fmt.Sprintf("cache-R%d-%x%s", algorithmRevision, seed[:8], endian))
os.Remove(path)
}
Expand All @@ -429,7 +429,7 @@ func (c *cache) finalizer() {
// by first checking against a list of in-memory caches, then against caches
// stored on disk, and finally generating one if none can be found.
func (progpow *Progpow) cache(block uint64) *cache {
epoch := block / epochLength
epoch := block / C_epochLength
currentI, futureI := progpow.caches.get(epoch)
current := currentI.(*cache)

Expand Down
2 changes: 1 addition & 1 deletion consensus/progpow/sealer.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ search:
ethashCache := progpow.cache(blockNumber)
if ethashCache.cDag == nil {
cDag := make([]uint32, progpowCacheWords)
generateCDag(cDag, ethashCache.cache, blockNumber/epochLength, progpow.logger)
generateCDag(cDag, ethashCache.cache, blockNumber/C_epochLength, progpow.logger)
ethashCache.cDag = cDag
}
return progpowLight(size, cache, hash, nonce, blockNumber, ethashCache.cDag, progpow.lookupCache)
Expand Down

0 comments on commit 371774c

Please sign in to comment.