Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ POSTGRES_DB=

HELIOS_UPDATE_FREQUENCY=

VECTOR_UPDATE_FREQUENCY=
VECTOR_UPDATE_FREQUENCY=

INDEXED_TX_CLEANUP_INTERVAL_SECONDS=

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ sqlx = { version = "0.8.6", features = ["postgres", "runtime-tokio-rustls", "mac
bigdecimal = { version = "0.4", features = ["serde"] }
uuid = { version = "1.18.0", features = ["v4"] }
log = "0.4.25"
parity-scale-codec = "3.6"

[target.'cfg(not(target_env = "msvc"))'.dependencies]
tikv-jemallocator = "0.6"
Expand Down
15 changes: 15 additions & 0 deletions migrations/0001_create_initiated_transactions.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
CREATE TABLE IF NOT EXISTS initiated_transactions (
source_transaction_hash TEXT PRIMARY KEY,
direction TEXT NOT NULL,
message_id TEXT NOT NULL DEFAULT '0',
sender TEXT NOT NULL,
receiver TEXT NOT NULL,
amount TEXT NOT NULL,
source_block_hash TEXT NOT NULL,
source_block_number INTEGER NOT NULL,
source_tx_index INTEGER,
timestamp BIGINT NOT NULL,
tx_type TEXT NOT NULL DEFAULT 'initiate'
);

CREATE INDEX IF NOT EXISTS idx_initiated_tx_sender ON initiated_transactions (sender);
1 change: 1 addition & 0 deletions sql/check_initiated_tx_by_block.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT EXISTS(SELECT 1 FROM initiated_transactions WHERE source_block_number = $1 AND source_tx_index = $2)
1 change: 1 addition & 0 deletions sql/check_initiated_tx_by_hash.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT EXISTS(SELECT 1 FROM initiated_transactions WHERE source_transaction_hash = $1)
21 changes: 21 additions & 0 deletions sql/delete_indexed_initiated_tx_global.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
DELETE FROM initiated_transactions it
WHERE
-- Clean up initiate records when source tx is indexed.
(it.tx_type = 'initiate' AND it.direction = 'EthAvail' AND EXISTS (
SELECT 1 FROM bridge_event be
WHERE be.source_transaction_hash = it.source_transaction_hash
))
OR (it.tx_type = 'initiate' AND it.direction = 'AvailEth' AND EXISTS (
SELECT 1 FROM avail_indexer ai
WHERE ai.ext_hash = it.source_transaction_hash
))
-- Clean up claim records when claim tx is indexed.
OR (it.tx_type = 'claim' AND it.direction = 'AvailEth' AND EXISTS (
SELECT 1 FROM bridge_event be
WHERE be.message_id::text = it.message_id
AND be.event_type = 'MessageReceived'
))
OR (it.tx_type = 'claim' AND it.direction = 'EthAvail' AND EXISTS (
SELECT 1 FROM avail_execute_table aet
WHERE aet.message_id::text = it.message_id
));
5 changes: 5 additions & 0 deletions sql/insert_initiated_tx.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
INSERT INTO initiated_transactions
(source_transaction_hash, direction, message_id, sender, receiver, amount,
source_block_hash, source_block_number, source_tx_index, timestamp, tx_type)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)
ON CONFLICT (source_transaction_hash) DO NOTHING
5 changes: 5 additions & 0 deletions sql/query_avail_claim_message_id.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SELECT aet.message_id::text
FROM avail_execute_table aet
JOIN avail_indexer ai ON ai.id = aet.id
WHERE ai.ext_hash = $1
LIMIT 1
4 changes: 2 additions & 2 deletions sql/query_avail_tx.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SELECT ai.id AS message_id,
ai.ext_hash AS source_transaction_hash,
ai.block_height AS source_block_height,
ai.ext_index AS source_tx_index,
es.block_timestamp,
EXTRACT(EPOCH FROM ai.block_timestamp)::bigint AS "block_timestamp!",
be.source_transaction_hash AS "destination_tx_hash?: String",
COALESCE(
CASE
Expand All @@ -23,5 +23,5 @@ WHERE ai.signature_address = $1
AND es.type = $2
AND (be.event_type = $3 or be.event_type is null)
AND ai.ext_success = $4
ORDER BY es.block_timestamp DESC
ORDER BY ai.block_timestamp DESC
LIMIT 1000;
5 changes: 5 additions & 0 deletions sql/query_claimed_tx.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SELECT message_id, source_transaction_hash, source_block_number, source_tx_index
FROM initiated_transactions
WHERE tx_type = 'claim'
AND message_id = ANY($1)
AND (sender = $2 OR sender = $3)
17 changes: 17 additions & 0 deletions sql/query_initiated_tx.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
SELECT source_transaction_hash, direction, message_id, sender, receiver,
amount, source_block_hash, source_block_number, source_tx_index, timestamp, tx_type
FROM initiated_transactions it
WHERE tx_type = 'initiate'
AND (it.sender = $1 OR it.sender = $2)
AND NOT EXISTS (
SELECT 1 FROM bridge_event be
WHERE be.source_transaction_hash = it.source_transaction_hash
AND it.direction = 'EthAvail'
)
AND NOT EXISTS (
SELECT 1 FROM avail_indexer ai
WHERE ai.ext_hash = it.source_transaction_hash
AND it.direction = 'AvailEth'
)
ORDER BY it.timestamp DESC
LIMIT 100
Loading
Loading