From ad6c3c46c0a2cd3cc342293c2539c0e644f2c44a Mon Sep 17 00:00:00 2001 From: onesuper Date: Fri, 8 Jul 2022 15:58:49 +0800 Subject: [PATCH] Prevent tx_traces to be NULL within trace block rpc --- ethereumetl/jobs/export_geth_traces_job.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ethereumetl/jobs/export_geth_traces_job.py b/ethereumetl/jobs/export_geth_traces_job.py index 745c403e2..c3cf0f83a 100644 --- a/ethereumetl/jobs/export_geth_traces_job.py +++ b/ethereumetl/jobs/export_geth_traces_job.py @@ -27,6 +27,7 @@ from blockchainetl.jobs.base_job import BaseJob from ethereumetl.mappers.geth_trace_mapper import EthGethTraceMapper from ethereumetl.utils import validate_range, rpc_response_to_result +from ethereumetl.misc.retriable_value_error import RetriableValueError # Exports geth traces @@ -68,6 +69,10 @@ def _export_batch(self, block_number_batch): block_number = response_item.get('id') result = rpc_response_to_result(response_item) + # We add this check because the response of trace block rpc is a list of tx_trace, + # so we need to make sure there is no error in each tx_trace + self._check_result(result, block_number) + geth_trace = self.geth_trace_mapper.json_dict_to_geth_trace({ 'block_number': block_number, 'transaction_traces': [tx_trace.get('result') for tx_trace in result], @@ -78,3 +83,11 @@ def _export_batch(self, block_number_batch): def _end(self): self.batch_work_executor.shutdown() self.item_exporter.close() + + def _check_result(self, result, block_number): + for tx_trace in result: + if tx_trace.get('result') is None: + raise RetriableValueError( + 'Error for trace in block {block}. Need to retry. Error: {err}, trace: {trace}' + .format(block=block_number, trace=json.dumps(tx_trace), err=tx_trace.get('error')) + )