Skip to content

Commit 1827a65

Browse files
authored
fix semver comparison to be more flexible around pre-release (#134)
1 parent 289b2a1 commit 1827a65

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

Cargo.lock

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

apps/jet/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "yellowstone-jet"
3-
version = "14.9.2"
3+
version = "14.9.3"
44
description = "Yellowstone Jet"
55
edition.workspace = true
66
authors.workspace = true

apps/jet/src/grpc_geyser.rs

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,21 @@ pub struct GeyserSubscriber {
162162
}
163163

164164
impl GeyserSubscriber {
165+
fn is_supported_geyser_version(version: &Version, required: &VersionReq) -> bool {
166+
if required.matches(version) {
167+
return true;
168+
}
169+
170+
// semver excludes prereleases from broad ranges (e.g. ">=1.14.1").
171+
// Treat prereleases as supported when their stable counterpart matches.
172+
if !version.pre.is_empty() {
173+
let stable = Version::new(version.major, version.minor, version.patch);
174+
return required.matches(&stable);
175+
}
176+
177+
false
178+
}
179+
165180
pub fn new(
166181
primary_grpc: ConfigUpstreamGrpc,
167182
include_transactions: bool,
@@ -723,7 +738,7 @@ impl GeyserSubscriber {
723738
GeyserError::VersionParse(format!("failed to parse required version: {e}"))
724739
})?;
725740

726-
if !required.matches(&version) {
741+
if !Self::is_supported_geyser_version(&version, &required) {
727742
return Err(GeyserError::VersionValidation(format!(
728743
"gRPC version {version} doesn't match required {required}"
729744
)));
@@ -767,7 +782,11 @@ impl GeyserStreams for GeyserSubscriber {
767782
#[cfg(test)]
768783
mod tests {
769784
use {
770-
crate::{grpc_geyser::SlotTrackingInfo, util::SlotStatus},
785+
crate::{
786+
grpc_geyser::{GeyserSubscriber, SlotTrackingInfo},
787+
util::SlotStatus,
788+
},
789+
semver::{Version, VersionReq},
771790
solana_hash::Hash,
772791
};
773792

@@ -832,4 +851,27 @@ mod tests {
832851
info.mark_status_seen(SlotStatus::SlotConfirmed);
833852
assert!(!info.has_seen_status(SlotStatus::SlotFinalized));
834853
}
854+
855+
#[test]
856+
fn it_should_parse_rc_version() {
857+
let version_str = "2.0.0-rc1";
858+
let version = Version::parse(version_str).unwrap();
859+
let required = VersionReq::parse(">=1.14.1").unwrap();
860+
861+
assert!(GeyserSubscriber::is_supported_geyser_version(
862+
&version, &required
863+
));
864+
865+
let version_str = "1.14.0-rc1";
866+
let version = Version::parse(version_str).unwrap();
867+
assert!(!GeyserSubscriber::is_supported_geyser_version(
868+
&version, &required
869+
));
870+
871+
let version_str = "1.14.0";
872+
let version = Version::parse(version_str).unwrap();
873+
assert!(!GeyserSubscriber::is_supported_geyser_version(
874+
&version, &required
875+
));
876+
}
835877
}

0 commit comments

Comments
 (0)