Skip to content

Commit

Permalink
Modified check in to make sure block hash is from the block number be…
Browse files Browse the repository at this point in the history
…ind displayed
  • Loading branch information
sfaber34 committed Sep 2, 2024
1 parent 1b62051 commit f70714e
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions https_connection/httpsConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,20 @@ export function initializeHttpConnection(httpConfig) {
let lastCheckedBlockNumber = -1;
const minCheckInInterval = 60000; // Minimum 60 seconds between check-ins

checkIn = async function (force = false) {
checkIn = async function (force = false, blockNumber = null) {
const now = Date.now();
if (!force && now - lastCheckInTime < minCheckInInterval) {
return;
}

let currentBlockNumber;
try {
currentBlockNumber = await localClient.getBlockNumber();
} catch (error) {
debugToFile(`Failed to get block number: ${error}`, () => {});
return;
let currentBlockNumber = blockNumber;
if (!currentBlockNumber) {
try {
currentBlockNumber = await localClient.getBlockNumber();
} catch (error) {
debugToFile(`Failed to get block number: ${error}`, () => {});
return;
}
}

if (!force && currentBlockNumber === lastCheckedBlockNumber) {
Expand All @@ -80,14 +82,13 @@ export function initializeHttpConnection(httpConfig) {
consensusClientResponse += " v" + httpConfig.lighthouseVer;
}

let possibleBlockNumber;
let possibleBlockNumber = currentBlockNumber;
let possibleBlockHash;
try {
possibleBlockNumber = await localClient.getBlockNumber();
const block = await localClient.getBlock();
const block = await localClient.getBlock(possibleBlockNumber);
possibleBlockHash = block.hash;
} catch (error) {
debugToFile(`Failed to get block number: ${error}`, () => {});
debugToFile(`Failed to get block hash: ${error}`, () => {});
}

try {
Expand Down Expand Up @@ -152,7 +153,7 @@ export function initializeHttpConnection(httpConfig) {
{
onBlock: (block) => {
if (block.number > 0) {
checkIn(true); // Force check-in for each new block
checkIn(true, block.number); // Pass block number to checkIn
}
},
},
Expand Down

0 comments on commit f70714e

Please sign in to comment.