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
15pub mod config_subscription;
16#[cfg(any(test, feature = "fuzzing"))]
17pub mod mock_time_service;
18pub mod time_service;
19
20/// Test command sent by RPCs to construct attack cases.
21#[derive(Debug)]
22pub enum TestCommand {
23 /// Make the node vote for the given proposal regardless of its consensus
24 /// state. It will not vote if the proposal was not received.
25 ForceVoteProposal(HashValue),
26 /// Make the node propose a block with given round, parent, and payload.
27 /// It will not propose if the parent does not have a valid QC.
28 ForcePropose {
29 /// Proposed block round.
30 round: Round,
31 /// Proposed block parent. A valid QC will be retrieved to match this
32 /// parent.
33 parent_id: HashValue,
34 /// Payload for the proposed block. The PoW internal contract events
35 /// will not be appended automatically.
36 payload: Vec<TransactionPayload>,
37 },
38 /// Trigger propose_timeout
39 ProposalTimeOut,
40 /// Trigger local_timeout
41 LocalTimeout,
42 /// Trigger new_round_timeout
43 NewRoundTimeout,
44 /// Sign and broadcast a pivot decision transaction
45 BroadcastPivotDecision(PivotBlockDecision),
46 /// Sign and broadcast an election transaction with a target term
47 BroadcastElection(u64),
48 /// Stop broadcasting elections to prepare for a restart
49 /// Return the round when the node is safe to be stopped without retiring.
50 StopElection(mpsc::SyncSender<Option<Round>>),
51 /// Start voting and return errors if it fails.
52 /// The first parameter is true means the node will start voting with its
53 /// local safety data.
54 StartVoting((bool, mpsc::SyncSender<anyhow::Result<()>>)),
55 /// Stop voting and return errors if it fails.
56 StopVoting(mpsc::SyncSender<anyhow::Result<()>>),
57 /// Return if the node is voting.
58 GetVotingStatus(mpsc::SyncSender<bool>),
59
60 /// Read-only command
61 /// Get the chosen to-vote proposal
62 GetChosenProposal(mpsc::SyncSender<Option<Block>>),
63}