ax(mining): rename mu to mutex in SimulatedMiner
AX Principle 1: predictable names over short names. mu → mutex matches the same fix already applied to Manager and SettingsManager. Co-Authored-By: Charon <charon@lethean.io>
This commit is contained in:
parent
9945f2b031
commit
c91752af2f
1 changed files with 22 additions and 22 deletions
|
|
@ -36,7 +36,7 @@ type SimulatedMiner struct {
|
|||
shares int
|
||||
rejected int
|
||||
logs []string
|
||||
mu sync.RWMutex
|
||||
mutex sync.RWMutex
|
||||
stopChan chan struct{}
|
||||
poolName string
|
||||
difficultyBase int
|
||||
|
|
@ -100,9 +100,9 @@ func (m *SimulatedMiner) Uninstall() error {
|
|||
|
||||
// if err := miner.Start(config); err != nil { /* already running */ }
|
||||
func (m *SimulatedMiner) Start(config *Config) error {
|
||||
m.mu.Lock()
|
||||
m.mutex.Lock()
|
||||
if m.Running {
|
||||
m.mu.Unlock()
|
||||
m.mutex.Unlock()
|
||||
return fmt.Errorf("simulated miner %s is already running", m.Name)
|
||||
}
|
||||
|
||||
|
|
@ -118,7 +118,7 @@ func (m *SimulatedMiner) Start(config *Config) error {
|
|||
fmt.Sprintf("[%s] Connecting to %s", time.Now().Format("15:04:05"), m.poolName),
|
||||
fmt.Sprintf("[%s] Pool connected, algorithm: %s", time.Now().Format("15:04:05"), m.Algorithm),
|
||||
}
|
||||
m.mu.Unlock()
|
||||
m.mutex.Unlock()
|
||||
|
||||
// Start background simulation
|
||||
go m.runSimulation()
|
||||
|
|
@ -128,8 +128,8 @@ func (m *SimulatedMiner) Start(config *Config) error {
|
|||
|
||||
// if err := miner.Stop(); err != nil { /* miner was not running */ }
|
||||
func (m *SimulatedMiner) Stop() error {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
m.mutex.Lock()
|
||||
defer m.mutex.Unlock()
|
||||
|
||||
if !m.Running {
|
||||
return fmt.Errorf("simulated miner %s is not running", m.Name)
|
||||
|
|
@ -164,8 +164,8 @@ func (m *SimulatedMiner) runSimulation() {
|
|||
}
|
||||
|
||||
func (m *SimulatedMiner) updateHashrate() {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
m.mutex.Lock()
|
||||
defer m.mutex.Unlock()
|
||||
|
||||
// Generate hashrate with variance and smooth transitions
|
||||
now := time.Now()
|
||||
|
|
@ -243,8 +243,8 @@ func (m *SimulatedMiner) updateHashrate() {
|
|||
}
|
||||
|
||||
func (m *SimulatedMiner) simulateShare() {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
m.mutex.Lock()
|
||||
defer m.mutex.Unlock()
|
||||
|
||||
// 2% chance of rejected share
|
||||
if rand.Float64() < 0.02 {
|
||||
|
|
@ -265,8 +265,8 @@ func (m *SimulatedMiner) simulateShare() {
|
|||
// metrics, err := miner.GetStats(ctx)
|
||||
// fmt.Printf("hashrate: %d H/s, shares: %d\n", metrics.Hashrate, metrics.Shares)
|
||||
func (m *SimulatedMiner) GetStats(ctx context.Context) (*PerformanceMetrics, error) {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
m.mutex.RLock()
|
||||
defer m.mutex.RUnlock()
|
||||
|
||||
if !m.Running {
|
||||
return nil, fmt.Errorf("simulated miner %s is not running", m.Name)
|
||||
|
|
@ -335,8 +335,8 @@ func (m *SimulatedMiner) GetLatestVersion() (string, error) {
|
|||
|
||||
// points := miner.GetHashrateHistory() // snapshot of high-res window (last 5 min)
|
||||
func (m *SimulatedMiner) GetHashrateHistory() []HashratePoint {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
m.mutex.RLock()
|
||||
defer m.mutex.RUnlock()
|
||||
|
||||
result := make([]HashratePoint, len(m.HashrateHistory))
|
||||
copy(result, m.HashrateHistory)
|
||||
|
|
@ -345,15 +345,15 @@ func (m *SimulatedMiner) GetHashrateHistory() []HashratePoint {
|
|||
|
||||
// miner.AddHashratePoint(HashratePoint{Timestamp: now, Hashrate: 5000})
|
||||
func (m *SimulatedMiner) AddHashratePoint(point HashratePoint) {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
m.mutex.Lock()
|
||||
defer m.mutex.Unlock()
|
||||
m.HashrateHistory = append(m.HashrateHistory, point)
|
||||
}
|
||||
|
||||
// manager.ReduceHashrateHistory(miner, time.Now())
|
||||
func (m *SimulatedMiner) ReduceHashrateHistory(now time.Time) {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
m.mutex.Lock()
|
||||
defer m.mutex.Unlock()
|
||||
|
||||
// Move old high-res points to low-res
|
||||
cutoff := now.Add(-HighResolutionDuration)
|
||||
|
|
@ -395,8 +395,8 @@ func (m *SimulatedMiner) ReduceHashrateHistory(now time.Time) {
|
|||
|
||||
// logs := miner.GetLogs() // capped at 100 lines, includes share accept/reject events
|
||||
func (m *SimulatedMiner) GetLogs() []string {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
m.mutex.RLock()
|
||||
defer m.mutex.RUnlock()
|
||||
|
||||
result := make([]string, len(m.logs))
|
||||
copy(result, m.logs)
|
||||
|
|
@ -405,8 +405,8 @@ func (m *SimulatedMiner) GetLogs() []string {
|
|||
|
||||
// if err := miner.WriteStdin("h"); err != nil { /* not running */ }
|
||||
func (m *SimulatedMiner) WriteStdin(input string) error {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
m.mutex.Lock()
|
||||
defer m.mutex.Unlock()
|
||||
|
||||
if !m.Running {
|
||||
return fmt.Errorf("simulated miner %s is not running", m.Name)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue