Skip to content

Commit

Permalink
Merge pull request #735 from blockscout/kf/feat/user-ops-logs-table-u…
Browse files Browse the repository at this point in the history
…pdate

[USER_OPS_INDEXER] Update logs table ddl
  • Loading branch information
k1rill-fedoseev authored Jan 9, 2024
2 parents de478f8 + 8945866 commit ede86f9
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ lazy_static! {
abigen!(IEntrypointV06, "./src/indexer/v06/abi.json");

pub fn matches_entrypoint_event<T: EthEvent>(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<T: EthEvent>(log: &Log) -> Result<T, Error> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
);
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
21 changes: 13 additions & 8 deletions user-ops-indexer/user-ops-indexer-logic/src/repository/user_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit ede86f9

Please sign in to comment.