refactor(proxy): align login flow with RFC order

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-04 22:13:10 +00:00
parent cfd669e4d2
commit 2b8bba790c
2 changed files with 12 additions and 8 deletions

View file

@ -200,7 +200,9 @@ func NewCustomDiff(globalDiff uint64) *CustomDiff {
return &CustomDiff{globalDiff: globalDiff}
}
// OnLogin parses +N suffixes and applies global difficulty fallbacks.
// OnLogin normalises the login user once during handshake.
//
// cd.OnLogin(proxy.Event{Miner: &proxy.Miner{user: "WALLET+50000"}})
func (cd *CustomDiff) OnLogin(e Event) {
if cd == nil || e.Miner == nil {
return
@ -225,6 +227,10 @@ func NewRateLimiter(config RateLimit) *RateLimiter {
}
// Allow returns true if the IP address is permitted to open a new connection.
//
// if rl.Allow("203.0.113.42:3333") {
// // accept the socket
// }
func (rl *RateLimiter) Allow(ip string) bool {
if rl == nil || rl.config.MaxConnectionsPerMinute <= 0 {
return true

View file

@ -916,13 +916,13 @@ func (m *Miner) handleLogin(req stratumRequest) {
m.loginAlgos = append([]string(nil), params.Algo...)
m.extAlgo = len(m.loginAlgos) > 0
m.rpcID = generateUUID()
m.state = MinerStateWaitReady
if m.onLogin != nil {
m.onLogin(m)
}
if m.state == MinerStateClosing {
return
}
m.state = MinerStateWaitReady
if m.extNH {
if m.MapperID() < 0 {
m.state = MinerStateWaitLogin
@ -1556,16 +1556,14 @@ func cloneWorkerRecord(record WorkerRecord) WorkerRecord {
return cloned
}
// Apply parses login suffixes and applies the configured global difficulty.
// Apply normalises one miner login at the same point the handshake does.
//
// cd.Apply(&proxy.Miner{user: "WALLET+50000"})
func (cd *CustomDiff) Apply(miner *Miner) {
if cd == nil || miner == nil {
return
}
if miner.customDiffResolved {
return
}
miner.user, miner.customDiff = parseLoginUser(miner.user, cd.globalDiff)
miner.customDiffResolved = true
cd.OnLogin(Event{Miner: miner})
}
// NewServer constructs a server instance.