Skip to content

Commit

Permalink
cmd/utils, eth, eth/protocols/eth: fix allow selecting protocol versi…
Browse files Browse the repository at this point in the history
…ons after merge
  • Loading branch information
ziogaschr committed May 10, 2021
1 parent 28e6007 commit b2d8181
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
10 changes: 5 additions & 5 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ var (
}
EthProtocolsFlag = cli.StringFlag{
Name: "eth.protocols",
Usage: "Sets the Ethereum Protocol versions (65|64|63) (default = 65,64,63 first is primary)",
Usage: "Sets the Ethereum Protocol versions (66|65|64) (default = 66,65,64 first is primary)",
Value: "",
}
ClassicFlag = cli.BoolFlag{
Expand Down Expand Up @@ -1731,7 +1731,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
if ctx.GlobalIsSet(EthProtocolsFlag.Name) {
protocolVersions := SplitAndTrim(ctx.GlobalString(EthProtocolsFlag.Name))
if len(protocolVersions) == 0 {
Fatalf("--%s must be comma separated list of %s", EthProtocolsFlag.Name, strings.Join(strings.Fields(fmt.Sprint(ethconfig.Defaults.ProtocolVersions)), ","))
Fatalf("--%s must be comma separated list of %s", EthProtocolsFlag.Name, strings.Join(strings.Fields(fmt.Sprint(eth.DefaultProtocolVersions)), ","))
}

seenVersions := map[uint]interface{}{}
Expand All @@ -1746,7 +1746,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
}

isValid := false
for _, proto := range ethconfig.Defaults.ProtocolVersions {
for _, proto := range eth.DefaultProtocolVersions {
if proto == uint(version) {
isValid = true
seenVersions[uint(version)] = nil
Expand All @@ -1755,15 +1755,15 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
}

if !isValid {
Fatalf("--%s must be comma separated list of %s", EthProtocolsFlag.Name, strings.Join(strings.Fields(fmt.Sprint(ethconfig.Defaults.ProtocolVersions)), ","))
Fatalf("--%s must be comma separated list of %s", EthProtocolsFlag.Name, strings.Join(strings.Fields(fmt.Sprint(eth.DefaultProtocolVersions)), ","))
}
cfg.ProtocolVersions = append(cfg.ProtocolVersions, uint(version))
}
}

// set default protocol versions
if len(cfg.ProtocolVersions) == 0 {
cfg.ProtocolVersions = ethconfig.Defaults.ProtocolVersions
cfg.ProtocolVersions = eth.DefaultProtocolVersions
}

// Set DNS discovery defaults for hard coded networks with DNS defaults.
Expand Down
6 changes: 3 additions & 3 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
if bcVersion != nil {
dbVer = fmt.Sprintf("%d", *bcVersion)
}
log.Info("Initialising Ethereum protocol", "versions", config.ProtocolVersions, "network", config.NetworkId, "dbversion", dbVer)
log.Info("Initialising Ethereum protocol", "network", config.NetworkId, "dbversion", dbVer)

if !config.SkipBcVersionCheck {
if bcVersion != nil && *bcVersion > core.BlockChainVersion {
Expand Down Expand Up @@ -532,7 +532,7 @@ func (s *Ethereum) Engine() consensus.Engine { return s.engine }
func (s *Ethereum) ChainDb() ethdb.Database { return s.chainDb }
func (s *Ethereum) IsListening() bool { return true } // Always listening
func (s *Ethereum) EthVersion() int {
return int(eth.MakeProtocols((*ethHandler)(s.handler), s.networkID, s.ethDialCandidates)[0].Version)
return int(eth.MakeProtocols((*ethHandler)(s.handler), s.networkID, s.config.ProtocolVersions, s.ethDialCandidates)[0].Version)
}
func (s *Ethereum) NetVersion() uint64 { return s.networkID }
func (s *Ethereum) Downloader() *downloader.Downloader { return s.handler.downloader }
Expand All @@ -543,7 +543,7 @@ func (s *Ethereum) BloomIndexer() *core.ChainIndexer { return s.bloomIndexer }
// Protocols returns all the currently configured
// network protocols to start.
func (s *Ethereum) Protocols() []p2p.Protocol {
protos := eth.MakeProtocols((*ethHandler)(s.handler), s.networkID, s.ethDialCandidates)
protos := eth.MakeProtocols((*ethHandler)(s.handler), s.networkID, s.config.ProtocolVersions, s.ethDialCandidates)
if s.config.SnapshotCache > 0 {
protos = append(protos, snap.MakeProtocols((*snapHandler)(s.handler), s.snapDialCandidates)...)
}
Expand Down
4 changes: 4 additions & 0 deletions eth/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ var (
syncChallengeTimeout = 15 * time.Second // Time allowance for a node to reply to the sync progress challenge
)

// DefaultProtocolVersions are the supported versions of the `eth` protocol (first
// is primary).
var DefaultProtocolVersions = []uint{eth.ETH66, eth.ETH65, eth.ETH64}

// txPool defines the methods needed from a transaction pool implementation to
// support all the operations needed by the Ethereum chain protocols.
type txPool interface {
Expand Down
6 changes: 3 additions & 3 deletions eth/protocols/eth/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ type TxPool interface {
}

// MakeProtocols constructs the P2P protocol definitions for `eth`.
func MakeProtocols(backend Backend, network uint64, dnsdisc enode.Iterator) []p2p.Protocol {
protocols := make([]p2p.Protocol, len(ProtocolVersions))
for i, version := range ProtocolVersions {
func MakeProtocols(backend Backend, network uint64, protocolVersions []uint, dnsdisc enode.Iterator) []p2p.Protocol {
protocols := make([]p2p.Protocol, len(protocolVersions))
for i, version := range protocolVersions {
version := version // Closure

protocols[i] = p2p.Protocol{
Expand Down

0 comments on commit b2d8181

Please sign in to comment.