Skip to content

Commit

Permalink
fix: eth1 provider error logging
Browse files Browse the repository at this point in the history
  • Loading branch information
nflaig committed Jun 7, 2024
1 parent c153277 commit d0f0428
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/beacon-node/src/eth1/provider/eth1Provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class Eth1Provider implements IEth1Provider {
if (this.state !== Eth1ProviderState.ONLINE) {
if (isOneMinutePassed()) {
this.logger?.error(
"Eth1Provider faced error",
"Eth1Provider error",
{
state: this.state,
lastErrorAt: new Date(Date.now() - isOneMinutePassed.msSinceLastCall).toLocaleTimeString(),
Expand Down
8 changes: 6 additions & 2 deletions packages/utils/src/waitFor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,13 @@ export function createElapsedTimeTracker({minElapsedTime}: {minElapsedTime: numb
function elapsedTimeTracker(): boolean {
const now = Date.now();
const msSinceLastCall = now - (lastTimeCalled ?? 0);
lastTimeCalled = now;

return msSinceLastCall > minElapsedTime;
if (msSinceLastCall > minElapsedTime) {
// Do not reset timer if called before timer elapsed
lastTimeCalled = now;
return true;
}
return false;
}

return Object.assign(elapsedTimeTracker, {
Expand Down
16 changes: 14 additions & 2 deletions packages/utils/test/unit/waitFor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ describe("waitFor", () => {
});
});

describe("waitForElapsedTime", () => {
it("should true for the first time", () => {
describe("createElapsedTimeTracker", () => {
it("should return true for the first time", () => {
const callIfTimePassed = createElapsedTimeTracker({minElapsedTime: 1000});

expect(callIfTimePassed()).toBe(true);
Expand All @@ -52,6 +52,18 @@ describe("waitForElapsedTime", () => {
expect(callIfTimePassed()).toBe(true);
});

it("should return true after the minElapsedTime has passed with intermediate calls", async () => {
const callIfTimePassed = createElapsedTimeTracker({minElapsedTime: 100});
callIfTimePassed();

await sleep(75);
// Time has not elapsed yet but it should not reset timer
expect(callIfTimePassed()).toBe(false);
await sleep(75);

expect(callIfTimePassed()).toBe(true);
});

it("should return false before the minElapsedTime has passed", async () => {
const callIfTimePassed = createElapsedTimeTracker({minElapsedTime: 100});
callIfTimePassed();
Expand Down

0 comments on commit d0f0428

Please sign in to comment.