Skip to content

Commit 69094ff

Browse files
committed
cleanup 🧹
1 parent 39cc015 commit 69094ff

File tree

3 files changed

+312
-368
lines changed

3 files changed

+312
-368
lines changed

consensus/src/marshal/actor.rs

Lines changed: 15 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -325,23 +325,13 @@ impl<
325325
let round = notarization.round();
326326
let commitment = notarization.proposal.payload;
327327

328-
// Block on waiting for the block to be reconstructed; We cannot move forward without
329-
// having the block digest.
330-
while !shard_layer.has_digest(&commitment).await {
331-
dbg!("spinning");
332-
shard_layer.try_reconstruct(commitment).await.expect("Reconstruction error not yet handled");
333-
}
334-
335-
// Request the block digest for the block corresponding to the coding commitment.
336-
let digest = shard_layer.get_digest(&commitment).await.unwrap();
337-
338328
// Store notarization by view
339-
self.cache.put_notarization(round, digest, notarization.clone()).await;
329+
self.cache.put_notarization(round, commitment, notarization.clone()).await;
340330

341331
// Search for block locally, otherwise fetch it remotely
342-
if let Some(block) = self.find_block(&mut shard_layer, digest).await {
332+
if let Some(block) = self.find_block(&mut shard_layer, commitment).await {
343333
// If found, persist the block
344-
self.cache_block(round, digest, block).await;
334+
self.cache_block(round, commitment, block).await;
345335
} else {
346336
debug!(?round, "notarized block missing");
347337
resolver.fetch(Request::<B>::Notarized { round }).await;
@@ -360,28 +350,18 @@ impl<
360350
let round = finalization.round();
361351
let commitment = finalization.proposal.payload;
362352

363-
// Block on waiting for the block to be reconstructed; We cannot move forward without
364-
// having the block digest.
365-
while !shard_layer.has_digest(&commitment).await {
366-
dbg!("spinning");
367-
shard_layer.try_reconstruct(commitment).await.expect("Reconstruction error not yet handled");
368-
}
369-
370-
// Request the block digest for the block corresponding to the coding commitment.
371-
let digest = shard_layer.get_digest(&commitment).await.unwrap();
372-
373-
self.cache.put_finalization(round, digest, finalization.clone()).await;
353+
self.cache.put_finalization(round, commitment, finalization.clone()).await;
374354

375355
// Search for block locally, otherwise fetch it remotely
376-
if let Some(block) = self.find_block(&mut shard_layer, digest).await {
356+
if let Some(block) = self.find_block(&mut shard_layer, commitment).await {
377357
// If found, persist the block
378358
let height = block.height();
379-
self.finalize(height, digest, block, Some(finalization), &mut notifier_tx).await;
359+
self.finalize(height, commitment, block, Some(finalization), &mut notifier_tx).await;
380360
debug!(?round, height, "finalized block stored");
381361
} else {
382362
// Otherwise, fetch the block from the network.
383-
debug!(?round, ?digest, "finalized block missing");
384-
resolver.fetch(Request::<B>::Block(digest)).await;
363+
debug!(?round, ?commitment, "finalized block missing");
364+
resolver.fetch(Request::<B>::Block(commitment)).await;
385365
}
386366
}
387367
Message::Get { commitment, response } => {
@@ -492,6 +472,11 @@ impl<
492472
// Iterate backwards, repairing blocks as we go.
493473
while cursor.height() > height {
494474
let commitment = cursor.parent();
475+
let Some(commitment) = shard_layer.get_digest(&commitment).await else {
476+
dbg!("Missing block digest");
477+
break;
478+
};
479+
495480
if let Some(block) = self.find_block(&mut shard_layer, commitment).await {
496481
let finalization = self.cache.get_finalization_for(commitment).await;
497482
self.finalize(block.height(), commitment, block.clone(), finalization, &mut notifier_tx).await;
@@ -559,15 +544,7 @@ impl<
559544

560545
// Get block
561546
let commitment = notarization.proposal.payload;
562-
let digest = match shard_layer.get_digest(&commitment).await {
563-
Some(digest) => digest,
564-
None => {
565-
debug!(?commitment, "notarized block missing commitment mapping on request");
566-
continue;
567-
}
568-
};
569-
570-
let Some(block) = self.find_block(&mut shard_layer, digest).await else {
547+
let Some(block) = self.find_block(&mut shard_layer, commitment).await else {
571548
debug!(?commitment, "block missing on request");
572549
continue;
573550
};
@@ -760,7 +737,7 @@ impl<
760737
) -> Option<B> {
761738
// Check shard layer.
762739
if let Some(block) = shards
763-
.block_by_digest(commitment)
740+
.try_reconstruct(commitment)
764741
.await
765742
.expect("reconstruction error not yet handled")
766743
{

consensus/src/marshal/ingress/coding.rs

Lines changed: 9 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ where
7575
block_codec_cfg: B::Cfg,
7676

7777
/// Map of block digests -> coding commitments.
78-
commitment_map: prunable::Archive<TwoCap, E, H::Digest, H::Digest>,
79-
80-
/// Map of coding commitments -> block digests.
8178
digest_map: prunable::Archive<TwoCap, E, H::Digest, H::Digest>,
8279
}
8380

@@ -105,18 +102,13 @@ where
105102
replay_buffer: cfg.replay_buffer,
106103
write_buffer: cfg.write_buffer,
107104
};
108-
let commitment_map =
109-
prunable::Archive::init(context.with_label("commitment-map"), cfg("commitment"))
110-
.await
111-
.unwrap_or_else(|_| panic!("Failed to initialize commitment archive"));
112105
let digest_map = prunable::Archive::init(context.with_label("digest-map"), cfg("digest"))
113106
.await
114107
.unwrap_or_else(|_| panic!("Failed to initialize digest archive"));
115108

116109
Self {
117110
mailbox,
118111
block_codec_cfg,
119-
commitment_map,
120112
digest_map,
121113
}
122114
}
@@ -186,12 +178,8 @@ where
186178
// Attempt to decode the block from the recovered data.
187179
let block = B::decode_cfg(&mut recovered.as_slice(), &self.block_codec_cfg)?;
188180

189-
self.commitment_map
190-
.put(block.height(), commitment, block.digest())
191-
.await
192-
.expect("failed to put commitment");
193181
self.digest_map
194-
.put(block.height(), block.digest(), commitment)
182+
.put(block.height(), commitment, block.digest())
195183
.await
196184
.expect("failed to put digest");
197185

@@ -213,45 +201,20 @@ where
213201
todo!("Subscribe to all chunks, reconstruct block when enough are available.");
214202
}
215203

216-
/// Attempts to fetch a reconstructed [Block] by its digest.
217-
pub async fn block_by_digest(
218-
&mut self,
219-
digest: B::Digest,
220-
) -> Result<Option<B>, ReconstructionError> {
221-
match self
222-
.digest_map
223-
.get(Identifier::Key(&digest))
224-
.await
225-
.expect("failed to get digest")
226-
{
227-
Some(commitment) => self.try_reconstruct(commitment).await,
228-
None => Ok(None),
229-
}
230-
}
231-
232-
/// Checks if the shard layer has the digest corresponding to a given coding commitment.
233-
pub async fn has_digest(&self, commitment: &B::Commitment) -> bool {
234-
self.commitment_map
235-
.has(Identifier::Key(commitment))
236-
.await
237-
.expect("failed to get commitment")
238-
}
239-
240-
/// Gets the digest corresponding to a given coding commitment, if known.
241-
pub async fn get_digest(&self, commitment: &B::Commitment) -> Option<B::Digest> {
242-
self.commitment_map
204+
/// Gets the block digest for a block with the given coding commitment, if known.
205+
pub async fn get_digest(&mut self, commitment: &B::Commitment) -> Option<B::Digest> {
206+
self.digest_map
243207
.get(Identifier::Key(commitment))
244208
.await
245-
.expect("failed to get commitment")
209+
.expect("failed to get digest")
246210
}
247211

248212
/// Prunes old entries from the internal maps.
249213
pub async fn prune(&mut self, up_to: u64) {
250-
futures::try_join!(
251-
self.commitment_map.prune(up_to),
252-
self.digest_map.prune(up_to)
253-
)
254-
.expect("failed to prune maps");
214+
self.digest_map
215+
.prune(up_to)
216+
.await
217+
.expect("failed to prune maps");
255218
}
256219
}
257220

0 commit comments

Comments
 (0)