Skip to content

Commit

Permalink
bugfix: Added lock and rlock around phCache access in relay
Browse files Browse the repository at this point in the history
  • Loading branch information
gameofpointers committed May 8, 2023
1 parent b215a9b commit 2122fd6
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions core/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,10 @@ func (sl *Slice) relayPh(block *types.Block, appendTime *time.Duration, reorg bo
nodeCtx := common.NodeLocation.Context()

if nodeCtx == common.ZONE_CTX {
sl.phCachemu.RLock()
// Send an empty header to miner
bestPh, exists := sl.phCache[sl.bestPhKey]
sl.phCachemu.RUnlock()
if exists {
bestPh.Header.SetLocation(common.NodeLocation)
sl.miner.worker.pendingHeaderFeed.Send(bestPh.Header)
Expand All @@ -260,9 +262,13 @@ func (sl *Slice) relayPh(block *types.Block, appendTime *time.Duration, reorg bo
return
} else {
pendingHeaderWithTermini.Header = sl.combinePendingHeader(localPendingHeader, pendingHeaderWithTermini.Header, nodeCtx, true)
sl.phCachemu.Lock()
sl.writeToPhCacheAndPickPhHead(pendingHeaderWithTermini, appendTime)
sl.phCachemu.Unlock()
}
sl.phCachemu.RLock()
bestPh, exists = sl.phCache[sl.bestPhKey]
sl.phCachemu.RUnlock()
if exists {
bestPh.Header.SetLocation(common.NodeLocation)
sl.miner.worker.pendingHeaderFeed.Send(bestPh.Header)
Expand Down Expand Up @@ -407,6 +413,8 @@ func (sl *Slice) poem(externS *big.Int, currentS *big.Int) bool {

// GetPendingHeader is used by the miner to request the current pending header
func (sl *Slice) GetPendingHeader() (*types.Header, error) {
sl.phCachemu.RLock()
defer sl.phCachemu.RUnlock()
if ph := sl.phCache[sl.bestPhKey].Header; ph != nil {
return ph, nil
} else {
Expand Down

0 comments on commit 2122fd6

Please sign in to comment.