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