Skip to content

Commit e10b0dd

Browse files
committed
refactor(types): consolidate wire format version into nodedb-types
Move WIRE_FORMAT_VERSION and MIN_WIRE_FORMAT_VERSION from the nodedb binary crate into a new nodedb-types::wire_version module so every crate that needs to stamp or validate the version shares a single source of truth. nodedb::version re-exports both constants. Tests pin the invariant that the minimum does not exceed the current version and that zero is reserved for legacy-client handling.
1 parent 12e4cff commit e10b0dd

3 files changed

Lines changed: 48 additions & 8 deletions

File tree

nodedb-types/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ pub mod vector_ann;
4141
pub mod vector_distance;
4242
pub mod vector_index_stats;
4343
pub mod vector_model;
44+
pub mod wire_version;
4445

4546
pub use approx::{CountMinSketch, HyperLogLog, SpaceSaving, TDigest};
4647
pub use array_cell::ArrayCell;

nodedb-types/src/wire_version.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//! Single source of truth for the `WIRE_FORMAT_VERSION` constant
2+
//! shared between every crate that needs to stamp or interpret it.
3+
//!
4+
//! This is the *cluster-wide* wire format version, distinct from:
5+
//! - `nodedb_cluster::wire::WIRE_VERSION` (the binary frame layout
6+
//! version of the `VShardEnvelope`),
7+
//! - the v3 RPC frame header version in
8+
//! `nodedb_cluster::rpc_codec::header` (a private constant of that
9+
//! module).
10+
//!
11+
//! Bump this when the SPSC bridge, WAL, or RPC payload schemas change
12+
//! in a way that requires a coordinated upgrade. Readers MUST reject
13+
//! messages stamped with a higher version than their own; readers
14+
//! SHOULD accept N-1 for rolling-upgrade compatibility.
15+
16+
/// Cluster-wide wire format version. Stamped on every `NodeInfo` and
17+
/// returned by `nodedb::version::WIRE_FORMAT_VERSION` (a re-export).
18+
pub const WIRE_FORMAT_VERSION: u16 = 4;
19+
20+
/// Minimum wire format version this build can read. Frames stamped
21+
/// below this are rejected.
22+
pub const MIN_WIRE_FORMAT_VERSION: u16 = 1;
23+
24+
#[cfg(test)]
25+
mod tests {
26+
use super::*;
27+
28+
#[test]
29+
fn min_does_not_exceed_current() {
30+
assert!(MIN_WIRE_FORMAT_VERSION <= WIRE_FORMAT_VERSION);
31+
}
32+
33+
#[test]
34+
fn current_is_nonzero() {
35+
// Version 0 is reserved for "unknown / legacy" handling on
36+
// downstream paths and must never be the active version.
37+
assert!(WIRE_FORMAT_VERSION > 0);
38+
}
39+
}

nodedb/src/version.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
/// Current NodeDB version.
99
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
1010

11-
/// Wire format version (incremented when SPSC bridge, WAL, or RPC formats change).
12-
/// Readers MUST reject messages with wire_version > their own.
13-
/// Readers SHOULD accept messages with wire_version == their own or one less (N-1).
14-
pub const WIRE_FORMAT_VERSION: u16 = 4;
15-
16-
/// Minimum wire format version this build can read.
17-
/// Messages below this version are rejected.
18-
pub const MIN_WIRE_FORMAT_VERSION: u16 = 1;
11+
/// Wire format version. Re-exported from `nodedb_types::wire_version`,
12+
/// which is the single source of truth shared with `nodedb-cluster`
13+
/// and any other crate that stamps or interprets the value.
14+
///
15+
/// Readers MUST reject messages with wire_version > their own. Readers
16+
/// SHOULD accept messages with wire_version == their own or one less
17+
/// (N-1).
18+
pub use nodedb_types::wire_version::{MIN_WIRE_FORMAT_VERSION, WIRE_FORMAT_VERSION};
1919

2020
/// Wire version assigned to legacy clients that send wire_version == 0.
2121
/// Must always equal MIN_WIRE_FORMAT_VERSION to prevent silent upgrades

0 commit comments

Comments
 (0)