From 415736a6ed2f93e4156462016efb5b6251987bd5 Mon Sep 17 00:00:00 2001 From: Josh Wilson Date: Wed, 19 Jun 2024 14:32:08 +0900 Subject: [PATCH] chore: update naming for clarity around replication --- sn_networking/src/event/request_response.rs | 4 +++- sn_networking/src/replication_fetcher.rs | 1 + sn_node/src/put_validation.rs | 14 +++++++++----- sn_node/src/replication.rs | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/sn_networking/src/event/request_response.rs b/sn_networking/src/event/request_response.rs index e0f102a9d1..5e6e50c820 100644 --- a/sn_networking/src/event/request_response.rs +++ b/sn_networking/src/event/request_response.rs @@ -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 = @@ -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 diff --git a/sn_networking/src/replication_fetcher.rs b/sn_networking/src/replication_fetcher.rs index bc1b1d270f..fb206973f2 100644 --- a/sn_networking/src/replication_fetcher.rs +++ b/sn_networking/src/replication_fetcher.rs @@ -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, diff --git a/sn_node/src/put_validation.rs b/sn_node/src/put_validation.rs index 931c827526..0b97131c25 100644 --- a/sn_node/src/put_validation.rs +++ b/sn_node/src/put_validation.rs @@ -86,7 +86,9 @@ impl Node { let record_key = record.key.clone(); let value_to_hash = record.value.clone(); let spends = try_deserialize_record::>(&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); @@ -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 { - trace!("Storing prepaid record {:?}", record.key); + pub(crate) async fn store_replicated_in_record(&self, record: Record) -> Result { + 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 @@ -193,7 +195,8 @@ impl Node { RecordKind::Spend => { let record_key = record.key.clone(); let spends = try_deserialize_record::>(&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::(&record)?; @@ -322,7 +325,8 @@ impl Node { } /// Validate and store `Vec` 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, record_key: &RecordKey, diff --git a/sn_node/src/replication.rs b/sn_node/src/replication.rs index d5e0c1bee9..ee0796951a 100644 --- a/sn_node/src/replication.rs +++ b/sn_node/src/replication.rs @@ -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:?}" );