Skip to content

Commit c38695e

Browse files
authored
feat(consensus): replace gc depth constants with consensus_gc_depth protocol config param (#8786)
# Description of change This PR replaces `MAX_LINEARIZER_DEPTH` and `MAX_TRANSACTIONS_ACK_DEPTH` with `protocol_config` field `consensus_gc_depth` accessed via the `gc_depth()` getter. ## Links to any relevant issues Closes #8379 ## How the change has been tested - [ ] 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 aff9daa commit c38695e

File tree

4 files changed

+25
-31
lines changed

4 files changed

+25
-31
lines changed

crates/starfish/core/src/commit_observer.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ use crate::{
1919
block_header::{BlockHeaderAPI, VerifiedBlockHeader},
2020
commit::{CommitAPI, CommitIndex, PendingSubDag, load_pending_subdag_from_store},
2121
context::Context,
22-
dag_state::{DagState, MAX_TRANSACTIONS_ACK_DEPTH},
22+
dag_state::DagState,
2323
data_manager::DataManager,
2424
error::{ConsensusError, ConsensusResult},
2525
leader_schedule::LeaderSchedule,
26-
linearizer::{Linearizer, MAX_LINEARIZER_DEPTH},
26+
linearizer::Linearizer,
2727
storage::Store,
2828
};
2929

@@ -174,11 +174,11 @@ impl CommitObserver {
174174

175175
// The earliest commit that still might acknowledge not-yet-committed
176176
// transactions that still have a chance of being committed is no higher than
177-
// `last_pending_commit_index - MAX_TRANSACTIONS_ACK_CHECK -
178-
// MAX_LINEARIZER_DEPTH`.
177+
// `last_pending_commit_index - protocol_config.gc_depth() * 2, once for
178+
// max linearizer depth and once for max transaction ack depth.
179179

180180
let commit_index_to_recover_acks =
181-
last_commit_index.saturating_sub(MAX_TRANSACTIONS_ACK_DEPTH + MAX_LINEARIZER_DEPTH);
181+
last_commit_index.saturating_sub(self.context.protocol_config.gc_depth() * 2);
182182

183183
recovery_lower_bound = recovery_lower_bound
184184
.min(commit_index_to_recover_acks)

crates/starfish/core/src/dag_state.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,10 @@ use crate::{
2929
},
3030
context::Context,
3131
leader_scoring::{ReputationScores, ScoringSubdag},
32-
linearizer::MAX_LINEARIZER_DEPTH,
3332
storage::{Store, WriteBatch},
3433
threshold_clock::ThresholdClock,
3534
};
3635

37-
/// Acknowledgment depth is the maximum number of rounds from current round
38-
/// for which acknowledgments are kept in memory and can be injected in a new
39-
/// block.
40-
// TODO: make it derivable from the protocol parameters
41-
pub(crate) const MAX_TRANSACTIONS_ACK_DEPTH: Round = 50;
4236
pub(crate) const MAX_HEADERS_PER_BUNDLE: usize = 150;
4337
pub(crate) const MAX_SHARDS_PER_BUNDLE: usize = 150;
4438

@@ -346,7 +340,8 @@ impl DagState {
346340
self.transactions_to_write.push(transactions);
347341
// If a block is not very old, add it to pending acknowledgments
348342
let clock_round = self.threshold_clock_round();
349-
let min_round: Round = clock_round.saturating_sub(MAX_TRANSACTIONS_ACK_DEPTH);
343+
let min_round: Round =
344+
clock_round.saturating_sub(self.context.protocol_config.gc_depth());
350345

351346
if block_ref.round >= min_round {
352347
self.add_pending_acknowledgment(block_ref);
@@ -1492,10 +1487,11 @@ impl DagState {
14921487
}
14931488

14941489
/// Function removes stalled pending acknowledgments that are older than
1495-
/// "current clock round minus MAX_TRANSACTIONS_ACK_DEPTH"
1490+
/// "current clock round minus protocol_config.gc_depth() aka
1491+
/// (MAX_TRANSACTIONS_ACK_DEPTH)"
14961492
pub(crate) fn evict_pending_acknowledgments(&mut self) {
14971493
let clock_round = self.threshold_clock_round();
1498-
let min_round: Round = clock_round.saturating_sub(MAX_TRANSACTIONS_ACK_DEPTH);
1494+
let min_round: Round = clock_round.saturating_sub(self.context.protocol_config.gc_depth());
14991495

15001496
// Construct a dummy BlockRef with the minimum round to split on.
15011497
// All entries < dummy will be removed.
@@ -1607,7 +1603,7 @@ impl DagState {
16071603

16081604
/// Return the garbage collection round with respect a given round.
16091605
pub(crate) fn gc_round(&self, round: Round) -> Round {
1610-
round.saturating_sub(MAX_LINEARIZER_DEPTH + MAX_TRANSACTIONS_ACK_DEPTH)
1606+
round.saturating_sub(self.context.protocol_config.gc_depth() * 2)
16111607
}
16121608

16131609
/// Last committed round per authority.
@@ -3214,7 +3210,7 @@ mod test {
32143210
// Calculate the eviction round for acknowledgments
32153211
let clock_round = dag_state.threshold_clock_round();
32163212
let acknowledgements_eviction_round =
3217-
clock_round.saturating_sub(MAX_TRANSACTIONS_ACK_DEPTH + 1);
3213+
clock_round.saturating_sub(context.protocol_config.gc_depth() + 1);
32183214

32193215
// Verify that for all blocks with round > eviction round, we have an
32203216
// acknowledgement

crates/starfish/core/src/linearizer.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,11 @@ use crate::{
1515
block_header::{BlockHeaderAPI, BlockHeaderDigest, BlockRef, VerifiedBlockHeader},
1616
commit::{Commit, CommitAPI, PendingSubDag, TrustedCommit, sort_sub_dag_blocks},
1717
context::Context,
18-
dag_state::{DagState, MAX_TRANSACTIONS_ACK_DEPTH},
18+
dag_state::DagState,
1919
leader_schedule::LeaderSchedule,
2020
stake_aggregator::{QuorumThreshold, StakeAggregator},
2121
};
2222

23-
/// The maximum depth of the linearizer, i.e. how many rounds back it will
24-
/// traverse the DAG from a committed leader block
25-
// TODO: https://github.com/iotaledger/iota/issues/8379
26-
// make it derivable from the protocol parameters
27-
pub(crate) const MAX_LINEARIZER_DEPTH: Round = 60;
28-
2923
/// The `StorageAPI` trait provides an interface for the block store and has
3024
/// been mostly introduced for allowing to inject the test store in
3125
/// `DagBuilder`.
@@ -92,6 +86,7 @@ impl Linearizer {
9286
leader_block.clone(),
9387
last_committed_rounds,
9488
&dag_state_guard,
89+
self.context.protocol_config.gc_depth(),
9590
);
9691

9792
drop(dag_state_guard);
@@ -152,6 +147,7 @@ impl Linearizer {
152147
leader_block: VerifiedBlockHeader,
153148
last_committed_rounds: Vec<u32>,
154149
dag_state: &impl BlockStoreAPI,
150+
max_linearizer_depth: u32,
155151
) -> Vec<VerifiedBlockHeader> {
156152
let leader_block_ref = leader_block.reference();
157153
let leader_round = leader_block.round();
@@ -177,7 +173,7 @@ impl Linearizer {
177173
!committed.contains(ancestor)
178174
&& last_committed_rounds[ancestor.author] < ancestor.round
179175
&& ancestor.round
180-
>= leader_round.saturating_sub(MAX_LINEARIZER_DEPTH)
176+
>= leader_round.saturating_sub(max_linearizer_depth)
181177
})
182178
.collect::<Vec<_>>(),
183179
)
@@ -260,8 +256,8 @@ impl Linearizer {
260256
/// called for solid committed leader round since we rely on the ack
261257
/// tracker in transaction synchronizer.
262258
pub(crate) fn evict_old_acknowledgments(&mut self, solid_commit_leader_round: Round) {
263-
let lower_bound_round = solid_commit_leader_round
264-
.saturating_sub(MAX_LINEARIZER_DEPTH + MAX_TRANSACTIONS_ACK_DEPTH);
259+
let lower_bound_round =
260+
solid_commit_leader_round.saturating_sub(self.context.protocol_config.gc_depth() * 2);
265261
let lower_bound = BlockRef::new(
266262
lower_bound_round + 1,
267263
AuthorityIndex::ZERO,
@@ -281,7 +277,7 @@ impl Linearizer {
281277
) -> Vec<BlockRef> {
282278
let mut acknowledged_data = Vec::new();
283279
for block_ref in acknowledgments {
284-
if block_ref.round < round.saturating_sub(MAX_TRANSACTIONS_ACK_DEPTH) {
280+
if block_ref.round < round.saturating_sub(self.context.protocol_config.gc_depth()) {
285281
continue; // Ignore acknowledgments for blocks that are too old
286282
}
287283
let votes_collector = self
@@ -735,10 +731,11 @@ mod tests {
735731
));
736732
let mut linearizer = Linearizer::new(context.clone(), dag_state.clone(), leader_schedule);
737733
let num_rounds_to_evict = 20;
738-
// Populate fully connected test blocks for round 0 ~ MAX_LINEARIZER_DEPTH +
739-
// MAX_TRANSACTIONS_ACK_DEPTH + num_rounds_to_evict, authorities 0 ~ 3.
740-
let num_rounds: u32 =
741-
MAX_LINEARIZER_DEPTH + MAX_TRANSACTIONS_ACK_DEPTH + num_rounds_to_evict;
734+
// Populate fully connected test blocks for round 0 ~ protocol_config.gc_depth()
735+
// * 2
736+
// + num_rounds_to_evict, authorities 0 ~
737+
// 3.
738+
let num_rounds: u32 = context.protocol_config.gc_depth() * 2 + num_rounds_to_evict;
742739
let mut dag_builder = DagBuilder::new(context.clone());
743740
dag_builder
744741
.layers(1..=num_rounds)

crates/starfish/core/src/test_dag_builder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ impl DagBuilder {
284284
leader_block,
285285
self.last_committed_rounds.clone(),
286286
&storage,
287+
self.context.protocol_config.gc_depth(),
287288
);
288289

289290
// Update the last committed rounds

0 commit comments

Comments
 (0)