Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 0 additions & 4 deletions packages/zaino-state/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,5 @@ fn main() -> io::Result<()> {
let build_user = whoami::username();
println!("cargo:rustc-env=BUILD_USER={build_user}");

// Set the version from Cargo.toml
let version = env::var("CARGO_PKG_VERSION").expect("Failed to get version from Cargo.toml");
println!("cargo:rustc-env=VERSION={version}");

Ok(())
}
2 changes: 1 addition & 1 deletion packages/zaino-state/src/backends/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl ZcashService for FetchService {

let zebra_build_data = fetcher.get_info().await?;
let data = ServiceMetadata::new(
get_build_info(),
get_build_info(config.indexer_version.clone()),
config.network.to_zebra_network(),
zebra_build_data.build,
zebra_build_data.subversion,
Expand Down
2 changes: 1 addition & 1 deletion packages/zaino-state/src/backends/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ impl ZcashService for StateService {
let zebra_build_data = rpc_client.get_info().await?;

let data = ServiceMetadata::new(
get_build_info(),
get_build_info(config.indexer_version.clone()),
config.network.to_zebra_network(),
zebra_build_data.build,
zebra_build_data.subversion,
Expand Down
18 changes: 18 additions & 0 deletions packages/zaino-state/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ pub struct StateServiceConfig {
pub network: Network,
/// Zcash donation UA address
pub donation_address: Option<DonationAddress>,
/// Version of the indexer binary embedding this service.
///
/// Reported on the wire via `LightdInfo.version`. Defaults to this
/// crate's `CARGO_PKG_VERSION` when constructed via [`Self::new`];
/// the embedding binary should overwrite it with its own
/// `CARGO_PKG_VERSION` so the wire reflects the deployed indexer
/// rather than the library crate.
pub indexer_version: String,
}

#[allow(deprecated)]
Expand Down Expand Up @@ -131,6 +139,7 @@ impl StateServiceConfig {
storage,
network,
donation_address,
indexer_version: env!("CARGO_PKG_VERSION").to_string(),
}
}
}
Expand All @@ -155,6 +164,14 @@ pub struct FetchServiceConfig {
pub network: Network,
/// Zcash donation UA address
pub donation_address: Option<DonationAddress>,
/// Version of the indexer binary embedding this service.
///
/// Reported on the wire via `LightdInfo.version`. Defaults to this
/// crate's `CARGO_PKG_VERSION` when constructed via [`Self::new`];
/// the embedding binary should overwrite it with its own
/// `CARGO_PKG_VERSION` so the wire reflects the deployed indexer
/// rather than the library crate.
pub indexer_version: String,
}

#[allow(deprecated)]
Expand All @@ -180,6 +197,7 @@ impl FetchServiceConfig {
storage,
network,
donation_address,
indexer_version: env!("CARGO_PKG_VERSION").to_string(),
}
}
}
Expand Down
22 changes: 20 additions & 2 deletions packages/zaino-state/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,17 @@ impl fmt::Display for BuildInfo {
}

/// Returns build info for Zingo-Indexer.
pub(crate) fn get_build_info() -> BuildInfo {
///
/// `version` is the version of the deployed indexer binary (e.g. `zainod`),
/// supplied by the caller. Library crates do not know which binary embeds
/// them, so each binary passes its own `CARGO_PKG_VERSION`.
pub(crate) fn get_build_info(version: String) -> BuildInfo {
BuildInfo {
commit_hash: env!("GIT_COMMIT").to_string(),
branch: env!("BRANCH").to_string(),
build_date: env!("BUILD_DATE").to_string(),
build_user: env!("BUILD_USER").to_string(),
version: env!("VERSION").to_string(),
version,
}
}

Expand Down Expand Up @@ -113,3 +117,17 @@ impl fmt::Display for ServiceMetadata {
writeln!(f, "Zebra Subversion: {}", self.zebra_subversion)
}
}

#[cfg(test)]
mod tests {
use super::*;

/// Regression test for issue #1057: the version flowed onto the wire via
/// `LightdInfo.version` must come from the caller-supplied string (the
/// embedding binary's `CARGO_PKG_VERSION`), not from this library crate.
#[test]
fn get_build_info_uses_caller_supplied_version() {
let build_info = get_build_info("9.9.9-test".to_string());
assert_eq!(build_info.version(), "9.9.9-test");
}
}
22 changes: 22 additions & 0 deletions packages/zainod/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ impl TryFrom<ZainodConfig> for StateServiceConfig {
storage: cfg.storage,
network: cfg.network,
donation_address: cfg.donation_address,
indexer_version: env!("CARGO_PKG_VERSION").to_string(),
})
}
}
Expand All @@ -402,6 +403,7 @@ impl TryFrom<ZainodConfig> for FetchServiceConfig {
storage: cfg.storage,
network: cfg.network,
donation_address: cfg.donation_address,
indexer_version: env!("CARGO_PKG_VERSION").to_string(),
})
}
}
Expand Down Expand Up @@ -1040,4 +1042,24 @@ listen_address = "127.0.0.1:8137"
let path = create_test_config_file(&dir, content, "invalid_donation.toml");
assert!(load_config(&path).is_err());
}

/// `LightdInfo.version` (issue #1057) is sourced from
/// `*ServiceConfig.indexer_version`. This must be set to `zainod`'s
/// `CARGO_PKG_VERSION` at the boundary so the wire reflects the
/// deployed binary, not zaino-state's library version.
#[test]
#[allow(deprecated)]
fn indexer_version_is_zainod_pkg_version() {
let _guard = EnvGuard::new();

let cfg = ZainodConfig::default();

let state_cfg = StateServiceConfig::try_from(cfg.clone())
.expect("StateServiceConfig conversion should succeed for default ZainodConfig");
assert_eq!(state_cfg.indexer_version, env!("CARGO_PKG_VERSION"));

let fetch_cfg = FetchServiceConfig::try_from(cfg)
.expect("FetchServiceConfig conversion should succeed for default ZainodConfig");
assert_eq!(fetch_cfg.indexer_version, env!("CARGO_PKG_VERSION"));
}
}
Loading