cfxcore/pos/protocol/message/
vote.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 consensus_types::vote_msg::VoteMsg;
13use diem_logger::prelude::diem_debug;
14use std::mem::discriminant;
15
16impl Handleable for VoteMsg {
17    fn handle(self, ctx: &Context) -> Result<(), Error> {
18        diem_debug!("on_vote, msg={:?}", &self);
19
20        let peer_address = ctx.get_peer_account_address()?;
21
22        /*ensure!(
23            self.vote().author() == peer_address,
24            "vote received must be from the sending peer"
25        );*/
26
27        //self.verify(&ctx.manager.network_task.epoch_info.read().verifier())?;
28        let author = self.vote().author();
29        let msg = ConsensusMsg::VoteMsg(Box::new(self));
30        ctx.manager
31            .consensus_network_task
32            .consensus_messages_tx
33            .push((author, discriminant(&msg)), (peer_address, msg))?;
34        Ok(())
35    }
36}