cfxcore/pos/protocol/message/
proposal.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};
12
13use consensus_types::proposal_msg::ProposalMsg;
14use diem_logger::prelude::diem_debug;
15use std::mem::discriminant;
16
17impl Handleable for ProposalMsg {
18    fn handle(self, ctx: &Context) -> Result<(), Error> {
19        diem_debug!("on_proposal, msg={:?}", &self);
20
21        let peer_address = ctx.get_peer_account_address()?;
22
23        /*ensure!(
24            self.author() == Some(peer_address),
25            "proposal received must be from the sending peer"
26        );*/
27
28        let author = self.proposer();
29        let msg = ConsensusMsg::ProposalMsg(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}