@@ -80,7 +80,10 @@ export class HttpBlobSinkClient implements BlobSinkClientInterface {
80
80
81
81
if ( blobs . length == 0 && this . config . l1ConsensusHostUrl ) {
82
82
// The beacon api can query by slot number, so we get that first
83
- this . log . debug ( 'Getting slot number from consensus host' ) ;
83
+ this . log . debug ( 'Getting slot number from consensus host' , {
84
+ blockHash,
85
+ consensusHostUrl : this . config . l1ConsensusHostUrl ,
86
+ } ) ;
84
87
const slotNumber = await this . getSlotNumber ( blockHash ) ;
85
88
if ( slotNumber ) {
86
89
const blobs = await this . getBlobSidecarFrom ( this . config . l1ConsensusHostUrl , slotNumber , indices ) ;
@@ -106,12 +109,16 @@ export class HttpBlobSinkClient implements BlobSinkClientInterface {
106
109
) : Promise < Blob [ ] > {
107
110
// TODO(md): right now we assume all blobs are ours, this will not yet work on sepolia
108
111
try {
109
- let url = `${ hostUrl } /eth/v1/beacon/blob_sidecars/${ blockHashOrSlot } ` ;
112
+ let baseUrl = `${ hostUrl } /eth/v1/beacon/blob_sidecars/${ blockHashOrSlot } ` ;
110
113
if ( indices && indices . length > 0 ) {
111
- url += `?indices=${ indices . join ( ',' ) } ` ;
114
+ baseUrl += `?indices=${ indices . join ( ',' ) } ` ;
112
115
}
113
116
114
- const res = await this . fetch ( url ) ;
117
+ const { url, ...options } = getBeaconNodeFetchOptions ( baseUrl , this . config ) ;
118
+
119
+ this . log . debug ( `Fetching blob sidecar from ${ url } with options` , options ) ;
120
+
121
+ const res = await this . fetch ( url , options ) ;
115
122
116
123
if ( res . ok ) {
117
124
const body = await res . json ( ) ;
@@ -183,7 +190,12 @@ export class HttpBlobSinkClient implements BlobSinkClientInterface {
183
190
184
191
// Query beacon chain to get the slot number for that block root
185
192
try {
186
- const res = await this . fetch ( `${ this . config . l1ConsensusHostUrl } /eth/v1/beacon/headers/${ parentBeaconBlockRoot } ` ) ;
193
+ const { url, ...options } = getBeaconNodeFetchOptions (
194
+ `${ this . config . l1ConsensusHostUrl } /eth/v1/beacon/headers/${ parentBeaconBlockRoot } ` ,
195
+ this . config ,
196
+ ) ;
197
+ const res = await this . fetch ( url , options ) ;
198
+
187
199
if ( res . ok ) {
188
200
const body = await res . json ( ) ;
189
201
@@ -210,3 +222,19 @@ function filterRelevantBlobs(blobs: Blob[], blobHashes: Buffer[]): Blob[] {
210
222
return blobHashes . some ( hash => hash . equals ( blobHash ) ) ;
211
223
} ) ;
212
224
}
225
+
226
+ function getBeaconNodeFetchOptions ( url : string , config : BlobSinkConfig ) {
227
+ let formattedUrl = url ;
228
+ if ( config . l1ConsensusHostApiKey && ! config . l1ConsensusHostApiKeyHeader ) {
229
+ formattedUrl += `${ formattedUrl . includes ( '?' ) ? '&' : '?' } key=${ config . l1ConsensusHostApiKey } ` ;
230
+ }
231
+ return {
232
+ url : formattedUrl ,
233
+ ...( config . l1ConsensusHostApiKey &&
234
+ config . l1ConsensusHostApiKeyHeader && {
235
+ headers : {
236
+ [ config . l1ConsensusHostApiKeyHeader ] : config . l1ConsensusHostApiKey ,
237
+ } ,
238
+ } ) ,
239
+ } ;
240
+ }
0 commit comments