Skip to content

Commit

Permalink
Refactor preload condition
Browse files Browse the repository at this point in the history
  • Loading branch information
hyeonLewis committed Jul 15, 2024
1 parent 7b38759 commit e549783
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions consensus/istanbul/backend/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,21 +168,18 @@ func (s *Snapshot) apply(headers []*types.Header, gov governance.Engine, addr co
}
}

if len(kaiaHeaders) > 0 {
sInfo := reward.GetStakingInfo(kaiaHeaders[0].Number.Uint64() + 1)
// The second condition is to make sure that the staking info is not already loaded
if len(kaiaHeaders) > 1 || (len(kaiaHeaders) == 1 && sInfo == nil) {
preloadNums, err := preloadStakingInfo(kaiaHeaders, gov.HeaderGov())
if err != nil {
return nil, err
}

defer func() {
for _, num := range preloadNums {
reward.UnloadStakingInfo(num)
}
}()
needPreload := len(kaiaHeaders) > 1 || (len(kaiaHeaders) == 1 && reward.GetStakingInfo(kaiaHeaders[0].Number.Uint64()+1) == nil)
if needPreload {
preloadNums, err := preloadStakingInfo(kaiaHeaders, gov.HeaderGov())
if err != nil {
return nil, err
}

defer func() {
for _, num := range preloadNums {
reward.UnloadStakingInfo(num)
}
}()
}

// Iterate through the headers and create a new snapshot
Expand Down

0 comments on commit e549783

Please sign in to comment.