Skip to content

Commit

Permalink
chore: update naming for clarity around replication
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuef committed Jun 19, 2024
1 parent 58defbc commit 415736a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
4 changes: 3 additions & 1 deletion sn_networking/src/event/request_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ impl SwarmDriver {
// fetch them if close enough to us
// 2, For those keys that we have and supposed to be held by the sender as well:
// start chunk_proof check against a randomly selected chunk type record to the sender
// 3, For those spends that we have that differ in the hash, we fetch the other version
// and update our local copy.

// For fetching, only handle those non-exist and in close range keys
let keys_to_store =
Expand Down Expand Up @@ -272,7 +274,7 @@ impl SwarmDriver {
if let Some((_, local_record_type)) = local {
let not_same_type = local_record_type != record_type;
if not_same_type {
// Shall only happens for Register
// Shall only happens for Register, or DoubleSpendAttempts
info!("Record {addr:?} has different type: local {local_record_type:?}, incoming {record_type:?}");
}
not_same_type
Expand Down
1 change: 1 addition & 0 deletions sn_networking/src/replication_fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ impl ReplicationFetcher {
}

/// Remove keys that we hold already and no longer need to be replicated.
/// This checks the hash on spends to ensure we pull in divergent spends.
fn remove_stored_keys(
&mut self,
existing_keys: &HashMap<RecordKey, (NetworkAddress, RecordType)>,
Expand Down
14 changes: 9 additions & 5 deletions sn_node/src/put_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ impl Node {
let record_key = record.key.clone();
let value_to_hash = record.value.clone();
let spends = try_deserialize_record::<Vec<SignedSpend>>(&record)?;
let result = self.validate_and_store_spends(spends, &record_key).await;
let result = self
.validate_merge_and_store_spends(spends, &record_key)
.await;
if result.is_ok() {
Marker::ValidSpendPutFromClient(&PrettyPrintRecordKey::from(&record_key)).log();
let content_hash = XorName::from_content(&value_to_hash);
Expand Down Expand Up @@ -162,8 +164,8 @@ impl Node {
}

/// Store a pre-validated, and already paid record to the RecordStore
pub(crate) async fn store_prepaid_record(&self, record: Record) -> Result<CmdOk> {
trace!("Storing prepaid record {:?}", record.key);
pub(crate) async fn store_replicated_in_record(&self, record: Record) -> Result<CmdOk> {
trace!("Storing record which was replicated to us {:?}", record.key);
let record_header = RecordHeader::from_record(&record)?;
match record_header.kind {
// A separate flow handles payment for chunks and registers
Expand Down Expand Up @@ -193,7 +195,8 @@ impl Node {
RecordKind::Spend => {
let record_key = record.key.clone();
let spends = try_deserialize_record::<Vec<SignedSpend>>(&record)?;
self.validate_and_store_spends(spends, &record_key).await
self.validate_merge_and_store_spends(spends, &record_key)
.await
}
RecordKind::Register => {
let register = try_deserialize_record::<SignedRegister>(&record)?;
Expand Down Expand Up @@ -322,7 +325,8 @@ impl Node {
}

/// Validate and store `Vec<SignedSpend>` to the RecordStore
pub(crate) async fn validate_and_store_spends(
/// If we already have a spend at this address, the Vec is extended and stored.
pub(crate) async fn validate_merge_and_store_spends(
&self,
signed_spends: Vec<SignedSpend>,
record_key: &RecordKey,
Expand Down
2 changes: 1 addition & 1 deletion sn_node/src/replication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl Node {
trace!(
"Got Replication Record {pretty_key:?} from network, validating and storing it"
);
let result = node.store_prepaid_record(record).await?;
let result = node.store_replicated_in_record(record).await?;
trace!(
"Completed storing Replication Record {pretty_key:?} from network, result: {result:?}"
);
Expand Down

0 comments on commit 415736a

Please sign in to comment.