Skip to content

Commit

Permalink
Filter out failed transactions
Browse files Browse the repository at this point in the history
 this fixes #301
  • Loading branch information
cannium committed May 25, 2022
1 parent 3c9fe3d commit bda2044
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
13 changes: 13 additions & 0 deletions mev_inspect/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions mev_inspect/schemas/receipts.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ class Receipt(CamelModel):
effective_gas_price: int
cumulative_gas_used: int
to: Optional[str]
status: int

@validator(
"block_number",
"transaction_index",
"gas_used",
"effective_gas_price",
"cumulative_gas_used",
"status",
pre=True,
)
def maybe_hex_to_int(v):
Expand Down
3 changes: 3 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit bda2044

Please sign in to comment.