fix(proxy): apply custom diff before worker login

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-04 20:56:16 +00:00
parent ce7d3301fc
commit 8faac7eee6
2 changed files with 36 additions and 2 deletions

View file

@ -56,9 +56,8 @@ func New(cfg *Config) (*Proxy, Result) {
shareLog: newShareLogSink(cfg.ShareLogFile),
done: make(chan struct{}),
}
p.workers.bindEvents(p.events)
p.events.Subscribe(EventLogin, p.customDiff.OnLogin)
p.workers.bindEvents(p.events)
if p.accessLog != nil {
p.events.Subscribe(EventLogin, p.accessLog.OnLogin)
p.events.Subscribe(EventClose, p.accessLog.OnClose)

View file

@ -47,3 +47,38 @@ func TestWorker_NewWorkers_Ugly(t *testing.T) {
t.Fatalf("expected a single subscription path, got %d connections", records[0].Connections)
}
}
func TestWorker_CustomDiffOrdering_Good(t *testing.T) {
cfg := &Config{
Mode: "nicehash",
Workers: WorkersByUser,
Bind: []BindAddr{{Host: "127.0.0.1", Port: 3333}},
Pools: []PoolConfig{{URL: "pool.example:3333", Enabled: true}},
CustomDiff: 50000,
AccessLogFile: "",
}
p, result := New(cfg)
if !result.OK {
t.Fatalf("expected valid proxy, got error: %v", result.Error)
}
miner := &Miner{
id: 21,
user: "WALLET+50000",
ip: "10.0.0.3",
conn: noopConn{},
}
p.events.Dispatch(Event{Type: EventLogin, Miner: miner})
records := p.WorkerRecords()
if len(records) != 1 {
t.Fatalf("expected one worker record, got %d", len(records))
}
if records[0].Name != "WALLET" {
t.Fatalf("expected custom diff login suffix to be stripped before worker registration, got %q", records[0].Name)
}
if miner.User() != "WALLET" {
t.Fatalf("expected miner user to be stripped before downstream consumers, got %q", miner.User())
}
}