Skip to content

Commit

Permalink
Add command to disable root based on index
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmcgary committed Sep 24, 2024
1 parent 53f7810 commit 836ec33
Show file tree
Hide file tree
Showing 7 changed files with 209 additions and 1 deletion.
107 changes: 107 additions & 0 deletions cmd/disableRoot.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package cmd

import (
"context"
"fmt"
"github.com/Layr-Labs/eigenlayer-rewards-updater/internal/logger"
"github.com/Layr-Labs/eigenlayer-rewards-updater/pkg/chainClient"
"github.com/Layr-Labs/eigenlayer-rewards-updater/pkg/config"
"github.com/Layr-Labs/eigenlayer-rewards-updater/pkg/disabler"
"github.com/Layr-Labs/eigenlayer-rewards-updater/pkg/services"
"github.com/Layr-Labs/eigenlayer-rewards-updater/pkg/tracer"
gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"go.uber.org/zap"
ddTracer "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
"log"
)

func runDisableRoot(ctx context.Context, cfg *config.DisableRootConfig, logger *zap.Logger) error {
span, ctx := ddTracer.StartSpanFromContext(ctx, "runDisableRoot")
defer span.Finish()

rootIndex := cfg.RootIndex
if rootIndex < 0 {
return fmt.Errorf("root index must be greater than or equal to 0")
}

logger.Sugar().Infow("Disabling root", zap.Uint32("rootIndex", cfg.RootIndex))

ethClient, err := ethclient.Dial(cfg.RPCUrl)
if err != nil {
logger.Sugar().Errorf("Failed to create new eth client", zap.Error(err))
return err
}

cc, err := chainClient.NewChainClient(ctx, ethClient, cfg.PrivateKey)
if err != nil {
logger.Sugar().Errorf("Failed to create new chain client with private key", zap.Error(err))
return err
}

transactor, err := services.NewTransactor(cc, gethcommon.HexToAddress(cfg.RewardsCoordinatorAddress))
if err != nil {
logger.Sugar().Errorf("Failed to initialize transactor", zap.Error(err))
return err
}

d, err := disabler.NewDisabler(transactor, logger)
if err != nil {
logger.Sugar().Errorf("Failed to create updater", zap.Error(err))
return err
}

err = d.DisableRoot(cfg.RootIndex)
if err != nil {
logger.Sugar().Infow("Failed to disable root", zap.Error(err))
return nil
}
logger.Sugar().Infow("Root disabled", zap.Uint32("rootIndex", cfg.RootIndex))
return nil
}

// distribution represents the updater command
var disableRootCmd = &cobra.Command{
Use: "disable-root",
Short: "Disable root",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
cfg := config.NewDisableRootConfig()

tracer.StartTracer(cfg.EnableTracing)
defer ddTracer.Stop()

span, ctx := ddTracer.StartSpanFromContext(context.Background(), "cmd::updater")
defer span.Finish()

logger, err := logger.NewLogger(&logger.LoggerConfig{
Debug: cfg.Debug,
})
if err != nil {
log.Fatalln(err)
}
defer logger.Sync()

err = runDisableRoot(ctx, cfg, logger)
if err != nil {
logger.Sugar().Error(err)
}
},
}

func init() {
rootCmd.AddCommand(disableRootCmd)

disableRootCmd.Flags().Int32("root-index", -1, "Index of the root to disable")

disableRootCmd.Flags().VisitAll(func(f *pflag.Flag) {
if err := viper.BindPFlag(config.KebabToSnakeCase(f.Name), f); err != nil {
fmt.Printf("Failed to bind flag '%s' - %+v\n", f.Name, err)
}
viper.BindEnv(f.Name)
})

}
19 changes: 19 additions & 0 deletions eigenlayer-rewards-updater/values-mainnetEthereum.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
environment: mainnet
network: ethereum
cronJob:
namespace: mainnet-ethereum
enabled: false
claimJob:
namespace: testnet-holesky
enabled: false
verifyRootJob:
enabled: true
config: |
debug: true
environment: "mainnet"
network: "ethereum"
rpc_url: "https://ethereum-rpc.publicnode.com"
proof_store_base_url: "https://eigenlabs-rewards-mainnet-ethereum.s3.amazonaws.com"
private_key: "..."
rewards_coordinator_address: "0x7750d328b314effa365a0402ccfd489b80b0adda"
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/Layr-Labs/eigenlayer-rewards-updater
go 1.21

require (
github.com/Layr-Labs/eigenlayer-contracts v0.3.0-rc3-holesky-preprod-rewards.0.20240618161038-04a0176562a0
github.com/Layr-Labs/eigenlayer-contracts v0.4.1-holesky-pepe.0.20240813143901-00fc4b95e9c1
github.com/ethereum/go-ethereum v1.14.0
github.com/google/go-cmp v0.6.0
github.com/pkg/errors v0.9.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ github.com/DataDog/zstd v1.4.5 h1:EndNeuB0l9syBZhut0wns3gV1hL8zX8LIu6ZiVHWLIQ=
github.com/DataDog/zstd v1.4.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
github.com/Layr-Labs/eigenlayer-contracts v0.3.0-rc3-holesky-preprod-rewards.0.20240618161038-04a0176562a0 h1:lnG8PqYWtbjRg3duimXD8eyOcIJ7qGeo91kJLvn8r1A=
github.com/Layr-Labs/eigenlayer-contracts v0.3.0-rc3-holesky-preprod-rewards.0.20240618161038-04a0176562a0/go.mod h1:Ie8YE3EQkTHqG6/tnUS0He7/UPMkXPo/3OFXwSy0iRo=
github.com/Layr-Labs/eigenlayer-contracts v0.4.1-holesky-pepe.0.20240813143901-00fc4b95e9c1 h1:VrPrlQe0T9A74L79FjE1EJkxyIRwKKBoZljwFW/lYWk=
github.com/Layr-Labs/eigenlayer-contracts v0.4.1-holesky-pepe.0.20240813143901-00fc4b95e9c1/go.mod h1:Ie8YE3EQkTHqG6/tnUS0He7/UPMkXPo/3OFXwSy0iRo=
github.com/Layr-Labs/eigenlayer-rewards-proofs v0.2.2 h1:ylepkAqepQogGRuG2lRQq+NRb5GvSrz47JXyVHweAzE=
github.com/Layr-Labs/eigenlayer-rewards-proofs v0.2.2/go.mod h1:W2a9mERHznfIU+jD1FUaZjdUAfx+9lwbZ0tYQaF+Vhc=
github.com/Microsoft/go-winio v0.5.0/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84=
Expand Down
26 changes: 26 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,22 @@ type ValidateConfig struct {
ProofStoreBaseUrl string `mapstructure:"proof_store_base_url"`
}

type DisableRootConfig struct {
GlobalConfig
Environment Environment `mapstructure:"environment"`
Network string `mapstructure:"network"`
RPCUrl string `mapstructure:"rpc_url"`
PrivateKey string `mapstructure:"private_key"`
RewardsCoordinatorAddress string `mapstructure:"rewards_coordinator_address"`
ProofStoreBaseUrl string `mapstructure:"proof_store_base_url"`
RootIndex uint32 `mapstructure:"root_index"`
}

var updaterConfig *UpdaterConfig
var distributionConfig *DistributionConfig
var claimConfig *ClaimConfig
var validateConfig *ValidateConfig
var disableRootConfig *DisableRootConfig

// parseEnvironment normalizes environment names to an enum value
func parseEnvironment(env string) Environment {
Expand Down Expand Up @@ -172,6 +184,20 @@ func NewValidateConfig() *ValidateConfig {
return validateConfig
}

func NewDisableRootConfig() *DisableRootConfig {
disableRootConfig = &DisableRootConfig{
GlobalConfig: GetGlobalConfig(),
Environment: parseEnvironment(viper.GetString("environment")),
Network: viper.GetString("network"),
RPCUrl: viper.GetString("rpc_url"),
PrivateKey: viper.GetString("private_key"),
RewardsCoordinatorAddress: viper.GetString("rewards_coordinator_address"),
ProofStoreBaseUrl: viper.GetString("proof_store_base_url"),
RootIndex: viper.GetUint32("root_index"),
}
return disableRootConfig
}

func getEnvNetwork(environment Environment, network string) (string, error) {
envString, err := StringEnvironmentFromEnum(environment)
if err != nil {
Expand Down
36 changes: 36 additions & 0 deletions pkg/disabler/disabler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package disabler

import (
"fmt"
"github.com/Layr-Labs/eigenlayer-rewards-updater/pkg/services"
"go.uber.org/zap"
)

type Disabler struct {
transactor services.Transactor
logger *zap.Logger
}

func NewDisabler(
transactor services.Transactor,
logger *zap.Logger,
) (*Disabler, error) {
return &Disabler{
transactor: transactor,
logger: logger,
}, nil
}

func (d *Disabler) DisableRoot(rootIndex uint32) error {
if rootIndex < 0 {
return fmt.Errorf("root index must be greater than or equal to 0")
}

err := d.transactor.DisableRoot(rootIndex)
if err != nil {
d.logger.Sugar().Errorf("Failed to disable root", zap.Error(err))
return err
}

return nil
}
18 changes: 18 additions & 0 deletions pkg/services/transactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Transactor interface {
SubmitRewardClaim(ctx context.Context, claim rewardsCoordinator.IRewardsCoordinatorRewardsMerkleClaim, earnerAddress gethcommon.Address) error
GetRootByIndex(index uint64) (*rewardsCoordinator.IRewardsCoordinatorDistributionRoot, error)
GetCurrentRoot() (*rewardsCoordinator.IRewardsCoordinatorDistributionRoot, error)
DisableRoot(rootIndex uint32) error
}

type TransactorImpl struct {
Expand Down Expand Up @@ -121,3 +122,20 @@ func (t *TransactorImpl) GetCurrentRoot() (*rewardsCoordinator.IRewardsCoordinat
}
return &root, nil
}

func (t *TransactorImpl) DisableRoot(rootIndex uint32) error {
tx, err := t.CoordinatorTransactor.DisableRoot(t.ChainClient.NoSendTransactOpts, rootIndex)

if err != nil {
return fmt.Errorf("Rewards coordinator, failed to disable root: %+v - %+v", err, tx)
}

receipt, err := t.ChainClient.EstimateGasPriceAndLimitAndSendTx(context.Background(), tx, "disableRoot")
if err != nil {
return fmt.Errorf("Failed to estimate gas: %+v\n", err)
}
if receipt.Status != 1 {
return chainClient.ErrTransactionFailed
}
return nil
}

0 comments on commit 836ec33

Please sign in to comment.