Skip to content

Commit

Permalink
chore: remove genesis flag (#261)
Browse files Browse the repository at this point in the history
* clean up unused parameter

* remove genesis flag

* fix lint

* fix more lint issues

* update docs
  • Loading branch information
minhd-vu committed Apr 16, 2024
1 parent b34f308 commit 584e74a
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 31 deletions.
26 changes: 0 additions & 26 deletions cmd/p2p/sensor/sensor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package sensor

import (
"crypto/ecdsa"
"encoding/json"
"errors"
"fmt"
"os"
Expand All @@ -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"
Expand Down Expand Up @@ -56,7 +54,6 @@ type (
Port int
DiscoveryPort int
RPC string
GenesisFile string
GenesisHash string
ForkID []byte
DialRatio int
Expand All @@ -68,7 +65,6 @@ type (
nodes []*enode.Node
trustedNodes []*enode.Node
privateKey *ecdsa.PrivateKey
genesis core.Genesis
nat nat.Interface
}
)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion doc/polycli_p2p_sensor.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions p2p/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -452,7 +450,7 @@ func (c *conn) handleGetPooledTransactions(msg ethp2p.Msg) error {
&eth.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

Expand Down

0 comments on commit 584e74a

Please sign in to comment.