Skip to content

Commit

Permalink
Disconnect the miner immediately when the connection to the mining po…
Browse files Browse the repository at this point in the history
…ol is not ready

This helps to solve the problem that the miner still thinks the connection is active when the BTCAgent's connection to the mining pool fails.
  • Loading branch information
SwimmingTiger committed Jan 4, 2022
1 parent 1fefab7 commit c679c2d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
7 changes: 7 additions & 0 deletions DownSessionBTC.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,11 @@ func (down *DownSessionBTC) exit() {
down.close()
}

func (down *DownSessionBTC) poolNotReady() {
glog.Warning(down.id, "pool connection not ready")
down.exit()
}

func (down *DownSessionBTC) handleEvent() {
down.eventLoopRunning = true
for down.eventLoopRunning {
Expand All @@ -506,6 +511,8 @@ func (down *DownSessionBTC) handleEvent() {
down.close()
case EventExit:
down.exit()
case EventPoolNotReady:
down.poolNotReady()
default:
glog.Error(down.id, "unknown event: ", e)
}
Expand Down
7 changes: 7 additions & 0 deletions DownSessionETH.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,11 @@ func (down *DownSessionETH) exit() {
down.close()
}

func (down *DownSessionETH) poolNotReady() {
glog.Warning(down.id, "pool connection not ready")
down.exit()
}

func (down *DownSessionETH) handleEvent() {
down.eventLoopRunning = true
for down.eventLoopRunning {
Expand All @@ -574,6 +579,8 @@ func (down *DownSessionETH) handleEvent() {
down.close()
case EventExit:
down.exit()
case EventPoolNotReady:
down.poolNotReady()
default:
glog.Error(down.id, "unknown event: ", e)
}
Expand Down
2 changes: 2 additions & 0 deletions Event.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ type EventType uint8

type EventExit struct{}

type EventPoolNotReady struct{}

type EventInitFinished struct{}

type EventUpSessionReady struct {
Expand Down
12 changes: 9 additions & 3 deletions UpSessionManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,15 @@ func (manager *UpSessionManager) addDownSession(e EventAddDownSession) {
return
}

// 服务器均未就绪,把矿机托管给 FakeUpSession
manager.fakeUpSession.minerNum++
e.Session.SendEvent(EventSetUpSession{manager.fakeUpSession.upSession})
// 服务器均未就绪,若已启用 AlwaysKeepDownconn,就把矿机托管给 FakeUpSession
if manager.config.AlwaysKeepDownconn {
manager.fakeUpSession.minerNum++
e.Session.SendEvent(EventSetUpSession{manager.fakeUpSession.upSession})
return
}

// 未启用 AlwaysKeepDownconn,直接断开连接,防止矿机认为 BTCAgent 连接活跃
e.Session.SendEvent(EventPoolNotReady{})
}

func (manager *UpSessionManager) upSessionReady(e EventUpSessionReady) {
Expand Down

0 comments on commit c679c2d

Please sign in to comment.