Consensus::spawn()メソッド
コンセンサスを実行するための以下の状態を更新する.
引数
code:.rs
impl Consensus {
pub fn spawn(
committee: Committee,
gc_depth: Round,
store: Arc<ConsensusStore>,
cert_store: CertificateStore,
rx_shutdown: ConditionalBroadcastReceiver,
rx_new_certificates: metered_channel::Receiver<Certificate>,
tx_committed_certificates: metered_channel::Sender<(Round, Vec<Certificate>)>,
tx_consensus_round_updates: watch::Sender<ConsensusRound>,
tx_sequence: metered_channel::Sender<CommittedSubDag>,
protocol: Bullshark,
metrics: Arc<ConsensusMetrics>,
) -> JoinHandle<()> { // 中略 }
状態更新箇所
code:.rs
let s = Self {
committee,
rx_shutdown,
rx_new_certificates,
tx_committed_certificates,
tx_consensus_round_updates,
tx_sequence,
protocol,
metrics,
state,
};
spawn_logged_monitored_task!(s.run(), "Consensus", INFO)
run()
非同期関数
run_inner()関数を実行する
うまくいかなった場合
エラー内容に基づいてログを残したり,プログラムを終了したりする
run_inner()
無限ループ処理,mainラベル
シャットダウン信号を受信した場合、関数を終了する
新しい証明書を受信した場合
let (_, committed_sub_dags) = self.protocol.process_certificate(&mut self.state, certificate)?;
Bullsharkのprocess_certificate()関数を実行
その後
コミットされた証明書のためのベクターを作って,コミットされた証明書を追加
最後のコミットラウンドがリーダーのコミットラウンドと一致することを確認
使っている構造体について
Consensus構造体
code:.rs
pub struct Consensus {
/// The committee information.
committee: Committee,
/// Receiver for shutdown.
rx_shutdown: ConditionalBroadcastReceiver,
/// Receives new certificates from the primary. The primary should send us new certificates only
/// if it already sent us its whole history.
rx_new_certificates: metered_channel::Receiver<Certificate>,
/// Outputs the sequence of ordered certificates to the primary (for cleanup and feedback).
tx_committed_certificates: metered_channel::Sender<(Round, Vec<Certificate>)>,
/// Outputs the highest committed round & corresponding gc_round in the consensus.
tx_consensus_round_updates: watch::Sender<ConsensusRound>,
/// Outputs the sequence of ordered certificates to the application layer.
tx_sequence: metered_channel::Sender<CommittedSubDag>,
/// The consensus protocol to run.
protocol: Bullshark,
/// Metrics handler
metrics: Arc<ConsensusMetrics>,
/// Inner state
state: ConsensusState,
}