Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spike: observe concurrent calls to fetch height logs #22

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 19 additions & 27 deletions services/fetchAndStoreHeightLogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

const BATCH_SIZE = 10; // 10 days

const calculateDaysDifference = (startTimestamp) => {

Check failure on line 14 in services/fetchAndStoreHeightLogs.js

View workflow job for this annotation

GitHub Actions / lint

'calculateDaysDifference' is assigned a value but never used. Allowed unused vars must match /^_/u
const startTime = new Date(startTimestamp);
const currentDate = new Date();

Expand Down Expand Up @@ -109,41 +109,33 @@
const COMMIT_BLOCK_FINISH_EVENT_TYPE =
'cosmic-swingset-commit-block-finish';

const foundBeginBlock = await fetchLogsByBlockEvents({
network,
blockHeight,
type: START_BLOCK_EVENT_TYPE,
});

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

console.log(
`Start time of block ${blockHeight}: ${foundBeginBlock.timestamp}`
);
const totalDaysCoverage = calculateDaysDifference(
foundBeginBlock.timestamp
);

const foundCommitBlockFinish = await fetchLogsByBlockEvents({
network,
blockHeight,
type: COMMIT_BLOCK_FINISH_EVENT_TYPE,
totalDaysCoverage,
});
const [foundBeginBlock, foundCommitBlockFinish] = await Promise.all([
fetchLogsByBlockEvents({
network,
blockHeight,
type: START_BLOCK_EVENT_TYPE,
}),
fetchLogsByBlockEvents({
network,
blockHeight,
type: COMMIT_BLOCK_FINISH_EVENT_TYPE,
}),
]);

if (!foundBeginBlock || !foundCommitBlockFinish) {
const missingEventType = !foundBeginBlock
? START_BLOCK_EVENT_TYPE
: COMMIT_BLOCK_FINISH_EVENT_TYPE;

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

const startTime = foundBeginBlock.timestamp;
const endTime = foundCommitBlockFinish.timestamp;

console.log(`Start time of block ${blockHeight}: ${startTime}`);
console.log(`End time of block ${blockHeight}: ${endTime}`);

let allEntries = [];
Expand Down
Loading