Skip to content

Commit

Permalink
Implement always_keep_downconn
Browse files Browse the repository at this point in the history
  • Loading branch information
SwimmingTiger committed Nov 18, 2021
1 parent 85a176c commit fc51278
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Event.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ type EventStopUpSessionManager struct {
}

type EventUpdateFakeJob struct {
FakeJob StratumJob
FakeJob *StratumJob
}

type EventTransferDownSessions struct{}
Expand Down
2 changes: 1 addition & 1 deletion FakeUpSession.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (up *FakeUpSession) downSessionBroken(e EventDownSessionBroken) {
}

func (up *FakeUpSession) updateFakeJob(e EventUpdateFakeJob) {
up.fakeJob = &e.FakeJob
up.fakeJob = e.FakeJob
}

func (up *FakeUpSession) fakeNotifyTicker() {
Expand Down
5 changes: 4 additions & 1 deletion StratumJob.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,16 @@ func IsFakeJobID(id string) bool {

func (job *StratumJob) ToNewFakeJob() {
now := uint64(time.Now().Unix())
job.ID = fmt.Sprintf("f%04d", now)

// job id
job.Params[0] = fmt.Sprintf("f%d", now%0xffff)

coinbase1, _ := job.Params[2].(string)
pos := len(coinbase1) - 8
if pos < 0 {
pos = 0
}

// coinbase1
job.Params[2] = coinbase1[:pos] + Uint64ToHex(now)
}
13 changes: 11 additions & 2 deletions UpSession.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,17 @@ func (up *UpSession) close() {
up.manager.SendEvent(EventUpSessionBroken{up.slot})
}

for _, down := range up.downSessions {
go down.SendEvent(EventExit{})
if up.config.AlwaysKeepDownconn {
if up.lastJob != nil {
up.manager.SendEvent(EventUpdateFakeJob{up.lastJob})
}
for _, down := range up.downSessions {
go up.manager.SendEvent(EventAddDownSession{down})
}
} else {
for _, down := range up.downSessions {
go down.SendEvent(EventExit{})
}
}

up.eventLoopRunning = false
Expand Down
6 changes: 6 additions & 0 deletions UpSessionManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ func (manager *UpSessionManager) updateMinerNum(e EventUpdateMinerNum) {
glog.Info("miner num update, slot: ", e.Slot, ", miners: ", manager.upSessions[e.Slot].minerNum)
}

func (manager *UpSessionManager) updateFakeJob(e EventUpdateFakeJob) {
manager.fakeUpSession.SendEvent(e)
}

func (manager *UpSessionManager) exit() {
manager.fakeUpSession.SendEvent(EventExit{})

Expand All @@ -158,6 +162,8 @@ func (manager *UpSessionManager) handleEvent() {
manager.upSessionBroken(e)
case EventUpdateMinerNum:
manager.updateMinerNum(e)
case EventUpdateFakeJob:
manager.updateFakeJob(e)
case EventExit:
manager.exit()
return
Expand Down

0 comments on commit fc51278

Please sign in to comment.