Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/stefan/send_pws' into stefan/sen…
Browse files Browse the repository at this point in the history
…dpwsbigwitness
  • Loading branch information
stedfn committed Dec 17, 2024
2 parents f9c3ff4 + 7270abb commit 243fb07
Showing 1 changed file with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,14 @@ impl PartialWitnessActor {
}

// Function to generate the parts of the state witness and return them as a tuple of chunk_validator and part.
fn generate_state_witness_parts(
fn generate_and_send_state_witness_parts(
&mut self,
epoch_id: EpochId,
chunk_header: &ShardChunkHeader,
witness_bytes: EncodedChunkStateWitness,
chunk_validators: &[AccountId],
signer: &ValidatorSigner,
) -> Result<Vec<(AccountId, PartialEncodedStateWitness)>, Error> {
) -> Result<(), Error> {
tracing::debug!(
target: "client",
chunk_hash=?chunk_header.chunk_hash(),
Expand All @@ -268,11 +268,8 @@ impl PartialWitnessActor {
let encoder = self.witness_encoders.entry(chunk_validators.len());
let (parts, encoded_length) = encoder.encode(&witness_bytes);

Ok(chunk_validators
.iter()
.zip_eq(parts)
.enumerate()
.map(|(part_ord, (chunk_validator, part))| {
chunk_validators.iter().zip_eq(parts).enumerate().for_each(
|(part_ord, (chunk_validator, part))| {
// It's fine to unwrap part here as we just constructed the parts above and we expect
// all of them to be present.
let partial_witness = PartialEncodedStateWitness::new(
Expand All @@ -283,9 +280,16 @@ impl PartialWitnessActor {
encoded_length,
signer,
);
(chunk_validator.clone(), partial_witness)
})
.collect_vec())
let validator_witness_tuple = (chunk_validator.clone(), partial_witness);

// Send the parts to the corresponding chunk validator owners.
self.network_adapter.send(PeerManagerMessageRequest::NetworkRequests(
NetworkRequests::PartialEncodedStateWitness(vec![validator_witness_tuple]),
));
},
);

Ok(())
}

fn generate_contract_deploys_parts(
Expand Down Expand Up @@ -340,10 +344,11 @@ impl PartialWitnessActor {

// Record time taken to encode the state witness parts.
let shard_id_label = chunk_header.shard_id().to_string();

let encode_timer = metrics::PARTIAL_WITNESS_ENCODE_TIME
.with_label_values(&[shard_id_label.as_str()])
.start_timer();
let validator_witness_tuple = self.generate_state_witness_parts(
self.generate_and_send_state_witness_parts(
epoch_id,
chunk_header,
witness_bytes,
Expand All @@ -357,13 +362,9 @@ impl PartialWitnessActor {
self.state_witness_tracker.record_witness_sent(
chunk_hash,
witness_size_in_bytes,
validator_witness_tuple.len(),
chunk_validators.len(),
);

// Send the parts to the corresponding chunk validator owners.
self.network_adapter.send(PeerManagerMessageRequest::NetworkRequests(
NetworkRequests::PartialEncodedStateWitness(validator_witness_tuple),
));
Ok(())
}

Expand Down

0 comments on commit 243fb07

Please sign in to comment.