Skip to content

Commit

Permalink
fix: tenderly node error response (#618)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsy1218 authored Jun 27, 2024
1 parent e4cd7f9 commit 17d1133
Showing 1 changed file with 60 additions and 31 deletions.
91 changes: 60 additions & 31 deletions src/providers/tenderly-simulation-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,19 @@ export type GasBody = {
gasUsed: string;
};

// Standard JSON RPC error response https://www.jsonrpc.org/specification#error_object
export type JsonRpcError = {
error: {
code: number;
message: string;
data: string;
};
};

export type TenderlyResponseEstimateGasBundle = {
id: number;
jsonrpc: string;
result: GasBody[];
result: Array<JsonRpcError | GasBody>;
};

enum TenderlySimulationType {
Expand Down Expand Up @@ -780,36 +789,55 @@ export class TenderlySimulator extends Simulator {
Math.min(gatewayResp.simulation_results.length, resp.result.length);
i++
) {
const gatewayGas = gatewayResp.simulation_results[i]!.transaction.gas;
const nodeGas = Number(resp.result[i]!.gas);
const gatewayGasUsed =
gatewayResp.simulation_results[i]!.transaction.gas_used;
const nodeGasUsed = Number(resp.result[i]!.gasUsed);

if (gatewayGas !== nodeGas) {
log.error(
`Gateway gas and node gas estimates do not match for index ${i}`,
{ gatewayGas, nodeGas, blockNumber }
);
metric.putMetric(
`TenderlyNodeGasEstimateBundleGasMismatch${i}`,
1,
MetricLoggerUnit.Count
);
gasEstimateMismatch = true;
}

if (gatewayGasUsed !== nodeGasUsed) {
log.error(
`Gateway gas and node gas used estimates do not match for index ${i}`,
{ gatewayGas, nodeGas, blockNumber }
);
metric.putMetric(
`TenderlyNodeGasEstimateBundleGasUsedMismatch${i}`,
1,
MetricLoggerUnit.Count
);
gasEstimateMismatch = true;
const singleNodeResp = resp.result[i];
const singleGatewayResp = gatewayResp.simulation_results[i];
if (
(singleNodeResp as GasBody).gas &&
(singleNodeResp as GasBody).gasUsed
) {
const gatewayGas = singleGatewayResp?.transaction.gas;
const nodeGas = Number((singleNodeResp as GasBody).gas);
const gatewayGasUsed = singleGatewayResp?.transaction.gas_used;
const nodeGasUsed = Number((singleNodeResp as GasBody).gasUsed);

if (gatewayGas !== nodeGas) {
log.error(
`Gateway gas and node gas estimates do not match for index ${i}`,
{ gatewayGas, nodeGas, blockNumber }
);
metric.putMetric(
`TenderlyNodeGasEstimateBundleGasMismatch${i}`,
1,
MetricLoggerUnit.Count
);
gasEstimateMismatch = true;
}

if (gatewayGasUsed !== nodeGasUsed) {
log.error(
`Gateway gas and node gas used estimates do not match for index ${i}`,
{ gatewayGas, nodeGas, blockNumber }
);
metric.putMetric(
`TenderlyNodeGasEstimateBundleGasUsedMismatch${i}`,
1,
MetricLoggerUnit.Count
);
gasEstimateMismatch = true;
}
} else if ((singleNodeResp as JsonRpcError).error) {
if (!singleGatewayResp?.transaction.error_message) {
log.error(
`Gateway and node error messages do not match for index ${i}`,
{ blockNumber }
);
metric.putMetric(
`TenderlyNodeGasEstimateBundleErrorMismatch${i}`,
1,
MetricLoggerUnit.Count
);
gasEstimateMismatch = true;
}
}
}

Expand All @@ -828,6 +856,7 @@ export class TenderlySimulator extends Simulator {
}
} catch (err) {
log.error(
{ err },
`Failed to invoke Tenderly Node Endpoint for gas estimation bundle ${JSON.stringify(
body,
null,
Expand Down

0 comments on commit 17d1133

Please sign in to comment.