From 782fa4c7a90f2533b024befad15c77fc80848b46 Mon Sep 17 00:00:00 2001 From: Kirill Fedoseev Date: Mon, 8 Jan 2024 15:33:20 +0200 Subject: [PATCH 1/2] feat: update logs table ddl --- .../repository/tests/blockscout_tables.sql | 14 ++++++------- .../src/repository/tests/fixtures.sql | 8 ++++--- .../src/repository/user_op.rs | 21 ++++++++++++------- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/user-ops-indexer/user-ops-indexer-logic/src/repository/tests/blockscout_tables.sql b/user-ops-indexer/user-ops-indexer-logic/src/repository/tests/blockscout_tables.sql index 8dc55f419..6683ada8b 100644 --- a/user-ops-indexer/user-ops-indexer-logic/src/repository/tests/blockscout_tables.sql +++ b/user-ops-indexer/user-ops-indexer-logic/src/repository/tests/blockscout_tables.sql @@ -4,7 +4,7 @@ CREATE TABLE public.blocks difficulty numeric(50, 0), gas_limit numeric(100, 0) NOT NULL, gas_used numeric(100, 0) NOT NULL, - hash bytea NOT NULL, + hash bytea NOT NULL PRIMARY KEY, miner_hash bytea NOT NULL, nonce bytea NOT NULL, number bigint NOT NULL, @@ -23,15 +23,15 @@ CREATE TABLE public.logs ( data bytea NOT NULL, index integer NOT NULL, - type character varying(255), - first_topic character varying(255), - second_topic character varying(255), - third_topic character varying(255), - fourth_topic character varying(255), + first_topic bytea, + second_topic bytea, + third_topic bytea, + fourth_topic bytea, inserted_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL, address_hash bytea, transaction_hash bytea NOT NULL, block_hash bytea NOT NULL, - block_number integer + block_number integer, + primary key (transaction_hash, block_hash, index) ); diff --git a/user-ops-indexer/user-ops-indexer-logic/src/repository/tests/fixtures.sql b/user-ops-indexer/user-ops-indexer-logic/src/repository/tests/fixtures.sql index 5ae14a69d..f491f0fb0 100644 --- a/user-ops-indexer/user-ops-indexer-logic/src/repository/tests/fixtures.sql +++ b/user-ops-indexer/user-ops-indexer-logic/src/repository/tests/fixtures.sql @@ -8,7 +8,9 @@ SELECT true, '\x', n, '\x', - '2024-01-01 00:00:00'::timestamp + interval '12 seconds' * n, now(), now() + '2024-01-01 00:00:00'::timestamp + interval '12 seconds' * n, + now(), + now() FROM generate_series(0, 999) n; INSERT INTO user_operations (hash, sender, nonce, call_data, call_gas_limit, verification_gas_limit, @@ -74,9 +76,9 @@ SET paymaster = '\x00000000000000000000000000000000000000e2', sponsor_type = 'paymaster_sponsor' WHERE block_number = 21; -INSERT INTO logs (data, index, type, first_topic, second_topic, third_topic, fourth_topic, inserted_at, updated_at, +INSERT INTO logs (data, index, first_topic, second_topic, third_topic, fourth_topic, inserted_at, updated_at, address_hash, transaction_hash, block_hash, block_number) -VALUES ('\x', 0, NULL, '0x49628fd1471006c1482da88028e9ce4dbb080b815c9b0344d39e5a8e6ec1419f', NULL, NULL, NULL, now(), +VALUES ('\x', 0, '\x49628fd1471006c1482da88028e9ce4dbb080b815c9b0344d39e5a8e6ec1419f', NULL, NULL, NULL, now(), now(), '\x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', '\x000000000000000000000000000000000000000000000000000000000000ffff', '\x000000000000000000000000000000000000000000000000000000000000ff00', 123); diff --git a/user-ops-indexer/user-ops-indexer-logic/src/repository/user_op.rs b/user-ops-indexer/user-ops-indexer-logic/src/repository/user_op.rs index 671765290..2cae3fe7c 100644 --- a/user-ops-indexer/user-ops-indexer-logic/src/repository/user_op.rs +++ b/user-ops-indexer/user-ops-indexer-logic/src/repository/user_op.rs @@ -198,19 +198,24 @@ pub async fn find_unprocessed_logs_tx_hashes( SELECT DISTINCT logs.transaction_hash as transaction_hash FROM logs JOIN blocks ON logs.block_hash = blocks.hash AND blocks.consensus - LEFT JOIN user_operations ON logs.second_topic = '0x' || ENCODE(user_operations.hash, 'hex') + LEFT JOIN user_operations ON logs.second_topic = user_operations.hash WHERE logs.address_hash = $1 - AND logs.first_topic = '0x' || ENCODE($2, 'hex') + AND logs.first_topic = $2 AND logs.block_number >= $3 AND logs.block_number <= $4 AND user_operations.hash IS NULL"#, - [addr.as_bytes().into(), topic.as_bytes().into(), from_block.into(), to_block.into()], + [ + addr.as_bytes().into(), + topic.as_bytes().into(), + from_block.into(), + to_block.into(), + ], )) - .all(db) - .await? - .into_iter() - .map(|tx| H256::from_slice(&tx.transaction_hash)) - .collect(); + .all(db) + .await? + .into_iter() + .map(|tx| H256::from_slice(&tx.transaction_hash)) + .collect(); Ok(tx_hashes) } From 89458669c614c4a6b967955aa83d766f991433d6 Mon Sep 17 00:00:00 2001 From: Kirill Fedoseev Date: Mon, 8 Jan 2024 15:53:13 +0200 Subject: [PATCH 2/2] fix: clippy --- .../user-ops-indexer-logic/src/indexer/v06/constants.rs | 2 +- .../user-ops-indexer-logic/src/indexer/v06/indexer.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/user-ops-indexer/user-ops-indexer-logic/src/indexer/v06/constants.rs b/user-ops-indexer/user-ops-indexer-logic/src/indexer/v06/constants.rs index a9f5805a0..5bcbd117b 100644 --- a/user-ops-indexer/user-ops-indexer-logic/src/indexer/v06/constants.rs +++ b/user-ops-indexer/user-ops-indexer-logic/src/indexer/v06/constants.rs @@ -13,7 +13,7 @@ lazy_static! { abigen!(IEntrypointV06, "./src/indexer/v06/abi.json"); pub fn matches_entrypoint_event(log: &Log) -> bool { - log.address == *ENTRYPOINT_V06 && log.topics.get(0) == Some(&T::signature()) + log.address == *ENTRYPOINT_V06 && log.topics.first() == Some(&T::signature()) } pub fn parse_event(log: &Log) -> Result { diff --git a/user-ops-indexer/user-ops-indexer-logic/src/indexer/v06/indexer.rs b/user-ops-indexer/user-ops-indexer-logic/src/indexer/v06/indexer.rs index cc555afef..f19f4c4ec 100644 --- a/user-ops-indexer/user-ops-indexer-logic/src/indexer/v06/indexer.rs +++ b/user-ops-indexer/user-ops-indexer-logic/src/indexer/v06/indexer.rs @@ -284,7 +284,7 @@ impl<'a, C: PubsubClient> IndexerV06<'a, C> { Ok(model) => Some(model), Err(err) => { let logs_start_index = - logs.get(0).and_then(|l| l.log_index).map(|i| i.as_u64()); + logs.first().and_then(|l| l.log_index).map(|i| i.as_u64()); let logs_count = logs.len(); tracing::error!( tx_hash = ?tx_hash,