From 1481ec9ac3c672ac2139d1866323b582d0b599a1 Mon Sep 17 00:00:00 2001 From: Kirill Fomichev Date: Mon, 14 Aug 2023 18:37:57 -0400 Subject: [PATCH] geyser: fix overflow for small slot number (#171) --- CHANGELOG.md | 2 ++ Cargo.lock | 24 ------------------------ yellowstone-grpc-geyser/Cargo.toml | 2 +- yellowstone-grpc-geyser/build.rs | 6 +----- yellowstone-grpc-geyser/src/grpc.rs | 20 ++++++++++++-------- 5 files changed, 16 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b328250..6034e8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ The minor version will be incremented upon a breaking change and the patch versi ### Fixes +geyser: fix overflow for small slot number ([#171](https://github.com/rpcpool/yellowstone-grpc/pull/171)). + ### Breaking ## 2023-08-10 diff --git a/Cargo.lock b/Cargo.lock index 0d784f4..0ca2b41 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1874,15 +1874,6 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" -[[package]] -name = "ntapi" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8a3895c6391c39d7fe7ebc444a87eb2991b2a0bc718fdabd071eec617fc68e4" -dependencies = [ - "winapi", -] - [[package]] name = "num" version = "0.2.1" @@ -3467,20 +3458,6 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" -[[package]] -name = "sysinfo" -version = "0.29.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9557d0845b86eea8182f7b10dff120214fb6cd9fd937b6f4917714e546a38695" -dependencies = [ - "cfg-if", - "core-foundation-sys", - "libc", - "ntapi", - "once_cell", - "winapi", -] - [[package]] name = "tempfile" version = "3.6.0" @@ -3929,7 +3906,6 @@ dependencies = [ "anyhow", "rustc_version", "rustversion", - "sysinfo", "time 0.3.22", ] diff --git a/yellowstone-grpc-geyser/Cargo.toml b/yellowstone-grpc-geyser/Cargo.toml index 13f7f5c..9fe58e4 100644 --- a/yellowstone-grpc-geyser/Cargo.toml +++ b/yellowstone-grpc-geyser/Cargo.toml @@ -40,4 +40,4 @@ yellowstone-grpc-proto = { path = "../yellowstone-grpc-proto" } anyhow = "1.0.62" cargo-lock = "9.0.0" git-version = "0.3.5" -vergen = { version = "8.2.1", features = ["build", "cargo", "git", "gitcl", "rustc", "si"] } +vergen = { version = "8.2.1", features = ["build", "rustc"] } diff --git a/yellowstone-grpc-geyser/build.rs b/yellowstone-grpc-geyser/build.rs index 80dae7a..92e1f4c 100644 --- a/yellowstone-grpc-geyser/build.rs +++ b/yellowstone-grpc-geyser/build.rs @@ -2,11 +2,7 @@ use {cargo_lock::Lockfile, std::collections::HashSet}; fn main() -> anyhow::Result<()> { let mut envs = vergen::EmitBuilder::builder(); - envs.all_build() - .all_cargo() - .all_git() - .all_rustc() - .all_sysinfo(); + envs.all_build().all_rustc(); envs.emit()?; // vergen git version does not looks cool diff --git a/yellowstone-grpc-geyser/src/grpc.rs b/yellowstone-grpc-geyser/src/grpc.rs index 3115ef4..a855ba0 100644 --- a/yellowstone-grpc-geyser/src/grpc.rs +++ b/yellowstone-grpc-geyser/src/grpc.rs @@ -509,13 +509,17 @@ impl BlockMetaStorage { } if msg.status == CommitmentLevel::Finalized { - let keep_slot = msg.slot - KEEP_SLOTS; - storage.blocks.retain(|slot, _block| *slot >= keep_slot); + if let Some(keep_slot) = msg.slot.checked_sub(KEEP_SLOTS) { + storage.blocks.retain(|slot, _block| *slot >= keep_slot); + } - let keep_slot = msg.slot - MAX_RECENT_BLOCKHASHES as u64 - 32; - storage - .blockhashes - .retain(|_blockhash, status| status.slot >= keep_slot); + if let Some(keep_slot) = + msg.slot.checked_sub(MAX_RECENT_BLOCKHASHES as u64 + 32) + { + storage + .blockhashes + .retain(|_blockhash, status| status.slot >= keep_slot); + } } } Message::BlockMeta(msg) => { @@ -775,10 +779,10 @@ impl GrpcService { match block_fail_action { ConfigBlockFailAction::Log => { INVALID_FULL_BLOCKS.inc(); - error!("unexpected message order for slot {}", $message.get_slot()); + error!("unexpected message ({}) order for slot {}", $message.kind(), $message.get_slot()); } ConfigBlockFailAction::Panic => { - panic!("unexpected message order for slot {}", $message.get_slot()); + panic!("unexpected message ({}) order for slot {}", $message.kind(), $message.get_slot()); } } }