cfxcore/sync/message/
state_sync_candidate_response.rs

1use crate::{
2    message::{
3        GetMaybeRequestId, Message, MessageProtocolVersionBound, MsgId,
4        RequestId,
5    },
6    sync::{
7        message::{msgid, Context, Handleable, StateSyncCandidateRequest},
8        state::storage::SnapshotSyncCandidate,
9        Error, SYNC_PROTO_V1, SYNC_PROTO_V3,
10    },
11};
12use network::service::ProtocolVersion;
13use rlp::Encodable;
14use rlp_derive::{RlpDecodable, RlpEncodable};
15
16#[derive(RlpEncodable, RlpDecodable, Debug)]
17pub struct StateSyncCandidateResponse {
18    pub request_id: RequestId,
19    pub supported_candidates: Vec<SnapshotSyncCandidate>,
20}
21
22build_msg_impl! {
23    StateSyncCandidateResponse, msgid::STATE_SYNC_CANDIDATE_RESPONSE,
24    "StateSyncCandidateResponse", SYNC_PROTO_V1, SYNC_PROTO_V3
25}
26
27impl Handleable for StateSyncCandidateResponse {
28    fn handle(self, ctx: &Context) -> Result<(), Error> {
29        let message = ctx.match_request(self.request_id)?;
30        let request = message.downcast_ref::<StateSyncCandidateRequest>(
31            ctx.io,
32            &ctx.manager.request_manager,
33        )?;
34        debug!("Receive StateSyncCandidateResponse={:?}", self);
35        ctx.manager.state_sync.handle_snapshot_candidate_response(
36            &ctx.node_id,
37            &self.supported_candidates,
38            &request.candidates,
39        );
40        Ok(())
41    }
42}