Expand test coverage across server, agent, and web; fix bugs found during audit.
Adds hundreds of unit/integration/e2e tests, fixes WS bcrypt auth, config merge, fleet analytics, agent schedule/log tail, and documents stale PROBLEMS items. Updates PROBLEMS.md, README, and test scripts; ignores local spread-kits and coverage dirs.
This commit is contained in:
@@ -24,6 +24,10 @@ type Pool struct {
|
||||
|
||||
mu sync.RWMutex
|
||||
currentJob *job.Job
|
||||
// jobGen is incremented atomically every time SetJob replaces the current job.
|
||||
// Workers compare their local snapshot to detect job changes inside the inner
|
||||
// hash loop without acquiring mu on every iteration.
|
||||
jobGen atomic.Uint64
|
||||
stopCh chan struct{}
|
||||
wg sync.WaitGroup
|
||||
paused atomic.Bool
|
||||
@@ -62,16 +66,24 @@ func NewPool(threads int, cfg config.RuntimeConfig, reporter *stats.Reporter, ha
|
||||
|
||||
func (p *Pool) SetJob(job *job.Job) {
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
p.currentJob = job
|
||||
// Bump generation while holding the write-lock so workers that check jobGen
|
||||
// inside their inner batch loop break out and re-snapshot the new job.
|
||||
gen := p.jobGen.Add(1)
|
||||
_ = gen
|
||||
if job == nil {
|
||||
p.mu.Unlock()
|
||||
return
|
||||
}
|
||||
seed := job.SeedHash
|
||||
if seed == "" && len(job.Blob) >= 64 {
|
||||
seed = job.Blob[:64]
|
||||
}
|
||||
for _, engine := range p.engines {
|
||||
// Capture engines slice before releasing the lock.
|
||||
engines := p.engines
|
||||
p.mu.Unlock()
|
||||
// Update all engines outside the pool lock — each Engine has its own mutex.
|
||||
for _, engine := range engines {
|
||||
if err := engine.SetJob(seed, job.Blob); err != nil {
|
||||
log.Printf("[miner] failed to set job: %v", err)
|
||||
}
|
||||
@@ -202,6 +214,10 @@ func (p *Pool) worker(id int, engine *Engine) {
|
||||
continue
|
||||
}
|
||||
|
||||
// Snapshot the generation before the inner loop so we can detect a new
|
||||
// job mid-batch and break early rather than hashing 256 stale nonces.
|
||||
startGen := p.jobGen.Load()
|
||||
|
||||
for batch := 0; batch < 256; batch++ {
|
||||
select {
|
||||
case <-p.stopCh:
|
||||
@@ -211,6 +227,10 @@ func (p *Pool) worker(id int, engine *Engine) {
|
||||
if p.paused.Load() || p.remotePause.Load() {
|
||||
break
|
||||
}
|
||||
// New job arrived — abandon this batch and re-snapshot immediately.
|
||||
if p.jobGen.Load() != startGen {
|
||||
break
|
||||
}
|
||||
|
||||
hashHex, _, err := engine.HashAtNonce(nonce)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user