Skip to content

Commit 7f7511e

Browse files
add minimal listener
1 parent 19b40ac commit 7f7511e

File tree

8 files changed

+131
-1
lines changed

8 files changed

+131
-1
lines changed

.github/workflows/publish.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,8 @@ jobs:
3232
continue-on-error: true
3333
env:
3434
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
35+
- name: Publish inspector
36+
run: cargo publish --manifest-path inspector/Cargo.toml
37+
continue-on-error: true
38+
env:
39+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

Cargo.lock

Lines changed: 18 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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
members = [
33
"chain",
44
"client",
5+
"inspector",
56
"types",
67
]
78
resolver = "2"
@@ -30,6 +31,7 @@ tracing = "0.1.41"
3031
tracing-subscriber = "0.3.19"
3132
governor = "0.6.3"
3233
prometheus-client = "0.22.3"
34+
clap = "4.5.18"
3335

3436
[profile.bench]
3537
# Because we enable overflow checks in "release," we should benchmark with them.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
* [chain](./chain/README.md): A minimal blockchain built with the [Commonware Library](https://github.com/commonwarexyz/monorepo).
1010
* [client](./client/README.md): Client for interacting with `alto`.
11+
* [inspector](./inspector/README.md): Monitor `alto` activity.
1112
* [types](./types/README.md): Common types used throughout `alto`.
1213

1314
## Licensing

chain/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ tracing = { workspace = true }
3131
tracing-subscriber = { workspace = true, features = ["fmt", "json"] }
3232
governor = { workspace = true }
3333
prometheus-client = { workspace = true }
34+
clap = { workspace = true }
3435
sysinfo = "0.33.1"
35-
clap = "4.5.18"
3636
axum = "0.8.1"
3737
uuid = "1.15.1"
3838
serde = { version = "1.0.218", features = ["derive"] }

inspector/Cargo.toml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[package]
2+
name = "alto-inspector"
3+
version = "0.0.2"
4+
publish = true
5+
edition = "2021"
6+
license = "MIT OR Apache-2.0"
7+
description = "Monitor alto activity."
8+
readme = "README.md"
9+
homepage = "https://alto.commonware.xyz"
10+
repository = "https://github.com/commonwarexyz/alto/tree/main/inspector"
11+
documentation = "https://docs.rs/alto-inspector"
12+
13+
[dependencies]
14+
commonware-cryptography = { workspace = true }
15+
commonware-utils = { workspace = true }
16+
alto-types = { workspace = true }
17+
alto-client = { workspace = true }
18+
bytes = { workspace = true }
19+
rand = { workspace = true }
20+
thiserror = { workspace = true }
21+
clap = { workspace = true }
22+
tracing = { workspace = true }
23+
tracing-subscriber = { workspace = true }
24+
tokio = { version = "1.40.0", features = ["full"] }
25+
futures = { workspace = true }

inspector/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# alto-inspector
2+
3+
[![Crates.io](https://img.shields.io/crates/v/alto-inspector.svg)](https://crates.io/crates/alto-inspector)
4+
[![Docs.rs](https://docs.rs/alto-inspector/badge.svg)](https://docs.rs/alto-inspector)
5+
6+
Monitor `alto` activity.
7+
8+
## Status
9+
10+
`alto-inspector` is **ALPHA** software and is not yet recommended for production use. Developers should expect breaking changes and occasional instability.

inspector/src/main.rs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
use alto_client::{consensus::Message, Client};
2+
use clap::{value_parser, Arg, Command};
3+
use commonware_cryptography::bls12381::PublicKey;
4+
use commonware_utils::from_hex_formatted;
5+
use futures::StreamExt;
6+
use tracing::info;
7+
8+
#[tokio::main]
9+
async fn main() {
10+
// Parse arguments
11+
let matches = Command::new("inspector")
12+
.about("Monitor alto activity.")
13+
.arg(
14+
Arg::new("indexer")
15+
.long("indexer")
16+
.required(false)
17+
.value_parser(value_parser!(String)),
18+
)
19+
.arg(
20+
Arg::new("identity")
21+
.long("identity")
22+
.required(false)
23+
.value_parser(value_parser!(String)),
24+
)
25+
.get_matches();
26+
27+
// Create logger
28+
tracing_subscriber::fmt().init();
29+
30+
// Parse the identity
31+
let identity = matches.get_one::<String>("identity").unwrap();
32+
let identity = from_hex_formatted(identity).unwrap();
33+
let identity = PublicKey::try_from(identity).expect("Invalid identity");
34+
35+
// Connect to the indexer
36+
let indexer = matches.get_one::<String>("indexer").unwrap();
37+
let client = Client::new(indexer, identity);
38+
39+
// Stream the chain
40+
let mut stream = client
41+
.register()
42+
.await
43+
.expect("Failed to connect to indexer");
44+
while let Some(message) = stream.next().await {
45+
let message = message.expect("Failed to receive message");
46+
match message {
47+
Message::Seed(seed) => {
48+
info!(view = seed.view, "seed");
49+
}
50+
Message::Notarization(notarized) => {
51+
info!(
52+
view = notarized.proof.view,
53+
height = notarized.block.height,
54+
timestamp = notarized.block.timestamp,
55+
digest = ?notarized.block.digest(),
56+
"notarized");
57+
}
58+
Message::Finalization(finalized) => {
59+
info!(
60+
view = finalized.proof.view,
61+
height = finalized.block.height,
62+
timestamp = finalized.block.timestamp,
63+
digest = ?finalized.block.digest(),
64+
"finalized"
65+
);
66+
}
67+
}
68+
}
69+
}

0 commit comments

Comments
 (0)