Skip to content

Commit 4d9f3cd

Browse files
eth: set networkID to chainID by default (#28250)
Co-authored-by: Felix Lange <[email protected]>
1 parent f20b334 commit 4d9f3cd

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

eth/backend.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
152152
if err != nil {
153153
return nil, err
154154
}
155+
networkID := config.NetworkId
156+
if networkID == 0 {
157+
networkID = chainConfig.ChainID.Uint64()
158+
}
155159
eth := &Ethereum{
156160
config: config,
157161
merger: consensus.NewMerger(chainDb),
@@ -160,7 +164,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
160164
accountManager: stack.AccountManager(),
161165
engine: engine,
162166
closeBloomHandler: make(chan struct{}),
163-
networkID: config.NetworkId,
167+
networkID: networkID,
164168
gasPrice: config.Miner.GasPrice,
165169
etherbase: config.Miner.Etherbase,
166170
bloomRequests: make(chan chan *bloombits.Retrieval),
@@ -173,7 +177,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
173177
if bcVersion != nil {
174178
dbVer = fmt.Sprintf("%d", *bcVersion)
175179
}
176-
log.Info("Initialising Ethereum protocol", "network", config.NetworkId, "dbversion", dbVer)
180+
log.Info("Initialising Ethereum protocol", "network", networkID, "dbversion", dbVer)
177181

178182
if !config.SkipBcVersionCheck {
179183
if bcVersion != nil && *bcVersion > core.BlockChainVersion {
@@ -236,7 +240,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
236240
Chain: eth.blockchain,
237241
TxPool: eth.txPool,
238242
Merger: eth.merger,
239-
Network: config.NetworkId,
243+
Network: networkID,
240244
Sync: config.SyncMode,
241245
BloomCache: uint64(cacheLimit),
242246
EventMux: eth.eventMux,
@@ -270,7 +274,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
270274
}
271275

272276
// Start the RPC service
273-
eth.netRPCService = ethapi.NewNetAPI(eth.p2pServer, config.NetworkId)
277+
eth.netRPCService = ethapi.NewNetAPI(eth.p2pServer, networkID)
274278

275279
// Register the backend on the node
276280
stack.RegisterAPIs(eth.APIs())

eth/ethconfig/config.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ var LightClientGPO = gasprice.Config{
5959
// Defaults contains default settings for use on the Ethereum main net.
6060
var Defaults = Config{
6161
SyncMode: downloader.SnapSync,
62-
NetworkId: 1,
62+
NetworkId: 0, // enable auto configuration of networkID == chainID
6363
TxLookupLimit: 2350000,
6464
TransactionHistory: 2350000,
6565
StateHistory: params.FullImmutabilityThreshold,
@@ -87,8 +87,9 @@ type Config struct {
8787
// If nil, the Ethereum main net block is used.
8888
Genesis *core.Genesis `toml:",omitempty"`
8989

90-
// Protocol options
91-
NetworkId uint64 // Network ID to use for selecting peers to connect to
90+
// Network ID separates blockchains on the peer-to-peer networking level. When left
91+
// zero, the chain ID is used as network ID.
92+
NetworkId uint64
9293
SyncMode downloader.SyncMode
9394

9495
// This can be set to list of enrtree:// URLs which will be queried for

ethclient/ethclient_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ func testStatusFunctions(t *testing.T, client *rpc.Client) {
481481
if err != nil {
482482
t.Fatalf("unexpected error: %v", err)
483483
}
484-
if networkID.Cmp(big.NewInt(0)) != 0 {
484+
if networkID.Cmp(big.NewInt(1337)) != 0 {
485485
t.Fatalf("unexpected networkID: %v", networkID)
486486
}
487487

0 commit comments

Comments
 (0)