mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-11 05:29:25 +00:00
Rename Round to RoundNumber
This commit is contained in:
@@ -31,7 +31,7 @@ impl<S: Send + Sync + Clone + PartialEq + Debug + Encode + Decode> Signature for
|
|||||||
pub struct BlockNumber(pub u64);
|
pub struct BlockNumber(pub u64);
|
||||||
/// A struct containing a round number, wrapped to have a distinct type.
|
/// A struct containing a round number, wrapped to have a distinct type.
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Encode, Decode)]
|
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Encode, Decode)]
|
||||||
pub struct Round(pub u32);
|
pub struct RoundNumber(pub u32);
|
||||||
|
|
||||||
/// A signer for a validator.
|
/// A signer for a validator.
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
@@ -147,7 +147,7 @@ pub trait Weights: Send + Sync {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Weighted round robin function.
|
/// Weighted round robin function.
|
||||||
fn proposer(&self, number: BlockNumber, round: Round) -> Self::ValidatorId;
|
fn proposer(&self, number: BlockNumber, round: RoundNumber) -> Self::ValidatorId;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<W: Weights> Weights for Arc<W> {
|
impl<W: Weights> Weights for Arc<W> {
|
||||||
@@ -161,7 +161,7 @@ impl<W: Weights> Weights for Arc<W> {
|
|||||||
self.as_ref().weight(validator)
|
self.as_ref().weight(validator)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn proposer(&self, number: BlockNumber, round: Round) -> Self::ValidatorId {
|
fn proposer(&self, number: BlockNumber, round: RoundNumber) -> Self::ValidatorId {
|
||||||
self.as_ref().proposer(number, round)
|
self.as_ref().proposer(number, round)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ enum Step {
|
|||||||
|
|
||||||
#[derive(Clone, Debug, Encode, Decode)]
|
#[derive(Clone, Debug, Encode, Decode)]
|
||||||
enum Data<B: Block, S: Signature> {
|
enum Data<B: Block, S: Signature> {
|
||||||
Proposal(Option<Round>, B),
|
Proposal(Option<RoundNumber>, B),
|
||||||
Prevote(Option<B::Id>),
|
Prevote(Option<B::Id>),
|
||||||
Precommit(Option<(B::Id, S)>),
|
Precommit(Option<(B::Id, S)>),
|
||||||
}
|
}
|
||||||
@@ -73,7 +73,7 @@ struct Message<V: ValidatorId, B: Block, S: Signature> {
|
|||||||
sender: V,
|
sender: V,
|
||||||
|
|
||||||
number: BlockNumber,
|
number: BlockNumber,
|
||||||
round: Round,
|
round: RoundNumber,
|
||||||
|
|
||||||
data: Data<B, S>,
|
data: Data<B, S>,
|
||||||
}
|
}
|
||||||
@@ -113,12 +113,12 @@ struct BlockData<N: Network> {
|
|||||||
|
|
||||||
log: MessageLog<N>,
|
log: MessageLog<N>,
|
||||||
slashes: HashSet<N::ValidatorId>,
|
slashes: HashSet<N::ValidatorId>,
|
||||||
end_time: HashMap<Round, CanonicalInstant>,
|
end_time: HashMap<RoundNumber, CanonicalInstant>,
|
||||||
|
|
||||||
round: RoundData<N>,
|
round: RoundData<N>,
|
||||||
|
|
||||||
locked: Option<(Round, <N::Block as Block>::Id)>,
|
locked: Option<(RoundNumber, <N::Block as Block>::Id)>,
|
||||||
valid: Option<(Round, N::Block)>,
|
valid: Option<(RoundNumber, N::Block)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A machine executing the Tendermint protocol.
|
/// A machine executing the Tendermint protocol.
|
||||||
@@ -171,33 +171,35 @@ impl<N: Network + 'static> TendermintMachine<N> {
|
|||||||
self.queue.push_back(Message {
|
self.queue.push_back(Message {
|
||||||
sender: *validator_id,
|
sender: *validator_id,
|
||||||
number: self.block.number,
|
number: self.block.number,
|
||||||
round: self.block.round.round,
|
round: self.block.round.number,
|
||||||
data,
|
data,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn populate_end_time(&mut self, round: Round) {
|
fn populate_end_time(&mut self, round: RoundNumber) {
|
||||||
for r in (self.block.round.round.0 + 1) .. round.0 {
|
for r in (self.block.round.number.0 + 1) .. round.0 {
|
||||||
self.block.end_time.insert(
|
self.block.end_time.insert(
|
||||||
Round(r),
|
RoundNumber(r),
|
||||||
RoundData::<N>::new(Round(r), self.block.end_time[&Round(r - 1)]).end_time(),
|
RoundData::<N>::new(RoundNumber(r), self.block.end_time[&RoundNumber(r - 1)]).end_time(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start a new round. Returns true if we were the proposer
|
// Start a new round. Returns true if we were the proposer
|
||||||
fn round(&mut self, round: Round, time: Option<CanonicalInstant>) -> bool {
|
fn round(&mut self, round: RoundNumber, time: Option<CanonicalInstant>) -> bool {
|
||||||
// If skipping rounds, populate end_time
|
// If skipping rounds, populate end_time
|
||||||
self.populate_end_time(round);
|
self.populate_end_time(round);
|
||||||
|
|
||||||
// 11-13
|
// 11-13
|
||||||
self.block.round =
|
self.block.round = RoundData::<N>::new(
|
||||||
RoundData::<N>::new(round, time.unwrap_or_else(|| self.block.end_time[&Round(round.0 - 1)]));
|
round,
|
||||||
|
time.unwrap_or_else(|| self.block.end_time[&RoundNumber(round.0 - 1)]),
|
||||||
|
);
|
||||||
self.block.end_time.insert(round, self.block.round.end_time());
|
self.block.end_time.insert(round, self.block.round.end_time());
|
||||||
|
|
||||||
// 14-21
|
// 14-21
|
||||||
if Some(self.weights.proposer(self.block.number, self.block.round.round)) ==
|
if Some(self.weights.proposer(self.block.number, self.block.round.number)) ==
|
||||||
self.block.validator_id
|
self.block.validator_id
|
||||||
{
|
{
|
||||||
let (round, block) = if let Some((round, block)) = &self.block.valid {
|
let (round, block) = if let Some((round, block)) = &self.block.valid {
|
||||||
@@ -214,7 +216,7 @@ impl<N: Network + 'static> TendermintMachine<N> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 53-54
|
// 53-54
|
||||||
async fn reset(&mut self, end_round: Round, proposal: N::Block) {
|
async fn reset(&mut self, end_round: RoundNumber, proposal: N::Block) {
|
||||||
// Ensure we have the end time data for the last round
|
// Ensure we have the end time data for the last round
|
||||||
self.populate_end_time(end_round);
|
self.populate_end_time(end_round);
|
||||||
|
|
||||||
@@ -236,18 +238,18 @@ impl<N: Network + 'static> TendermintMachine<N> {
|
|||||||
end_time: HashMap::new(),
|
end_time: HashMap::new(),
|
||||||
|
|
||||||
// This will be populated in the following round() call
|
// This will be populated in the following round() call
|
||||||
round: RoundData::<N>::new(Round(0), CanonicalInstant::new(0)),
|
round: RoundData::<N>::new(RoundNumber(0), CanonicalInstant::new(0)),
|
||||||
|
|
||||||
locked: None,
|
locked: None,
|
||||||
valid: None,
|
valid: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Start the first round
|
// Start the first round
|
||||||
self.round(Round(0), Some(round_end));
|
self.round(RoundNumber(0), Some(round_end));
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn reset_by_commit(&mut self, commit: Commit<N::SignatureScheme>, proposal: N::Block) {
|
async fn reset_by_commit(&mut self, commit: Commit<N::SignatureScheme>, proposal: N::Block) {
|
||||||
let mut round = self.block.round.round;
|
let mut round = self.block.round.number;
|
||||||
// If this commit is for a round we don't have, jump up to it
|
// If this commit is for a round we don't have, jump up to it
|
||||||
while self.block.end_time[&round].canonical() < commit.end_time {
|
while self.block.end_time[&round].canonical() < commit.end_time {
|
||||||
round.0 += 1;
|
round.0 += 1;
|
||||||
@@ -316,7 +318,7 @@ impl<N: Network + 'static> TendermintMachine<N> {
|
|||||||
end_time: HashMap::new(),
|
end_time: HashMap::new(),
|
||||||
|
|
||||||
// This will be populated in the following round() call
|
// This will be populated in the following round() call
|
||||||
round: RoundData::<N>::new(Round(0), CanonicalInstant::new(0)),
|
round: RoundData::<N>::new(RoundNumber(0), CanonicalInstant::new(0)),
|
||||||
|
|
||||||
locked: None,
|
locked: None,
|
||||||
valid: None,
|
valid: None,
|
||||||
@@ -330,7 +332,7 @@ impl<N: Network + 'static> TendermintMachine<N> {
|
|||||||
// after it, without the standard amount of separation (so their times will be
|
// after it, without the standard amount of separation (so their times will be
|
||||||
// equivalent or minimally offset)
|
// equivalent or minimally offset)
|
||||||
// For callers wishing to avoid this, they should pass (0, GENESIS + N::block_time())
|
// For callers wishing to avoid this, they should pass (0, GENESIS + N::block_time())
|
||||||
machine.round(Round(0), Some(CanonicalInstant::new(last.1)));
|
machine.round(RoundNumber(0), Some(CanonicalInstant::new(last.1)));
|
||||||
machine
|
machine
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -372,12 +374,12 @@ impl<N: Network + 'static> TendermintMachine<N> {
|
|||||||
match step {
|
match step {
|
||||||
Step::Propose => {
|
Step::Propose => {
|
||||||
// Slash the validator for not proposing when they should've
|
// Slash the validator for not proposing when they should've
|
||||||
self.slash(self.weights.proposer(self.block.number, self.block.round.round)).await;
|
self.slash(self.weights.proposer(self.block.number, self.block.round.number)).await;
|
||||||
self.broadcast(Data::Prevote(None));
|
self.broadcast(Data::Prevote(None));
|
||||||
},
|
},
|
||||||
Step::Prevote => self.broadcast(Data::Precommit(None)),
|
Step::Prevote => self.broadcast(Data::Precommit(None)),
|
||||||
Step::Precommit => {
|
Step::Precommit => {
|
||||||
self.round(Round(self.block.round.round.0 + 1), None);
|
self.round(RoundNumber(self.block.round.number.0 + 1), None);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -445,7 +447,7 @@ impl<N: Network + 'static> TendermintMachine<N> {
|
|||||||
fn verify_precommit_signature(
|
fn verify_precommit_signature(
|
||||||
&self,
|
&self,
|
||||||
sender: N::ValidatorId,
|
sender: N::ValidatorId,
|
||||||
round: Round,
|
round: RoundNumber,
|
||||||
data: &Data<N::Block, <N::SignatureScheme as SignatureScheme>::Signature>,
|
data: &Data<N::Block, <N::SignatureScheme as SignatureScheme>::Signature>,
|
||||||
) -> Result<(), TendermintError<N::ValidatorId>> {
|
) -> Result<(), TendermintError<N::ValidatorId>> {
|
||||||
if let Data::Precommit(Some((id, sig))) = data {
|
if let Data::Precommit(Some((id, sig))) = data {
|
||||||
@@ -507,10 +509,10 @@ impl<N: Network + 'static> TendermintMachine<N> {
|
|||||||
|
|
||||||
// Else, check if we need to jump ahead
|
// Else, check if we need to jump ahead
|
||||||
#[allow(clippy::comparison_chain)]
|
#[allow(clippy::comparison_chain)]
|
||||||
if msg.round.0 < self.block.round.round.0 {
|
if msg.round.0 < self.block.round.number.0 {
|
||||||
// Prior round, disregard if not finalizing
|
// Prior round, disregard if not finalizing
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
} else if msg.round.0 > self.block.round.round.0 {
|
} else if msg.round.0 > self.block.round.number.0 {
|
||||||
// 55-56
|
// 55-56
|
||||||
// Jump, enabling processing by the below code
|
// Jump, enabling processing by the below code
|
||||||
if self.block.log.round_participation(msg.round) > self.weights.fault_thresold() {
|
if self.block.log.round_participation(msg.round) > self.weights.fault_thresold() {
|
||||||
@@ -539,7 +541,7 @@ impl<N: Network + 'static> TendermintMachine<N> {
|
|||||||
// of the round map
|
// of the round map
|
||||||
if (self.block.round.step == Step::Prevote) && matches!(msg.data, Data::Prevote(_)) {
|
if (self.block.round.step == Step::Prevote) && matches!(msg.data, Data::Prevote(_)) {
|
||||||
let (participation, weight) =
|
let (participation, weight) =
|
||||||
self.block.log.message_instances(self.block.round.round, Data::Prevote(None));
|
self.block.log.message_instances(self.block.round.number, Data::Prevote(None));
|
||||||
// 34-35
|
// 34-35
|
||||||
if participation >= self.weights.threshold() {
|
if participation >= self.weights.threshold() {
|
||||||
self.block.round.set_timeout(Step::Prevote);
|
self.block.round.set_timeout(Step::Prevote);
|
||||||
@@ -554,14 +556,14 @@ impl<N: Network + 'static> TendermintMachine<N> {
|
|||||||
|
|
||||||
// 47-48
|
// 47-48
|
||||||
if matches!(msg.data, Data::Precommit(_)) &&
|
if matches!(msg.data, Data::Precommit(_)) &&
|
||||||
self.block.log.has_participation(self.block.round.round, Step::Precommit)
|
self.block.log.has_participation(self.block.round.number, Step::Precommit)
|
||||||
{
|
{
|
||||||
self.block.round.set_timeout(Step::Precommit);
|
self.block.round.set_timeout(Step::Precommit);
|
||||||
}
|
}
|
||||||
|
|
||||||
let proposer = self.weights.proposer(self.block.number, self.block.round.round);
|
let proposer = self.weights.proposer(self.block.number, self.block.round.number);
|
||||||
if let Some(Data::Proposal(vr, block)) =
|
if let Some(Data::Proposal(vr, block)) =
|
||||||
self.block.log.get(self.block.round.round, proposer, Step::Propose)
|
self.block.log.get(self.block.round.number, proposer, Step::Propose)
|
||||||
{
|
{
|
||||||
// 22-33
|
// 22-33
|
||||||
if self.block.round.step == Step::Propose {
|
if self.block.round.step == Step::Propose {
|
||||||
@@ -583,7 +585,7 @@ impl<N: Network + 'static> TendermintMachine<N> {
|
|||||||
|
|
||||||
if let Some(vr) = vr {
|
if let Some(vr) = vr {
|
||||||
// Malformed message
|
// Malformed message
|
||||||
if vr.0 >= self.block.round.round.0 {
|
if vr.0 >= self.block.round.number.0 {
|
||||||
Err(TendermintError::Malicious(msg.sender))?;
|
Err(TendermintError::Malicious(msg.sender))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -605,7 +607,7 @@ impl<N: Network + 'static> TendermintMachine<N> {
|
|||||||
.block
|
.block
|
||||||
.valid
|
.valid
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|(round, _)| round != &self.block.round.round)
|
.map(|(round, _)| round != &self.block.round.number)
|
||||||
.unwrap_or(true)
|
.unwrap_or(true)
|
||||||
{
|
{
|
||||||
// 36-43
|
// 36-43
|
||||||
@@ -613,22 +615,22 @@ impl<N: Network + 'static> TendermintMachine<N> {
|
|||||||
// The run once condition is implemented above. Sinve valid will always be set, it not
|
// The run once condition is implemented above. Sinve valid will always be set, it not
|
||||||
// being set, or only being set historically, means this has yet to be run
|
// being set, or only being set historically, means this has yet to be run
|
||||||
|
|
||||||
if self.block.log.has_consensus(self.block.round.round, Data::Prevote(Some(block.id()))) {
|
if self.block.log.has_consensus(self.block.round.number, Data::Prevote(Some(block.id()))) {
|
||||||
match self.network.validate(block).await {
|
match self.network.validate(block).await {
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
Err(BlockError::Temporal) => (),
|
Err(BlockError::Temporal) => (),
|
||||||
Err(BlockError::Fatal) => Err(TendermintError::Malicious(proposer))?,
|
Err(BlockError::Fatal) => Err(TendermintError::Malicious(proposer))?,
|
||||||
};
|
};
|
||||||
|
|
||||||
self.block.valid = Some((self.block.round.round, block.clone()));
|
self.block.valid = Some((self.block.round.number, block.clone()));
|
||||||
if self.block.round.step == Step::Prevote {
|
if self.block.round.step == Step::Prevote {
|
||||||
self.block.locked = Some((self.block.round.round, block.id()));
|
self.block.locked = Some((self.block.round.number, block.id()));
|
||||||
self.broadcast(Data::Precommit(Some((
|
self.broadcast(Data::Precommit(Some((
|
||||||
block.id(),
|
block.id(),
|
||||||
self
|
self
|
||||||
.signer
|
.signer
|
||||||
.sign(&commit_msg(
|
.sign(&commit_msg(
|
||||||
self.block.end_time[&self.block.round.round].canonical(),
|
self.block.end_time[&self.block.round.number].canonical(),
|
||||||
block.id().as_ref(),
|
block.id().as_ref(),
|
||||||
))
|
))
|
||||||
.await,
|
.await,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use std::{sync::Arc, collections::HashMap};
|
use std::{sync::Arc, collections::HashMap};
|
||||||
|
|
||||||
use crate::{ext::*, Round, Step, Data, Message, TendermintError};
|
use crate::{ext::*, RoundNumber, Step, Data, Message, TendermintError};
|
||||||
|
|
||||||
pub(crate) struct MessageLog<N: Network> {
|
pub(crate) struct MessageLog<N: Network> {
|
||||||
weights: Arc<N::Weights>,
|
weights: Arc<N::Weights>,
|
||||||
@@ -9,7 +9,7 @@ pub(crate) struct MessageLog<N: Network> {
|
|||||||
(<N::Block as Block>::Id, <N::SignatureScheme as SignatureScheme>::Signature),
|
(<N::Block as Block>::Id, <N::SignatureScheme as SignatureScheme>::Signature),
|
||||||
>,
|
>,
|
||||||
pub(crate) log: HashMap<
|
pub(crate) log: HashMap<
|
||||||
Round,
|
RoundNumber,
|
||||||
HashMap<
|
HashMap<
|
||||||
N::ValidatorId,
|
N::ValidatorId,
|
||||||
HashMap<Step, Data<N::Block, <N::SignatureScheme as SignatureScheme>::Signature>>,
|
HashMap<Step, Data<N::Block, <N::SignatureScheme as SignatureScheme>::Signature>>,
|
||||||
@@ -57,7 +57,7 @@ impl<N: Network> MessageLog<N> {
|
|||||||
// the data.
|
// the data.
|
||||||
pub(crate) fn message_instances(
|
pub(crate) fn message_instances(
|
||||||
&self,
|
&self,
|
||||||
round: Round,
|
round: RoundNumber,
|
||||||
data: Data<N::Block, <N::SignatureScheme as SignatureScheme>::Signature>,
|
data: Data<N::Block, <N::SignatureScheme as SignatureScheme>::Signature>,
|
||||||
) -> (u64, u64) {
|
) -> (u64, u64) {
|
||||||
let mut participating = 0;
|
let mut participating = 0;
|
||||||
@@ -75,7 +75,7 @@ impl<N: Network> MessageLog<N> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the participation in a given round
|
// Get the participation in a given round
|
||||||
pub(crate) fn round_participation(&self, round: Round) -> u64 {
|
pub(crate) fn round_participation(&self, round: RoundNumber) -> u64 {
|
||||||
let mut weight = 0;
|
let mut weight = 0;
|
||||||
if let Some(round) = self.log.get(&round) {
|
if let Some(round) = self.log.get(&round) {
|
||||||
for participant in round.keys() {
|
for participant in round.keys() {
|
||||||
@@ -86,7 +86,7 @@ impl<N: Network> MessageLog<N> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if a supermajority of nodes have participated on a specific step
|
// Check if a supermajority of nodes have participated on a specific step
|
||||||
pub(crate) fn has_participation(&self, round: Round, step: Step) -> bool {
|
pub(crate) fn has_participation(&self, round: RoundNumber, step: Step) -> bool {
|
||||||
let mut participating = 0;
|
let mut participating = 0;
|
||||||
for (participant, msgs) in &self.log[&round] {
|
for (participant, msgs) in &self.log[&round] {
|
||||||
if msgs.get(&step).is_some() {
|
if msgs.get(&step).is_some() {
|
||||||
@@ -99,7 +99,7 @@ impl<N: Network> MessageLog<N> {
|
|||||||
// Check if consensus has been reached on a specific piece of data
|
// Check if consensus has been reached on a specific piece of data
|
||||||
pub(crate) fn has_consensus(
|
pub(crate) fn has_consensus(
|
||||||
&self,
|
&self,
|
||||||
round: Round,
|
round: RoundNumber,
|
||||||
data: Data<N::Block, <N::SignatureScheme as SignatureScheme>::Signature>,
|
data: Data<N::Block, <N::SignatureScheme as SignatureScheme>::Signature>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let (_, weight) = self.message_instances(round, data);
|
let (_, weight) = self.message_instances(round, data);
|
||||||
@@ -108,7 +108,7 @@ impl<N: Network> MessageLog<N> {
|
|||||||
|
|
||||||
pub(crate) fn get(
|
pub(crate) fn get(
|
||||||
&self,
|
&self,
|
||||||
round: Round,
|
round: RoundNumber,
|
||||||
sender: N::ValidatorId,
|
sender: N::ValidatorId,
|
||||||
step: Step,
|
step: Step,
|
||||||
) -> Option<&Data<N::Block, <N::SignatureScheme as SignatureScheme>::Signature>> {
|
) -> Option<&Data<N::Block, <N::SignatureScheme as SignatureScheme>::Signature>> {
|
||||||
|
|||||||
@@ -10,22 +10,22 @@ use tokio::time::sleep;
|
|||||||
use crate::{
|
use crate::{
|
||||||
time::CanonicalInstant,
|
time::CanonicalInstant,
|
||||||
Step,
|
Step,
|
||||||
ext::{Round, Network},
|
ext::{RoundNumber, Network},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub(crate) struct RoundData<N: Network> {
|
pub(crate) struct RoundData<N: Network> {
|
||||||
_network: PhantomData<N>,
|
_network: PhantomData<N>,
|
||||||
pub(crate) round: Round,
|
pub(crate) number: RoundNumber,
|
||||||
pub(crate) start_time: CanonicalInstant,
|
pub(crate) start_time: CanonicalInstant,
|
||||||
pub(crate) step: Step,
|
pub(crate) step: Step,
|
||||||
pub(crate) timeouts: HashMap<Step, Instant>,
|
pub(crate) timeouts: HashMap<Step, Instant>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Network> RoundData<N> {
|
impl<N: Network> RoundData<N> {
|
||||||
pub(crate) fn new(round: Round, start_time: CanonicalInstant) -> Self {
|
pub(crate) fn new(number: RoundNumber, start_time: CanonicalInstant) -> Self {
|
||||||
RoundData {
|
RoundData {
|
||||||
_network: PhantomData,
|
_network: PhantomData,
|
||||||
round,
|
number,
|
||||||
start_time,
|
start_time,
|
||||||
step: Step::Propose,
|
step: Step::Propose,
|
||||||
timeouts: HashMap::new(),
|
timeouts: HashMap::new(),
|
||||||
@@ -33,8 +33,8 @@ impl<N: Network> RoundData<N> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn timeout(&self, step: Step) -> CanonicalInstant {
|
fn timeout(&self, step: Step) -> CanonicalInstant {
|
||||||
let adjusted_block = N::BLOCK_PROCESSING_TIME * (self.round.0 + 1);
|
let adjusted_block = N::BLOCK_PROCESSING_TIME * (self.number.0 + 1);
|
||||||
let adjusted_latency = N::LATENCY_TIME * (self.round.0 + 1);
|
let adjusted_latency = N::LATENCY_TIME * (self.number.0 + 1);
|
||||||
let offset = Duration::from_secs(
|
let offset = Duration::from_secs(
|
||||||
(match step {
|
(match step {
|
||||||
Step::Propose => adjusted_block + adjusted_latency,
|
Step::Propose => adjusted_block + adjusted_latency,
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ impl Weights for TestWeights {
|
|||||||
[1; 4][usize::try_from(id).unwrap()]
|
[1; 4][usize::try_from(id).unwrap()]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn proposer(&self, number: BlockNumber, round: Round) -> TestValidatorId {
|
fn proposer(&self, number: BlockNumber, round: RoundNumber) -> TestValidatorId {
|
||||||
TestValidatorId::try_from((number.0 + u64::from(round.0)) % 4).unwrap()
|
TestValidatorId::try_from((number.0 + u64::from(round.0)) % 4).unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user