Skip to content

Commit

Permalink
add chronological sorting of event logs (BlazeWasHere#11)
Browse files Browse the repository at this point in the history
fix moonriver and moonbean json rpc inconsistency with eth_getLogs
  • Loading branch information
ChiTimesChi authored Jan 17, 2022
1 parent 8536970 commit 216319c
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions syn/utils/wrappa/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,16 @@ def get_logs(
}

logs: List[LogReceipt] = w3.eth.get_logs(params)
# Apparently, some RPC nodes don't bother
# sorting events in a chronological order.
# Let's sort them by block (from oldest to newest)
# And by transaction index (within the same block,
# also in ascending order)
logs = sorted(
logs,
key=lambda k: (k['blockNumber'], k['transactionIndex'])
)

for log in logs:
# Skip transactions from the very first block
# that are already in the DB
Expand Down

0 comments on commit 216319c

Please sign in to comment.