Skip to content

Commit b5f016f

Browse files
authored
cleanup(consensus): remove linearizer_v2 (#6551)
# Description of change This PR removes linearizer_v2. Linearizer_v2 works only when gc is enabled. We removed gc, so linearizer v2 is also removed. ## Links to any relevant issues Be sure to reference any related issues by adding `fixes #(issue)`. ## Type of change Cleanup ## How the change has been tested CI ## Change checklist Tick the boxes that are relevant to your changes, and delete any items that are not. - [x] I have followed the contribution guidelines for this project - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] I have added tests that prove my fix is effective or that my feature works - [x] I have checked that new and existing unit tests pass locally with my changes ### Release Notes - [ ] Protocol: - [ ] Nodes (Validators and Full nodes): - [ ] Indexer: - [ ] JSON-RPC: - [ ] GraphQL: - [ ] CLI: - [ ] Rust SDK: - [ ] REST API:
1 parent 9cd31c8 commit b5f016f

File tree

5 files changed

+46
-212
lines changed

5 files changed

+46
-212
lines changed

crates/starfish/core/src/block_header.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ pub struct VerifiedBlockHeader {
513513
digest: BlockHeaderDigest,
514514
serialized: Bytes,
515515
}
516+
516517
impl VerifiedBlockHeader {
517518
/// Creates VerifiedBlockHeader from a verified SignedBlockHeader and its
518519
/// serialized bytes.

crates/starfish/core/src/dag_state.rs

Lines changed: 13 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub(crate) struct DagState {
4848

4949
// Contains recent blocks within CACHED_ROUNDS from the last committed round per authority.
5050
// Note: all uncommitted blocks are kept in memory.
51-
recent_blocks: BTreeMap<BlockRef, BlockInfo>,
51+
recent_blocks: BTreeMap<BlockRef, VerifiedBlockHeader>,
5252

5353
// Indexes recent block refs by their authorities.
5454
// Vec position corresponds to the authority index.
@@ -257,8 +257,7 @@ impl DagState {
257257
/// Updates internal metadata for a block.
258258
fn update_block_metadata(&mut self, block: &VerifiedBlockHeader) {
259259
let block_ref = block.reference();
260-
self.recent_blocks
261-
.insert(block_ref, BlockInfo::new(block.clone()));
260+
self.recent_blocks.insert(block_ref, block.clone());
262261
self.recent_refs_by_authority[block_ref.author].insert(block_ref);
263262
self.threshold_clock.add_block(block_ref);
264263
self.highest_accepted_round = max(self.highest_accepted_round, block.round());
@@ -315,8 +314,8 @@ impl DagState {
315314
}
316315
continue;
317316
}
318-
if let Some(block_info) = self.recent_blocks.get(block_ref) {
319-
blocks[index] = Some(block_info.block.clone());
317+
if let Some(block) = self.recent_blocks.get(block_ref) {
318+
blocks[index] = Some(block.clone());
320319
continue;
321320
}
322321
missing.push((index, block_ref));
@@ -348,31 +347,6 @@ impl DagState {
348347
blocks
349348
}
350349

351-
// Sets the block as committed in the cache. If the block is set as committed
352-
// for first time, then true is returned, otherwise false is returned instead.
353-
// Method will panic if the block is not found in the cache.
354-
pub(crate) fn set_committed(&mut self, block_ref: &BlockRef) -> bool {
355-
if let Some(block_info) = self.recent_blocks.get_mut(block_ref) {
356-
if !block_info.committed {
357-
block_info.committed = true;
358-
return true;
359-
}
360-
false
361-
} else {
362-
panic!(
363-
"Block {:?} not found in cache to set as committed.",
364-
block_ref
365-
);
366-
}
367-
}
368-
369-
pub(crate) fn is_committed(&self, block_ref: &BlockRef) -> bool {
370-
self.recent_blocks
371-
.get(block_ref)
372-
.unwrap_or_else(|| panic!("Attempted to query for commit status for a block not in cached data {block_ref}"))
373-
.committed
374-
}
375-
376350
/// Gets all uncommitted blocks in a slot.
377351
/// Uncommitted blocks must exist in memory, so only in-memory blocks are
378352
/// checked.
@@ -382,7 +356,7 @@ impl DagState {
382356
// to edge cases.
383357

384358
let mut blocks = vec![];
385-
for (_block_ref, block_info) in self.recent_blocks.range((
359+
for (_block_ref, block) in self.recent_blocks.range((
386360
Included(BlockRef::new(
387361
slot.round,
388362
slot.authority,
@@ -394,7 +368,7 @@ impl DagState {
394368
BlockHeaderDigest::MAX,
395369
)),
396370
)) {
397-
blocks.push(block_info.block.clone())
371+
blocks.push(block.clone())
398372
}
399373
blocks
400374
}
@@ -408,7 +382,7 @@ impl DagState {
408382
}
409383

410384
let mut blocks = vec![];
411-
for (_block_ref, block_info) in self.recent_blocks.range((
385+
for (_block_ref, block) in self.recent_blocks.range((
412386
Included(BlockRef::new(
413387
round,
414388
AuthorityIndex::ZERO,
@@ -420,7 +394,7 @@ impl DagState {
420394
BlockHeaderDigest::MIN,
421395
)),
422396
)) {
423-
blocks.push(block_info.block.clone())
397+
blocks.push(block.clone())
424398
}
425399
blocks
426400
}
@@ -480,7 +454,6 @@ impl DagState {
480454
.recent_blocks
481455
.get(last)
482456
.expect("Block should be found in recent blocks")
483-
.block
484457
.clone();
485458
}
486459

@@ -508,11 +481,11 @@ impl DagState {
508481
Included(BlockRef::new(start, authority, BlockHeaderDigest::MIN)),
509482
Unbounded,
510483
)) {
511-
let block_info = self
484+
let block = self
512485
.recent_blocks
513486
.get(block_ref)
514487
.expect("Block should exist in recent blocks");
515-
blocks.push(block_info.block.clone());
488+
blocks.push(block.clone());
516489
}
517490
blocks
518491
}
@@ -547,9 +520,7 @@ impl DagState {
547520
))
548521
.last()?;
549522

550-
self.recent_blocks
551-
.get(block_ref)
552-
.map(|block_info| block_info.block.clone())
523+
self.recent_blocks.get(block_ref).cloned()
553524
}
554525

555526
/// Returns the last block proposed per authority with `evicted round <
@@ -611,11 +582,11 @@ impl DagState {
611582
for block_ref in block_ref_iter {
612583
if last_round == 0 {
613584
last_round = block_ref.round;
614-
let block_info = self
585+
let block = self
615586
.recent_blocks
616587
.get(block_ref)
617588
.expect("Block should exist in recent blocks");
618-
blocks[authority_index] = block_info.block.clone();
589+
blocks[authority_index] = block.clone();
619590
continue;
620591
}
621592
if block_ref.round < last_round {
@@ -1026,22 +997,6 @@ impl DagState {
1026997
self.last_commit = Some(commit);
1027998
}
1028999
}
1029-
1030-
struct BlockInfo {
1031-
block: VerifiedBlockHeader,
1032-
// Whether the block has been committed
1033-
committed: bool,
1034-
}
1035-
1036-
impl BlockInfo {
1037-
fn new(block: VerifiedBlockHeader) -> Self {
1038-
Self {
1039-
block,
1040-
committed: false,
1041-
}
1042-
}
1043-
}
1044-
10451000
#[cfg(test)]
10461001
mod test {
10471002
use std::vec;
@@ -1674,44 +1629,6 @@ mod test {
16741629
assert_eq!(dag_state.scoring_subdags_count(), 5);
16751630
}
16761631

1677-
#[tokio::test]
1678-
async fn test_block_info_as_committed() {
1679-
let num_authorities: u32 = 4;
1680-
let (context, _) = Context::new_for_test(num_authorities as usize);
1681-
let context = Arc::new(context);
1682-
1683-
let store = Arc::new(MemStore::new());
1684-
let mut dag_state = DagState::new(context.clone(), store.clone());
1685-
1686-
// Accept a block
1687-
let block = VerifiedBlockHeader::new_for_test(
1688-
TestBlockHeader::new(1, 0)
1689-
.set_timestamp_ms(1000)
1690-
.set_ancestors(vec![])
1691-
.build(),
1692-
);
1693-
1694-
dag_state.accept_block(block.clone());
1695-
1696-
// Query is committed
1697-
assert!(!dag_state.is_committed(&block.reference()));
1698-
1699-
// Set block as committed for first time should return true
1700-
assert!(
1701-
dag_state.set_committed(&block.reference()),
1702-
"Block should be successfully set as committed for first time"
1703-
);
1704-
1705-
// Now it should appear as committed
1706-
assert!(dag_state.is_committed(&block.reference()));
1707-
1708-
// Trying to set the block as committed again, it should return false.
1709-
assert!(
1710-
!dag_state.set_committed(&block.reference()),
1711-
"Block should not be successfully set as committed"
1712-
);
1713-
}
1714-
17151632
#[tokio::test]
17161633
async fn test_get_cached_blocks() {
17171634
let (mut context, _) = Context::new_for_test(4);

0 commit comments

Comments
 (0)