Skip to content

Commit

Permalink
fix logs
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrower95 committed Aug 13, 2024
1 parent 94278dc commit f854015
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 57 deletions.
18 changes: 13 additions & 5 deletions cli/core/beaconClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ type BeaconClient interface {

type beaconClient struct {
eth2client eth2client.Service
verbose bool
}

func NewBeaconClient(endpoint string) (BeaconClient, context.CancelFunc, error) {
beaconClient := beaconClient{}
func NewBeaconClient(endpoint string, verbose bool) (BeaconClient, context.CancelFunc, error) {
beaconClient := beaconClient{verbose: verbose}
ctx, cancel := context.WithCancel(context.Background())

client, err := http.New(ctx,
Expand All @@ -42,7 +43,10 @@ func NewBeaconClient(endpoint string) (BeaconClient, context.CancelFunc, error)
if err != nil {
return nil, cancel, err
}
log.Info().Msgf("Connected to %s\n", client.Name())

if verbose {
log.Info().Msgf("Connected to %s\n", client.Name())
}

beaconClient.eth2client = client
return &beaconClient, cancel, nil
Expand All @@ -64,7 +68,9 @@ func (b *beaconClient) GetBeaconHeader(ctx context.Context, blockId string) (*v1
func (b *beaconClient) GetBeaconState(ctx context.Context, stateId string) (*spec.VersionedBeaconState, error) {
timeout, _ := time.ParseDuration("200s")
if provider, ok := b.eth2client.(eth2client.BeaconStateProvider); ok {
log.Info().Msgf("downloading beacon state %s", stateId)
if b.verbose {
log.Info().Msgf("downloading beacon state %s", stateId)
}
opts := &api.BeaconStateOpts{State: stateId, Common: api.CommonOpts{
Timeout: timeout,
}}
Expand All @@ -77,7 +83,9 @@ func (b *beaconClient) GetBeaconState(ctx context.Context, stateId string) (*spe
return nil, errors.New("beacon state is nil")
}

log.Info().Msg("finished download")
if b.verbose {
log.Info().Msg("finished download")
}
return beaconState.Data, nil
}

Expand Down
12 changes: 5 additions & 7 deletions cli/core/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,11 @@ func StartCheckpoint(ctx context.Context, eigenpodAddress string, ownerPrivateKe
return nil, fmt.Errorf("failed to start checkpoint: %w", err)
}

color.Green("starting checkpoint: %s..", txn.Hash().Hex())

return txn, nil
}

func GetBeaconClient(beaconUri string) (BeaconClient, error) {
beaconClient, _, err := NewBeaconClient(beaconUri)
func GetBeaconClient(beaconUri string, verbose bool) (BeaconClient, error) {
beaconClient, _, err := NewBeaconClient(beaconUri, verbose)
return beaconClient, err
}

Expand Down Expand Up @@ -271,7 +269,7 @@ func GetCurrentCheckpointBlockRoot(eigenpodAddress string, eth *ethclient.Client
return &checkpoint.BeaconBlockRoot, nil
}

func GetClients(ctx context.Context, node, beaconNodeUri string) (*ethclient.Client, BeaconClient, *big.Int, error) {
func GetClients(ctx context.Context, node, beaconNodeUri string, enableLogs bool) (*ethclient.Client, BeaconClient, *big.Int, error) {
eth, err := ethclient.Dial(node)
if err != nil {
return nil, nil, nil, fmt.Errorf("failed to reach eth --node: %w", err)
Expand All @@ -283,10 +281,10 @@ func GetClients(ctx context.Context, node, beaconNodeUri string) (*ethclient.Cli
}

if chainId == nil || chainId.Int64() != 17000 {
return nil, nil, nil, fmt.Errorf("This tool only supports the Holesky network.")
return nil, nil, nil, errors.New("this tool only supports the Holesky network")
}

beaconClient, err := GetBeaconClient(beaconNodeUri)
beaconClient, err := GetBeaconClient(beaconNodeUri, enableLogs)
if err != nil {
return nil, nil, nil, fmt.Errorf("failed to reach beacon client: %w", err)
}
Expand Down
54 changes: 32 additions & 22 deletions cli/core/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ func LoadValidatorProofFromFile(path string) (*SerializableCredentialProof, erro
return &res, nil
}

func SubmitValidatorProof(ctx context.Context, owner, eigenpodAddress string, chainId *big.Int, eth *ethclient.Client, batchSize uint64, proofs *eigenpodproofs.VerifyValidatorFieldsCallParams, oracleBeaconTimesetamp uint64, noPrompt bool, noSend bool) ([]*types.Transaction, error) {
func SubmitValidatorProof(ctx context.Context, owner, eigenpodAddress string, chainId *big.Int, eth *ethclient.Client, batchSize uint64, proofs *eigenpodproofs.VerifyValidatorFieldsCallParams, oracleBeaconTimesetamp uint64, noPrompt bool, noSend bool, verbose bool) ([]*types.Transaction, [][]*big.Int, error) {
ownerAccount, err := PrepareAccount(&owner, chainId, noSend)
if err != nil {
return nil, err
return nil, [][]*big.Int{}, err
}
PanicOnError("failed to parse private key", err)

eigenPod, err := onchain.NewEigenPod(common.HexToAddress(eigenpodAddress), eth)
if err != nil {
return nil, err
return nil, [][]*big.Int{}, err
}

indices := Uint64ArrayToBigIntArray(proofs.ValidatorIndices)
Expand All @@ -61,14 +61,16 @@ func SubmitValidatorProof(ctx context.Context, owner, eigenpodAddress string, ch
transactions := []*types.Transaction{}
numChunks := len(validatorIndicesChunks)

color.Green("calling EigenPod.VerifyWithdrawalCredentials() (using %d txn(s), max(%d) proofs per txn [%s])", numChunks, batchSize, func() string {
if ownerAccount.TransactionOptions.NoSend {
return "simulated"
} else {
return "live"
}
}())
color.Green("Submitting proofs with %d transactions", numChunks)
if verbose {
color.Green("calling EigenPod.VerifyWithdrawalCredentials() (using %d txn(s), max(%d) proofs per txn [%s])", numChunks, batchSize, func() string {
if ownerAccount.TransactionOptions.NoSend {
return "simulated"
} else {
return "live"
}
}())
color.Green("Submitting proofs with %d transactions", numChunks)
}

for i := 0; i < numChunks; i++ {
curValidatorIndices := validatorIndicesChunks[i]
Expand All @@ -81,20 +83,24 @@ func SubmitValidatorProof(ctx context.Context, owner, eigenpodAddress string, ch
}
var curValidatorFields [][][32]byte = CastValidatorFields(validatorFieldsChunks[i])

fmt.Printf("Submitted chunk %d/%d -- waiting for transaction...: ", i+1, numChunks)
txn, err := SubmitValidatorProofChunk(ctx, ownerAccount, eigenPod, chainId, eth, curValidatorIndices, curValidatorFields, proofs.StateRootProof, validatorFieldsProofs, oracleBeaconTimesetamp)
if verbose {
fmt.Printf("Submitted chunk %d/%d -- waiting for transaction...: ", i+1, numChunks)
}
txn, err := SubmitValidatorProofChunk(ctx, ownerAccount, eigenPod, chainId, eth, curValidatorIndices, curValidatorFields, proofs.StateRootProof, validatorFieldsProofs, oracleBeaconTimesetamp, verbose)
if err != nil {
return transactions, err
return transactions, validatorIndicesChunks, err
}

transactions = append(transactions, txn)
}

return transactions, err
return transactions, validatorIndicesChunks, err
}

func SubmitValidatorProofChunk(ctx context.Context, ownerAccount *Owner, eigenPod *onchain.EigenPod, chainId *big.Int, eth *ethclient.Client, indices []*big.Int, validatorFields [][][32]byte, stateRootProofs *eigenpodproofs.StateRootProof, validatorFieldsProofs [][]byte, oracleBeaconTimesetamp uint64) (*types.Transaction, error) {
color.Green("submitting onchain...")
func SubmitValidatorProofChunk(ctx context.Context, ownerAccount *Owner, eigenPod *onchain.EigenPod, chainId *big.Int, eth *ethclient.Client, indices []*big.Int, validatorFields [][][32]byte, stateRootProofs *eigenpodproofs.StateRootProof, validatorFieldsProofs [][]byte, oracleBeaconTimesetamp uint64, verbose bool) (*types.Transaction, error) {
if verbose {
color.Green("submitting onchain...")
}
txn, err := eigenPod.VerifyWithdrawalCredentials(
ownerAccount.TransactionOptions,
oracleBeaconTimesetamp,
Expand All @@ -114,7 +120,7 @@ func SubmitValidatorProofChunk(ctx context.Context, ownerAccount *Owner, eigenPo
* Generates a .ProveValidatorContainers() proof for all eligible validators on the pod. If `validatorIndex` is set, it will only generate a proof
* against that validator, regardless of the validator's state.
*/
func GenerateValidatorProof(ctx context.Context, eigenpodAddress string, eth *ethclient.Client, chainId *big.Int, beaconClient BeaconClient, validatorIndex *big.Int) (*eigenpodproofs.VerifyValidatorFieldsCallParams, uint64, error) {
func GenerateValidatorProof(ctx context.Context, eigenpodAddress string, eth *ethclient.Client, chainId *big.Int, beaconClient BeaconClient, validatorIndex *big.Int, verbose bool) (*eigenpodproofs.VerifyValidatorFieldsCallParams, uint64, error) {
latestBlock, err := eth.BlockByNumber(ctx, nil)
if err != nil {
return nil, 0, fmt.Errorf("failed to load latest block: %w", err)
Expand Down Expand Up @@ -145,11 +151,11 @@ func GenerateValidatorProof(ctx context.Context, eigenpodAddress string, eth *et
return nil, 0, fmt.Errorf("failed to initialize provider: %w", err)
}

proofs, err := GenerateValidatorProofAtState(proofExecutor, eigenpodAddress, beaconState, eth, chainId, header, latestBlock.Time(), validatorIndex)
proofs, err := GenerateValidatorProofAtState(proofExecutor, eigenpodAddress, beaconState, eth, chainId, header, latestBlock.Time(), validatorIndex, verbose)
return proofs, latestBlock.Time(), err
}

func GenerateValidatorProofAtState(proofs *eigenpodproofs.EigenPodProofs, eigenpodAddress string, beaconState *spec.VersionedBeaconState, eth *ethclient.Client, chainId *big.Int, header *v1.BeaconBlockHeader, blockTimestamp uint64, forSpecificValidatorIndex *big.Int) (*eigenpodproofs.VerifyValidatorFieldsCallParams, error) {
func GenerateValidatorProofAtState(proofs *eigenpodproofs.EigenPodProofs, eigenpodAddress string, beaconState *spec.VersionedBeaconState, eth *ethclient.Client, chainId *big.Int, header *v1.BeaconBlockHeader, blockTimestamp uint64, forSpecificValidatorIndex *big.Int, verbose bool) (*eigenpodproofs.VerifyValidatorFieldsCallParams, error) {
allValidators, err := FindAllValidatorsForEigenpod(eigenpodAddress, beaconState)
if err != nil {
return nil, fmt.Errorf("failed to find validators: %w", err)
Expand Down Expand Up @@ -178,10 +184,14 @@ func GenerateValidatorProofAtState(proofs *eigenpodproofs.EigenPodProofs, eigenp
}

if len(awaitingCredentialValidators) == 0 {
color.Red("You have no inactive validators to verify. Everything up-to-date.")
if verbose {
color.Red("You have no inactive validators to verify. Everything up-to-date.")
}
return nil, nil
} else {
color.Blue("Verifying %d inactive validators", len(awaitingCredentialValidators))
if verbose {
color.Blue("Verifying %d inactive validators", len(awaitingCredentialValidators))
}
}

validatorIndices := make([]uint64, len(awaitingCredentialValidators))
Expand Down
Loading

0 comments on commit f854015

Please sign in to comment.