Skip to content

Commit

Permalink
fix submit work and getwork (#132)
Browse files Browse the repository at this point in the history
Co-authored-by: Muhaimin Anando <[email protected]>
  • Loading branch information
meta-bot and Muhaimin Anando authored Dec 28, 2021
1 parent 56526b4 commit 753e93d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
25 changes: 18 additions & 7 deletions consensus/pandora/pandora.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type Pandora struct {
fetchShardingInfoCh chan *shardingInfoReq // Channel used for remote sealer to fetch mining work
submitShardingInfoCh chan *shardingResult
newSealRequestCh chan *sealTask
updateInfoCh chan<- SealHashUpdate
updatedSealHash event.Feed
scope event.SubscriptionScope
skipBLSValidation bool // This is only for test purpose so that we can insert blocks easily without needing help from orchestrator
Expand Down Expand Up @@ -201,9 +202,9 @@ func (p *Pandora) APIs(chain consensus.ChainHeaderReader) []rpc.API {
}
}

// SubscribeToUpdateSealHashEvent when sealHash updates it will notify worker.go
func (p *Pandora) SubscribeToUpdateSealHashEvent(ch chan<- SealHashUpdate) event.Subscription {
return p.scope.Track(p.updatedSealHash.Subscribe(ch))
// SetUpdateInfoChannel when sealHash updates it will notify worker.go
func (p *Pandora) SetUpdateInfoChannel(ch chan<- SealHashUpdate) {
p.updateInfoCh = ch
}

func (p *Pandora) SubscribePandoraChainHeadShiftedEvent(ch chan<- struct{}) event.Subscription {
Expand All @@ -223,7 +224,7 @@ func (p *Pandora) setCurrentBlock(block *types.Block) {
p.currentBlock = block
}

func (p *Pandora) updateBlockHeader(currentBlock *types.Block, slotNumber uint64, epoch uint64) [4]string {
func (p *Pandora) updateBlockHeader(currentBlock *types.Block, slotNumber uint64, epoch uint64) ([4]string, error) {
currentHeader := currentBlock.Header()
previousSealHash := p.SealHash(currentHeader)
// modify the header with slot, epoch and turn
Expand Down Expand Up @@ -254,7 +255,12 @@ func (p *Pandora) updateBlockHeader(currentBlock *types.Block, slotNumber uint64

hash := p.SealHash(updatedBlock.Header())
// seal hash is updated and worker.go is holding previous seal hash. notify worker.go to update it
p.updatedSealHash.Send(SealHashUpdate{UpdatedHash: hash, PreviousHash: previousSealHash})
select {
case p.updateInfoCh <- SealHashUpdate{UpdatedHash: hash, PreviousHash: previousSealHash}:
log.Debug("send update info to worker.go from pandora.go")
default:
return [4]string{}, errors.New("could not send update information to worker.go")
}

var retVal [4]string
retVal[0] = hash.Hex()
Expand All @@ -264,7 +270,7 @@ func (p *Pandora) updateBlockHeader(currentBlock *types.Block, slotNumber uint64

p.works[hash] = updatedBlock

return retVal
return retVal, nil
}

// run subscribes to all the services for the ETH1.0 chain.
Expand Down Expand Up @@ -320,7 +326,12 @@ func (p *Pandora) run(done <-chan struct{}) {
}
// now modify the current block header and generate seal hash
log.Debug("for GetShardingWork updating block header extra data", "slot", shardingInfoReq.slot, "epoch", shardingInfoReq.epoch)
shardingInfoReq.res <- p.updateBlockHeader(cpBlock, shardingInfoReq.slot, shardingInfoReq.epoch)
work, err := p.updateBlockHeader(cpBlock, shardingInfoReq.slot, shardingInfoReq.epoch)
if err != nil {
shardingInfoReq.errc <- err
continue
}
shardingInfoReq.res <- work
}

case submitSignatureData := <-p.submitShardingInfoCh:
Expand Down
6 changes: 2 additions & 4 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,7 @@ type worker struct {
resubmitHook func(time.Duration, time.Duration) // Method to call upon updating resubmitting interval.

// if pandora is running then seal hash will be changed. track if is changed
updateTracker chan pandora.SealHashUpdate
updateTrackerSub event.Subscription
updateTracker chan pandora.SealHashUpdate

pandoraHeadShiftCh chan struct{}
pandoraHeadShiftSub event.Subscription
Expand Down Expand Up @@ -228,8 +227,8 @@ func newWorker(config *Config, chainConfig *params.ChainConfig, engine consensus
worker.chainSideSub = eth.BlockChain().SubscribeChainSideEvent(worker.chainSideCh)

if pandoraEngine, pandoraRunning := worker.isPandora(); pandoraRunning {
pandoraEngine.SetUpdateInfoChannel(worker.updateTracker)
// pandora is running so subscribe with event
worker.updateTrackerSub = pandoraEngine.SubscribeToUpdateSealHashEvent(worker.updateTracker)
worker.pandoraHeadShiftSub = pandoraEngine.SubscribePandoraChainHeadShiftedEvent(worker.pandoraHeadShiftCh)
}

Expand Down Expand Up @@ -483,7 +482,6 @@ func (w *worker) mainLoop() {
defer func() {
if _, running := w.isPandora(); running {
// pandora is running so close subscription
w.updateTrackerSub.Unsubscribe()
w.pandoraHeadShiftSub.Unsubscribe()
}
}()
Expand Down

0 comments on commit 753e93d

Please sign in to comment.