cfxcore/pos/protocol/message/
sync_info.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::sync_info::SyncInfo;
13use diem_logger::prelude::diem_debug;
14use std::mem::discriminant;
15
16impl Handleable for SyncInfo {
17    fn handle(self, ctx: &Context) -> Result<(), Error> {
18        diem_debug!("on_sync_info, msg={:?}", &self);
19
20        let peer_address = ctx.get_peer_account_address()?;
21
22        let msg = ConsensusMsg::SyncInfo(Box::new(self));
23        ctx.manager
24            .consensus_network_task
25            .consensus_messages_tx
26            .push((peer_address, discriminant(&msg)), (peer_address, msg))?;
27        Ok(())
28    }
29}