Skip to content

Commit

Permalink
chore: improve default RPC URLs and validate genesis hash format
Browse files Browse the repository at this point in the history
Updated the default ETH and Engine API URLs to use localhost for better clarity and security. Introduced a `PreRunE` validation step to ensure the genesis hash is in a valid hex format, improving error handling and configuration robustness. Removed redundant initialization of the `runCmd` in the root command file.
  • Loading branch information
tzdybal committed Feb 10, 2025
1 parent 955e419 commit dcbfc07
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 0 additions & 4 deletions cmd/evm-middleware/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ var rootCmd = &cobra.Command{
Short: "EVM middleware for Rollkit",
}

func init() {
rootCmd.AddCommand(runCmd)
}

// Execute executes the root command.
func Execute() error {
return rootCmd.Execute()
Expand Down
11 changes: 9 additions & 2 deletions cmd/evm-middleware/commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"sync"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/spf13/cobra"
"google.golang.org/grpc"

Expand All @@ -32,8 +33,8 @@ func init() {
}
runCmd.Flags().StringVar(&listenAddress, "listen-address", "0.0.0.0:40041", "Address to listen for gRPC connections")
runCmd.Flags().StringVar(&genesisHashHex, "genesis-hash", "0x8bf225d50da44f60dee1c4ee6f810fe5b44723c76ac765654b6692d50459f216", "Genesis hash of the EVM chain")
runCmd.Flags().StringVar(&ethURL, "eth-url", "http://:8545", "URL of the ETH API exposed by EVM node")
runCmd.Flags().StringVar(&engineURL, "engine-url", "http://:8551", "URL of the Engine API exposed by EVM node")
runCmd.Flags().StringVar(&ethURL, "eth-url", "http://127.0.0.1:8545", "URL of the ETH API exposed by EVM node")
runCmd.Flags().StringVar(&engineURL, "engine-url", "http://127.0.0.1:8551", "URL of the Engine API exposed by EVM node")

// Attach the `runCmd` to the root command
rootCmd.AddCommand(runCmd)
Expand All @@ -43,6 +44,12 @@ var runCmd = &cobra.Command{
Use: "run",
Aliases: []string{"start", "node"},
Short: "Run the EVM middleware for Rollkit",
PreRunE: func(cmd *cobra.Command, args []string) error {
if _, err := hexutil.Decode(genesisHashHex); err != nil {
return fmt.Errorf("invalid genesis hash format: %s, error: %w", genesisHashHex, err)
}
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
listener, err := net.Listen("tcp", listenAddress)
if err != nil {
Expand Down

0 comments on commit dcbfc07

Please sign in to comment.