docs: clarify mining lifecycle names
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run

This commit is contained in:
Virgil 2026-04-04 08:35:12 +00:00
parent 895f9da069
commit 14839e58cf
6 changed files with 43 additions and 43 deletions

View file

@ -62,17 +62,17 @@ func AuthConfigFromEnv() AuthConfig {
// digestAuth := NewDigestAuth(authConfig); router.Use(digestAuth.Middleware()); defer digestAuth.Stop()
type DigestAuth struct {
config AuthConfig
nonces sync.Map // map[string]time.Time for nonce expiry tracking
stopChan chan struct{}
stopOnce sync.Once
config AuthConfig
nonces sync.Map // map[string]time.Time for nonce expiry tracking
stopChannel chan struct{}
stopOnce sync.Once
}
// digestAuth := NewDigestAuth(AuthConfigFromEnv()); router.Use(digestAuth.Middleware())
func NewDigestAuth(config AuthConfig) *DigestAuth {
digestAuth := &DigestAuth{
config: config,
stopChan: make(chan struct{}),
config: config,
stopChannel: make(chan struct{}),
}
// go digestAuth.cleanupNonces() // clears expired nonces every 5 minutes
go digestAuth.cleanupNonces()
@ -82,7 +82,7 @@ func NewDigestAuth(config AuthConfig) *DigestAuth {
// defer digestAuth.Stop() // safe to call multiple times; stops the nonce cleanup goroutine
func (digestAuth *DigestAuth) Stop() {
digestAuth.stopOnce.Do(func() {
close(digestAuth.stopChan)
close(digestAuth.stopChannel)
})
}
@ -206,7 +206,7 @@ func (digestAuth *DigestAuth) generateOpaque() string {
return md5Hash(digestAuth.config.Realm)
}
// go digestAuth.cleanupNonces() // runs until stopChan is closed; interval = NonceExpiry
// go digestAuth.cleanupNonces() // runs until stopChannel is closed; interval = NonceExpiry
func (digestAuth *DigestAuth) cleanupNonces() {
interval := digestAuth.config.NonceExpiry
if interval <= 0 {
@ -217,7 +217,7 @@ func (digestAuth *DigestAuth) cleanupNonces() {
for {
select {
case <-digestAuth.stopChan:
case <-digestAuth.stopChannel:
return
case <-ticker.C:
now := time.Now()

View file

@ -50,15 +50,15 @@ type Container struct {
hashrateStore database.HashrateStore
initialized bool
transportStarted bool
shutdownCh chan struct{}
shutdownChannel chan struct{}
}
// container := NewContainer(DefaultContainerConfig())
// container.Initialize(ctx)
func NewContainer(config ContainerConfig) *Container {
return &Container{
config: config,
shutdownCh: make(chan struct{}),
config: config,
shutdownChannel: make(chan struct{}),
}
}
@ -184,7 +184,7 @@ func (container *Container) Shutdown(ctx context.Context) error {
}
container.initialized = false
close(container.shutdownCh)
close(container.shutdownChannel)
if len(errs) > 0 {
return ErrInternal("shutdown completed with errors").WithCause(errs[0])
@ -243,7 +243,7 @@ func (container *Container) SetHashrateStore(store database.HashrateStore) {
// <-container.ShutdownCh() // blocks until `mining serve` finishes shutting down.
func (container *Container) ShutdownCh() <-chan struct{} {
return container.shutdownCh
return container.shutdownChannel
}
// if container.IsInitialized() { container.Start(ctx) }

View file

@ -65,7 +65,7 @@ type ManagerInterface interface {
type Manager struct {
miners map[string]Miner
mutex sync.RWMutex
stopChan chan struct{}
stopChannel chan struct{}
stopOnce sync.Once
waitGroup sync.WaitGroup
databaseEnabled bool
@ -99,9 +99,9 @@ var _ ManagerInterface = (*Manager)(nil)
// defer manager.Stop() // stops miner goroutines and the hourly database cleanup loop
func NewManager() *Manager {
manager := &Manager{
miners: make(map[string]Miner),
stopChan: make(chan struct{}),
waitGroup: sync.WaitGroup{},
miners: make(map[string]Miner),
stopChannel: make(chan struct{}),
waitGroup: sync.WaitGroup{},
}
manager.syncMinersConfig()
manager.initDatabase()
@ -114,9 +114,9 @@ func NewManager() *Manager {
// manager.StartMiner(ctx, "xmrig", &Config{Algo: "rx/0"})
func NewManagerForSimulation() *Manager {
manager := &Manager{
miners: make(map[string]Miner),
stopChan: make(chan struct{}),
waitGroup: sync.WaitGroup{},
miners: make(map[string]Miner),
stopChannel: make(chan struct{}),
waitGroup: sync.WaitGroup{},
}
manager.startStatsCollection()
return manager
@ -181,7 +181,7 @@ func (manager *Manager) startDBCleanup() {
if err := database.Cleanup(manager.databaseRetention); err != nil {
logging.Warn("database cleanup failed", logging.Fields{"error": err})
}
case <-manager.stopChan:
case <-manager.stopChannel:
return
}
}
@ -574,7 +574,7 @@ func (manager *Manager) startStatsCollection() {
select {
case <-ticker.C:
manager.collectMinerStats()
case <-manager.stopChan:
case <-manager.stopChannel:
return
}
}
@ -738,7 +738,7 @@ func (manager *Manager) Stop() {
}
manager.mutex.Unlock()
close(manager.stopChan)
close(manager.stopChannel)
// Wait for goroutines with timeout
done := make(chan struct{})

View file

@ -15,7 +15,7 @@ type RateLimiter struct {
burst int
clients map[string]*rateLimitClient
mutex sync.RWMutex
stopChan chan struct{}
stopChannel chan struct{}
stopped bool
}
@ -31,7 +31,7 @@ func NewRateLimiter(requestsPerSecond, burst int) *RateLimiter {
requestsPerSecond: requestsPerSecond,
burst: burst,
clients: make(map[string]*rateLimitClient),
stopChan: make(chan struct{}),
stopChannel: make(chan struct{}),
}
// Start cleanup goroutine
@ -47,7 +47,7 @@ func (limiter *RateLimiter) cleanupLoop() {
for {
select {
case <-limiter.stopChan:
case <-limiter.stopChannel:
return
case <-ticker.C:
limiter.cleanup()
@ -73,7 +73,7 @@ func (limiter *RateLimiter) Stop() {
defer limiter.mutex.Unlock()
if !limiter.stopped {
close(limiter.stopChan)
close(limiter.stopChannel)
limiter.stopped = true
}
}

View file

@ -46,7 +46,7 @@ type Service struct {
APIBasePath string
SwaggerUIPath string
rateLimiter *RateLimiter
auth *DigestAuth
digestAuth *DigestAuth
mcpServer *ginmcp.GinMCP
}
@ -435,9 +435,9 @@ func NewService(manager ManagerInterface, listenAddress string, displayAddress s
// AuthConfigFromEnv() enables digest auth for requests like GET /api/v1/mining/status when credentials are present.
authConfig := AuthConfigFromEnv()
var auth *DigestAuth
var digestAuth *DigestAuth
if authConfig.Enabled {
auth = NewDigestAuth(authConfig)
digestAuth = NewDigestAuth(authConfig)
logging.Info("API authentication enabled", logging.Fields{"realm": authConfig.Realm})
}
@ -457,7 +457,7 @@ func NewService(manager ManagerInterface, listenAddress string, displayAddress s
SwaggerInstanceName: instanceName,
APIBasePath: apiBasePath,
SwaggerUIPath: swaggerUIPath,
auth: auth,
digestAuth: digestAuth,
}, nil
}
@ -523,7 +523,7 @@ func (service *Service) InitRouter() {
service.SetupRoutes()
}
// Example: service.Stop() stops rate limiting, auth, event hub, and node transport during shutdown.
// Example: service.Stop() stops rate limiting, digest auth, event hub, and node transport during shutdown.
func (service *Service) Stop() {
if service.rateLimiter != nil {
service.rateLimiter.Stop()
@ -531,8 +531,8 @@ func (service *Service) Stop() {
if service.EventHub != nil {
service.EventHub.Stop()
}
if service.auth != nil {
service.auth.Stop()
if service.digestAuth != nil {
service.digestAuth.Stop()
}
if service.NodeService != nil {
if err := service.NodeService.StopTransport(); err != nil {
@ -559,7 +559,7 @@ func (service *Service) ServiceStartup(runContext context.Context) error {
go func() {
<-runContext.Done()
service.Stop() // Example: service.Stop() shuts down auth, the event hub, and node transport after `context.WithCancel(...)`.
service.Stop() // Example: service.Stop() shuts down digest auth, the event hub, and node transport after `context.WithCancel(...)`.
service.Manager.Stop()
shutdownContext, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
@ -599,9 +599,9 @@ func (service *Service) SetupRoutes() {
apiRoutes.GET("/health", service.handleHealth)
apiRoutes.GET("/ready", service.handleReady)
// service.auth.Middleware() protects routes such as POST /api/v1/mining/doctor when API auth is enabled.
if service.auth != nil {
apiRoutes.Use(service.auth.Middleware())
// service.digestAuth.Middleware() protects routes such as POST /api/v1/mining/doctor when API auth is enabled.
if service.digestAuth != nil {
apiRoutes.Use(service.digestAuth.Middleware())
}
{

View file

@ -37,7 +37,7 @@ type SimulatedMiner struct {
rejected int
logs []string
mutex sync.RWMutex
stopChan chan struct{}
stopChannel chan struct{}
poolName string
difficultyBase int
}
@ -110,7 +110,7 @@ func (m *SimulatedMiner) Start(config *Config) error {
m.startTime = time.Now()
m.shares = 0
m.rejected = 0
m.stopChan = make(chan struct{})
m.stopChannel = make(chan struct{})
m.HashrateHistory = make([]HashratePoint, 0)
m.LowResHistory = make([]HashratePoint, 0)
timestamp := time.Now().Format("15:04:05")
@ -136,7 +136,7 @@ func (m *SimulatedMiner) Stop() error {
return ErrMinerNotRunning(m.Name)
}
close(m.stopChan)
close(m.stopChannel)
m.Running = false
m.logs = append(m.logs, "["+time.Now().Format("15:04:05")+"] Miner stopped")
@ -152,7 +152,7 @@ func (m *SimulatedMiner) runSimulation() {
for {
select {
case <-m.stopChan:
case <-m.stopChannel:
return
case <-ticker.C:
m.updateHashrate()