Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
fix: fixing review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Paitrault <[email protected]>
  • Loading branch information
Freyskeyd committed Feb 7, 2024
1 parent f6ffc46 commit bf3e1c3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
4 changes: 2 additions & 2 deletions crates/topos-tce-storage/src/tests/checkpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async fn get_checkpoint_diff_with_no_input(store: Arc<ValidatorStore>) {
}

let checkpoint = store
.get_checkpoint_diff(vec![])
.get_checkpoint_diff(&[])
.unwrap()
.into_iter()
.map(|(subnet, proofs)| {
Expand Down Expand Up @@ -97,7 +97,7 @@ async fn get_checkpoint_diff_with_input(store: Arc<ValidatorStore>) {
}

let checkpoint = store
.get_checkpoint_diff(vec![checkpoint])
.get_checkpoint_diff(&[checkpoint])
.unwrap()
.into_iter()
.map(|(subnet, proofs)| {
Expand Down
28 changes: 18 additions & 10 deletions crates/topos-tce-storage/src/validator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use topos_core::{
},
uci::{Certificate, CertificateId, SubnetId, INITIAL_CERTIFICATE_ID},
};
use tracing::{debug, info, instrument};
use tracing::{debug, error, info, instrument};

use crate::{
errors::{InternalStorageError, StorageError},
Expand Down Expand Up @@ -336,14 +336,17 @@ impl ValidatorStore {

pub fn get_checkpoint_diff(
&self,
from: Vec<ProofOfDelivery>,
from: &[ProofOfDelivery],
) -> Result<HashMap<SubnetId, Vec<ProofOfDelivery>>, StorageError> {
// Parse the from in order to extract the different position per subnets
let mut from_positions: HashMap<SubnetId, Vec<ProofOfDelivery>> = from
.into_iter()
.map(|v| (v.delivery_position.subnet_id, vec![v]))
let from_positions: HashMap<SubnetId, &ProofOfDelivery> = from
.iter()
.map(|v| (v.delivery_position.subnet_id, v))
.collect();

let mut output: HashMap<SubnetId, Vec<ProofOfDelivery>> =
from_positions.iter().map(|(s, _)| (*s, vec![])).collect();

// Request the local head checkpoint
let subnets: HashMap<SubnetId, Position> = self
.fullnode_store
Expand All @@ -356,9 +359,7 @@ impl ValidatorStore {
// For every local known subnets we want to iterate and check if there
// is a delta between the from_position and our head position.
for (subnet, local_position) in subnets {
let entry = from_positions.entry(subnet).or_default();

let certs: Vec<_> = if let Some(position) = entry.pop() {
let certs: Vec<_> = if let Some(position) = from_positions.get(&subnet) {
if local_position <= position.delivery_position.position {
continue;
}
Expand Down Expand Up @@ -393,10 +394,17 @@ impl ValidatorStore {
subnet,
proofs.len()
);
entry.extend_from_slice(&proofs[..]);

if let Some(old_value) = output.insert(subnet, proofs) {
error!(
"Certificate Sync: This should not happen, we are overwriting a value during \
sync of {subnet}. Overwriting {}",
old_value.len()
);
}
}

Ok(from_positions)
Ok(output)
}

#[cfg(test)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,10 @@ impl CheckpointSynchronizer {
let len = proofs.len();
let unverified_certs = self.store.insert_unverified_proofs(proofs)?;

debug!("Persist {} unverified proofs for {}", len, subnet);
debug!(
"Persist {} unverified proof of delivery for {}",
len, subnet
);
certs.extend(&unverified_certs[..]);
}

Expand Down
2 changes: 1 addition & 1 deletion crates/topos-tce-synchronizer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ impl GrpcSynchronizerService for SynchronizerService {

debug!("Request {} contains {} proof_of_delivery", id, res.len());
trace!("Request {} contains {:?}", id, res);
let diff = match self.validator_store.get_checkpoint_diff(res) {
let diff = match self.validator_store.get_checkpoint_diff(&res) {
Ok(diff) => {
debug!(
"Fetched checkpoint diff from storage for request {}, got {:?}",
Expand Down

0 comments on commit bf3e1c3

Please sign in to comment.