Skip to content

Commit 2bba74b

Browse files
frisitanogreged93
andauthored
Indexer Component (#35)
* ci: add dprint * feat: initial work + handle_latest_block * Rollup node manager (#21) * init bridge implementation * extend bridge implementation * refactor and clean up dependencies * add .vscode to .gitignore * lint * spacing * cleanup * wrap inner block import in bridge * add bridge integration test * refactor and clean up * add comments * migrate shared dependencies to workspace * feature propogation * lints and feature fix * remove scroll feature * add scroll feature * integrate reth upstream changes * address PR feedback * stash * add systemd service file * update systemd file * update systemd file * address comments * rollup node manager * merge main * add Cargo.lock * lint * lint * lint * lint * ci remove no-dev-deps * fix serde dep - scroll-wire * skip no_std on scroll-engine and scroll-rollup-node * skip no_std on scroll-engine and scroll-rollup-node * address comments * lints * cleanup * tsets * lint + refactor * refactor engine api call ordering * lint * fix fcu * lint * remove syncing error return on new payload * update forkchoice state after succesfully new payload * update reth following chainspec fork id logic change * PR feedback * lints * lints * feat(watcher): reorg detection * feat(primitives): add batch and l1 transaction * feat(watcher): contracts and constants * feat(watcher): imports * feat(watcher): add error types * feat(watcher): handle l1 messages and commit logs * feat: handle batch commit and finalize * test: handle_latest_block * test: wip events decoding * test: commit and finalize batch logs * test: utils * feat: tracing * test: wip reorg integration * test: reorg detection integration test * test: gaps * fix: lints * feat: point deps to default reth branch * fix: security issue on ring * fix: bump alloy * feat: move abi to separate crate * chore: remove ArbitraryTxBuilder * init database * add database iterator * add test * update streaming implementation * init indexer * fix: answer comments * fix: lints * fix: no std issues * fix: cargo features check * extend indexer * extend and refactor database, migrations and batch primitive * lint * lint * lint * improve database implementation * lint * lint * database transaction refactor * lint: * use GAT for DatabaseConnectionProvider trait * refactor & lint * merge database and refactor * clippy fix * skip rolllup-node-indexer no_std * refactor databse interface for insert_batch_input * refactor * lint * refactor indexer * refactor indexer * lint: * lint --------- Co-authored-by: Gregory Edison <[email protected]>
1 parent ac1588e commit 2bba74b

File tree

9 files changed

+386
-3
lines changed

9 files changed

+386
-3
lines changed

.github/workflows/lint.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ jobs:
127127
include:
128128
- type: wasm
129129
target: wasm32-unknown-unknown
130-
exclude: scroll-engine,scroll-wire,scroll-bridge,scroll-network,rollup-node-manager,rollup-node-watcher,scroll-db,scroll-migration
130+
exclude: scroll-engine,scroll-wire,scroll-bridge,scroll-network,rollup-node-manager,rollup-node-watcher,scroll-db,scroll-migration,rollup-node-indexer
131131
- type: riscv
132132
target: riscv32imac-unknown-none-elf
133-
exclude: scroll-engine,scroll-wire,scroll-bridge,scroll-network,rollup-node-manager,rollup-node-watcher,scroll-db,scroll-migration
133+
exclude: scroll-engine,scroll-wire,scroll-bridge,scroll-network,rollup-node-manager,rollup-node-watcher,scroll-db,scroll-migration,rollup-node-indexer
134134
steps:
135135
- uses: actions/checkout@v4
136136
- uses: rui314/setup-mold@v1

Cargo.lock

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ members = [
1111
"crates/database/db",
1212
"crates/database/migration",
1313
"crates/engine",
14+
"crates/indexer",
1415
"crates/l1",
1516
"crates/node",
1617
"crates/network",
@@ -136,6 +137,7 @@ reth-network-peers = { git = "https://github.com/scroll-tech/reth.git", default-
136137
reth-primitives = { git = "https://github.com/scroll-tech/reth.git", default-features = false }
137138
reth-provider = { git = "https://github.com/scroll-tech/reth.git", default-features = false }
138139
reth-tasks = { git = "https://github.com/scroll-tech/reth.git" }
140+
reth-tokio-util = { git = "https://github.com/scroll-tech/reth.git", default-features = false }
139141

140142
# reth-scroll
141143
reth-scroll-chainspec = { git = "https://github.com/scroll-tech/reth.git", default-features = false }
@@ -147,6 +149,7 @@ reth-scroll-primitives = { git = "https://github.com/scroll-tech/reth.git", defa
147149
rollup-node-manager = { path = "crates/node" }
148150
rollup-node-primitives = { path = "crates/primitives" }
149151
rollup-node-watcher = { path = "crates/watcher" }
152+
scroll-db = { path = "crates/database/db" }
150153
scroll-engine = { path = "crates/engine" }
151154
scroll-l1 = { path = "crates/l1" }
152155
scroll-network = { path = "crates/network" }

crates/indexer/Cargo.toml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[package]
2+
name = "rollup-node-indexer"
3+
version.workspace = true
4+
edition.workspace = true
5+
rust-version.workspace = true
6+
license.workspace = true
7+
exclude.workspace = true
8+
9+
[lints]
10+
workspace = true
11+
12+
[dependencies]
13+
# alloy
14+
alloy-primitives.workspace = true
15+
16+
# rollup-node
17+
scroll-db.workspace = true
18+
rollup-node-primitives.workspace = true
19+
rollup-node-watcher.workspace = true
20+
21+
# misc
22+
futures.workspace = true
23+
thiserror.workspace = true
24+
tokio.workspace = true
25+
tracing.workspace = true
26+
27+
[dev-dependencies]
28+
alloy-primitives = { workspace = true, features = ["arbitrary"] }
29+
30+
# rollup-node
31+
scroll-db = { workspace = true, features = ["test-utils"] }
32+
rollup-node-primitives = { workspace = true, features = ["arbitrary"] }
33+
34+
# misc
35+
arbitrary.workspace = true
36+
futures.workspace = true
37+
rand.workspace = true
38+
tokio.workspace = true

crates/indexer/src/action.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
use super::{IndexerError, IndexerEvent};
2+
use std::{
3+
fmt,
4+
future::Future,
5+
pin::Pin,
6+
task::{Context, Poll},
7+
};
8+
9+
/// A future that resolves to a `Result<IndexerEvent, IndexerError>`.
10+
type PendingIndexerFuture =
11+
Pin<Box<dyn Future<Output = Result<IndexerEvent, IndexerError>> + Send>>;
12+
13+
/// A type that represents a future that is being executed by the indexer.
14+
pub(super) enum IndexerFuture {
15+
HandleReorg(PendingIndexerFuture),
16+
HandleBatchCommit(PendingIndexerFuture),
17+
HandleBatchFinalization(PendingIndexerFuture),
18+
HandleL1Message(PendingIndexerFuture),
19+
}
20+
21+
impl IndexerFuture {
22+
/// Polls the future to completion.
23+
pub(super) fn poll(
24+
&mut self,
25+
cx: &mut Context<'_>,
26+
) -> Poll<Result<IndexerEvent, IndexerError>> {
27+
match self {
28+
Self::HandleReorg(fut) |
29+
Self::HandleBatchCommit(fut) |
30+
Self::HandleBatchFinalization(fut) |
31+
Self::HandleL1Message(fut) => fut.as_mut().poll(cx),
32+
}
33+
}
34+
}
35+
36+
// We implement the Debug trait for IndexerFuture to provide a human-readable representation of the
37+
// enum variants.
38+
impl fmt::Debug for IndexerFuture {
39+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
40+
match self {
41+
Self::HandleReorg(_) => write!(f, "HandleReorg"),
42+
Self::HandleBatchCommit(_) => write!(f, "HandleBatchCommit"),
43+
Self::HandleBatchFinalization(_) => write!(f, "HandleBatchFinalization"),
44+
Self::HandleL1Message(_) => write!(f, "HandleL1Message"),
45+
}
46+
}
47+
}

crates/indexer/src/error.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use scroll_db::DatabaseError;
2+
3+
/// A type that represents an error that occurred during indexing.
4+
#[derive(Debug, thiserror::Error)]
5+
pub enum IndexerError {
6+
/// An error occurred while interacting with the database.
7+
#[error("indexing failed due to database error: {0}")]
8+
DatabaseError(#[from] DatabaseError),
9+
}

crates/indexer/src/event.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use alloy_primitives::B256;
2+
3+
/// An event emitted by the indexer.
4+
#[derive(Debug, Clone, Copy)]
5+
pub enum IndexerEvent {
6+
/// A `BatchCommit` event has been indexed returning the batch index.
7+
BatchCommitIndexed(u64),
8+
/// A `BatchFinalization` event has been indexed returning the batch index.
9+
BatchFinalizationIndexed(B256),
10+
/// A `L1Message` event has been indexed returning the message queue index.
11+
L1MessageIndexed(u64),
12+
/// A `Reorg` event has been indexed returning the reorg block number.
13+
ReorgIndexed(u64),
14+
}

0 commit comments

Comments
 (0)