Skip to content

Commit

Permalink
fix: eth1 provider error logging (#6863)
Browse files Browse the repository at this point in the history
  • Loading branch information
nflaig authored Jul 5, 2024
1 parent b6e2077 commit 29d1c22
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/beacon-node/src/eth1/provider/eth1Provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class Eth1Provider implements IEth1Provider {
this.state = Eth1ProviderState.ONLINE;

if (oldState !== Eth1ProviderState.ONLINE) {
this.logger?.info("Eth1Provider is back online", {oldState, newState: this.state});
this.logger?.info("Eth1 provider is back online", {oldState, newState: this.state});
}
});

Expand All @@ -109,7 +109,7 @@ export class Eth1Provider implements IEth1Provider {
if (this.state !== Eth1ProviderState.ONLINE) {
if (isOneMinutePassed()) {
this.logger?.error(
"Eth1Provider faced error",
"Eth1 provider 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 29d1c22

Please sign in to comment.