@@ -2,7 +2,7 @@ import {Connection, PeerId} from "@libp2p/interface";
2
2
import { BitArray , toHexString } from "@chainsafe/ssz" ;
3
3
import { SYNC_COMMITTEE_SUBNET_COUNT } from "@lodestar/params" ;
4
4
import { BeaconConfig } from "@lodestar/config" ;
5
- import { Metadata , altair , phase0 } from "@lodestar/types" ;
5
+ import { Metadata , electra , phase0 } from "@lodestar/types" ;
6
6
import { withTimeout } from "@lodestar/utils" ;
7
7
import { LoggerNode } from "@lodestar/logger/node" ;
8
8
import { GoodByeReasonCode , GOODBYE_KNOWN_CODES , Libp2pEvent } from "../../constants/index.js" ;
@@ -308,6 +308,11 @@ export class PeerManager {
308
308
private onPing ( peer : PeerId , seqNumber : phase0 . Ping ) : void {
309
309
// if the sequence number is unknown update the peer's metadata
310
310
const metadata = this . connectedPeers . get ( peer . toString ( ) ) ?. metadata ;
311
+ this . logger . warn ( "onPing" , {
312
+ seqNumber,
313
+ metaSeqNumber : metadata ?. seqNumber ,
314
+ cond : ! metadata || metadata . seqNumber < seqNumber ,
315
+ } ) ;
311
316
if ( ! metadata || metadata . seqNumber < seqNumber ) {
312
317
void this . requestMetadata ( peer ) ;
313
318
}
@@ -320,12 +325,22 @@ export class PeerManager {
320
325
// Store metadata always in case the peer updates attnets but not the sequence number
321
326
// Trust that the peer always sends the latest metadata (From Lighthouse)
322
327
const peerData = this . connectedPeers . get ( peer . toString ( ) ) ;
328
+ this . logger . warn ( "onMetadata" , { peer : peer . toString ( ) , peerData : peerData !== undefined } ) ;
329
+ console . log ( "onMetadata" , metadata ) ;
323
330
if ( peerData ) {
331
+ const oldMetadata = peerData . metadata ;
324
332
peerData . metadata = {
325
333
seqNumber : metadata . seqNumber ,
326
334
attnets : metadata . attnets ,
327
- syncnets : ( metadata as Partial < altair . Metadata > ) . syncnets ?? BitArray . fromBitLen ( SYNC_COMMITTEE_SUBNET_COUNT ) ,
335
+ syncnets : ( metadata as Partial < electra . Metadata > ) . syncnets ?? BitArray . fromBitLen ( SYNC_COMMITTEE_SUBNET_COUNT ) ,
336
+ csc :
337
+ ( metadata as Partial < electra . Metadata > ) . csc ??
338
+ this . discovery ?. [ "peerIdToCustodySubnetCount" ] . get ( peer . toString ( ) ) ??
339
+ this . config . CUSTODY_REQUIREMENT ,
328
340
} ;
341
+ if ( oldMetadata === null || oldMetadata . csc !== peerData . metadata . csc ) {
342
+ void this . requestStatus ( peer , this . statusCache . get ( ) ) ;
343
+ }
329
344
}
330
345
}
331
346
@@ -392,10 +407,10 @@ export class PeerManager {
392
407
}
393
408
if ( getConnection ( this . libp2p , peer . toString ( ) ) ) {
394
409
const nodeId = peerData ?. nodeId ?? computeNodeId ( peer ) ;
395
- const custodySubnetCount =
396
- peerData ?. custodySubnetCount ?? this . discovery ?. [ "peerIdToCustodySubnetCount" ] . get ( peer . toString ( ) ) ;
410
+ console . log ( "onStatus" , peerData ?. metadata ) ;
411
+ const custodySubnetCount = peerData ?. metadata ?. csc ;
397
412
398
- const peerCustodySubnetCount = custodySubnetCount ?? this . config . CUSTODY_REQUIREMENT ;
413
+ const peerCustodySubnetCount = custodySubnetCount ?? 4 ;
399
414
const peerCustodySubnets = getCustodyColumnSubnets ( nodeId , peerCustodySubnetCount ) ;
400
415
401
416
const matchingSubnetsNum = this . custodySubnets . reduce (
@@ -407,6 +422,7 @@ export class PeerManager {
407
422
408
423
this . logger . warn ( `onStatus ${ custodySubnetCount == undefined ? "undefined custody count assuming 4" : "" } ` , {
409
424
nodeId : toHexString ( nodeId ) ,
425
+ myNodeId : toHexString ( this . nodeId ) ,
410
426
peerId : peer . toString ( ) ,
411
427
custodySubnetCount,
412
428
hasAllColumns,
@@ -438,14 +454,17 @@ export class PeerManager {
438
454
439
455
private async requestMetadata ( peer : PeerId ) : Promise < void > {
440
456
try {
457
+ this . logger . warn ( "requestMetadata" , { peer : peer . toString ( ) } ) ;
441
458
this . onMetadata ( peer , await this . reqResp . sendMetadata ( peer ) ) ;
442
459
} catch ( e ) {
460
+ console . log ( "requestMetadata" , e ) ;
443
461
// TODO: Downvote peer here or in the reqResp layer
444
462
}
445
463
}
446
464
447
465
private async requestPing ( peer : PeerId ) : Promise < void > {
448
466
try {
467
+ this . logger . warn ( "requestPing" , { peer : peer . toString ( ) } ) ;
449
468
this . onPing ( peer , await this . reqResp . sendPing ( peer ) ) ;
450
469
451
470
// If peer replies a PING request also update lastReceivedMsg
@@ -643,7 +662,6 @@ export class PeerManager {
643
662
// If that happens, it's okay. Only the "outbound" connection triggers immediate action
644
663
const now = Date . now ( ) ;
645
664
const nodeId = computeNodeId ( remotePeer ) ;
646
- const custodySubnetCount = this . discovery ?. [ "peerIdToCustodySubnetCount" ] . get ( remotePeer . toString ( ) ) ?? null ;
647
665
const peerData : PeerData = {
648
666
lastReceivedMsgUnixTsMs : direction === "outbound" ? 0 : now ,
649
667
// If inbound, request after STATUS_INBOUND_GRACE_PERIOD
@@ -657,12 +675,11 @@ export class PeerManager {
657
675
agentVersion : null ,
658
676
agentClient : null ,
659
677
encodingPreference : null ,
660
- custodySubnetCount,
661
678
} ;
662
679
this . connectedPeers . set ( remotePeer . toString ( ) , peerData ) ;
663
680
664
681
if ( direction === "outbound" ) {
665
- //this.pingAndStatusTimeouts();
682
+ // this.pingAndStatusTimeouts();
666
683
void this . requestPing ( remotePeer ) ;
667
684
void this . requestStatus ( remotePeer , this . statusCache . get ( ) ) ;
668
685
}
0 commit comments