Skip to content

Commit

Permalink
Optimize repeated ProcessingState calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
Djadih committed May 7, 2024
1 parent 333669a commit 8492e9c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
3 changes: 2 additions & 1 deletion core/bodydb.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ type BodyDb struct {
woCache *lru.Cache
processor *StateProcessor

slicesRunning []common.Location
slicesRunning []common.Location
processingState bool

logger *log.Logger
}
Expand Down
31 changes: 27 additions & 4 deletions core/headerchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ type HeaderChain struct {
running int32 // 0 if chain is running, 1 when stopped
procInterrupt int32 // interrupt signaler for block processing

headermu sync.RWMutex
heads []*types.WorkObject
slicesRunning []common.Location
headermu sync.RWMutex
heads []*types.WorkObject
slicesRunning []common.Location
processingState bool

logger *log.Logger

Expand Down Expand Up @@ -124,6 +125,9 @@ func NewHeaderChain(db ethdb.Database, engine consensus.Engine, pEtxsRollupFetch
return nil, err
}

// Record if the chain is processing state
hc.processingState = hc.setStateProcessing()

pendingEtxsRollup, _ := lru.New(c_maxPendingEtxsRollup)
hc.pendingEtxsRollup = pendingEtxsRollup

Expand Down Expand Up @@ -314,7 +318,26 @@ func (hc *HeaderChain) AppendHeader(header *types.WorkObject) error {
return nil
}
func (hc *HeaderChain) ProcessingState() bool {
return hc.bc.ProcessingState()
return hc.processingState
}

func (hc *HeaderChain) setStateProcessing() bool {
nodeCtx := hc.NodeCtx()
for _, slice := range hc.slicesRunning {
switch nodeCtx {
case common.PRIME_CTX:
return true
case common.REGION_CTX:
if slice.Region() == hc.NodeLocation().Region() {
return true
}
case common.ZONE_CTX:
if slice.Equal(hc.NodeLocation()) {
return true
}
}
}
return false
}

// Append
Expand Down

0 comments on commit 8492e9c

Please sign in to comment.