Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix put record event handling in case of an error #742

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 1.0.4

- Fix put record metric event in case of errors
- Fix telemetry naming, put project name as prefix instead of suffix
- Add timeouts to RPC subscriptions
- Integrate upstream `rust-libp2p` `0.54` changes to the bootstrap process
Expand Down
11 changes: 5 additions & 6 deletions core/src/network/p2p/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use libp2p::{
use std::time::{Duration, Instant};
use sysinfo::System;
use tokio::sync::{mpsc::UnboundedSender, oneshot};
use tracing::{debug, info, trace};
use tracing::{debug, info, trace, warn};

use super::{
event_loop::ConnectionEstablishedInfo, is_global, is_multiaddr_global, Command, EventLoop,
Expand Down Expand Up @@ -195,11 +195,10 @@ impl Client {
self.command_sender
.send(Box::new(move |context: &mut EventLoop| {
for record in records.clone() {
let _ = context
.swarm
.behaviour_mut()
.kademlia
.put_record(record, quorum);
let kademlia = &mut context.swarm.behaviour_mut().kademlia;
if let Err(error) = kademlia.put_record(record, quorum) {
warn!("Put record failed: {error}");
}
}

context
Expand Down
10 changes: 2 additions & 8 deletions core/src/network/p2p/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,16 +308,12 @@ impl EventLoop {
_ => (),
},
QueryResult::PutRecord(Err(error)) => {
if self.pending_kad_queries.remove(&id).is_none() {
return;
};

match error {
kad::PutRecordError::QuorumFailed { key, .. }
| kad::PutRecordError::Timeout { key, .. } => {
// Remove local records for fat clients (memory optimization)
if self.event_loop_config.is_fat_client {
debug!("Pruning local records on fat client");
trace!("Pruning local records on fat client");
self.swarm.behaviour_mut().kademlia.remove_record(&key);
}

Expand All @@ -330,11 +326,9 @@ impl EventLoop {
},

QueryResult::PutRecord(Ok(PutRecordOk { key })) => {
_ = self.pending_kad_queries.remove(&id);

// Remove local records for fat clients (memory optimization)
if self.event_loop_config.is_fat_client {
debug!("Pruning local records on fat client");
trace!("Pruning local records on fat client");
self.swarm.behaviour_mut().kademlia.remove_record(&key);
}

Expand Down
Loading