Skip to content

Commit

Permalink
[Consensus 2.0] one ancestor per authority in block proposal (#16280)
Browse files Browse the repository at this point in the history
## Description 

A small refactoring to ensure that only ancestor per authority is
included per block proposal - that should happen mostly under some out
of order block processing or byzantine cases

## Test Plan 

CI

---
If your changes are not user-facing and do not break anything, you can
skip the following section. Otherwise, please briefly describe what has
changed under the Release Notes section.

### Type of Change (Check all that apply)

- [ ] protocol change
- [ ] user-visible impact
- [ ] breaking change for a client SDKs
- [ ] breaking change for FNs (FN binary must upgrade)
- [ ] breaking change for validators or node operators (must upgrade
binaries)
- [ ] breaking change for on-chain data layout
- [ ] necessitate either a data wipe or data migration

### Release notes
  • Loading branch information
akichidis authored Feb 22, 2024
1 parent 823a5cb commit 9f7e0a6
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions consensus/core/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,6 @@ impl Core {

//3. create the block and insert to storage.
// TODO: take a decision on whether we want to flush to disk at this point the DagState.

// TODO: this will be refactored once the signing path/approach has been introduced. Adding as is for now
// to keep things rolling in the implementation.
let block = Block::V1(BlockV1::new(
self.context.committee.epoch(),
clock_round,
Expand Down Expand Up @@ -348,23 +345,31 @@ impl Core {
.flat_map(|block| block.ancestors())
.collect();

let mut to_propose = HashSet::new();
// Keep block refs to propose in a map, so even if somehow a byzantine node managed to provide blocks that don't
// form a valid chain we can still pick one block per author.
let mut to_propose = BTreeMap::new();
for block in ancestors.into_iter() {
if !all_ancestors_parents.contains(&block.reference()) {
to_propose.insert(block.reference());
to_propose.insert(block.author(), block.reference());
}
}

// always include our last block to ensure that is not somehow excluded by the DAG compression
to_propose.insert(self.last_proposed_block.reference());

assert!(!to_propose.is_empty());

// Now clean up the pending ancestors
self.pending_ancestors
.retain(|round, _blocks| *round >= clock_round);

to_propose.into_iter().collect()
// always include our last proposed block in front of the vector and make sure that we do not
// double insert.
let mut result = vec![self.last_proposed_block.reference()];
for (authority_index, block_ref) in to_propose {
if authority_index != self.context.own_index {
result.push(block_ref);
}
}

result
}

/// Checks whether all the leaders of the previous quorum exist.
Expand Down

0 comments on commit 9f7e0a6

Please sign in to comment.