From 68791b06465250db861e8d7ce9c6b5b2ccdb074b Mon Sep 17 00:00:00 2001 From: Matheus Degiovani Date: Sat, 20 Jan 2024 09:57:12 -0300 Subject: [PATCH] miner: Remove need for dcrd in benchmark mode. This makes it possible to run gominer in benchmark mode (-B) without having setup a dcrd instance. This is particularly useful when comissioning new machines or testing the software, so that users do not have to setup an entire simnet environment or wait for a full mainnet dcrd and dcrwallet sync. --- miner.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/miner.go b/miner.go index 495a094..58fdce3 100644 --- a/miner.go +++ b/miner.go @@ -128,6 +128,10 @@ func newSoloMiner(ctx context.Context, devices []*Device) (*Miner, error) { return m, nil } +func newBenchmarkMiner(devices []*Device) *Miner { + return &Miner{devices: devices} +} + func NewMiner(ctx context.Context) (*Miner, error) { workDone := make(chan []byte, 10) @@ -140,9 +144,12 @@ func NewMiner(ctx context.Context) (*Miner, error) { } var m *Miner - if cfg.Pool == "" { + switch { + case cfg.Benchmark: + m = newBenchmarkMiner(devices) + case cfg.Pool == "": m, err = newSoloMiner(ctx, devices) - } else { + default: m, err = newStratum(devices) } if err != nil { @@ -152,6 +159,12 @@ func NewMiner(ctx context.Context) (*Miner, error) { m.workDone = workDone m.started = uint32(time.Now().Unix()) + // Return early on benchmark mode to avoid requiring a dcrd instance to + // be running. + if cfg.Benchmark { + return m, nil + } + // Perform an initial call to getwork when solo mining so work is available // immediately. if cfg.Pool == "" {