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

Make a crate of grpc_stream #397

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
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
34 changes: 34 additions & 0 deletions rust/Cargo.lock

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

11 changes: 10 additions & 1 deletion rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
[workspace]
resolver = "2"

members = ["indexer-metrics", "moving-average", "processor", "server-framework"]
members = [
"aptos-indexer-transaction-stream",
"indexer-metrics",
"moving-average",
"processor",
"server-framework",
"transaction-filter",
]

[workspace.package]
authors = ["Aptos Labs <[email protected]>"]
Expand All @@ -16,6 +23,8 @@ rust-version = "1.75"
processor = { path = "processor" }
server-framework = { path = "server-framework" }
aptos-moving-average = { path = "moving-average" }
aptos-indexer-transaction-stream = { path = "aptos-indexer-transaction-stream" }
transaction-filter = { path = "transaction-filter" }

ahash = { version = "0.8.7", features = ["serde"] }
anyhow = "1.0.62"
Expand Down
32 changes: 32 additions & 0 deletions rust/aptos-indexer-transaction-stream/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[package]
name = "aptos-indexer-transaction-stream"
version = "0.1.0"

# Workspace inherited keys
authors = { workspace = true }
edition = { workspace = true }
homepage = { workspace = true }
license = { workspace = true }
publish = { workspace = true }
repository = { workspace = true }
rust-version = { workspace = true }
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = { workspace = true }
aptos-moving-average = { workspace = true }
aptos-protos = { workspace = true }
bigdecimal = { workspace = true }
chrono = { workspace = true }
futures-util = { workspace = true }
itertools = { workspace = true }
kanal = { workspace = true }
once_cell = { workspace = true }
prometheus = { workspace = true }
prost = { workspace = true }
serde = { workspace = true }
tokio = { workspace = true }
tonic = { workspace = true }
tracing = { workspace = true }
transaction-filter = { workspace = true }
url = { workspace = true }
60 changes: 60 additions & 0 deletions rust/aptos-indexer-transaction-stream/src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
use serde::{Deserialize, Serialize};
use std::time::Duration;
use url::Url;

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
pub struct TransactionStreamConfig {
pub indexer_grpc_data_service_address: Url,
pub starting_version: u64,
pub request_ending_version: Option<u64>,
pub auth_token: String,
pub request_name_header: String,
#[serde(default = "TransactionStreamConfig::default_indexer_grpc_http2_ping_interval")]
pub indexer_grpc_http2_ping_interval_secs: u64,
#[serde(default = "TransactionStreamConfig::default_indexer_grpc_http2_ping_timeout")]
pub indexer_grpc_http2_ping_timeout_secs: u64,
#[serde(default = "TransactionStreamConfig::default_indexer_grpc_reconnection_timeout")]
pub indexer_grpc_reconnection_timeout_secs: u64,
#[serde(default = "TransactionStreamConfig::default_indexer_grpc_response_item_timeout")]
pub indexer_grpc_response_item_timeout_secs: u64,
}

impl TransactionStreamConfig {
pub const fn indexer_grpc_http2_ping_interval(&self) -> Duration {
Duration::from_secs(self.indexer_grpc_http2_ping_interval_secs)
}

pub const fn indexer_grpc_http2_ping_timeout(&self) -> Duration {
Duration::from_secs(self.indexer_grpc_http2_ping_timeout_secs)
}

pub const fn indexer_grpc_reconnection_timeout(&self) -> Duration {
Duration::from_secs(self.indexer_grpc_reconnection_timeout_secs)
}

pub const fn indexer_grpc_response_item_timeout(&self) -> Duration {
Duration::from_secs(self.indexer_grpc_response_item_timeout_secs)
}

/// Indexer GRPC http2 ping interval in seconds. Defaults to 30.
/// Tonic ref: https://docs.rs/tonic/latest/tonic/transport/channel/struct.Endpoint.html#method.http2_keep_alive_interval
pub const fn default_indexer_grpc_http2_ping_interval() -> u64 {
30
}

/// Indexer GRPC http2 ping timeout in seconds. Defaults to 10.
pub const fn default_indexer_grpc_http2_ping_timeout() -> u64 {
10
}

/// Default timeout for establishing a grpc connection. Defaults to 5 seconds.
pub const fn default_indexer_grpc_reconnection_timeout() -> u64 {
5
}

/// Default timeout for receiving an item from grpc stream. Defaults to 60 seconds.
pub const fn default_indexer_grpc_response_item_timeout() -> u64 {
60
}
}
6 changes: 6 additions & 0 deletions rust/aptos-indexer-transaction-stream/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pub mod config;
pub mod transaction_stream;
pub mod utils;

pub use config::TransactionStreamConfig;
pub use transaction_stream::{TransactionStream, TransactionsPBResponse};
Loading
Loading