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

feat: improve txservice logs #6197

Merged
merged 2 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
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
14 changes: 13 additions & 1 deletion packages/adapters/txservice/src/aggregator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,19 @@ export class RpcProviderAggregator {
return await provider.call(formatted, blockTag);
}
} catch (error: unknown) {
throw new TransactionReadError(TransactionReadError.reasons.ContractReadError, { error });
throw new TransactionReadError(TransactionReadError.reasons.ContractReadError, {
error,
provider: {
url: provider.name,
blockNumber: provider.syncedBlockNumber,
lag: provider.lag,
synced: provider.synced,
metrics: {
reliability: provider.reliability,
priority: provider.priority,
},
},
});
}
});
}
Expand Down
23 changes: 21 additions & 2 deletions packages/adapters/txservice/test/aggregator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ describe("RpcProviderAggregator", () => {
coreSyncProvider = Sinon.createStubInstance(SyncProvider);
(coreSyncProvider as any)._syncedBlockNumber = 123;
(coreSyncProvider as any).synced = true;
(coreSyncProvider as any).name = "-------fakeProvider------";
(coreSyncProvider as any).lag = 1;
(coreSyncProvider as any).reliability = 1.0;
(coreSyncProvider as any).priority = 0;
(coreSyncProvider as any).url = "https://-------fakeProvider------";
Sinon.stub(coreSyncProvider, "syncedBlockNumber").get(() => (coreSyncProvider as any)._syncedBlockNumber);
(chainProvider as any).providers = [coreSyncProvider];
Expand Down Expand Up @@ -290,9 +294,24 @@ describe("RpcProviderAggregator", () => {
it("should return error result if the signer readContract call throws", async () => {
const testError = new Error("test error");
signer.call.rejects(testError);

// The error.context.error is the "test error" thrown by the signer.call.
await expect(chainProvider.readContract(TEST_READ_TX)).to.be.rejectedWith(TransactionReadError);
await expect(chainProvider.readContract(TEST_READ_TX)).to.rejected.then((error) => {
if (error instanceof TransactionReadError) {
expect(error.context.error).to.eq(testError);
expect(error.context.provider).to.deep.eq({
url: coreSyncProvider.name,
blockNumber: coreSyncProvider.syncedBlockNumber,
lag: coreSyncProvider.lag,
synced: coreSyncProvider.synced,
metrics: {
reliability: coreSyncProvider.reliability,
priority: coreSyncProvider.priority,
},
});
} else {
expect.fail("Error should be a TransactionReadError");
}
});
});

it("should execute with provider if no signer available", async () => {
Expand Down
Loading