-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #132 from Layr-Labs/jb/pepe-healthcheck
`--find-stale-pods` and `--correct-stale-pod`
- Loading branch information
Showing
9 changed files
with
485 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package commands | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/Layr-Labs/eigenpod-proofs-generation/cli/core" | ||
"github.com/fatih/color" | ||
) | ||
|
||
type TFindStalePodsCommandArgs struct { | ||
EthNode string | ||
BeaconNode string | ||
Verbose bool | ||
} | ||
|
||
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) | ||
core.PanicOnError("failed to find stale eigenpods", err) | ||
|
||
if !args.Verbose { | ||
// just print json and be done | ||
jsonStr, _ := json.MarshalIndent(results, "", " ") | ||
fmt.Println(string(jsonStr)) | ||
return nil | ||
} | ||
|
||
for pod, res := range results { | ||
color.Red("pod %s\n", pod) | ||
for _, validator := range res { | ||
fmt.Printf("\t[#%d] (%s) - %d\n", validator.Index, func() string { | ||
if validator.Validator.Slashed { | ||
return "slashed" | ||
} else { | ||
return "not slashed" | ||
} | ||
}(), validator.Validator.EffectiveBalance) | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package commands | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"math/big" | ||
|
||
eigenpodproofs "github.com/Layr-Labs/eigenpod-proofs-generation" | ||
"github.com/Layr-Labs/eigenpod-proofs-generation/cli/core" | ||
"github.com/Layr-Labs/eigenpod-proofs-generation/cli/core/onchain" | ||
"github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/fatih/color" | ||
) | ||
|
||
type TFixStaleBalanceArgs struct { | ||
EthNode string | ||
BeaconNode string | ||
Sender string | ||
EigenpodAddress string | ||
SlashedValidatorIndex int64 | ||
Verbose bool | ||
CheckpointBatchSize uint64 | ||
NoPrompt bool | ||
} | ||
|
||
// another fun cast brought to you by golang! | ||
func proofCast(proof []eigenpodproofs.Bytes32) [][32]byte { | ||
res := make([][32]byte, len(proof)) | ||
for i, elt := range proof { | ||
res[i] = elt | ||
} | ||
return res | ||
} | ||
|
||
func FixStaleBalance(args TFixStaleBalanceArgs) error { | ||
ctx := context.Background() | ||
|
||
eth, beacon, chainId, err := core.GetClients(ctx, args.EthNode, args.BeaconNode, args.Verbose) | ||
core.PanicOnError("failed to get clients", err) | ||
|
||
validator, err := beacon.GetValidator(ctx, uint64(args.SlashedValidatorIndex)) | ||
core.PanicOnError("failed to fetch validator state", err) | ||
|
||
if !validator.Validator.Slashed { | ||
core.Panic("Provided validator was not slashed.") | ||
return nil | ||
} | ||
|
||
ownerAccount, err := core.PrepareAccount(&args.Sender, chainId, false /* noSend */) | ||
core.PanicOnError("failed to parse sender PK", err) | ||
|
||
eigenpod, err := onchain.NewEigenPod(common.HexToAddress(args.EigenpodAddress), eth) | ||
core.PanicOnError("failed to reach eigenpod", err) | ||
|
||
currentCheckpointTimestamp, err := eigenpod.CurrentCheckpointTimestamp(nil) | ||
core.PanicOnError("failed to fetch any existing checkpoint info", err) | ||
|
||
if currentCheckpointTimestamp > 0 { | ||
if args.Verbose { | ||
color.Red("This eigenpod has an outstanding checkpoint (since %d). You must complete it before continuing.", currentCheckpointTimestamp) | ||
} | ||
|
||
proofs, err := core.GenerateCheckpointProof(ctx, args.EigenpodAddress, eth, chainId, beacon) | ||
core.PanicOnError("failed to generate checkpoint proofs", err) | ||
|
||
txns, err := core.SubmitCheckpointProof(ctx, args.Sender, args.EigenpodAddress, chainId, proofs, eth, args.CheckpointBatchSize, args.NoPrompt /* noSend */, false) | ||
core.PanicOnError("failed to submit checkpoint proofs", err) | ||
|
||
for i, txn := range txns { | ||
if args.Verbose { | ||
fmt.Printf("sending txn[%d/%d]: %s (waiting)...", i, len(txns), txn.Hash()) | ||
} | ||
bind.WaitMined(ctx, eth, txn) | ||
} | ||
} | ||
|
||
proof, oracleBeaconTimesetamp, err := core.GenerateValidatorProof(ctx, args.EigenpodAddress, eth, chainId, beacon, new(big.Int).SetUint64(uint64(args.SlashedValidatorIndex)), args.Verbose) | ||
core.PanicOnError("failed to generate credential proof for slashed validator", err) | ||
|
||
if !args.NoPrompt { | ||
core.PanicIfNoConsent("This will invoke `EigenPod.verifyStaleBalance()` on the given eigenpod, which will start a checkpoint. Once started, this checkpoint must be completed.") | ||
} | ||
|
||
if args.Verbose { | ||
color.Black("Calling verifyStaleBalance() to update pod.") | ||
} | ||
|
||
txn, err := eigenpod.VerifyStaleBalance( | ||
ownerAccount.TransactionOptions, | ||
oracleBeaconTimesetamp, | ||
onchain.BeaconChainProofsStateRootProof{ | ||
Proof: proof.StateRootProof.Proof.ToByteSlice(), | ||
BeaconStateRoot: proof.StateRootProof.BeaconStateRoot, | ||
}, | ||
onchain.BeaconChainProofsValidatorProof{ | ||
ValidatorFields: proofCast(proof.ValidatorFields[0]), | ||
Proof: proof.ValidatorFieldsProofs[0].ToByteSlice(), | ||
}, | ||
) | ||
core.PanicOnError("failed to call verifyStaleBalance()", err) | ||
|
||
fmt.Printf("txn: %s\n", txn.Hash()) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.