From 584e74a52084281ff4d601d0b642840ff7ba1746 Mon Sep 17 00:00:00 2001 From: Minh Vu Date: Tue, 16 Apr 2024 10:33:47 -0400 Subject: [PATCH] chore: remove genesis flag (#261) * clean up unused parameter * remove genesis flag * fix lint * fix more lint issues * update docs --- cmd/p2p/sensor/sensor.go | 26 -------------------------- doc/polycli_p2p_sensor.md | 1 - p2p/protocol.go | 6 ++---- 3 files changed, 2 insertions(+), 31 deletions(-) diff --git a/cmd/p2p/sensor/sensor.go b/cmd/p2p/sensor/sensor.go index 573e9855..e76c89db 100644 --- a/cmd/p2p/sensor/sensor.go +++ b/cmd/p2p/sensor/sensor.go @@ -2,7 +2,6 @@ package sensor import ( "crypto/ecdsa" - "encoding/json" "errors" "fmt" "os" @@ -15,7 +14,6 @@ import ( _ "net/http/pprof" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/forkid" "github.com/ethereum/go-ethereum/crypto" ethp2p "github.com/ethereum/go-ethereum/p2p" @@ -56,7 +54,6 @@ type ( Port int DiscoveryPort int RPC string - GenesisFile string GenesisHash string ForkID []byte DialRatio int @@ -68,7 +65,6 @@ type ( nodes []*enode.Node trustedNodes []*enode.Node privateKey *ecdsa.PrivateKey - genesis core.Genesis nat nat.Interface } ) @@ -149,12 +145,6 @@ var SensorCmd = &cobra.Command{ } } - inputSensorParams.genesis, err = loadGenesis(inputSensorParams.GenesisFile) - if err != nil { - log.Error().Err(err).Msg("Failed to load genesis file") - return err - } - inputSensorParams.nat, err = nat.Parse(inputSensorParams.NAT) if err != nil { log.Error().Err(err).Msg("Failed to parse NAT") @@ -204,7 +194,6 @@ var SensorCmd = &cobra.Command{ opts := p2p.EthProtocolOptions{ Context: cmd.Context(), Database: db, - Genesis: &inputSensorParams.genesis, GenesisHash: common.HexToHash(inputSensorParams.GenesisHash), RPC: inputSensorParams.RPC, SensorID: inputSensorParams.SensorID, @@ -294,20 +283,6 @@ var SensorCmd = &cobra.Command{ }, } -// loadGenesis unmarshals the genesis file into the core.Genesis struct. -func loadGenesis(genesisFile string) (core.Genesis, error) { - chainConfig, err := os.ReadFile(genesisFile) - - if err != nil { - return core.Genesis{}, err - } - var gen core.Genesis - if err := json.Unmarshal(chainConfig, &gen); err != nil { - return core.Genesis{}, err - } - return gen, nil -} - // getLatestBlock will get the latest block from an RPC provider. func getLatestBlock(url string) (*rpctypes.RawBlockResponse, error) { client, err := rpc.Dial(url) @@ -358,7 +333,6 @@ significantly increase CPU and memory usage.`) SensorCmd.Flags().IntVar(&inputSensorParams.Port, "port", 30303, "TCP network listening port") SensorCmd.Flags().IntVar(&inputSensorParams.DiscoveryPort, "discovery-port", 30303, "UDP P2P discovery port") SensorCmd.Flags().StringVar(&inputSensorParams.RPC, "rpc", "https://polygon-rpc.com", "RPC endpoint used to fetch the latest block") - SensorCmd.Flags().StringVar(&inputSensorParams.GenesisFile, "genesis", "genesis.json", "Genesis file") SensorCmd.Flags().StringVar(&inputSensorParams.GenesisHash, "genesis-hash", "0xa9c28ce2141b56c474f1dc504bee9b01eb1bd7d1a507580d5519d4437a97de1b", "The genesis block hash") SensorCmd.Flags().BytesHexVar(&inputSensorParams.ForkID, "fork-id", []byte{240, 151, 188, 19}, "The hex encoded fork id (omit the 0x)") SensorCmd.Flags().IntVar(&inputSensorParams.DialRatio, "dial-ratio", 0, diff --git a/doc/polycli_p2p_sensor.md b/doc/polycli_p2p_sensor.md index 8e91cc74..19bdee65 100644 --- a/doc/polycli_p2p_sensor.md +++ b/doc/polycli_p2p_sensor.md @@ -29,7 +29,6 @@ If no nodes.json file exists, it will be created. connections to be dialed. Setting this to 0 defaults it to 3. --discovery-port int UDP P2P discovery port (default 30303) --fork-id bytesHex The hex encoded fork id (omit the 0x) (default F097BC13) - --genesis string Genesis file (default "genesis.json") --genesis-hash string The genesis block hash (default "0xa9c28ce2141b56c474f1dc504bee9b01eb1bd7d1a507580d5519d4437a97de1b") -h, --help help for sensor -k, --key-file string Private key file diff --git a/p2p/protocol.go b/p2p/protocol.go index fd81639f..ceb604ff 100644 --- a/p2p/protocol.go +++ b/p2p/protocol.go @@ -11,7 +11,6 @@ import ( "time" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/forkid" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/eth/protocols/eth" @@ -50,7 +49,6 @@ type conn struct { type EthProtocolOptions struct { Context context.Context Database database.Database - Genesis *core.Genesis GenesisHash common.Hash RPC string SensorID string @@ -137,7 +135,7 @@ func NewEthProtocol(version uint, opts EthProtocolOptions) ethp2p.Protocol { case eth.NewBlockMsg: err = c.handleNewBlock(ctx, msg) case eth.NewPooledTransactionHashesMsg: - err = c.handleNewPooledTransactionHashes(ctx, version, msg) + err = c.handleNewPooledTransactionHashes(version, msg) case eth.GetPooledTransactionsMsg: err = c.handleGetPooledTransactions(msg) case eth.PooledTransactionsMsg: @@ -452,7 +450,7 @@ func (c *conn) handleGetPooledTransactions(msg ethp2p.Msg) error { ð.PooledTransactionsPacket{RequestId: request.RequestId}) } -func (c *conn) handleNewPooledTransactionHashes(ctx context.Context, version uint, msg ethp2p.Msg) error { +func (c *conn) handleNewPooledTransactionHashes(version uint, msg ethp2p.Msg) error { var hashes []common.Hash var name string