Skip to content

Commit

Permalink
propose multiple rounds
Browse files Browse the repository at this point in the history
  • Loading branch information
akichidis committed Dec 4, 2023
1 parent a2fa7a0 commit 63974e4
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 9 deletions.
36 changes: 29 additions & 7 deletions mysticeti-core/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub struct Core<H: BlockHandler> {
last_own_block: OwnBlockData,
block_handler: H,
authority: AuthorityIndex,
threshold_clock: ThresholdClockAggregator,
pub threshold_clock: ThresholdClockAggregator,
committee: Arc<Committee>,
last_decided_leader: AuthorityRound,
wal_writer: WalWriter,
Expand Down Expand Up @@ -209,16 +209,15 @@ impl<H: BlockHandler> Core<H> {
.push_back((position, MetaStatement::Payload(statements)));
}

pub fn try_new_block(&mut self) -> Option<Data<StatementBlock>> {
let _timer = self
.metrics
.utilization_timer
.utilization_timer("Core::try_new_block");
let clock_round = self.threshold_clock.get_round();
pub fn try_new_block_by_round(
&mut self,
clock_round: RoundNumber,
) -> Option<Data<StatementBlock>> {
if clock_round <= self.last_proposed() {
return None;
}

// will attempt to create all the possible blocks
let mut includes = vec![];
let mut statements = vec![];

Expand Down Expand Up @@ -309,9 +308,20 @@ impl<H: BlockHandler> Core<H> {
}

tracing::debug!("Created block {block:?}");

Some(block)
}

pub fn try_new_block(&mut self) -> Option<Data<StatementBlock>> {
let _timer = self
.metrics
.utilization_timer
.utilization_timer("Core::try_new_block");
let clock_round = self.threshold_clock.get_round();

self.try_new_block_by_round(clock_round)
}

pub fn leaders(&self, leader_round: RoundNumber) -> Vec<&Authority> {
let leaders = self.committer.get_leaders(leader_round);

Expand Down Expand Up @@ -386,6 +396,18 @@ impl<H: BlockHandler> Core<H> {

// Leader round we check if we have a leader block
if quorum_round > self.last_decided_leader.round().max(period - 1) {
// if we do have more rounds that we haven't proposed for, then we consider it ready to propose.
// Then on the propose we'll try to iterate from the older to most recent round we can propose
// to send a block.
if quorum_round - self.last_proposed() > 1 {
tracing::debug!(
"Recent quorum {}, last proposed {}, ready to propose",
quorum_round,
self.last_proposed()
);
return true;
}

let leader_round = quorum_round - 1;
let leaders = self.committer.get_leaders(leader_round);
if leaders.is_empty() {
Expand Down
22 changes: 20 additions & 2 deletions mysticeti-core/src/syncer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,27 @@ impl<H: BlockHandler, S: SyncerSignals, C: CommitObserver> Syncer<H, S, C> {
if self.force_new_block
|| self
.core
.ready_new_block(self.commit_period, connected_authorities)
.ready_new_block(self.commit_period, connected_authorities.clone())
{
if self.core.try_new_block().is_none() {
let mut block_created = false;
for clock_round in
self.core().last_proposed() + 1..=self.core().threshold_clock.get_round()
{
if self.core.try_new_block_by_round(clock_round).is_some() {
block_created = true;
} else {
break;
}

if !self
.core
.ready_new_block(self.commit_period, connected_authorities.clone())
{
break;
}
}

if !block_created {
return;
}

Expand Down

0 comments on commit 63974e4

Please sign in to comment.