From bda20447a1286b38d1db763fd75ea0769cdea867 Mon Sep 17 00:00:00 2001 From: zhangcan Date: Wed, 25 May 2022 15:46:49 +0800 Subject: [PATCH] Filter out failed transactions this fixes #301 --- mev_inspect/block.py | 13 +++++++++++++ mev_inspect/schemas/receipts.py | 2 ++ tests/utils.py | 3 +++ 3 files changed, 18 insertions(+) diff --git a/mev_inspect/block.py b/mev_inspect/block.py index cf80fa54..4e9063c6 100644 --- a/mev_inspect/block.py +++ b/mev_inspect/block.py @@ -35,6 +35,19 @@ async def create_from_block_number( _find_or_fetch_base_fee_per_gas(w3, block_number, trace_db_session), ) + # filter out failed transactions + failed_transactions = set( + receipt.transaction_hash for receipt in receipts if receipt.status == 0 + ) + receipts = [ + receipt + for receipt in receipts + if receipt.transaction_hash not in failed_transactions + ] + traces = [ + trace for trace in traces if trace.transaction_hash not in failed_transactions + ] + miner_address = _get_miner_address_from_traces(traces) return Block( diff --git a/mev_inspect/schemas/receipts.py b/mev_inspect/schemas/receipts.py index a5772b03..861fbcb9 100644 --- a/mev_inspect/schemas/receipts.py +++ b/mev_inspect/schemas/receipts.py @@ -15,6 +15,7 @@ class Receipt(CamelModel): effective_gas_price: int cumulative_gas_used: int to: Optional[str] + status: int @validator( "block_number", @@ -22,6 +23,7 @@ class Receipt(CamelModel): "gas_used", "effective_gas_price", "cumulative_gas_used", + "status", pre=True, ) def maybe_hex_to_int(v): diff --git a/tests/utils.py b/tests/utils.py index ec843d59..4c5da628 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -23,6 +23,9 @@ def load_test_block(block_number: int) -> Block: with open(block_path, "r") as block_file: block_json = json.load(block_file) + for item in block_json["receipts"]: + if "status" not in item: + item["status"] = "0x1" return Block( **{ **defaults,