cfxcore/pos/consensus/util/
mod.rs

1// Copyright (c) The Diem Core Contributors
2// SPDX-License-Identifier: Apache-2.0
3
4// Copyright 2021 Conflux Foundation. All rights reserved.
5// Conflux is free software and distributed under GNU General Public License.
6// See http://www.gnu.org/licenses/
7
8use consensus_types::{block::Block, common::Round};
9use diem_crypto::HashValue;
10use diem_types::{
11    block_info::PivotBlockDecision, transaction::TransactionPayload,
12};
13use std::sync::mpsc;
14
15#[cfg(any(test, feature = "fuzzing"))]
16pub mod mock_time_service;
17pub mod time_service;
18
19/// Test command sent by RPCs to construct attack cases.
20#[derive(Debug)]
21pub enum TestCommand {
22    /// Make the node vote for the given proposal regardless of its consensus
23    /// state. It will not vote if the proposal was not received.
24    ForceVoteProposal(HashValue),
25    /// Make the node propose a block with given round, parent, and payload.
26    /// It will not propose if the parent does not have a valid QC.
27    ForcePropose {
28        /// Proposed block round.
29        round: Round,
30        /// Proposed block parent. A valid QC will be retrieved to match this
31        /// parent.
32        parent_id: HashValue,
33        /// Payload for the proposed block. The PoW internal contract events
34        /// will not be appended automatically.
35        payload: Vec<TransactionPayload>,
36    },
37    /// Trigger propose_timeout
38    ProposalTimeOut,
39    /// Trigger local_timeout
40    LocalTimeout,
41    /// Trigger new_round_timeout
42    NewRoundTimeout,
43    /// Sign and broadcast a pivot decision transaction
44    BroadcastPivotDecision(PivotBlockDecision),
45    /// Sign and broadcast an election transaction with a target term
46    BroadcastElection(u64),
47    /// Stop broadcasting elections to prepare for a restart
48    /// Return the round when the node is safe to be stopped without retiring.
49    StopElection(mpsc::SyncSender<Option<Round>>),
50    /// Start voting and return errors if it fails.
51    /// The first parameter is true means the node will start voting with its
52    /// local safety data.
53    StartVoting((bool, mpsc::SyncSender<anyhow::Result<()>>)),
54    /// Stop voting and return errors if it fails.
55    StopVoting(mpsc::SyncSender<anyhow::Result<()>>),
56    /// Return if the node is voting.
57    GetVotingStatus(mpsc::SyncSender<bool>),
58
59    /// Read-only command
60    /// Get the chosen to-vote proposal
61    GetChosenProposal(mpsc::SyncSender<Option<Block>>),
62}