Skip to content

Commit

Permalink
naming
Browse files Browse the repository at this point in the history
  • Loading branch information
cryi committed Jun 22, 2024
1 parent 22e124c commit c79ed9f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
20 changes: 10 additions & 10 deletions core/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,32 +227,32 @@ func (e *Engine) fetchAutomatically() {
default:
time.Sleep(constants.OGUN_CYCLE_FETCH_FREQUENCY_MINUTES * time.Minute)

lastCompletedCycle, err := e.collector.GetLastCompletedCycle(e.ctx)
lastOnChainCompletedCycle, err := e.collector.GetLastCompletedCycle(e.ctx)
if err != nil {
e.logger.Error("failed to fetch last completed cycle number", "error", err.Error())
return
}

if e.state.lastOnChainCompletedCycle == lastCompletedCycle {
slog.Debug("no new cycle completed", "last_on_chain_completed_cycle", e.state.lastOnChainCompletedCycle, "last_completed_cycle", lastCompletedCycle)
if e.state.lastFetchedCycle == lastOnChainCompletedCycle {
slog.Debug("no new cycle completed", "last_on_chain_completed_cycle", e.state.lastFetchedCycle, "last_completed_cycle", lastOnChainCompletedCycle)
continue
}

if e.state.lastOnChainCompletedCycle == 0 {
if e.state.lastFetchedCycle == 0 {
cycle, _ := e.store.GetLastFetchedCycle()
switch cycle {
case 0:
e.state.SetLastOnChainCompletedCycle(lastCompletedCycle - 1)
e.state.SetLastFetchedCycle(lastOnChainCompletedCycle - 1)
default:
e.state.SetLastOnChainCompletedCycle(cycle)
e.state.SetLastFetchedCycle(cycle)
}
}

if e.state.lastOnChainCompletedCycle+1 <= lastCompletedCycle {
e.logger.Info("fetching missing delegation states", "last_on_chain_completed_cycle", e.state.lastOnChainCompletedCycle, "last_completed_cycle", lastCompletedCycle)
if e.state.lastFetchedCycle+1 <= lastOnChainCompletedCycle {
e.logger.Info("fetching missing delegation states", "last_on_chain_completed_cycle", e.state.lastFetchedCycle, "last_completed_cycle", lastOnChainCompletedCycle)
}

for cycle := e.state.lastOnChainCompletedCycle + 1; cycle <= lastCompletedCycle; cycle++ {
for cycle := e.state.lastFetchedCycle + 1; cycle <= lastOnChainCompletedCycle; cycle++ {
if err = e.FetchCycleDelegationStates(e.ctx, cycle, nil); err != nil {
e.logger.Error("failed to fetch cycle delegation states", "cycle", cycle, "error", err.Error())
}
Expand All @@ -261,7 +261,7 @@ func (e *Engine) fetchAutomatically() {
}
}

e.state.SetLastOnChainCompletedCycle(lastCompletedCycle)
e.state.SetLastFetchedCycle(lastOnChainCompletedCycle)
}
}
}()
Expand Down
10 changes: 5 additions & 5 deletions core/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ var (
)

type state struct {
lastOnChainCompletedCycle int64
delegatesBeingFetched map[int64][]tezos.Address
lastFetchedCycle int64
delegatesBeingFetched map[int64][]tezos.Address
}

func newState() *state {
Expand Down Expand Up @@ -59,16 +59,16 @@ func (s *state) IsDelegateBeingFetched(cycle int64, delegate tezos.Address) bool
return slices.Contains(s.delegatesBeingFetched[cycle], delegate)
}

func (s *state) SetLastOnChainCompletedCycle(cycle int64) {
func (s *state) SetLastFetchedCycle(cycle int64) {
mtx.Lock()
defer mtx.Unlock()

s.lastOnChainCompletedCycle = cycle
s.lastFetchedCycle = cycle
}

func (s *state) GetLastOnChainCompletedCycle() int64 {
mtx.RLock()
defer mtx.RUnlock()

return s.lastOnChainCompletedCycle
return s.lastFetchedCycle
}

0 comments on commit c79ed9f

Please sign in to comment.