Skip to content

Commit 2176678

Browse files
committed
fix: miners mode upgrade checks
1 parent fafcc2e commit 2176678

5 files changed

Lines changed: 46 additions & 27 deletions

File tree

‎scheduler/config.go‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ type Config struct {
4040
HealthCheckPort int `json:"health_check_port"` // Port for health check endpoint (0 = disabled)
4141

4242
// FanR thresholds for work mode switching
43-
FanRHighThreshold int `json:"fanr_high_threshold"` // FanR threshold to decrease work mode
44-
FanRLowThreshold int `json:"fanr_low_threshold"` // FanR threshold to increase work mode
43+
FanRHighThreshold int `json:"fanr_high_threshold"` // FanR threshold to decrease work mode
44+
FanRLowThreshold int `json:"fanr_low_threshold"` // FanR threshold to increase work mode
45+
MinerWorkModeUpgradeChecks int `json:"miner_work_mode_upgrade_checks"` // Number of consecutive checks at current work mode required before upgrading
4546

4647
// Power consumption settings (in kilowatts)
4748
MinersPowerLimit float64 `json:"miners_power_limit"` // Maximum total power limit for miners in kW
@@ -135,6 +136,7 @@ func DefaultConfig() *Config {
135136
ImportPriceOperatorFee: 8.5, // 8.5 EUR/MWh from Operator
136137
ImportPriceDeliveryFee: 40.0, // 40 EUR/MWh for delivery
137138
ExportPriceOperatorFee: 17.0, // 17 EUR/MWh from Operator
139+
MinerWorkModeUpgradeChecks: 5, // 5 consecutive checks required before upgrading work mode
138140
MinersPowerLimit: 30.0, // 30 kW total power limit for miners
139141
MinerPowerStandby: 0.05, // 0.05 kW (50 W) in standby
140142
MinerPowerEco: 0.8, // 0.8 kW (800 W) in eco mode
@@ -236,6 +238,10 @@ func (c *Config) Validate() error {
236238
return fmt.Errorf("miner_max_consecutive_errors must be greater than 0, got: %d", c.MinerMaxConsecutiveErrors)
237239
}
238240

241+
if c.MinerWorkModeUpgradeChecks <= 0 {
242+
return fmt.Errorf("miner_work_mode_upgrade_checks must be greater than 0, got: %d", c.MinerWorkModeUpgradeChecks)
243+
}
244+
239245
if c.APITimeout <= 0 {
240246
return fmt.Errorf("api_timeout must be greater than 0, got: %s", c.APITimeout)
241247
}

‎scheduler/miners.go‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,14 @@ func (s *MinerScheduler) controlMiner(m *miners.AvalonQHost, totalPower float64,
309309
}
310310
return currentState, newWorkMode
311311
} else if fanR < s.config.FanRLowThreshold && totalPower <= effectiveLimit {
312-
// Increase work mode only if all LiteStatsHistory fanR values match criteria
313-
if len(m.LiteStatsHistory) < 5 || currentWorkMode == miners.AvalonSuperMode {
312+
// Increase work mode only if the last N consecutive checks all passed at the current work mode
313+
requiredChecks := s.config.MinerWorkModeUpgradeChecks
314+
if len(m.LiteStatsHistory) < requiredChecks || currentWorkMode == miners.AvalonSuperMode {
314315
return currentState, currentWorkMode
315316
}
316-
for _, stat := range m.LiteStatsHistory {
317-
if stat.FanR >= s.config.FanRLowThreshold {
317+
recentHistory := m.LiteStatsHistory[len(m.LiteStatsHistory)-requiredChecks:]
318+
for _, stat := range recentHistory {
319+
if stat.FanR >= s.config.FanRLowThreshold || stat.WorkMode != currentWorkMode {
318320
return currentState, currentWorkMode
319321
}
320322
}

‎scheduler/miners_test.go‎

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@ import (
3030
func newTestScheduler(cfg *Config) *MinerScheduler {
3131
if cfg == nil {
3232
cfg = &Config{
33-
FanRHighThreshold: 80,
34-
FanRLowThreshold: 50,
35-
MinerPowerStandby: 0.1,
36-
MinerPowerEco: 1.0,
37-
MinerPowerStandard: 1.5,
38-
MinerPowerSuper: 2.0,
39-
MinersPowerLimit: 10.0,
33+
FanRHighThreshold: 80,
34+
FanRLowThreshold: 50,
35+
MinerPowerStandby: 0.1,
36+
MinerPowerEco: 1.0,
37+
MinerPowerStandard: 1.5,
38+
MinerPowerSuper: 2.0,
39+
MinersPowerLimit: 10.0,
40+
MinerWorkModeUpgradeChecks: 5,
4041
}
4142
}
4243
return NewMinerScheduler(cfg, log.New(os.Stdout, "TEST: ", log.LstdFlags))
@@ -404,13 +405,14 @@ func TestControlMiner_DecreaseWhenNewPowerWouldStillExceedLimit(t *testing.T) {
404405
func TestControlMiner_CustomThresholds(t *testing.T) {
405406
// Test with custom FanR thresholds
406407
cfg := &Config{
407-
FanRHighThreshold: 70,
408-
FanRLowThreshold: 40,
409-
MinerPowerStandby: 0.1,
410-
MinerPowerEco: 1.0,
411-
MinerPowerStandard: 1.5,
412-
MinerPowerSuper: 2.0,
413-
MinersPowerLimit: 10.0,
408+
FanRHighThreshold: 70,
409+
FanRLowThreshold: 40,
410+
MinerPowerStandby: 0.1,
411+
MinerPowerEco: 1.0,
412+
MinerPowerStandard: 1.5,
413+
MinerPowerSuper: 2.0,
414+
MinersPowerLimit: 10.0,
415+
MinerWorkModeUpgradeChecks: 5,
414416
}
415417
scheduler := newTestScheduler(cfg)
416418

@@ -615,13 +617,14 @@ func TestValidate_MinerMaxConsecutiveErrors(t *testing.T) {
615617

616618
func TestControlMiner_PowerCalculation(t *testing.T) {
617619
cfg := &Config{
618-
FanRHighThreshold: 80,
619-
FanRLowThreshold: 50,
620-
MinerPowerStandby: 0.2,
621-
MinerPowerEco: 1.2,
622-
MinerPowerStandard: 1.8,
623-
MinerPowerSuper: 2.5,
624-
MinersPowerLimit: 10.0,
620+
FanRHighThreshold: 80,
621+
FanRLowThreshold: 50,
622+
MinerPowerStandby: 0.2,
623+
MinerPowerEco: 1.2,
624+
MinerPowerStandard: 1.8,
625+
MinerPowerSuper: 2.5,
626+
MinersPowerLimit: 10.0,
627+
MinerWorkModeUpgradeChecks: 5,
625628
}
626629
scheduler := newTestScheduler(cfg)
627630

‎web/src/components/ConfigMenu.tsx‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,13 @@ const SECTIONS: Section[] = [
165165
unit: "%",
166166
hint: "Increase work mode below this FanR",
167167
},
168+
{
169+
key: "miner_work_mode_upgrade_checks",
170+
label: "Work Mode Upgrade Checks",
171+
type: "number",
172+
min: 1,
173+
hint: "Consecutive checks at current work mode required before upgrading",
174+
},
168175
{
169176
key: "miners_power_limit",
170177
label: "Total Power Limit",

‎web/src/types/api.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export interface EmsConfig {
1616
health_check_port: number;
1717
fanr_high_threshold: number;
1818
fanr_low_threshold: number;
19+
miner_work_mode_upgrade_checks: number;
1920
miners_power_limit: number;
2021
miner_power_standby: number;
2122
miner_power_eco: number;

0 commit comments

Comments
 (0)