@@ -44,18 +44,20 @@ export function initializeHttpConnection(httpConfig) {
4444 let lastCheckedBlockNumber = - 1 ;
4545 const minCheckInInterval = 60000 ; // Minimum 60 seconds between check-ins
4646
47- checkIn = async function ( force = false ) {
47+ checkIn = async function ( force = false , blockNumber = null ) {
4848 const now = Date . now ( ) ;
4949 if ( ! force && now - lastCheckInTime < minCheckInInterval ) {
5050 return ;
5151 }
5252
53- let currentBlockNumber ;
54- try {
55- currentBlockNumber = await localClient . getBlockNumber ( ) ;
56- } catch ( error ) {
57- debugToFile ( `Failed to get block number: ${ error } ` , ( ) => { } ) ;
58- return ;
53+ let currentBlockNumber = blockNumber ;
54+ if ( ! currentBlockNumber ) {
55+ try {
56+ currentBlockNumber = await localClient . getBlockNumber ( ) ;
57+ } catch ( error ) {
58+ debugToFile ( `Failed to get block number: ${ error } ` , ( ) => { } ) ;
59+ return ;
60+ }
5961 }
6062
6163 if ( ! force && currentBlockNumber === lastCheckedBlockNumber ) {
@@ -80,14 +82,13 @@ export function initializeHttpConnection(httpConfig) {
8082 consensusClientResponse += " v" + httpConfig . lighthouseVer ;
8183 }
8284
83- let possibleBlockNumber ;
85+ let possibleBlockNumber = currentBlockNumber ;
8486 let possibleBlockHash ;
8587 try {
86- possibleBlockNumber = await localClient . getBlockNumber ( ) ;
87- const block = await localClient . getBlock ( ) ;
88+ const block = await localClient . getBlock ( possibleBlockNumber ) ;
8889 possibleBlockHash = block . hash ;
8990 } catch ( error ) {
90- debugToFile ( `Failed to get block number : ${ error } ` , ( ) => { } ) ;
91+ debugToFile ( `Failed to get block hash : ${ error } ` , ( ) => { } ) ;
9192 }
9293
9394 try {
@@ -152,7 +153,7 @@ export function initializeHttpConnection(httpConfig) {
152153 {
153154 onBlock : ( block ) => {
154155 if ( block . number > 0 ) {
155- checkIn ( true ) ; // Force check-in for each new block
156+ checkIn ( true , block . number ) ; // Pass block number to checkIn
156157 }
157158 } ,
158159 } ,
0 commit comments