Skip to content

Commit 60f0e35

Browse files
foriequal0majecty
authored andcommitted
Remove vote_collector::Message trait
ConsensusMessage is the only implementation.
1 parent d243fc4 commit 60f0e35

File tree

10 files changed

+132
-223
lines changed

10 files changed

+132
-223
lines changed

core/src/consensus/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ pub use self::tendermint::{
3737
};
3838
pub use self::validator_set::validator_list::RoundRobinValidator;
3939
pub use self::validator_set::{DynamicValidator, ValidatorSet};
40-
pub use self::vote_collector::Message;
4140

4241
use std::fmt;
4342
use std::sync::{Arc, Weak};

core/src/consensus/solo/mod.rs

Lines changed: 3 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,16 @@ mod params;
1818

1919
use std::sync::Arc;
2020

21-
use ckey::{Address, Error as KeyError, Public, SchnorrSignature};
21+
use ckey::Address;
2222
use cstate::{ActionHandler, HitHandler};
2323
use ctypes::{CommonParams, Header};
24-
use primitives::H256;
25-
use rlp::{Decodable, DecoderError, Encodable, RlpStream, UntrustedRlp};
2624

2725
use self::params::SoloParams;
2826
use super::stake;
2927
use super::{ConsensusEngine, Seal};
3028
use crate::block::{ExecutedBlock, IsBlock};
3129
use crate::codechain_machine::CodeChainMachine;
32-
use crate::consensus::{EngineError, EngineType, Message};
30+
use crate::consensus::{EngineError, EngineType};
3331
use crate::error::Error;
3432

3533
/// A consensus engine which does not provide any consensus mechanism.
@@ -39,61 +37,14 @@ pub struct Solo {
3937
action_handlers: Vec<Arc<ActionHandler>>,
4038
}
4139

42-
#[derive(Debug, PartialEq, Eq, Clone, Hash, Default)]
43-
pub struct SoloMessage {}
44-
45-
impl Encodable for SoloMessage {
46-
fn rlp_append(&self, s: &mut RlpStream) {
47-
s.append_empty_data();
48-
}
49-
}
50-
51-
impl Decodable for SoloMessage {
52-
fn decode(_rlp: &UntrustedRlp) -> Result<Self, DecoderError> {
53-
Ok(SoloMessage {})
54-
}
55-
}
56-
57-
impl Message for SoloMessage {
58-
type Round = bool;
59-
60-
fn signature(&self) -> SchnorrSignature {
61-
SchnorrSignature::random()
62-
}
63-
64-
fn signer_index(&self) -> usize {
65-
Default::default()
66-
}
67-
68-
fn block_hash(&self) -> Option<H256> {
69-
None
70-
}
71-
72-
fn round(&self) -> &bool {
73-
&false
74-
}
75-
76-
fn height(&self) -> u64 {
77-
0
78-
}
79-
80-
fn is_broadcastable(&self) -> bool {
81-
false
82-
}
83-
84-
fn verify(&self, _signer_public: &Public) -> Result<bool, KeyError> {
85-
Ok(true)
86-
}
87-
}
88-
8940
impl Solo {
9041
/// Returns new instance of Solo over the given state machine.
9142
pub fn new(params: SoloParams, machine: CodeChainMachine) -> Self {
9243
let mut action_handlers: Vec<Arc<ActionHandler>> = Vec::new();
9344
if params.enable_hit_handler {
9445
action_handlers.push(Arc::new(HitHandler::new()));
9546
}
96-
action_handlers.push(Arc::new(stake::Stake::<SoloMessage>::new(params.genesis_stakes.clone())));
47+
action_handlers.push(Arc::new(stake::Stake::new(params.genesis_stakes.clone())));
9748

9849
Solo {
9950
params,

core/src/consensus/stake/actions.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ use std::sync::Arc;
1919
use ccrypto::Blake;
2020
use ckey::{recover, Address, Signature};
2121
use client::ConsensusClient;
22-
use consensus::vote_collector::Message;
23-
use consensus::ValidatorSet;
2422
use ctypes::errors::SyntaxError;
2523
use ctypes::CommonParams;
2624
use primitives::{Bytes, H256};
2725
use rlp::{Decodable, DecoderError, Encodable, RlpStream, UntrustedRlp};
2826

27+
use crate::consensus::{ConsensusMessage, ValidatorSet};
28+
2929
const ACTION_TAG_TRANSFER_CCS: u8 = 1;
3030
const ACTION_TAG_DELEGATE_CCS: u8 = 2;
3131
const ACTION_TAG_REVOKE: u8 = 3;
@@ -35,7 +35,7 @@ const ACTION_TAG_REDELEGATE: u8 = 6;
3535
const ACTION_TAG_CHANGE_PARAMS: u8 = 0xFF;
3636

3737
#[derive(Debug, PartialEq)]
38-
pub enum Action<M: Message> {
38+
pub enum Action {
3939
TransferCCS {
4040
address: Address,
4141
quantity: u64,
@@ -62,13 +62,14 @@ pub enum Action<M: Message> {
6262
params: Box<CommonParams>,
6363
signatures: Vec<Signature>,
6464
},
65+
// TODO: ConsensusMessage is tied to the Tendermint
6566
ReportDoubleVote {
66-
message1: M,
67-
message2: M,
67+
message1: ConsensusMessage,
68+
message2: ConsensusMessage,
6869
},
6970
}
7071

71-
impl<M: Message> Action<M> {
72+
impl Action {
7273
pub fn verify(
7374
&self,
7475
current_params: &CommonParams,
@@ -113,7 +114,7 @@ impl<M: Message> Action<M> {
113114
)))
114115
}
115116
params.verify().map_err(SyntaxError::InvalidCustomAction)?;
116-
let action = Action::<M>::ChangeParams {
117+
let action = Action::ChangeParams {
117118
metadata_seq: *metadata_seq,
118119
params: params.clone(),
119120
signatures: vec![],
@@ -183,7 +184,7 @@ impl<M: Message> Action<M> {
183184
}
184185
}
185186

186-
impl<M: Message> Encodable for Action<M> {
187+
impl Encodable for Action {
187188
fn rlp_append(&self, s: &mut RlpStream) {
188189
match self {
189190
Action::TransferCCS {
@@ -244,7 +245,7 @@ impl<M: Message> Encodable for Action<M> {
244245
}
245246
}
246247

247-
impl<M: Message> Decodable for Action<M> {
248+
impl Decodable for Action {
248249
fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> {
249250
let tag = rlp.val_at(0)?;
250251
match tag {
@@ -357,13 +358,12 @@ mod tests {
357358
use ccrypto::blake256;
358359
use ckey::sign_schnorr;
359360
use client::TestBlockChainClient;
360-
use consensus::solo::SoloMessage;
361361
use consensus::{message_info_rlp, ConsensusMessage, DynamicValidator, Step, VoteOn, VoteStep};
362362
use rlp::rlp_encode_and_decode_test;
363363

364364
#[test]
365365
fn decode_fail_if_change_params_have_no_signatures() {
366-
let action = Action::<SoloMessage>::ChangeParams {
366+
let action = Action::ChangeParams {
367367
metadata_seq: 3,
368368
params: CommonParams::default_for_test().into(),
369369
signatures: vec![],
@@ -373,13 +373,13 @@ mod tests {
373373
expected: 4,
374374
got: 3,
375375
}),
376-
UntrustedRlp::new(&rlp::encode(&action)).as_val::<Action<SoloMessage>>()
376+
UntrustedRlp::new(&rlp::encode(&action)).as_val::<Action>()
377377
);
378378
}
379379

380380
#[test]
381381
fn rlp_of_change_params() {
382-
rlp_encode_and_decode_test!(Action::<SoloMessage>::ChangeParams {
382+
rlp_encode_and_decode_test!(Action::ChangeParams {
383383
metadata_seq: 3,
384384
params: CommonParams::default_for_test().into(),
385385
signatures: vec![Signature::random(), Signature::random()],
@@ -448,7 +448,7 @@ mod tests {
448448
create_consensus_message(message_info1, &test_client, vote_step_twister, block_hash_twister);
449449
let consensus_message2 =
450450
create_consensus_message(message_info2, &test_client, vote_step_twister, block_hash_twister);
451-
let action = Action::<ConsensusMessage>::ReportDoubleVote {
451+
let action = Action::ReportDoubleVote {
452452
message1: consensus_message1,
453453
message2: consensus_message2,
454454
};

0 commit comments

Comments
 (0)