@@ -70,8 +70,8 @@ import {
7070import type { ENR } from '@chainsafe/enr'
7171
7272import { RunStatusCode } from '@lodestar/light-client'
73- import type { Debugger } from 'debug'
7473import type { LightClientHeader } from '@lodestar/types/lib/deneb/types.js'
74+ import type { Debugger } from 'debug'
7575
7676export class HistoryNetwork extends BaseNetwork {
7777 networkId : NetworkId . HistoryNetwork
@@ -651,7 +651,11 @@ export class HistoryNetwork extends BaseNetwork {
651651
652652 this . emit ( 'ContentAdded' , contentKey , value )
653653 if ( this . routingTable . values ( ) . length > 0 ) {
654- if ( contentType !== HistoryNetworkContentType . EphemeralHeader && contentType !== HistoryNetworkContentType . EphemeralHeaderOffer && contentType !== HistoryNetworkContentType . EphemeralHeaderFindContent ) {
654+ if (
655+ contentType !== HistoryNetworkContentType . EphemeralHeader &&
656+ contentType !== HistoryNetworkContentType . EphemeralHeaderOffer &&
657+ contentType !== HistoryNetworkContentType . EphemeralHeaderFindContent
658+ ) {
655659 // Gossip new content to network except for ephemeral headers
656660 this . gossipManager . add ( contentKey )
657661 }
@@ -770,49 +774,69 @@ export class HistoryNetwork extends BaseNetwork {
770774 version : Version ,
771775 ) {
772776 this . logger . extend ( 'ACCEPT' ) (
773- `Received from ${ shortId ( src . nodeId , this . routingTable ) } with ${ msg . contentKeys . length
777+ `Received from ${ shortId ( src . nodeId , this . routingTable ) } with ${
778+ msg . contentKeys . length
774779 } pieces of content.`,
775780 )
776- const decodedContentKeys = msg . contentKeys . map ( key => decodeHistoryNetworkContentKey ( key ) )
781+ const decodedContentKeys = msg . contentKeys . map ( ( key ) => decodeHistoryNetworkContentKey ( key ) )
777782 // Check to see if the first content key is for ephemeral headers. If so, we expect all
778783 // content keys to be for ephemeral headers.
779784 if ( decodedContentKeys [ 0 ] . contentType === HistoryNetworkContentType . EphemeralHeaderOffer ) {
780- this . logger . extend ( 'OFFER' ) . extend ( 'EPHEMERALHEADERS' ) ( 'Received offer for ephemeral headers starting with block hash: ' + bytesToHex ( decodedContentKeys [ 0 ] . keyOpt as Uint8Array ) )
785+ this . logger . extend ( 'OFFER' ) . extend ( 'EPHEMERALHEADERS' ) (
786+ 'Received offer for ephemeral headers starting with block hash: ' +
787+ bytesToHex ( decodedContentKeys [ 0 ] . keyOpt as Uint8Array ) ,
788+ )
781789 const contentIds : number [ ] = Array ( msg . contentKeys . length ) . fill ( AcceptCode . GENERIC_DECLINE )
782790 const desiredContentKeys : Uint8Array [ ] = [ ]
783791 let headHash : Uint8Array | undefined
784792 let headHashIndex = - 1
785793 do {
786794 for ( const key of decodedContentKeys ) {
787795 if ( key . contentType !== HistoryNetworkContentType . EphemeralHeaderOffer ) {
788- this . logger . extend ( 'ACCEPT' ) . extend ( 'EPHEMERALHEADERS' ) ( 'Received non-ephemeral header in offer for ephemeral headers. Declining offer.' )
796+ this . logger . extend ( 'ACCEPT' ) . extend ( 'EPHEMERALHEADERS' ) (
797+ 'Received non-ephemeral header in offer for ephemeral headers. Declining offer.' ,
798+ )
789799 // If we get an offer for ephemeral headers, all offered content keys should be for ephemeral headers
790800 // TODO: Ban/descore peers who send spec-noncompliant offers
791801 break
792802 }
793803 }
794804 const beacon = this . portal . networks . get ( NetworkId . BeaconChainNetwork ) as BeaconNetwork
795- if ( beacon === undefined || ( beacon . lightClient ?. status !== RunStatusCode . started && beacon . lightClient ?. status !== RunStatusCode . syncing ) ) {
805+ if (
806+ beacon === undefined ||
807+ ( beacon . lightClient ?. status !== RunStatusCode . started &&
808+ beacon . lightClient ?. status !== RunStatusCode . syncing )
809+ ) {
796810 // We can't validate ephemeral headers if our light client is not active and/or syncing
797- this . logger . extend ( 'ACCEPT' ) . extend ( 'EPHEMERALHEADERS' ) ( 'Light client is not active and/or syncing. Declining offer.' )
811+ this . logger . extend ( 'ACCEPT' ) . extend ( 'EPHEMERALHEADERS' ) (
812+ 'Light client is not active and/or syncing. Declining offer.' ,
813+ )
798814 break
799815 }
800816 // TODO: Make this fork safe (and not assume deneb)
801817 headHash = ( beacon . lightClient . getHead ( ) as LightClientHeader ) . execution . blockHash
802- headHashIndex = decodedContentKeys . findIndex ( ( key ) => equalsBytes ( key . keyOpt as Uint8Array , headHash ! ) )
818+ headHashIndex = decodedContentKeys . findIndex ( ( key ) =>
819+ equalsBytes ( key . keyOpt as Uint8Array , headHash ! ) ,
820+ )
803821 if ( headHashIndex === - 1 ) {
804822 // If our known head hash isn't in the request, we can't validate other ephemeral headers so decline
805- this . logger . extend ( 'ACCEPT' ) . extend ( 'EPHEMERALHEADERS' ) ( 'Known head hash not found in offer. Declining offer.' )
823+ this . logger . extend ( 'ACCEPT' ) . extend ( 'EPHEMERALHEADERS' ) (
824+ 'Known head hash not found in offer. Declining offer.' ,
825+ )
806826 break
807827 }
808828 for ( let i = headHashIndex ; i < decodedContentKeys . length ; i ++ ) {
809829 const key = decodedContentKeys [ i ]
810- if ( this . ephemeralHeaderIndex . getByValue ( bytesToHex ( key . keyOpt as Uint8Array ) ) === undefined ) {
830+ if (
831+ this . ephemeralHeaderIndex . getByValue ( bytesToHex ( key . keyOpt as Uint8Array ) ) === undefined
832+ ) {
811833 contentIds [ i ] = AcceptCode . ACCEPT
812834 desiredContentKeys . push ( msg . contentKeys [ i ] )
813835 }
814836 }
815- this . logger . extend ( 'ACCEPT' ) . extend ( 'EPHEMERALHEADERS' ) ( `Sending accept for ${ desiredContentKeys . length } desired headers` )
837+ this . logger . extend ( 'ACCEPT' ) . extend ( 'EPHEMERALHEADERS' ) (
838+ `Sending accept for ${ desiredContentKeys . length } desired headers` ,
839+ )
816840 // biome-ignore lint/correctness/noConstantCondition: We only want to do `sendAccept` once
817841 } while ( false )
818842
@@ -833,7 +857,7 @@ export class HistoryNetwork extends BaseNetwork {
833857
834858 // if (equalsBytes(desiredContentKeys[desiredContentKeys.length - 1], contentKey)) {
835859 // // Once we've received the last desired header, gossip all offered ephemeral headers starting with the head hash
836- // // We either already have all of the headers or have received them from this gossip message and the spec calls for
860+ // // We either already have all of the headers or have received them from this gossip message and the spec calls for
837861 // // us to neighborhood gossip all of these
838862 // this.removeListener('ContentAdded', gossipEphemeralHeaders)
839863 // const content = []
@@ -869,7 +893,6 @@ export class HistoryNetwork extends BaseNetwork {
869893 // return
870894 // }
871895 // })
872- } else
873- await super . handleOffer ( src , requestId , msg , version )
896+ } else await super . handleOffer ( src , requestId , msg , version )
874897 }
875898}
0 commit comments