cfxcore/pos/protocol/message/
consensus_msg.rs1use crate::{
6 pos::{
7 consensus::network::ConsensusMsg,
8 protocol::sync_protocol::{Context, Handleable},
9 },
10 sync::Error,
11};
12use diem_logger::prelude::{diem_debug, diem_trace};
13use std::mem::discriminant;
14
15impl Handleable for ConsensusMsg {
16 fn handle(self, ctx: &Context) -> Result<(), Error> {
17 diem_debug!("on_consensus_msg, msg={:?}", &self);
18 let peer_address = ctx.get_peer_account_address()?;
19 let author = match &self {
22 ConsensusMsg::ProposalMsg(p) => p.proposer().ok_or_else(|| {
23 diem_trace!(
24 "Dropping authorless proposal from {:?}",
25 peer_address
26 );
27 Error::InvalidMessageFormat
28 })?,
29 ConsensusMsg::VoteMsg(v) => v.vote().author(),
30 _ => peer_address,
31 };
32 ctx.manager
33 .consensus_network_task
34 .consensus_messages_tx
35 .push((author, discriminant(&self)), (peer_address, self))?;
36 Ok(())
37 }
38}