From e28709096cb9c9b7521ed1ce13ebb02b11e73bf8 Mon Sep 17 00:00:00 2001 From: Jonathan Downing Date: Thu, 9 May 2024 17:53:49 -0500 Subject: [PATCH] Updated blake3pow and progpow to allow setting thread count --- consensus/blake3pow/blake3pow.go | 9 ++++++--- consensus/consensus.go | 2 ++ consensus/progpow/progpow.go | 11 +++++++---- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/consensus/blake3pow/blake3pow.go b/consensus/blake3pow/blake3pow.go index b5230638b6..a0f520668e 100644 --- a/consensus/blake3pow/blake3pow.go +++ b/consensus/blake3pow/blake3pow.go @@ -43,6 +43,8 @@ type Config struct { NotifyFull bool Log *log.Logger `toml:"-"` + // Number of threads to mine on if mining + NumThreads int } // Blake3pow is a proof-of-work consensus engine using the blake3 hash algorithm @@ -70,9 +72,10 @@ type Blake3pow struct { // packages. func New(config Config, notify []string, noverify bool, logger *log.Logger) *Blake3pow { blake3pow := &Blake3pow{ - config: config, - update: make(chan struct{}), - logger: logger, + config: config, + update: make(chan struct{}), + logger: logger, + threads: config.NumThreads, } if config.PowMode == ModeShared { blake3pow.shared = sharedBlake3pow diff --git a/consensus/consensus.go b/consensus/consensus.go index 1e00aaf0c6..0d892c6c81 100644 --- a/consensus/consensus.go +++ b/consensus/consensus.go @@ -175,6 +175,8 @@ type Engine interface { // VerifySeal computes the PowHash and checks if work meets the difficulty // requirement specified in header VerifySeal(header *types.WorkObjectHeader) (common.Hash, error) + + SetThreads(threads int) } func TargetToDifficulty(target *big.Int) *big.Int { diff --git a/consensus/progpow/progpow.go b/consensus/progpow/progpow.go index 71b1e66f06..4999d65aa2 100644 --- a/consensus/progpow/progpow.go +++ b/consensus/progpow/progpow.go @@ -157,6 +157,8 @@ type Config struct { NotifyFull bool Log *log.Logger `toml:"-"` + // Number of threads to mine on if mining + NumThreads int } // Progpow is a proof-of-work consensus engine using the blake3 hash algorithm @@ -196,10 +198,11 @@ func New(config Config, notify []string, noverify bool, logger *log.Logger) *Pro }).Info("Disk storage enabled for ethash caches") } progpow := &Progpow{ - config: config, - caches: newlru("cache", config.CachesInMem, newCache, logger), - update: make(chan struct{}), - logger: logger, + config: config, + caches: newlru("cache", config.CachesInMem, newCache, logger), + update: make(chan struct{}), + logger: logger, + threads: config.NumThreads, } if config.PowMode == ModeShared { progpow.shared = sharedProgpow