Skip to content

Commit

Permalink
chore: return early if no logs for START_BLOCK_EVENT_TYPE
Browse files Browse the repository at this point in the history
  • Loading branch information
rabi-siddique committed Nov 9, 2024
1 parent 3c5a1ea commit d175ee4
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions services/fetchAndStoreHeightLogs.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// @ts-check
import { getAccessToken } from '../helpers/getAccessToken.js';
import { networks } from '../helpers/constants.js';
import { logError } from '../helpers/logGCPError.js';
import { getCredentials } from '../helpers/getGCPCredentials.js';
import { fetchGCPLogs } from './fetchGCPLogs.js';
import { fs } from 'zx';
Expand Down Expand Up @@ -114,7 +113,7 @@ const fetchLogsByBlockEvents = async ({ network, blockHeight, type }) => {

return logs?.[0] || null;
} catch (error) {
logError(error);
console.error(error);
}
};

Expand All @@ -139,14 +138,22 @@ export const fetchAndStoreHeightLogs = async ({
type: START_BLOCK_EVENT_TYPE,
});

if (!foundBeginBlock) {
throw Error(
`No log entry found for event ${START_BLOCK_EVENT_TYPE} at block height ${blockHeight}`
);
}

const foundCommitBlockFinish = await fetchLogsByBlockEvents({
network,
blockHeight,
type: COMMIT_BLOCK_FINISH_EVENT_TYPE,
});

if (!foundBeginBlock || !foundCommitBlockFinish) {
throw Error('Could not find both log entries.');
if (!foundCommitBlockFinish) {
throw Error(
`No log entry found for event ${COMMIT_BLOCK_FINISH_EVENT_TYPE} at block height ${blockHeight}`
);
}

const startTime = foundBeginBlock.timestamp;
Expand Down

0 comments on commit d175ee4

Please sign in to comment.