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, diem_trace};
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        // Drop NilBlock/Genesis-shaped peer proposals: the channel keys
29        // by `(author, discriminant)` so we need a real author here.
30        let author = self.proposer().ok_or_else(|| {
31            diem_trace!("Dropping authorless proposal from {:?}", peer_address);
32            Error::InvalidMessageFormat
33        })?;
34        let msg = ConsensusMsg::ProposalMsg(Box::new(self));
35        ctx.manager
36            .consensus_network_task
37            .consensus_messages_tx
38            .push((author, discriminant(&msg)), (peer_address, msg))?;
39        Ok(())
40    }
41}