cfxcore/pos/protocol/message/
consensus_msg.rs

1// Copyright 2019-2020 Conflux Foundation. All rights reserved.
2// TreeGraph is free software and distributed under Apache License 2.0.
3// See https://www.apache.org/licenses/LICENSE-2.0
4
5use crate::{
6    pos::{
7        consensus::network::ConsensusMsg,
8        protocol::sync_protocol::{Context, Handleable},
9    },
10    sync::Error,
11};
12use diem_logger::prelude::diem_debug;
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 {
20            ConsensusMsg::ProposalMsg(p) => p.proposer(),
21            ConsensusMsg::VoteMsg(v) => v.vote().author(),
22            _ => peer_address,
23        };
24        ctx.manager
25            .consensus_network_task
26            .consensus_messages_tx
27            .push((author, discriminant(&self)), (peer_address, self))?;
28        Ok(())
29    }
30}