From 9e66c8ce0f5847646a4b80f5bcd69c6bc2785c9c Mon Sep 17 00:00:00 2001 From: SwimmingTiger Date: Sat, 11 Jun 2022 20:37:41 +0800 Subject: [PATCH 1/2] =?UTF-8?q?ETH=EF=BC=9A=E7=9F=BF=E6=B1=A0=E5=B7=B2?= =?UTF-8?q?=E6=BB=A1=E5=90=8E=E4=B8=8D=E5=86=8D=E5=90=91=E5=85=B6=E5=88=86?= =?UTF-8?q?=E9=85=8D=E6=96=B0=E7=9F=BF=E6=9C=BA=EF=BC=8C=E9=98=B2=E6=AD=A2?= =?UTF-8?q?=E5=A7=8B=E7=BB=88=E5=87=BA=E7=8E=B0=E2=80=9Cpool=20server=20is?= =?UTF-8?q?=20full=E2=80=9D=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Event.go | 4 ++++ UpSessionETH.go | 5 +++++ UpSessionManager.go | 10 +++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Event.go b/Event.go index cede35b..7e90f11 100644 --- a/Event.go +++ b/Event.go @@ -58,6 +58,10 @@ type EventUpSessionBroken struct { Slot int } +type EventUpSessionFull struct { + Slot int +} + type EventSubmitShareBTC struct { ID interface{} Message *ExMessageSubmitShareBTC diff --git a/UpSessionETH.go b/UpSessionETH.go index 956b8ba..eec870f 100644 --- a/UpSessionETH.go +++ b/UpSessionETH.go @@ -704,6 +704,11 @@ func (up *UpSessionETH) handleExMessageSetExtraNonce(ex *ExMessage) { down := up.downSessions[msg.SessionID] if down != nil { + // 矿池服务器满了,无法连接新矿机 + if msg.ExtraNonce == EthereumInvalidExtraNonce { + up.manager.SendEvent(EventUpSessionFull{up.slot}) + } + down.SendEvent(EventSetExtraNonce{msg.ExtraNonce}) if up.lastJob != nil { down.SendEvent(EventStratumJobETH{up.lastJob}) diff --git a/UpSessionManager.go b/UpSessionManager.go index 56f82c8..b960686 100644 --- a/UpSessionManager.go +++ b/UpSessionManager.go @@ -10,6 +10,7 @@ import ( type UpSessionInfo struct { minerNum int ready bool + full bool upSession UpSession } @@ -90,7 +91,7 @@ func (manager *UpSessionManager) addDownSession(e EventAddDownSession) { // 寻找连接数最少的服务器 for i := range manager.upSessions { info := &manager.upSessions[i] - if info.ready && (selected == nil || info.minerNum < selected.minerNum) { + if info.ready && !info.full && (selected == nil || info.minerNum < selected.minerNum) { selected = info } } @@ -155,6 +156,11 @@ func (manager *UpSessionManager) upSessionBroken(e EventUpSessionBroken) { go manager.connect(e.Slot) } +func (manager *UpSessionManager) upSessionFull(e EventUpSessionFull) { + info := &manager.upSessions[e.Slot] + info.full = true +} + func (manager *UpSessionManager) updateMinerNum(e EventUpdateMinerNum) { defer manager.tryPrintMinerNum() @@ -233,6 +239,8 @@ func (manager *UpSessionManager) handleEvent() { manager.addDownSession(e) case EventUpSessionBroken: manager.upSessionBroken(e) + case EventUpSessionFull: + manager.upSessionFull(e) case EventUpdateMinerNum: manager.updateMinerNum(e) case EventUpdateFakeMinerNum: From 68388bc986dce8cd85b639e2ce3eee01b460ac77 Mon Sep 17 00:00:00 2001 From: SwimmingTiger Date: Sat, 11 Jun 2022 21:18:10 +0800 Subject: [PATCH 2/2] =?UTF-8?q?ETH=EF=BC=9A=E5=A6=82=E6=9E=9C=E5=B7=B2?= =?UTF-8?q?=E6=BB=A1=E7=9A=84=E7=9F=BF=E6=B1=A0=E8=BF=9E=E6=8E=A5=E4=B8=8A?= =?UTF-8?q?=E5=B7=B2=E7=BB=8F=E6=B2=A1=E6=9C=89=E4=BB=BB=E4=BD=95=E7=9F=BF?= =?UTF-8?q?=E6=9C=BA=EF=BC=8C=E5=B0=B1=E8=87=AA=E5=8A=A8=E9=87=8D=E8=BF=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- UpSessionBTC.go | 2 +- UpSessionETH.go | 12 ++++++------ UpSessionManager.go | 14 ++++++++++++-- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/UpSessionBTC.go b/UpSessionBTC.go index 6838ed3..6fa1ec3 100644 --- a/UpSessionBTC.go +++ b/UpSessionBTC.go @@ -307,7 +307,7 @@ func (up *UpSessionBTC) close() { up.manager.SendEvent(EventUpSessionBroken{up.slot}) } - if up.config.AlwaysKeepDownconn { + if up.stat != StatExit && up.config.AlwaysKeepDownconn { if up.lastJob != nil { up.manager.SendEvent(EventUpdateFakeJobBTC{up.lastJob}) } diff --git a/UpSessionETH.go b/UpSessionETH.go index eec870f..0ce9435 100644 --- a/UpSessionETH.go +++ b/UpSessionETH.go @@ -295,7 +295,7 @@ func (up *UpSessionETH) close() { up.manager.SendEvent(EventUpSessionBroken{up.slot}) } - if up.config.AlwaysKeepDownconn { + if up.stat != StatExit && up.config.AlwaysKeepDownconn { if up.lastJob != nil { up.manager.SendEvent(EventUpdateFakeJobETH{up.lastJob}) } @@ -702,13 +702,13 @@ func (up *UpSessionETH) handleExMessageSetExtraNonce(ex *ExMessage) { return } + // 矿池服务器满了,无法连接新矿机 + if msg.ExtraNonce == EthereumInvalidExtraNonce { + up.manager.SendEvent(EventUpSessionFull{up.slot}) + } + down := up.downSessions[msg.SessionID] if down != nil { - // 矿池服务器满了,无法连接新矿机 - if msg.ExtraNonce == EthereumInvalidExtraNonce { - up.manager.SendEvent(EventUpSessionFull{up.slot}) - } - down.SendEvent(EventSetExtraNonce{msg.ExtraNonce}) if up.lastJob != nil { down.SendEvent(EventStratumJobETH{up.lastJob}) diff --git a/UpSessionManager.go b/UpSessionManager.go index b960686..7b771f8 100644 --- a/UpSessionManager.go +++ b/UpSessionManager.go @@ -164,10 +164,11 @@ func (manager *UpSessionManager) upSessionFull(e EventUpSessionFull) { func (manager *UpSessionManager) updateMinerNum(e EventUpdateMinerNum) { defer manager.tryPrintMinerNum() - manager.upSessions[e.Slot].minerNum -= e.DisconnectedMinerCounter + up := &manager.upSessions[e.Slot] + up.minerNum -= e.DisconnectedMinerCounter if glog.V(3) { - glog.Info(manager.id, "miner num update, slot: ", e.Slot, ", miners: ", manager.upSessions[e.Slot].minerNum) + glog.Info(manager.id, "miner num update, slot: ", e.Slot, ", miners: ", up.minerNum) } if manager.config.MultiUserMode { @@ -180,6 +181,15 @@ func (manager *UpSessionManager) updateMinerNum(e EventUpdateMinerNum) { manager.parent.SendEvent(EventStopUpSessionManager{manager.subAccount}) } } + + if up.full && up.minerNum == 0 { + // 重连矿池服务器已满的空闲连接 + go func() { + glog.Info(manager.id, "reconnect full pool session #", e.Slot) + up.upSession.SendEvent(EventExit{}) + manager.SendEvent(EventUpSessionBroken{e.Slot}) + }() + } } func (manager *UpSessionManager) updateFakeMinerNum(e EventUpdateFakeMinerNum) {