From 0fbda26e2ac50d4daf338b0b66c10aa1418555c5 Mon Sep 17 00:00:00 2001 From: Gheorghe Pinzaru Date: Tue, 10 Sep 2024 19:54:41 +0200 Subject: [PATCH 1/2] Add ability to disable trace and decode only based on receipt and logs --- .changeset/proud-books-boil.md | 5 +++++ packages/transaction-decoder/src/public-client.ts | 2 +- .../transaction-decoder/src/transaction-loader.ts | 14 ++++++++------ 3 files changed, 14 insertions(+), 7 deletions(-) create mode 100644 .changeset/proud-books-boil.md diff --git a/.changeset/proud-books-boil.md b/.changeset/proud-books-boil.md new file mode 100644 index 00000000..a46ae0fe --- /dev/null +++ b/.changeset/proud-books-boil.md @@ -0,0 +1,5 @@ +--- +'@3loop/transaction-decoder': minor +--- + +Allow disabling tracer for an RPC client thus relaying only on logs and receipt diff --git a/packages/transaction-decoder/src/public-client.ts b/packages/transaction-decoder/src/public-client.ts index b34a93fb..f702054d 100644 --- a/packages/transaction-decoder/src/public-client.ts +++ b/packages/transaction-decoder/src/public-client.ts @@ -12,7 +12,7 @@ export class RPCFetchError { } export interface PublicClientConfig { - readonly supportTraceAPI?: boolean + readonly traceAPI?: 'parity' | 'geth' | 'none' } export interface PublicClientObject { diff --git a/packages/transaction-decoder/src/transaction-loader.ts b/packages/transaction-decoder/src/transaction-loader.ts index 4047263f..dcbca1e5 100644 --- a/packages/transaction-decoder/src/transaction-loader.ts +++ b/packages/transaction-decoder/src/transaction-loader.ts @@ -43,10 +43,10 @@ export const getTransactionReceipt = (hash: Hash, chainID: number) => export const getTrace = (hash: Hash, chainID: number) => Effect.gen(function* () { const service = yield* PublicClient - const { client, config } = yield* service.getPublicClient(chainID) - const traceAPISupport = config?.supportTraceAPI ?? true + const { client, config = {} } = yield* service.getPublicClient(chainID) + const traceAPI = config.traceAPI ?? 'parity' - if (traceAPISupport) { + if (traceAPI === 'parity') { const trace = yield* Effect.withSpan( Effect.tryPromise({ try: async () => { @@ -60,7 +60,7 @@ export const getTrace = (hash: Hash, chainID: number) => catch: () => new RPCFetchError('Get trace'), }), 'TransactionLoader.Trace', - { attributes: { hash, chainID, traceAPISupport } }, + { attributes: { hash, chainID, traceAPI } }, ) const effects: Effect.Effect[] = trace.map((log: string) => { @@ -73,7 +73,7 @@ export const getTrace = (hash: Hash, chainID: number) => }) return results - } else { + } else if (traceAPI === 'geth') { const trace = yield* Effect.withSpan( Effect.tryPromise({ try: async () => { @@ -87,13 +87,15 @@ export const getTrace = (hash: Hash, chainID: number) => catch: (e) => new RPCFetchError(e), }), 'TransactionLoader.Trace', - { attributes: { hash, chainID, traceAPISupport } }, + { attributes: { hash, chainID, traceAPI } }, ) const transformedTrace = transformTraceTree(trace as unknown as TraceLogTree) return transformedTrace } + + return [] }) export const getBlockTimestamp = (blockNumber: bigint, chainID: number) => From 67cfed4b6457857f814ce54af85017a0b9031e98 Mon Sep 17 00:00:00 2001 From: Gheorghe Pinzaru Date: Tue, 10 Sep 2024 20:01:00 +0200 Subject: [PATCH 2/2] Update the usage of supportTraceAPI in docs and web playground --- apps/docs/src/content/docs/recipes/fc-bot.mdx | 4 ++-- apps/web/src/app/data.ts | 18 ++++++++++++------ apps/web/src/lib/rpc-provider.ts | 2 +- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/apps/docs/src/content/docs/recipes/fc-bot.mdx b/apps/docs/src/content/docs/recipes/fc-bot.mdx index 4d157cb2..5017f036 100644 --- a/apps/docs/src/content/docs/recipes/fc-bot.mdx +++ b/apps/docs/src/content/docs/recipes/fc-bot.mdx @@ -73,7 +73,7 @@ The `constants.ts` file contains the RPC URL and configuration. The Base RPCs do export const RPC = { 8453: { url: `wss://base-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_API_KEY}`, - supportTraceAPI: false, + traceAPI: 'none', }, } ``` @@ -95,7 +95,7 @@ const getPublicClient = (chainId: number) => { transport: webSocket(rpc.url), }), config: { - supportTraceAPI: rpc.supportTraceAPI, + traceAPI: rpc.traceAPI, }, } } diff --git a/apps/web/src/app/data.ts b/apps/web/src/app/data.ts index 57678ab6..32433462 100644 --- a/apps/web/src/app/data.ts +++ b/apps/web/src/app/data.ts @@ -85,7 +85,13 @@ export const EXAMPLE_TXS = { ], } -export const supportedChains = [ +export const supportedChains: { + name: string + chainID: number + rpcUrl: string + traceAPI?: 'parity' | 'geth' | 'none' + batchMaxCount?: number +}[] = [ { name: 'Ethereum Mainnet', chainID: 1, @@ -100,32 +106,32 @@ export const supportedChains = [ name: 'Base mainnet', chainID: 8453, rpcUrl: process.env.BASE_RPC_URL as string, - supportTraceAPI: false, + traceAPI: 'geth', batchMaxCount: 1, }, { name: 'Polygon Mainnet', chainID: 137, rpcUrl: (process.env.POLYGON_RPC_URL as string) ?? 'https://rpc.ankr.com/polygon', - suppurtTraceAPI: true, + traceAPI: 'geth', }, { name: 'Optimism Mainnet', chainID: 10, rpcUrl: process.env.OPTIMISM_RPC_URL as string, - supportTraceAPI: false, + traceAPI: 'geth', }, { name: 'Arbitrum One', chainID: 42161, rpcUrl: process.env.ARBITRUM_RPC_URL as string, - supportTraceAPI: false, + traceAPI: 'geth', }, { name: 'Manta pacific', chainID: 169, rpcUrl: (process.env.MANTA_RPC_URL as string) ?? 'https://pacific-rpc.manta.network/http', - supportTraceAPI: false, + traceAPI: 'geth', }, ] diff --git a/apps/web/src/lib/rpc-provider.ts b/apps/web/src/lib/rpc-provider.ts index 77e8fced..139fc95d 100644 --- a/apps/web/src/lib/rpc-provider.ts +++ b/apps/web/src/lib/rpc-provider.ts @@ -25,7 +25,7 @@ export function getProvider(chainID: number): PublicClientObject | null { transport: http(url), }), config: { - supportTraceAPI: providerConfigs[chainID]?.supportTraceAPI, + traceAPI: providerConfigs[chainID]?.traceAPI, }, }