Skip to content

Commit

Permalink
Cache the proposal for a round
Browse files Browse the repository at this point in the history
  • Loading branch information
kayabaNerve committed Apr 28, 2024
1 parent 85aece2 commit f3f7683
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
26 changes: 15 additions & 11 deletions coordinator/tributary/tendermint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use core::fmt::Debug;
use std::{
sync::Arc,
time::{SystemTime, Instant, Duration},
collections::VecDeque,
collections::{VecDeque, HashMap},
};

use parity_scale_codec::{Encode, Decode, IoReader};
Expand Down Expand Up @@ -263,6 +263,9 @@ pub struct TendermintMachine<N: Network> {
synced_block_result_send: mpsc::UnboundedSender<bool>,

block: BlockData<N>,
// TODO: Move this into the Block struct
round_proposals: HashMap<RoundNumber, (Option<RoundNumber>, N::Block)>,
// TODO: Move this into the Round struct
upons: Upons,
}

Expand Down Expand Up @@ -372,6 +375,9 @@ impl<N: Network + 'static> TendermintMachine<N> {
proposal,
);

// Reset the round proposals
self.round_proposals = HashMap::new();

// Start the first round
self.round(RoundNumber(0), Some(round_end));
}
Expand Down Expand Up @@ -410,16 +416,7 @@ impl<N: Network + 'static> TendermintMachine<N> {
}

fn proposal_for_round(&self, round: RoundNumber) -> Option<(Option<RoundNumber>, &N::Block)> {
let proposer = self.weights.proposer(self.block.number, round);
if let Some(proposal_signed) = self.block.log.get(round, proposer, Step::Propose) {
if let Data::Proposal(vr, block) = &proposal_signed.msg.data {
Some((*vr, block))
} else {
panic!("message for Step::Propose didn't have Data::Proposal");
}
} else {
None?
}
self.round_proposals.get(&round).map(|(round, block)| (*round, block))
}

// L22-27
Expand Down Expand Up @@ -745,6 +742,11 @@ impl<N: Network + 'static> TendermintMachine<N> {
msg.data.step(),
);

// If this is a proposal, insert it
if let Data::Proposal(vr, block) = &msg.data {
self.round_proposals.insert(msg.round, (*vr, block.clone()));
}

// L55-56
// Jump ahead if we should
if (msg.round.0 > self.block.round().number.0) &&
Expand Down Expand Up @@ -885,6 +887,8 @@ impl<N: Network + 'static> TendermintMachine<N> {
Some(proposal),
),

round_proposals: HashMap::new(),

upons: Upons {
upon_prevotes: false,
upon_successful_current_round_prevotes: false,
Expand Down
9 changes: 0 additions & 9 deletions coordinator/tributary/tendermint/src/message_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,4 @@ impl<N: Network> MessageLog<N> {
let (_, weight) = self.message_instances(round, data);
weight >= self.weights.threshold()
}

pub(crate) fn get(
&self,
round: RoundNumber,
sender: N::ValidatorId,
step: Step,
) -> Option<&SignedMessageFor<N>> {
self.log.get(&round).and_then(|round| round.get(&sender).and_then(|msgs| msgs.get(&step)))
}
}

0 comments on commit f3f7683

Please sign in to comment.