Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
romac committed Jun 18, 2024
1 parent f4ffe9a commit 38d1790
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 22 deletions.
26 changes: 9 additions & 17 deletions code/crates/starknet-host/src/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,27 +68,19 @@ impl StarknetHost {
return None;
}

let last_part = block_parts.last().expect("block_parts is not empty");

let mut block_hasher = sha2::Sha256::new();
let mut metadata = None;

for block_part in block_parts {
match block_part.part.as_ref() {
ProposalPart::TxBatch(_, tx_batch) => {
// Compute the expected block hash/value from the block parts.
tx_batch.transactions().iter().for_each(|tx| {
block_hasher.update(tx.as_bytes());
});
}
// All block parts should have been received, including the metadata that has the block hash/value.
ProposalPart::Metadata(_, meta) => {
metadata = Some(meta.clone());
}
if let ProposalPart::TxBatch(_, tx_batch) = block_part.part.as_ref() {
// Compute the expected block hash/value from the block parts.
tx_batch.transactions().iter().for_each(|tx| {
block_hasher.update(tx.as_bytes());
});
}
}

let Some(metadata) = metadata else {
let last_part = block_parts.last().expect("block_parts is not empty");

let Some(metadata) = last_part.metadata() else {
error!("Block is missing metadata");
return None;
};
Expand All @@ -103,7 +95,7 @@ impl StarknetHost {
Validity::Valid
};

let content = ProposalContent::new(metadata);
let content = ProposalContent::new(metadata.clone());
Some((content, last_part.validator_address, valid))
}

Expand Down
6 changes: 1 addition & 5 deletions code/crates/starknet-host/src/mock/types/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,13 @@ impl ProposalContent {
pub fn block_hash(&self) -> BlockHash {
self.metadata.hash
}

pub fn size_bytes(&self) -> usize {
self.metadata.size_bytes()
}
}

impl common::Value for ProposalContent {
type Id = BlockHash;

fn id(&self) -> Self::Id {
self.metadata.hash
self.block_hash()
}
}

Expand Down

0 comments on commit 38d1790

Please sign in to comment.