Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--tolerance on find-stale-pods #144

Merged
merged 5 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cli/commands/findStalePods.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ type TFindStalePodsCommandArgs struct {
EthNode string
BeaconNode string
Verbose bool
Tolerance float64
}

func FindStalePodsCommand(args TFindStalePodsCommandArgs) error {
ctx := context.Background()
eth, beacon, chainId, err := core.GetClients(ctx, args.EthNode, args.BeaconNode /* verbose */, args.Verbose)
core.PanicOnError("failed to dial clients", err)

results, err := core.FindStaleEigenpods(ctx, eth, args.EthNode, beacon, chainId, args.Verbose)
results, err := core.FindStaleEigenpods(ctx, eth, args.EthNode, beacon, chainId, args.Verbose, args.Tolerance)
core.PanicOnError("failed to find stale eigenpods", err)

if !args.Verbose {
Expand Down
8 changes: 3 additions & 5 deletions cli/core/findStalePods.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ type PodOwnerShare struct {
IsEigenpod bool
}

const ACCEPTABLE_BALANCE_DEVIATION = float64(0.95)

var cache Cache // valid for the duration of a command.

func isEigenpod(eth *ethclient.Client, chainId uint64, eigenpodAddress string) (bool, error) {
Expand Down Expand Up @@ -127,7 +125,7 @@ func executionWithdrawalAddress(withdrawalCredentials []byte) *string {
return &addr
}

func FindStaleEigenpods(ctx context.Context, eth *ethclient.Client, nodeUrl string, beacon BeaconClient, chainId *big.Int, verbose bool) (map[string][]ValidatorWithIndex, error) {
func FindStaleEigenpods(ctx context.Context, eth *ethclient.Client, nodeUrl string, beacon BeaconClient, chainId *big.Int, verbose bool, tolerance float64) (map[string][]ValidatorWithIndex, error) {
beaconState, err := beacon.GetBeaconState(ctx, "head")
if err != nil {
return nil, fmt.Errorf("error downloading beacon state: %s", err.Error())
Expand Down Expand Up @@ -246,7 +244,7 @@ func FindStaleEigenpods(ctx context.Context, eth *ethclient.Client, nodeUrl stri
return false
}
executionBalance := cache.PodOwnerShares[eigenpod].SharesWei
if balance <= uint64(float64(executionBalance)*ACCEPTABLE_BALANCE_DEVIATION) {
if balance <= uint64(float64(executionBalance)*(1-(tolerance/100))) {
if verbose {
log.Printf("[%s] %.2f%% deviation (beacon: %d -> execution: %d)\n", eigenpod, 100*(float64(executionBalance)-float64(balance))/float64(executionBalance), balance, executionBalance)
}
Expand All @@ -258,7 +256,7 @@ func FindStaleEigenpods(ctx context.Context, eth *ethclient.Client, nodeUrl stri

if len(unhealthyEigenpods) == 0 {
if verbose {
log.Println("All slashed eigenpods are within 5% of their expected balance.")
log.Printf("All slashed eigenpods are within %f%% of their expected balance.\n", tolerance)
}
return map[string][]ValidatorWithIndex{}, nil
}
Expand Down
8 changes: 8 additions & 0 deletions cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
var disableColor = false
var verbose = false
var noPrompt = false
var tolerance float64 = 5.0

Check failure on line 25 in cli/main.go

View workflow job for this annotation

GitHub Actions / lint

var-declaration: should omit type float64 from declaration of var tolerance; it will be inferred from the right-hand side (revive)

app := &cli.App{
Name: "Eigenlayer Proofs CLi",
Expand All @@ -38,12 +39,19 @@
Flags: []cli.Flag{
ExecNodeFlag,
BeaconNodeFlag,
&cli.Float64Flag{
Name: "tolerance",
Value: 5,

Check failure on line 44 in cli/main.go

View workflow job for this annotation

GitHub Actions / lint

Magic number: 5, in <assign> detected (gomnd)
Usage: "The percentage balance deviation to tolerate when deciding whether an eigenpod should be corrected. Default is 5% (e.g --tolerance 5).",
Destination: &tolerance,
},
},
Action: func(_ *cli.Context) error {
return commands.FindStalePodsCommand(commands.TFindStalePodsCommandArgs{
EthNode: node,
BeaconNode: beacon,
Verbose: verbose,
Tolerance: tolerance,
})
},
},
Expand Down
Loading