Packet::from_data is ignoring serialization errors:
https://github.com/solana-labs/solana/blob/d08c3232e/sdk/src/packet.rs#L42-L48
This is likely never useful as the packet will be sent over the wire
taking bandwidth but at the receiving end will either fail to
deserialize or it will be invalid.
This commit will propagate the errors out of the function to the
call-site, allowing the call-site to handle the error.
(cherry picked from commit 73ac104df2
)
Co-authored-by: behzad nouri <behzadnouri@gmail.com>
This commit is contained in:
@ -1978,8 +1978,10 @@ impl ClusterInfo {
|
|||||||
let (check, ping) = ping_cache.check(now, node, &mut pingf);
|
let (check, ping) = ping_cache.check(now, node, &mut pingf);
|
||||||
if let Some(ping) = ping {
|
if let Some(ping) = ping {
|
||||||
let ping = Protocol::PingMessage(ping);
|
let ping = Protocol::PingMessage(ping);
|
||||||
let ping = Packet::from_data(&node.1, ping);
|
match Packet::from_data(&node.1, ping) {
|
||||||
packets.packets.push(ping);
|
Ok(packet) => packets.packets.push(packet),
|
||||||
|
Err(err) => error!("failed to write ping packet: {:?}", err),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
if !check {
|
if !check {
|
||||||
self.stats
|
self.stats
|
||||||
@ -2083,16 +2085,20 @@ impl ClusterInfo {
|
|||||||
let from_addr = pull_responses[stat.to].1;
|
let from_addr = pull_responses[stat.to].1;
|
||||||
let response = pull_responses[stat.to].0[stat.responses_index].clone();
|
let response = pull_responses[stat.to].0[stat.responses_index].clone();
|
||||||
let protocol = Protocol::PullResponse(self_id, vec![response]);
|
let protocol = Protocol::PullResponse(self_id, vec![response]);
|
||||||
let new_packet = Packet::from_data(&from_addr, protocol);
|
match Packet::from_data(&from_addr, protocol) {
|
||||||
if self.outbound_budget.take(new_packet.meta.size) {
|
Err(err) => error!("failed to write pull-response packet: {:?}", err),
|
||||||
|
Ok(packet) => {
|
||||||
|
if self.outbound_budget.take(packet.meta.size) {
|
||||||
sent.insert(index);
|
sent.insert(index);
|
||||||
total_bytes += new_packet.meta.size;
|
total_bytes += packet.meta.size;
|
||||||
packets.packets.push(new_packet)
|
packets.packets.push(packet)
|
||||||
} else {
|
} else {
|
||||||
inc_new_counter_info!("gossip_pull_request-no_budget", 1);
|
inc_new_counter_info!("gossip_pull_request-no_budget", 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
time.stop();
|
time.stop();
|
||||||
inc_new_counter_info!("gossip_pull_request-sent_requests", sent.len());
|
inc_new_counter_info!("gossip_pull_request-sent_requests", sent.len());
|
||||||
inc_new_counter_info!(
|
inc_new_counter_info!(
|
||||||
@ -2281,8 +2287,13 @@ impl ClusterInfo {
|
|||||||
.filter_map(|(addr, ping)| {
|
.filter_map(|(addr, ping)| {
|
||||||
let pong = Pong::new(&ping, &self.keypair).ok()?;
|
let pong = Pong::new(&ping, &self.keypair).ok()?;
|
||||||
let pong = Protocol::PongMessage(pong);
|
let pong = Protocol::PongMessage(pong);
|
||||||
let packet = Packet::from_data(&addr, pong);
|
match Packet::from_data(&addr, pong) {
|
||||||
Some(packet)
|
Ok(packet) => Some(packet),
|
||||||
|
Err(err) => {
|
||||||
|
error!("failed to write pong packet: {:?}", err);
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
if packets.is_empty() {
|
if packets.is_empty() {
|
||||||
@ -2413,8 +2424,10 @@ impl ClusterInfo {
|
|||||||
inc_new_counter_debug!("cluster_info-push_message-pushes", new_push_requests.len());
|
inc_new_counter_debug!("cluster_info-push_message-pushes", new_push_requests.len());
|
||||||
for (address, request) in new_push_requests {
|
for (address, request) in new_push_requests {
|
||||||
if ContactInfo::is_valid_address(&address) {
|
if ContactInfo::is_valid_address(&address) {
|
||||||
let packet = Packet::from_data(&address, &request);
|
match Packet::from_data(&address, &request) {
|
||||||
packets.packets.push(packet);
|
Ok(packet) => packets.packets.push(packet),
|
||||||
|
Err(err) => error!("failed to write push-request packet: {:?}", err),
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
trace!("Dropping Gossip push response, as destination is unknown");
|
trace!("Dropping Gossip push response, as destination is unknown");
|
||||||
}
|
}
|
||||||
|
@ -39,12 +39,10 @@ impl Packet {
|
|||||||
Self { data, meta }
|
Self { data, meta }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_data<T: Serialize>(dest: &SocketAddr, data: T) -> Self {
|
pub fn from_data<T: Serialize>(dest: &SocketAddr, data: T) -> Result<Self> {
|
||||||
let mut me = Packet::default();
|
let mut packet = Packet::default();
|
||||||
if let Err(e) = Self::populate_packet(&mut me, Some(dest), &data) {
|
Self::populate_packet(&mut packet, Some(dest), &data)?;
|
||||||
logger::error!("Couldn't write to packet {:?}. Data skipped.", e);
|
Ok(packet)
|
||||||
}
|
|
||||||
me
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn populate_packet<T: Serialize>(
|
pub fn populate_packet<T: Serialize>(
|
||||||
|
Reference in New Issue
Block a user