Skip to content

Commit 744150f

Browse files
feat: separate proto files into standalone crate
Extract protocol buffer definitions into a separate `snapchain-proto` crate so consumers can import protos without depending on the entire snapchain project. Changes: - Create `proto/` workspace member with its own Cargo.toml and build.rs - Move proto definitions from `src/proto/` to `proto/definitions/` - Move proto-only impls (Height, ShardHash, Message, etc.) to proto crate - Add extension traits for methods requiring main crate types: - CommitsExt for commit certificate conversion - FullProposalExt for proposer address - HubEventExt for event construction - HubEventStorageExt for storage operations - Update imports throughout codebase to use extension traits - Rename HubEvent::from() to HubEvent::new_event() to avoid trait conflict
1 parent dc71155 commit 744150f

40 files changed

+434
-309
lines changed

Cargo.lock

Lines changed: 14 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
[workspace]
2+
members = ["proto"]
3+
resolver = "2"
4+
15
[package]
26
name = "snapchain"
37
version = "0.11.0"
@@ -7,7 +11,9 @@ default-run = "snapchain"
711
[lib]
812
name = "snapchain"
913
path = "src/lib.rs"
14+
1015
[dependencies]
16+
snapchain-proto = { path = "proto" }
1117
tokio = { version = "1.40.0", features = ["full"] }
1218
tokio-stream = "0.1"
1319
serde = { version = "1.0", features = ["derive"] }
@@ -98,8 +104,6 @@ solar-macros = "=0.1.1"
98104
solar-config = "=0.1.1"
99105
nix = { version = "0.29", features = ["resource"] }
100106

101-
[build-dependencies]
102-
tonic-build = "0.9.2"
103107

104108
[dev-dependencies]
105109
serial_test = "3.1.1"
@@ -108,3 +112,4 @@ insta = { version = "1.40", features = ["json"] }
108112

109113
[package.metadata.precommit]
110114
fmt = "cargo fmt --check --quiet"
115+

Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ EOF
3030
# since the Cargo configuration references files in src.
3131
# This means we'll re-fetch all crates every time the source code changes,
3232
# which isn't ideal.
33-
COPY Cargo.lock Cargo.toml build.rs ./
33+
COPY Cargo.lock Cargo.toml ./
34+
COPY proto ./proto
3435
COPY src ./src
3536

3637
ENV RUST_BACKTRACE=full
@@ -59,7 +60,7 @@ RUN <<EOF
5960
EOF
6061

6162
WORKDIR /app
62-
COPY --from=builder /usr/src/app/src/proto /app/proto
63+
COPY --from=builder /usr/src/app/proto/definitions /app/proto
6364
COPY --from=builder /usr/src/app/nodes /app/nodes
6465
COPY --from=builder \
6566
/usr/src/app/target/release/snapchain \

proto/Cargo.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[package]
2+
name = "snapchain-proto"
3+
version = "0.11.0"
4+
edition = "2021"
5+
description = "Protocol buffer definitions for Snapchain"
6+
license = "MIT"
7+
8+
[dependencies]
9+
prost = "0.13.3"
10+
tonic = { version = "0.12.3", features = ["tls", "tls-native-roots"] }
11+
serde = { version = "1.0", features = ["derive"] }
12+
futures-core = "0.3.31"
13+
hex = "0.4.3"
14+
informalsystems-malachitebft-core-types = { path = "../../malachite/code/crates/core-types" }
15+
16+
[build-dependencies]
17+
tonic-build = "0.9.2"

build.rs renamed to proto/build.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
1111
// TODO: auto-discover proto files
1212
builder.compile(
1313
&[
14-
"src/proto/admin_rpc.proto",
15-
"src/proto/blocks.proto",
16-
"src/proto/rpc.proto",
17-
"src/proto/message.proto",
18-
"src/proto/onchain_event.proto",
19-
"src/proto/hub_event.proto",
20-
"src/proto/username_proof.proto",
21-
"src/proto/sync_trie.proto",
22-
"src/proto/node_state.proto",
23-
"src/proto/gossip.proto",
24-
"src/proto/request_response.proto",
25-
"src/proto/replication.proto",
14+
"definitions/admin_rpc.proto",
15+
"definitions/blocks.proto",
16+
"definitions/rpc.proto",
17+
"definitions/message.proto",
18+
"definitions/onchain_event.proto",
19+
"definitions/hub_event.proto",
20+
"definitions/username_proof.proto",
21+
"definitions/sync_trie.proto",
22+
"definitions/node_state.proto",
23+
"definitions/gossip.proto",
24+
"definitions/request_response.proto",
25+
"definitions/replication.proto",
2626
],
27-
&["src/proto"],
27+
&["definitions"],
2828
)?;
2929

3030
Ok(())
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)