2026-04-04 11:16:28 +01:00
|
|
|
package nicehash
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"sync"
|
2026-04-04 10:29:02 +00:00
|
|
|
"time"
|
2026-04-04 11:16:28 +01:00
|
|
|
|
2026-04-04 16:10:33 +01:00
|
|
|
"dappco.re/go/proxy"
|
|
|
|
|
"dappco.re/go/proxy/pool"
|
2026-04-04 11:16:28 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// NonceMapper manages one outbound pool connection and the 256-slot NonceStorage.
|
|
|
|
|
// It implements pool.StratumListener to receive job and result events from the pool.
|
|
|
|
|
//
|
|
|
|
|
// m := nicehash.NewNonceMapper(id, cfg, strategy)
|
|
|
|
|
// m.Start()
|
|
|
|
|
type NonceMapper struct {
|
|
|
|
|
id int64
|
|
|
|
|
storage *NonceStorage
|
2026-04-04 10:29:02 +00:00
|
|
|
strategy pool.Strategy // manages pool client lifecycle and failover
|
2026-04-04 11:16:28 +01:00
|
|
|
pending map[int64]SubmitContext // sequence → {requestID, minerID}
|
2026-04-04 22:06:18 +00:00
|
|
|
config *proxy.Config
|
2026-04-04 10:29:02 +00:00
|
|
|
events *proxy.EventBus
|
2026-04-04 11:16:28 +01:00
|
|
|
active bool // true once pool has sent at least one job
|
|
|
|
|
suspended int // > 0 when pool connection is in error/reconnecting
|
2026-04-04 10:29:02 +00:00
|
|
|
lastUsed time.Time
|
2026-04-04 18:53:16 +00:00
|
|
|
startOnce sync.Once
|
2026-04-04 11:16:28 +01:00
|
|
|
mu sync.Mutex
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SubmitContext tracks one in-flight share submission waiting for pool reply.
|
|
|
|
|
//
|
|
|
|
|
// ctx := SubmitContext{RequestID: 42, MinerID: 7}
|
|
|
|
|
type SubmitContext struct {
|
|
|
|
|
RequestID int64 // JSON-RPC id from the miner's submit request
|
|
|
|
|
MinerID int64 // miner that submitted
|
2026-04-04 10:29:02 +00:00
|
|
|
JobID string
|
2026-04-05 00:32:43 +00:00
|
|
|
Diff uint64
|
2026-04-04 18:38:28 +00:00
|
|
|
StartedAt time.Time
|
2026-04-04 11:16:28 +01:00
|
|
|
}
|