1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
// Copyright (c) The Diem Core Contributors
// SPDX-License-Identifier: Apache-2.0
// Copyright 2021 Conflux Foundation. All rights reserved.
// Conflux is free software and distributed under GNU General Public License.
// See http://www.gnu.org/licenses/
use crate::pos::consensus::liveness::proposer_election::ProposerElection;
use consensus_types::common::{Author, Round};
use std::collections::HashMap;
/// The round proposer maps a round to author
pub struct RoundProposer {
// A pre-defined map specifying proposers per round
proposers: HashMap<Round, Author>,
// Default proposer to use if proposer for a round is unspecified.
// We hardcode this to the first proposer
default_proposer: Author,
}
impl RoundProposer {
pub fn new(
proposers: HashMap<Round, Author>, default_proposer: Author,
) -> Self {
Self {
proposers,
default_proposer,
}
}
}
impl ProposerElection for RoundProposer {
fn get_valid_proposer(&self, round: Round) -> Author {
match self.proposers.get(&round) {
None => self.default_proposer,
Some(round_proposer) => *round_proposer,
}
}
}