Skip to content

Commit

Permalink
Rename a command checking slots covered percentage
Browse files Browse the repository at this point in the history
Plus minor fixups after testing
  • Loading branch information
georgeee committed Jan 10, 2024
1 parent 7b4b843 commit 1b6a079
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/app/itn_orchestrator/src/itn_orchestrator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func init() {
addAction(actions, lib.StopDaemonAction{})
addAction(actions, lib.RotateAction{})
addAction(actions, lib.SetZkappSoftLimitAction{})
addAction(actions, lib.MajorityStakeCheckAction{})
addAction(actions, lib.SlotsCoveredCheckAction{})
}

type AppConfig struct {
Expand Down
6 changes: 6 additions & 0 deletions src/app/itn_orchestrator/src/params.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package itn_orchestrator

import (
"bytes"
"encoding/json"
"fmt"
"io"
Expand Down Expand Up @@ -113,8 +114,13 @@ func ResolveParam(config ResolutionConfig, step int, raw json.RawMessage) (json.
}
}

var nullJson = json.RawMessage([]byte("null"))

func ResolveParams(config ResolutionConfig, step int, raw RawParams) (json.RawMessage, error) {
for k, v := range raw {
if bytes.Equal(v, nullJson) {
continue
}
v_, err := ResolveParam(config, step, v)
if err != nil {
return nil, err
Expand Down
17 changes: 9 additions & 8 deletions src/app/itn_orchestrator/src/slots_won.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ func (SlotsWonAction) Name() string { return "slots-won" }

var _ Action = SlotsWonAction{}

type MajorityStakeCheckParams struct {
type SlotsCoveredCheckParams struct {
Threshold float64 `json:"threshold"`
SlotsWon []SlotsWonOutput `json:"slotsWon"`
}

func MajorityStakeCheck(config Config, params MajorityStakeCheckParams) error {
func SlotsCoveredCheck(config Config, params SlotsCoveredCheckParams) error {
threshold := params.Threshold
allSlots := map[int]struct{}{}
minSlot := math.MaxInt
Expand All @@ -73,19 +73,20 @@ func MajorityStakeCheck(config Config, params MajorityStakeCheckParams) error {
if proportion < threshold {
return fmt.Errorf("proportion %f of slots covered by queried nodes is lower than threshold %f", proportion, threshold)
}
config.Log.Infof("Total %.2f%% of slots are covered", proportion*100)
return nil
}

type MajorityStakeCheckAction struct{}
type SlotsCoveredCheckAction struct{}

func (MajorityStakeCheckAction) Run(config Config, rawParams json.RawMessage, output OutputF) error {
var params MajorityStakeCheckParams
func (SlotsCoveredCheckAction) Run(config Config, rawParams json.RawMessage, output OutputF) error {
var params SlotsCoveredCheckParams
if err := json.Unmarshal(rawParams, &params); err != nil {
return err
}
return MajorityStakeCheck(config, params)
return SlotsCoveredCheck(config, params)
}

func (MajorityStakeCheckAction) Name() string { return "majority-stake-check" }
func (SlotsCoveredCheckAction) Name() string { return "slots-covered-check" }

var _ Action = MajorityStakeCheckAction{}
var _ Action = SlotsCoveredCheckAction{}

0 comments on commit 1b6a079

Please sign in to comment.