Skip to content

Commit

Permalink
feat: transaction count stats
Browse files Browse the repository at this point in the history
  • Loading branch information
Otto-AA committed Jul 15, 2024
1 parent 0ad2702 commit 77f8970
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/integration/snapshots/snap_test_snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@
"same_sender": 174,
},
},
"candidates_unique_transactions": 399,
"collisions": {"balance": 229, "storage": 385},
"collisions_before_filters": {"balance": 1526, "nonce": 879, "storage": 710},
"state_diffs": {"balance": 2577, "code": 3, "nonce": 880, "storage": 2594},
"transactions": 1002,
}
12 changes: 12 additions & 0 deletions tod_attack_miner/db/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,22 @@ def count_candidates_original(self):
"""
return cursor.execute(sql).fetchall()[0][0]

def count_transactions(self) -> int:
with self._con.cursor() as cursor:
return cursor.execute("SELECT COUNT(*) FROM transactions").fetchall()[0][0]

def count_candidates(self) -> int:
with self._con.cursor() as cursor:
return cursor.execute("SELECT COUNT(*) FROM candidates").fetchall()[0][0]

def count_unique_candidate_transactions(self) -> int:
sql = """
SELECT COUNT(DISTINCT hash)
FROM transactions
INNER JOIN candidates ON tx_write_hash = hash OR tx_access_hash = hash"""
with self._con.cursor() as cursor:
return cursor.execute(sql).fetchall()[0][0]

def insert_block(self, block: BlockWithTransactions):
tx_values = [
(
Expand Down
2 changes: 2 additions & 0 deletions tod_attack_miner/miner/miner.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ def get_stats(self):
"collisions_before_filters": self._original_collisions,
"candidates_filters": self._filter_stats,
"candidates": self.db.count_candidates(),
"candidates_unique_transactions": self.db.count_unique_candidate_transactions(),
"transactions": self.db.count_transactions(),
"addresses_est": self.db.get_unique_addresses_stats(),
"addresses_est_total": self.db.get_unique_addresses_total(),
}

0 comments on commit 77f8970

Please sign in to comment.