Skip to content

Commit

Permalink
fix: client carry out merge when verify register storage
Browse files Browse the repository at this point in the history
  • Loading branch information
maqi authored and joshuef committed Oct 26, 2023
1 parent c7b7f12 commit ad104d5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 19 deletions.
18 changes: 3 additions & 15 deletions sn_client/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ impl Client {
.await;
let record = match maybe_record {
Ok(r) => r,
Err(NetworkError::SplitRecord(map)) => {
return merge_split_register_records(address, &map)
Err(NetworkError::SplitRecord { result_map }) => {
return merge_split_register_records(address, &result_map)
}
Err(e) => {
warn!("Failed to get record at {address:?} from the network: {e:?}");
Expand Down Expand Up @@ -442,19 +442,7 @@ impl Client {
/// Verify if a `Register` is stored by expected nodes on the network.
pub async fn verify_register_stored(&self, address: RegisterAddress) -> Result<SignedRegister> {
info!("Verifying register: {address:?}");
let key = NetworkAddress::from_register_address(address).to_record_key();
let record = self
.network
.get_record_from_network(key, None, GetQuorum::All, false, Default::default())
.await?;

let header = RecordHeader::from_record(&record)?;
if let RecordKind::Register = header.kind {
let register = get_register_from_record(record)?;
Ok(register)
} else {
Err(ProtocolError::RecordKindMismatch(RecordKind::Register).into())
}
self.get_signed_register_from_network(address).await
}

/// Send a `SpendCashNote` request to the network
Expand Down
7 changes: 5 additions & 2 deletions sn_networking/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,11 @@ pub enum Error {
#[error("Gossipsub subscribe Error: {0}")]
GossipsubSubscriptionError(#[from] SubscriptionError),

#[error("Split Record: {0:?}")]
SplitRecord(HashMap<XorName, (Record, HashSet<PeerId>)>),
// Avoid logging the whole `Record` content by accident
#[error("Split Record has {} different copies", result_map.len())]
SplitRecord {
result_map: HashMap<XorName, (Record, HashSet<PeerId>)>,
},

#[error("Record header is incorrect")]
InCorrectRecordHeader,
Expand Down
2 changes: 1 addition & 1 deletion sn_networking/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,7 @@ impl SwarmDriver {
let _ = sender.send(result);
} else {
debug!("For record {pretty_key:?} task {query_id:?}, fetch completed with split record");
let _ = sender.send(Err(Error::SplitRecord(result_map)));
let _ = sender.send(Err(Error::SplitRecord { result_map }));
}
} else {
let _ = self
Expand Down
3 changes: 2 additions & 1 deletion sn_networking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,8 @@ impl Network {
warn!("No holder of record '{pretty_key:?}' found. Retrying the fetch ...",);
}
Err(error) => {
error!("{error:?}");
error!("Getting record {pretty_key:?} attempts #{verification_attempts}/{total_attempts} , encountered {error:?}");

if verification_attempts >= total_attempts {
break;
}
Expand Down

0 comments on commit ad104d5

Please sign in to comment.