Skip to content

Commit

Permalink
feat(upgrade): complete upgrade task if validator sign after height g…
Browse files Browse the repository at this point in the history
…iven
  • Loading branch information
bdeneux committed Feb 1, 2023
1 parent 5f38875 commit faf5cb0
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/actor/subscription/actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ func (a *Actor) handleNewBlockEvent(data map[string]interface{}) {
logger.Panic().Err(err).Msg("🤕 Failed complete vote proposal task.")
}

if err := a.store.CompleteUpgradeTask(a.ctx, e.Time, consensusAddr, uint64(e.Height)); err != nil {
logger.Panic().Err(err).Msg("🤕 Failed complete upgrade task.")
}

if err := a.store.UpdatePhaseBlocks(a.ctx, e.Time, e.Height); err != nil {
logger.Panic().Err(err).Msg("🤕 Failed update phase block range.")
}
Expand Down
18 changes: 18 additions & 0 deletions app/nemeton/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -781,3 +781,21 @@ func (s *Store) CompleteVoteProposalTask(ctx context.Context, when time.Time, ms

return nil
}

func (s *Store) CompleteUpgradeTask(ctx context.Context, when time.Time, consensusAddrs []types.ConsAddress, height uint64) error {
phase, task := s.getTaskPhaseByType(TaskTypeUpgrade, when)
if phase == nil || task == nil {
return nil
}

startBlock, endBlock := task.GetParamUpgradeStartBlock(), task.GetParamUpgradeEndBlock()
if startBlock == nil || endBlock == nil {
return fmt.Errorf("couldn't get upgrade task params (startBlock: %d) (endBlock: %d)", startBlock, endBlock)
}

if height >= *startBlock && height < *endBlock {
return s.ensureTaskCompleted(ctx, bson.M{"valcons": bson.M{"$in": consensusAddrs}}, phase.Number, task.ID, *task.Rewards)
}

return nil
}
20 changes: 20 additions & 0 deletions app/nemeton/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,26 @@ func (t Task) GetParamProposalID() *uint64 {
return nil
}

func (t Task) GetParamUpgradeStartBlock() *uint64 {
if v, ok := t.Params[taskParamUpgradeStartBlock]; ok {
if startBlock, ok := v.(int64); ok {
p := uint64(startBlock)
return &p
}
}
return nil
}

func (t Task) GetParamUpgradeEndBlock() *uint64 {
if v, ok := t.Params[taskParamUpgradeEndBlock]; ok {
if endBlock, ok := v.(int64); ok {
p := uint64(endBlock)
return &p
}
}
return nil
}

func makeTask(
ttype, id, name, description string,
start, end time.Time,
Expand Down

0 comments on commit faf5cb0

Please sign in to comment.