-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add timestamp indexing wip (#4713)
## Describe your changes - builds on top of #4722 - consumes timestamps from raw events to create detailed_blocks in processed events db ## Issue ticket number and link fixes #4675
- Loading branch information
Showing
6 changed files
with
84 additions
and
20 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,25 @@ | ||
[package] | ||
name = "pindexer" | ||
version = {workspace = true} | ||
authors = {workspace = true} | ||
edition = {workspace = true} | ||
repository = {workspace = true} | ||
homepage = {workspace = true} | ||
license = {workspace = true} | ||
version = { workspace = true } | ||
authors = { workspace = true } | ||
edition = { workspace = true } | ||
repository = { workspace = true } | ||
homepage = { workspace = true } | ||
license = { workspace = true } | ||
publish = false | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
cometindex = {workspace = true} | ||
penumbra-shielded-pool = {workspace = true, default-features = false} | ||
penumbra-stake = {workspace = true, default-features = false} | ||
penumbra-app = {workspace = true, default-features = false} | ||
penumbra-num = {workspace = true, default-features = false} | ||
penumbra-asset = {workspace = true, default-features = false} | ||
penumbra-proto = {workspace = true, default-features = false} | ||
tokio = {workspace = true, features = ["full"]} | ||
anyhow = {workspace = true} | ||
serde_json = {workspace = true} | ||
tracing = {workspace = true} | ||
sqlx = { workspace = true, features = ["chrono"] } | ||
cometindex = { workspace = true } | ||
penumbra-shielded-pool = { workspace = true, default-features = false } | ||
penumbra-stake = { workspace = true, default-features = false } | ||
penumbra-app = { workspace = true, default-features = false } | ||
penumbra-num = { workspace = true, default-features = false } | ||
penumbra-asset = { workspace = true, default-features = false } | ||
penumbra-proto = { workspace = true, default-features = false } | ||
tokio = { workspace = true, features = ["full"] } | ||
anyhow = { workspace = true } | ||
serde_json = { workspace = true } | ||
tracing = { workspace = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use cometindex::{async_trait, sqlx, AppView, ContextualizedEvent, PgTransaction}; | ||
use penumbra_proto::{core::component::sct::v1 as pb, event::ProtoEvent}; | ||
use sqlx::types::chrono::DateTime; | ||
|
||
#[derive(Debug)] | ||
pub struct Block {} | ||
|
||
#[async_trait] | ||
impl AppView for Block { | ||
async fn init_chain( | ||
&self, | ||
dbtx: &mut PgTransaction, | ||
_: &serde_json::Value, | ||
) -> Result<(), anyhow::Error> { | ||
sqlx::query( | ||
// table name is module path + struct name | ||
" | ||
CREATE TABLE IF NOT EXISTS block_details ( | ||
id SERIAL PRIMARY KEY, | ||
root BYTEA NOT NULL, | ||
height INT8 NOT NULL, | ||
timestamp TIMESTAMPTZ NOT NULL | ||
); | ||
", | ||
) | ||
.execute(dbtx.as_mut()) | ||
.await?; | ||
Ok(()) | ||
} | ||
|
||
fn is_relevant(&self, type_str: &str) -> bool { | ||
type_str == "penumbra.core.component.sct.v1.EventBlockRoot" | ||
} | ||
|
||
async fn index_event( | ||
&self, | ||
dbtx: &mut PgTransaction, | ||
event: &ContextualizedEvent, | ||
) -> Result<(), anyhow::Error> { | ||
let pe = pb::EventBlockRoot::from_event(event.as_ref())?; | ||
let timestamp = pe.timestamp.expect("Block has no timestamp"); | ||
|
||
sqlx::query( | ||
" | ||
INSERT INTO block_details (height, timestamp, root) | ||
VALUES ($1, $2, $3) | ||
", | ||
) | ||
.bind(pe.height as i64) | ||
.bind(DateTime::from_timestamp(timestamp.seconds, timestamp.nanos as u32).unwrap()) | ||
.bind(pe.root.unwrap().inner) | ||
.execute(dbtx.as_mut()) | ||
.await?; | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters