@@ -90,7 +90,7 @@ export class BeaconNetwork extends BaseNetwork {
9090 this . logger = debug ( this . enr . nodeId . slice ( 0 , 5 ) ) . extend ( 'Portal' ) . extend ( 'BeaconNetwork' )
9191 this . routingTable . setLogger ( this . logger )
9292 this . forkDigest = Uint8Array . from ( [ 0 , 0 , 0 , 0 ] )
93- this . on ( ' ContentAdded' , async ( contentKey : Uint8Array ) => {
93+ this . portal . on ( ` ${ this . networkId } : ContentAdded` , async ( contentKey : Uint8Array ) => {
9494 if ( contentKey [ 0 ] === BeaconNetworkContentType . LightClientUpdate ) {
9595 // don't gossip individual LightClientUpdates since they aren't officially supported
9696 return
@@ -111,14 +111,14 @@ export class BeaconNetwork extends BaseNetwork {
111111 switch ( this . syncStrategy ) {
112112 case SyncStrategy . PollNetwork :
113113 this . bootstrapFinder = new Map ( )
114- this . portal . on ( ' NodeAdded' , this . getBootStrapVote )
114+ this . portal . on ( ` ${ this . networkId } : NodeAdded` , this . getBootStrapVote )
115115 break
116116 case SyncStrategy . TrustedBlockRoot :
117117 if ( trustedBlockRoot === undefined )
118118 throw new Error ( 'must provided trusted block root with SyncStrategy.TrustedBlockRoot' )
119119 this . bootstrapFinder = new Map ( )
120120 this . trustedBlockRoot = trustedBlockRoot
121- this . portal . on ( ' NodeAdded' , this . getBootstrap )
121+ this . portal . on ( ` ${ this . networkId } : NodeAdded` , this . getBootstrap )
122122 break
123123 }
124124 }
@@ -130,9 +130,7 @@ export class BeaconNetwork extends BaseNetwork {
130130 * @param nodeId NodeId for a peer that was just discovered by the Portal Network `client`
131131 * @param network the network ID for the node just discovered
132132 */
133- private getBootstrap = async ( nodeId : string , network : NetworkId ) => {
134- // We check the network ID because NodeAdded is emitted regardless of network
135- if ( network !== this . networkId ) return
133+ private getBootstrap = async ( nodeId : string ) => {
136134 const enr = getENR ( this . routingTable , nodeId )
137135 if ( enr === undefined ) return
138136 const decoded = await this . sendFindContent (
@@ -153,7 +151,7 @@ export class BeaconNetwork extends BaseNetwork {
153151 )
154152 if ( headerHash === this . trustedBlockRoot ) {
155153 void this . initializeLightClient ( headerHash )
156- this . portal . removeListener ( ' NodeAdded' , this . getBootstrap )
154+ this . portal . removeListener ( ` ${ this . networkId } : NodeAdded` , this . getBootstrap )
157155 }
158156 }
159157 }
@@ -168,9 +166,9 @@ export class BeaconNetwork extends BaseNetwork {
168166 * @param nodeId NodeId for a peer that was just discovered by the Portal Network `client`
169167 * @param network the network ID for the node just discovered
170168 */
171- private getBootStrapVote = async ( nodeId : string , network : NetworkId ) => {
169+ private getBootStrapVote = async ( nodeId : string ) => {
172170 try {
173- if ( network === this . networkId ) {
171+
174172 // We check the network ID because NodeAdded is emitted regardless of network
175173 if ( this . bootstrapFinder . has ( nodeId ) ) {
176174 return
@@ -257,7 +255,7 @@ export class BeaconNetwork extends BaseNetwork {
257255 ssz [ fork ] . LightClientBootstrap . deserialize ( res . content . slice ( 4 ) )
258256 this . logger . extend ( 'BOOTSTRAP' ) ( `found a valid bootstrap - ${ results [ x ] [ 0 ] } ` )
259257 await this . store ( bootstrapKey , res . content )
260- this . portal . removeListener ( ' NodeAdded' , this . getBootStrapVote )
258+ this . portal . removeListener ( ` ${ this . networkId } : NodeAdded` , this . getBootStrapVote )
261259 this . logger . extend ( 'BOOTSTRAP' ) ( 'Terminating Light Client bootstrap process' )
262260 await this . initializeLightClient ( results [ x ] [ 0 ] )
263261 return
@@ -274,7 +272,7 @@ export class BeaconNetwork extends BaseNetwork {
274272 this . bootstrapFinder . set ( peer , { } )
275273 }
276274 }
277- }
275+
278276 } catch ( err ) {
279277 this . logger . extend ( 'BOOTSTRAP' ) ( err )
280278 }
@@ -287,8 +285,8 @@ export class BeaconNetwork extends BaseNetwork {
287285 */
288286 public initializeLightClient = async ( blockRoot : string ) => {
289287 // Ensure bootstrap finder mechanism is disabled if currently running
290- this . portal . removeListener ( ' NodeAdded' , this . getBootStrapVote )
291- this . portal . removeListener ( ' NodeAdded' , this . getBootstrap )
288+ this . portal . removeListener ( ` ${ this . networkId } : NodeAdded` , this . getBootStrapVote )
289+ this . portal . removeListener ( ` ${ this . networkId } : NodeAdded` , this . getBootstrap )
292290
293291 // Setup the Lodestar light client logger using our debug logger
294292 const lcLogger = this . logger . extend ( 'LightClient' )
@@ -473,7 +471,7 @@ export class BeaconNetwork extends BaseNetwork {
473471 this . logger . extend ( 'FOUNDCONTENT' ) ( `received uTP Connection ID ${ id } ` )
474472 response = await new Promise ( ( resolve , _reject ) => {
475473 // TODO: Figure out how to clear this listener
476- this . on ( ' ContentAdded' , ( contentKey : Uint8Array , value ) => {
474+ this . portal . on ( ` ${ this . networkId } : ContentAdded` , ( contentKey : Uint8Array , value ) => {
477475 if ( equalsBytes ( contentKey , key ) === true ) {
478476 this . logger . extend ( 'FOUNDCONTENT' ) ( `received content for uTP Connection ID ${ id } ` )
479477 resolve ( { content : value , utp : true } )
@@ -739,7 +737,7 @@ export class BeaconNetwork extends BaseNetwork {
739737 this . logger (
740738 `storing ${ BeaconNetworkContentType [ contentType ] } content corresponding to ${ bytesToHex ( contentKey ) } ` ,
741739 )
742- this . emit ( ' ContentAdded' , contentKey , value )
740+ this . portal . emit ( ` ${ this . networkId } : ContentAdded` , contentKey , value )
743741 }
744742
745743 /**
0 commit comments