Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit f2fda14

Browse files
authored
Reduce max snapshot hashes to stay under MTU (bp #8541) (#8544)
automerge
1 parent 1c576d4 commit f2fda14

File tree

3 files changed

+29
-13
lines changed

3 files changed

+29
-13
lines changed

core/src/cluster_info.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ const MAX_GOSSIP_TRAFFIC: usize = 128_000_000 / PACKET_DATA_SIZE;
8484
const NUM_BITS_PER_BYTE: u64 = 8;
8585
const MIN_SIZE_TO_COMPRESS_GZIP: u64 = 64;
8686

87+
/// Keep the number of snapshot hashes a node publishes under MAX_PROTOCOL_PAYLOAD_SIZE
88+
pub const MAX_SNAPSHOT_HASHES: usize = 16;
89+
8790
#[derive(Debug, PartialEq, Eq)]
8891
pub enum ClusterInfoError {
8992
NoPeers,
@@ -441,6 +444,14 @@ impl ClusterInfo {
441444
}
442445

443446
pub fn push_snapshot_hashes(&mut self, snapshot_hashes: Vec<(Slot, Hash)>) {
447+
if snapshot_hashes.len() > MAX_SNAPSHOT_HASHES {
448+
warn!(
449+
"snapshot_hashes too large, ignored: {}",
450+
snapshot_hashes.len()
451+
);
452+
return;
453+
}
454+
444455
let now = timestamp();
445456
let entry = CrdsValue::new_signed(
446457
CrdsData::SnapshotHash(SnapshotHash::new(self.id(), snapshot_hashes, now)),
@@ -1059,7 +1070,7 @@ impl ClusterInfo {
10591070
}
10601071

10611072
/// Splits a Vec of CrdsValues into a nested Vec, trying to make sure that
1062-
/// each Vec is no larger than `PROTOCOL_PAYLOAD_SIZE`
1073+
/// each Vec is no larger than `MAX_PROTOCOL_PAYLOAD_SIZE`
10631074
/// Note: some messages cannot be contained within that size so in the worst case this returns
10641075
/// N nested Vecs with 1 item each.
10651076
fn split_gossip_messages(msgs: Vec<CrdsValue>) -> Vec<Vec<CrdsValue>> {

core/src/snapshot_packager_service.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::cluster_info::ClusterInfo;
1+
use crate::cluster_info::{ClusterInfo, MAX_SNAPSHOT_HASHES};
22
use solana_ledger::{
33
snapshot_package::SnapshotPackageReceiver, snapshot_utils::archive_snapshot_package,
44
};
@@ -16,8 +16,6 @@ pub struct SnapshotPackagerService {
1616
t_snapshot_packager: JoinHandle<()>,
1717
}
1818

19-
const MAX_SNAPSHOT_HASHES: usize = 24;
20-
2119
impl SnapshotPackagerService {
2220
pub fn new(
2321
snapshot_package_receiver: SnapshotPackageReceiver,

validator/src/main.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,15 @@ fn download_file(url: &str, destination_file: &Path) -> Result<(), String> {
9393
let progress_bar = new_spinner_progress_bar();
9494
progress_bar.set_message(&format!("{}Downloading {}...", TRUCK, url));
9595

96-
let client = reqwest::blocking::Client::new();
97-
let response = client.get(url).send().map_err(|err| err.to_string())?;
96+
let response = reqwest::blocking::Client::new()
97+
.get(url)
98+
.send()
99+
.and_then(|response| response.error_for_status())
100+
.map_err(|err| {
101+
progress_bar.finish_and_clear();
102+
err.to_string()
103+
})?;
98104

99-
let response = response
100-
.error_for_status()
101-
.map_err(|err| format!("Unable to download {}: {}", url, err))?;
102105
let download_size = {
103106
response
104107
.headers()
@@ -139,9 +142,8 @@ fn download_file(url: &str, destination_file: &Path) -> Result<(), String> {
139142
response,
140143
};
141144

142-
let mut file = File::create(&temp_destination_file)
143-
.map_err(|err| format!("Unable to create {:?}: {:?}", temp_destination_file, err))?;
144-
std::io::copy(&mut source, &mut file)
145+
File::create(&temp_destination_file)
146+
.and_then(|mut file| std::io::copy(&mut source, &mut file))
145147
.map_err(|err| format!("Unable to write {:?}: {:?}", temp_destination_file, err))?;
146148

147149
source.progress_bar.finish_and_clear();
@@ -1138,7 +1140,12 @@ pub fn main() {
11381140
})
11391141
.and_then(|_| {
11401142
if let Some(snapshot_hash) = snapshot_hash {
1141-
download_snapshot(&rpc_contact_info.rpc, &ledger_path, snapshot_hash)
1143+
rpc_client.get_slot()
1144+
.map_err(|err| format!("Failed to get RPC node slot: {}", err))
1145+
.and_then(|slot| {
1146+
info!("RPC node root slot: {}", slot);
1147+
download_snapshot(&rpc_contact_info.rpc, &ledger_path, snapshot_hash)
1148+
})
11421149
} else {
11431150
Ok(())
11441151
}

0 commit comments

Comments
 (0)