fix: 3 regressions from previous session - dropper expansion, pool backup initial connect, bcrypt auth cache

This commit is contained in:
drjones
2026-05-30 14:40:09 -07:00
parent 0e19eb9eb9
commit 2e36483158
3 changed files with 95 additions and 18 deletions

View File

@@ -7,6 +7,7 @@ import (
"time"
)
// Manager maintains Stratum connections keyed by forged pool + wallet settings.
type Manager struct {
mu sync.RWMutex
@@ -46,17 +47,46 @@ func poolKey(cfg *Config) string {
return fmt.Sprintf("%s:%d:tls=%v:wallet=%s", cfg.Host, cfg.Port, cfg.UseTLS, cfg.Wallet)
}
// EnsurePoolWithBackups is like EnsurePool but also registers backup configs
// that the proxy will rotate through on reconnect.
// EnsurePoolWithBackups connects to cfg and registers backup pool configs for
// automatic failover on reconnect. If the primary cfg is unreachable it tries
// each backup in order at initial connect time as well — restoring the behaviour
// that existed before the reconnect-rotation refactor.
func (m *Manager) EnsurePoolWithBackups(cfg *Config, backups []Config) (*Proxy, error) {
// Try primary first.
p, err := m.EnsurePool(cfg)
if err != nil {
return nil, err
if err == nil {
// Primary connected — register backups for later reconnect rotation.
if len(backups) > 0 {
p.SetBackupConfigs(backups)
}
return p, nil
}
if len(backups) > 0 {
p.SetBackupConfigs(backups)
// Primary failed — work through the backup list.
log.Printf("[PoolManager] Primary pool unreachable (%v), trying %d backup(s)…", err, len(backups))
for i, bp := range backups {
if bp.Host == "" || bp.Port <= 0 {
continue
}
bpCopy := bp // local copy so we can take its address
p2, err2 := m.EnsurePool(&bpCopy)
if err2 == nil {
log.Printf("[PoolManager] Connected to backup pool #%d (%s:%d)", i+1, bp.Host, bp.Port)
// Register remaining backups (skip the one we just connected to).
remaining := make([]Config, 0, len(backups))
remaining = append(remaining, *cfg) // original primary becomes a backup
for j, b := range backups {
if j != i {
remaining = append(remaining, b)
}
}
p2.SetBackupConfigs(remaining)
return p2, nil
}
log.Printf("[PoolManager] Backup pool #%d (%s:%d) also failed: %v", i+1, bp.Host, bp.Port, err2)
}
return p, nil
return nil, fmt.Errorf("all pool endpoints unreachable (primary: %w)", err)
}
// EnsurePool returns a connected proxy for the forged pool settings, starting one if needed.