Skip to content

Commit

Permalink
Only log waiting for block height if timed out.
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSaso committed Oct 4, 2023
1 parent 4f6b4be commit a5320aa
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/scripts/export/trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,6 @@ const trace = async () => {
if (!blockHeightToTimeCache.has(blockHeight) && webSocketConnected) {
const blockHeights = blockHeightToTimeCache.dump().map(([key]) => key)
if (blockHeights.every((b) => b < blockHeight)) {
const earliestBlockHeight = blockHeights.reduce(
(acc, curr) => (curr < acc ? curr : acc),
Infinity
)
const latestBlockHeight = blockHeights.reduce(
(acc, curr) => (curr > acc ? curr : acc),
-Infinity
)
console.log(
`[${new Date().toISOString()}] Waiting for ${blockHeight.toLocaleString()}'s time... (${earliestBlockHeight.toLocaleString()}${latestBlockHeight.toLocaleString()})`
)

const time = await new Promise<number | undefined>((resolve) => {
const interval = setInterval(() => {
if (blockHeightToTimeCache.has(blockHeight)) {
Expand All @@ -141,6 +129,21 @@ const trace = async () => {
}, 50)

const timeout = setTimeout(() => {
const blockHeights = blockHeightToTimeCache
.dump()
.map(([key]) => key)
const earliestBlockHeight = blockHeights.reduce(
(acc, curr) => (curr < acc ? curr : acc),
Infinity
)
const latestBlockHeight = blockHeights.reduce(
(acc, curr) => (curr > acc ? curr : acc),
-Infinity
)

console.log(
`[${new Date().toISOString()}] Timed out waiting for ${blockHeight.toLocaleString()}'s time... (${earliestBlockHeight.toLocaleString()}${latestBlockHeight.toLocaleString()})`
)
clearInterval(interval)
resolve(undefined)
}, 3000)
Expand Down

0 comments on commit a5320aa

Please sign in to comment.