@@ -62,6 +62,9 @@ export interface Options {
6262}
6363
6464export class Config {
65+ // Initialize Common with an explicit 'chainstart' HF set until
66+ // hardfork awareness is implemented within the library
67+ // Also a fix for https://github.com/ethereumjs/ethereumjs-vm/issues/757
6568 public static readonly COMMON_DEFAULT = new Common ( { chain : 'mainnet' , hardfork : 'chainstart' } )
6669 public static readonly LOGGER_DEFAULT = defaultLogger
6770 public static readonly SYNCMODE_DEFAULT = 'fast'
@@ -71,22 +74,18 @@ export class Config {
7174 public static readonly MINPEERS_DEFAULT = 2
7275 public static readonly MAXPEERS_DEFAULT = 25
7376
74- public common : Common
75- public logger : Logger
76- public syncmode : string
77- public lightserv : boolean
78- public datadir : string
79- public transports : string [ ]
80- public minPeers : number
81- public maxPeers : number
77+ public readonly common : Common
78+ public readonly logger : Logger
79+ public readonly syncmode : string
80+ public readonly lightserv : boolean
81+ public readonly datadir : string
82+ public readonly transports : string [ ]
83+ public readonly minPeers : number
84+ public readonly maxPeers : number
8285
83- private servers : ( RlpxServer | Libp2pServer ) [ ] = [ ]
86+ public readonly servers : ( RlpxServer | Libp2pServer ) [ ] = [ ]
8487
8588 constructor ( options : Options = { } ) {
86- // Initialize Common with an explicit 'chainstart' HF set until
87- // hardfork awareness is implemented within the library
88- // Also a fix for https://github.com/ethereumjs/ethereumjs-vm/issues/757
89-
9089 // TODO: map chainParams (and lib/util.parseParams) to new Common format
9190 this . common = options . common ?? Config . COMMON_DEFAULT
9291 this . logger = options . logger ?? Config . LOGGER_DEFAULT
@@ -97,7 +96,20 @@ export class Config {
9796 this . minPeers = options . minPeers ?? Config . MINPEERS_DEFAULT
9897 this . maxPeers = options . maxPeers ?? Config . MAXPEERS_DEFAULT
9998
100- this . servers = options . servers ? options . servers : this . getTransportServers ( )
99+ if ( options . servers ) {
100+ // Servers option takes precedence
101+ this . servers = options . servers
102+ } else {
103+ // Otherwise parse transports from transports option
104+ this . servers = parseTransports ( this . transports ) . map ( ( t ) => {
105+ if ( t . name === 'rlpx' ) {
106+ t . options . bootnodes = t . options . bootnodes || this . common . bootstrapNodes ( )
107+ return new RlpxServer ( { config : this , ...t . options } )
108+ } else {
109+ return new Libp2pServer ( { config : this , ...t . options } )
110+ }
111+ } )
112+ }
101113 }
102114
103115 /**
@@ -112,21 +124,4 @@ export class Config {
112124 const dataDir = `${ this . datadir } /${ networkDirName } ethereumjs/${ syncDirName } `
113125 return dataDir
114126 }
115-
116- /**
117- * Returns the transport servers created from the `transports` option
118- */
119- getTransportServers ( ) : ( RlpxServer | Libp2pServer ) [ ] {
120- if ( this . servers . length === 0 ) {
121- this . servers = parseTransports ( this . transports ) . map ( ( t ) => {
122- if ( t . name === 'rlpx' ) {
123- t . options . bootnodes = t . options . bootnodes || this . common . bootstrapNodes ( )
124- return new RlpxServer ( { config : this , ...t . options } )
125- } else {
126- return new Libp2pServer ( { config : this , ...t . options } )
127- }
128- } )
129- }
130- return this . servers
131- }
132127}
0 commit comments