Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial implementation for tx & prover search #19

Merged
merged 2 commits into from
Mar 28, 2024
Merged

Conversation

tuommaki
Copy link
Contributor

Devnet explorer has a search field where user can give transaction hash or prover program hash as an input and the backend should return 50 newest events for that query.

Devnet explorer has a search field where user can give transaction hash
or prover program hash as an input and the backend should return 50
newest events for that query.
@tuommaki tuommaki self-assigned this Mar 27, 2024
Comment on lines +104 to +146
const query = `
WITH t2 AS ((
(SELECT created_at, t.hash, t.kind FROM transaction AS t WHERE t.hash = $1)
UNION ALL
(SELECT created_at, t.hash, t.kind FROM transaction AS t JOIN workflow_step AS ws ON ws.tx=t.hash WHERE ws.sequence=1 AND ws.program = $1)
UNION ALL
(SELECT created_at, t.hash, t.kind FROM transaction AS t JOIN proof AS p ON t.hash = p.tx WHERE p.prover = $1)
UNION ALL
(SELECT created_at, t.hash, t.kind FROM transaction AS t JOIN verification AS v ON t.hash = v.tx JOIN proof AS p ON v.parent = p.tx WHERE p.prover = $1)
) ORDER BY created_at DESC LIMIT 50)
SELECT
CASE WHEN t2.kind = 'run' THEN
CASE WHEN (SELECT COUNT(*) FROM proof WHERE parent = t2.hash) = 0 THEN 'Submitted'
WHEN ((SELECT COUNT(*) FROM proof WHERE parent = t2.hash) >= 1 AND (SELECT COUNT(*) FROM verification AS v JOIN proof AS p ON v.parent=p.tx WHERE p.parent = t2.hash) = 0) IS TRUE THEN 'Proving'
WHEN (SELECT COUNT(*) FROM verification AS v JOIN proof AS p ON v.parent=p.tx WHERE p.parent = t2.hash) = 1 THEN 'Verifying'
WHEN (SELECT COUNT(*) FROM verification AS v JOIN proof AS p ON v.parent=p.tx WHERE p.parent = t2.hash) = 2 THEN 'Verifying'
WHEN (SELECT COUNT(*) FROM verification AS v JOIN proof AS p ON v.parent=p.tx WHERE p.parent = t2.hash) > 2 THEN 'Complete'
END
WHEN t2.kind = 'proof' THEN
CASE WHEN (SELECT COUNT(*) FROM proof WHERE parent = (SELECT parent FROM proof WHERE tx = t2.hash)) = 1 THEN 'Proving'
WHEN (SELECT COUNT(*) FROM verification AS v JOIN proof AS p ON v.parent=p.tx WHERE p.parent = (SELECT parent FROM proof WHERE tx = t2.hash)) = 1 THEN 'Verifying'
WHEN (SELECT COUNT(*) FROM verification AS v JOIN proof AS p ON v.parent=p.tx WHERE p.parent = (SELECT parent FROM proof WHERE tx = t2.hash)) = 2 THEN 'Verifying'
WHEN (SELECT COUNT(*) FROM verification AS v JOIN proof AS p ON v.parent=p.tx WHERE p.parent = (SELECT parent FROM proof WHERE tx = t2.hash)) > 2 THEN 'Complete'
END
WHEN t2.kind = 'verification' THEN
CASE WHEN (SELECT COUNT(*) FROM verification AS v JOIN proof AS p ON v.parent=p.tx WHERE p.parent = (SELECT p2.parent FROM proof AS p2 JOIN verification AS v2 ON p2.tx=v2.parent WHERE v2.tx = t2.hash)) = 1 THEN 'Verifying'
WHEN (SELECT COUNT(*) FROM verification AS v JOIN proof AS p ON v.parent=p.tx WHERE p.parent = (SELECT p2.parent FROM proof AS p2 JOIN verification AS v2 ON p2.tx=v2.parent WHERE v2.tx = t2.hash)) = 2 THEN 'Verifying'
WHEN (SELECT COUNT(*) FROM verification AS v JOIN proof AS p ON v.parent=p.tx WHERE p.parent = (SELECT p2.parent FROM proof AS p2 JOIN verification AS v2 ON p2.tx=v2.parent WHERE v2.tx = t2.hash)) > 2 THEN 'Complete'
END
END AS state,
t.hash AS tx_id,
(
(SELECT name AS tag FROM program AS p JOIN workflow_step AS ws ON p.hash = ws.program JOIN t2 ON ws.tx = t2.hash WHERE ws.sequence = 1)
UNION
(SELECT name AS tag FROM program WHERE hash = $1)
),
(
(SELECT program AS prover_id FROM workflow_step AS ws JOIN t2 ON ws.tx = t2.hash WHERE ws.sequence = 1)
UNION
(SELECT hash AS prover_id FROM program WHERE hash = $1)
),
t.created_at AS timestamp FROM transaction AS t JOIN t2 ON t.hash = t2.hash
`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this should be implemented as a separate function in Postgres as well. It's inhuman to compute this in head 🤯

@tuommaki tuommaki requested a review from heppu March 27, 2024 15:41
Copy link

LOCATION FUNCTION COVERAGE
api/api.go:39: New 90.0%
api/api.go:63: ServeHTTP 100.0%
api/api.go:67: index 22.2%
api/api.go:82: stats 57.1%
api/api.go:96: table 26.7%
api/api.go:123: stream 65.4%
api/api.go:162: SearchFilter 0.0%
api/api.go:171: NoFilter 100.0%
api/broadcaster.go:36: NewBroadcaster 100.0%
api/broadcaster.go:45: Subscribe 100.0%
api/broadcaster.go:73: Run 71.4%
api/broadcaster.go:88: broadcast 90.9%
api/broadcaster.go:126: Stop 100.0%
api/broadcaster.go:131: writeEvent 80.0%
api/server.go:16: NewServer 75.0%
api/server.go:30: Run 80.0%
api/server.go:39: Stop 100.0%
api/templates/index_templ.go:23: Index 75.7%
api/templates/index_templ.go:75: Stats 74.2%
api/templates/index_templ.go:159: Table 71.4%
api/templates/index_templ.go:209: Row 59.3%
api/templates/index_templ.go:325: head 68.8%
api/templates/index_templ.go:349: header 68.8%
api/templates/index_templ.go:373: footer 69.2%
api/templates/index_templ.go:412: format 100.0%
app/app.go:23: Run 80.0%
app/app.go:65: ParseConfig 75.0%
app/runner.go:21: NewRunner 100.0%
app/runner.go:32: Run 100.0%
app/runner.go:48: Stop 0.0%
cmd/devnet-explorer/main.go:15: init 100.0%
cmd/devnet-explorer/main.go:19: main 42.9%
signalhandler/signal_handler.go:14: New 100.0%
signalhandler/signal_handler.go:21: Run 83.3%
signalhandler/signal_handler.go:32: Stop 100.0%
store/mock/store.go:24: New 0.0%
store/mock/store.go:32: Stats 0.0%
store/mock/store.go:40: Run 0.0%
store/mock/store.go:56: Events 0.0%
store/mock/store.go:60: Search 0.0%
store/mock/store.go:76: Stop 0.0%
store/mock/store.go:81: randomEvent 0.0%
store/pg/store.go:27: New 80.0%
store/pg/store.go:42: Run 77.3%
store/pg/store.go:83: Stats 80.0%
store/pg/store.go:99: Search 0.0%
store/pg/store.go:157: Events 100.0%
store/pg/store.go:161: Stop 100.0%
total: (statements) 66.5%

@tuommaki tuommaki merged commit 73f1982 into main Mar 28, 2024
1 check passed
@tuommaki tuommaki deleted the implement-db-search branch March 28, 2024 06:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant