@@ -7,6 +7,7 @@ const { fromName: serverFromName } = require('../lib/net/server')
77import Node from '../lib/node'
88import { Server as RPCServer } from 'jayson'
99import { Config } from '../lib/config'
10+ import Common from '@ethereumjs/common'
1011const RPCManager = require ( '../lib/rpc' )
1112const level = require ( 'level' )
1213const os = require ( 'os' )
@@ -82,7 +83,7 @@ const args = require('yargs')
8283 . locale ( 'en_EN' ) . argv
8384const logger = getLogger ( { loglevel : args . loglevel } )
8485
85- async function runNode ( options : any , config : Config ) {
86+ async function runNode ( options : any ) {
8687 logger . info ( 'Initializing Ethereumjs client...' )
8788 if ( options . lightserv ) {
8889 logger . info ( `Serving light peer requests` )
@@ -95,7 +96,7 @@ async function runNode(options: any, config: Config) {
9596 node . on ( 'synchronized' , ( ) => {
9697 logger . info ( 'Synchronized' )
9798 } )
98- logger . info ( `Connecting to network: ${ config . common . chainName ( ) } ` )
99+ logger . info ( `Connecting to network: ${ options . config . common . chainName ( ) } ` )
99100 await node . open ( )
100101 logger . info ( 'Synchronizing blockchain...' )
101102 await node . start ( )
@@ -114,13 +115,6 @@ function runRpcServer(node: any, options: any) {
114115}
115116
116117async function run ( ) {
117- const config = new Config ( {
118- logger,
119- syncmode : args . syncmode ,
120- minPeers : args . minPeers ,
121- maxPeers : args . maxPeers ,
122- } )
123-
124118 const syncDirName = args . syncmode === 'light' ? 'lightchaindata' : 'chaindata'
125119 // give network id precedence over network name
126120 if ( args . networkId ) {
@@ -131,6 +125,15 @@ async function run() {
131125 }
132126 const networkDirName = args . network === 'mainnet' ? '' : `${ args . network } /`
133127
128+ const common = new Common ( { chain : args . network , hardfork : 'chainstart' } )
129+ const config = new Config ( {
130+ common,
131+ logger,
132+ syncmode : args . syncmode ,
133+ minPeers : args . minPeers ,
134+ maxPeers : args . maxPeers ,
135+ } )
136+
134137 // TODO: see todo below wrt resolving chain param parsing
135138 // eslint-disable-next-line @typescript-eslint/no-unused-vars
136139 const chainParams = args . params ? await parseParams ( args . params ) : args . network
@@ -140,21 +143,22 @@ async function run() {
140143 if ( t . name === 'rlpx' ) {
141144 t . options . bootnodes = t . options . bootnodes || config . common . bootstrapNodes ( )
142145 }
143- return new Server ( { logger , ...t . options } )
146+ return new Server ( { config , ...t . options } )
144147 } )
145148 const dataDir = `${ args . datadir } /${ networkDirName } ethereumjs/${ syncDirName } `
146149
147150 fs . ensureDirSync ( dataDir )
148151 logger . info ( `Data directory: ${ dataDir } ` )
149152
150153 const options = {
154+ config,
151155 servers,
152156 lightserv : args . lightserv ,
153157 db : level ( dataDir ) ,
154158 rpcport : args . rpcport ,
155159 rpcaddr : args . rpcaddr ,
156160 }
157- const node = await runNode ( options , config )
161+ const node = await runNode ( options )
158162 const server = args . rpc ? runRpcServer ( node , options ) : null
159163
160164 process . on ( 'SIGINT' , async ( ) => {
0 commit comments