diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2019-01-14 19:53:14 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2019-01-14 19:53:14 +0800 |
commit | 092a851bb3c54a6bc37c9b2456e890c75e8f6739 (patch) | |
tree | 4553c48f8b579f9bd2e8ad70a5d2b8f8a9b5b446 | |
parent | bd71f4a4807cf1221444362ce983c44f0531f494 (diff) | |
download | dexon-sol-tools-092a851bb3c54a6bc37c9b2456e890c75e8f6739.tar dexon-sol-tools-092a851bb3c54a6bc37c9b2456e890c75e8f6739.tar.gz dexon-sol-tools-092a851bb3c54a6bc37c9b2456e890c75e8f6739.tar.bz2 dexon-sol-tools-092a851bb3c54a6bc37c9b2456e890c75e8f6739.tar.lz dexon-sol-tools-092a851bb3c54a6bc37c9b2456e890c75e8f6739.tar.xz dexon-sol-tools-092a851bb3c54a6bc37c9b2456e890c75e8f6739.tar.zst dexon-sol-tools-092a851bb3c54a6bc37c9b2456e890c75e8f6739.zip |
Use custom JS tracer only if the node is geth
-rw-r--r-- | packages/sol-tracing-utils/src/trace_info_subprovider.ts | 58 |
1 files changed, 36 insertions, 22 deletions
diff --git a/packages/sol-tracing-utils/src/trace_info_subprovider.ts b/packages/sol-tracing-utils/src/trace_info_subprovider.ts index 43853e152..698867056 100644 --- a/packages/sol-tracing-utils/src/trace_info_subprovider.ts +++ b/packages/sol-tracing-utils/src/trace_info_subprovider.ts @@ -1,3 +1,4 @@ +import { NodeType } from '@0x/web3-wrapper'; import * as _ from 'lodash'; import { constants } from './constants'; @@ -12,28 +13,41 @@ export abstract class TraceInfoSubprovider extends TraceCollectionSubprovider { protected abstract _handleTraceInfoAsync(traceInfo: TraceInfo): Promise<void>; protected async _recordTxTraceAsync(address: string, data: string | undefined, txHash: string): Promise<void> { await this._web3Wrapper.awaitTransactionMinedAsync(txHash, 0); - // For very large traces we use a custom tracer that outputs a format compatible with a - // regular trace. We only need the 2nd item on the stack when the instruction is a call. - // By not including othe stack values, we severly limit the amount of data to be collectd. - const tracer = ` - { - data: [], - step: function(log) { - const op = log.op.toString(); - const opn = 0 | log.op.toNumber(); - const pc = 0 | log.getPC(); - const depth = 0 | log.getDepth(); - const gasCost = 0 | log.getCost(); - const gas = 0 | log.getGas(); - const isCall = opn == 0xf1 || opn == 0xf2 || opn == 0xf4 || opn == 0xf5; - const stack = isCall ? ['0x'+log.stack.peek(1).toString(16), null] : null; - this.data.push({ pc, gasCost, depth, op, stack, gas }); - }, - fault: function() { }, - result: function() { return {structLogs: this.data}; } - } - `; - const trace = await this._web3Wrapper.getTransactionTraceAsync(txHash, { tracer, timeout: '600s' }); + const nodeType = await this._web3Wrapper.getNodeTypeAsync(); + let trace; + if (nodeType === NodeType.Geth) { + // For very large traces we use a custom tracer that outputs a format compatible with a + // regular trace. We only need the 2nd item on the stack when the instruction is a call. + // By not including othe stack values, we severly limit the amount of data to be collectd. + const tracer = ` + { + data: [], + step: function(log) { + const op = log.op.toString(); + const opn = 0 | log.op.toNumber(); + const pc = 0 | log.getPC(); + const depth = 0 | log.getDepth(); + const gasCost = 0 | log.getCost(); + const gas = 0 | log.getGas(); + const isCall = opn == 0xf1 || opn == 0xf2 || opn == 0xf4 || opn == 0xf5; + const stack = isCall ? ['0x'+log.stack.peek(1).toString(16), null] : null; + this.data.push({ pc, gasCost, depth, op, stack, gas }); + }, + fault: function() { }, + result: function() { return {structLogs: this.data}; } + } + `; + trace = await this._web3Wrapper.getTransactionTraceAsync(txHash, { tracer, timeout: '600s' }); + } else { + /** + * Ganache doesn't support custom tracers yet. + */ + trace = await this._web3Wrapper.getTransactionTraceAsync(txHash, { + disableMemory: true, + disableStack: false, + disableStorage: true, + }); + } const tracesByContractAddress = getTracesByContractAddress(trace.structLogs, address); const subcallAddresses = _.keys(tracesByContractAddress); if (address === constants.NEW_CONTRACT) { |