Skip to content

Commit

Permalink
Add BlockHeight and ChainId to BlobState. (#2879)
Browse files Browse the repository at this point in the history
* Add the block_height and the chain_id to the BlobState.
* Remove one expensive `read_certificates` call from `updater.rs`.
  • Loading branch information
MathieuDutSik authored Nov 13, 2024
1 parent 484471c commit 419f9ca
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 2 additions & 0 deletions linera-core/src/chain_worker/state/attempted_changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ where
// Update the blob state with last used certificate hash.
let blob_state = BlobState {
last_used_by: certificate_hash,
chain_id: block.chain_id,
block_height,
epoch: block.epoch,
};
self.state
Expand Down
10 changes: 3 additions & 7 deletions linera-core/src/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,14 +292,10 @@ where
.await;
let local_storage = self.local_node.storage_client();
let blob_states = local_storage.read_blob_states(&missing_blob_ids).await?;
let certificates = local_storage
.read_certificates(blob_states.into_iter().map(|x| x.last_used_by))
.await?;
let mut chain_heights = BTreeMap::new();
for certificate in certificates {
let block_chain_id = certificate.executed_block().block.chain_id;
let block_height =
certificate.executed_block().block.height.try_add_one()?;
for blob_state in blob_states {
let block_chain_id = blob_state.chain_id;
let block_height = blob_state.block_height.try_add_one()?;
chain_heights
.entry(block_chain_id)
.and_modify(|h| *h = block_height.max(*h))
Expand Down
4 changes: 4 additions & 0 deletions linera-execution/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,10 @@ impl From<Vec<u8>> for Response {
pub struct BlobState {
/// Hash of the last `Certificate` that published or used this blob.
pub last_used_by: CryptoHash,
/// The `ChainId` of the chain that published the change
pub chain_id: ChainId,
/// The `BlockHeight` of the chain that published the change
pub block_height: BlockHeight,
/// Epoch of the `last_used_by` certificate.
pub epoch: Epoch,
}
Expand Down

0 comments on commit 419f9ca

Please sign in to comment.