Skip to content

Commit 3d7adee

Browse files
authored
feat(starfish): evict shards (#8781)
# Description of change PR adds eviction for recent_shards and makes some refactoring of evicting headers. ## Links to any relevant issues ## How the change has been tested - [x] Basic tests (linting, compilation, formatting, unit/integration tests) - [ ] Patch-specific tests (correctness, functionality coverage) - [ ] 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
1 parent 514e4b1 commit 3d7adee

File tree

1 file changed

+32
-19
lines changed

1 file changed

+32
-19
lines changed

crates/starfish/core/src/dag_state.rs

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,6 +1326,34 @@ impl DagState {
13261326
votes
13271327
}
13281328

1329+
/// Clean up old cached data for each authority, all cached blocks
1330+
/// are guaranteed to be persisted. Used after flushing.
1331+
pub(crate) fn evict_headers(&mut self) {
1332+
for (authority_index, _) in self.context.committee.authorities() {
1333+
let eviction_round = self.calculate_authority_eviction_round(authority_index);
1334+
let recent_refs = &mut self.recent_headers_refs_by_authority[authority_index];
1335+
1336+
// Evict everything below split_key
1337+
let split_key =
1338+
BlockRef::new(eviction_round + 1, authority_index, BlockHeaderDigest::MIN);
1339+
1340+
let to_keep = recent_refs.split_off(&split_key);
1341+
let evicted = std::mem::replace(recent_refs, to_keep);
1342+
1343+
// Remove evicted headers from recent_block_headers
1344+
for block_ref in &evicted {
1345+
self.recent_block_headers.remove(block_ref);
1346+
}
1347+
self.evicted_rounds[authority_index] = eviction_round;
1348+
}
1349+
}
1350+
1351+
/// Clean up old shards. Used after flushing.
1352+
pub(crate) fn evict_shards(&mut self) {
1353+
self.recent_shards
1354+
.retain(|block_ref, _| block_ref.round > self.evicted_rounds[block_ref.author]);
1355+
}
1356+
13291357
/// Function removes stalled transactions that are older than
13301358
/// "last consume leader round minus MAX_TRANSACTIONS_ACK_DEPTH minus
13311359
/// MAX_LINEARIZER_DEPTH"
@@ -1541,26 +1569,11 @@ impl DagState {
15411569
.dag_state_store_write_count
15421570
.inc();
15431571

1544-
// Clean up old cached data for each authority after flushing, all cached blocks
1545-
// are guaranteed to be persisted.
1546-
for (authority_index, _) in self.context.committee.authorities() {
1547-
let eviction_round = self.calculate_authority_eviction_round(authority_index);
1548-
let recent_refs = &mut self.recent_headers_refs_by_authority[authority_index];
1549-
1550-
// Evict everything below split_key
1551-
let split_key =
1552-
BlockRef::new(eviction_round + 1, authority_index, BlockHeaderDigest::MIN);
1572+
// Clean up old headers
1573+
self.evict_headers();
15531574

1554-
let to_keep = recent_refs.split_off(&split_key);
1555-
let evicted = std::mem::replace(recent_refs, to_keep);
1556-
1557-
// Remove evicted headers from recent_block_headers
1558-
for block_ref in &evicted {
1559-
self.recent_block_headers.remove(block_ref);
1560-
}
1561-
1562-
self.evicted_rounds[authority_index] = eviction_round;
1563-
}
1575+
// Evict old shards
1576+
self.evict_shards();
15641577

15651578
// Clean up old transactions depending on the last solid leader round.
15661579
self.evict_transactions();

0 commit comments

Comments
 (0)