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

feat(node): remove outdated un-decryptable record copies #2370

Merged
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
30 changes: 28 additions & 2 deletions sn_networking/src/record_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,22 @@ impl NodeRecordStore {
let record = match fs::read(path) {
Ok(bytes) => {
// and the stored record
Self::get_record_from_bytes(bytes, &key, encryption_details)?
if let Some(record) =
Self::get_record_from_bytes(bytes, &key, encryption_details)
{
record
} else {
// This will be due to node restart, result in different encrypt_detail.
// Hence need to clean up the old copy.
info!("Failed to decrypt record from file {filename:?}, clean it up.");
if let Err(e) = fs::remove_file(path) {
warn!(
"Failed to remove outdated record file {filename:?} from storage dir: {:?}",
e
);
}
return None;
}
}
Err(err) => {
error!("Error while reading file. filename: {filename}, error: {err:?}");
Expand All @@ -198,7 +213,18 @@ impl NodeRecordStore {
RecordType::NonChunk(xorname_hash)
}
Err(error) => {
warn!("Failed to parse record type from record: {:?}", error);
warn!(
"Failed to parse record type of record {filename:?}: {:?}",
error
);
// In correct decryption using different key could result in this.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// In correct decryption using different key could result in this.
// Incorrect decryption using different key could result in this.

// In that case, a cleanup shall be carried out.
if let Err(e) = fs::remove_file(path) {
warn!(
"Failed to remove invalid record file {filename:?} from storage dir: {:?}",
e
);
}
return None;
}
};
Expand Down
Loading