tendermint/abci/response/
apply_snapshot_chunk.rs

1use crate::prelude::*;
2
3#[doc = include_str!("../doc/response-applysnapshotchunk.md")]
4#[derive(Clone, PartialEq, Eq, Debug, Default)]
5pub struct ApplySnapshotChunk {
6    /// The result of applying the snapshot chunk.
7    pub result: ApplySnapshotChunkResult,
8    /// Refetch and reapply the given chunks, regardless of `result`.
9    ///
10    /// Only the listed chunks will be refetched, and reapplied in sequential
11    /// order.
12    pub refetch_chunks: Vec<u32>,
13    /// Reject the given P2P senders, regardless of `result`.
14    ///
15    /// Any chunks already applied will not be refetched unless explicitly
16    /// requested, but queued chunks from these senders will be discarded, and
17    /// new chunks or other snapshots rejected.
18    pub reject_senders: Vec<String>,
19}
20
21/// The result of applying a snapshot chunk.
22#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
23#[repr(i32)]
24pub enum ApplySnapshotChunkResult {
25    /// Unknown result, abort all snapshot restoration.
26    Unknown = 0,
27    /// The chunk was accepted.
28    Accept = 1,
29    /// Abort snapshot restoration, and don't try any other snapshots.
30    Abort = 2,
31    /// Reapply this chunk, combine with
32    /// [`refetch_chunks`](ApplySnapshotChunk::refetch_chunks) and
33    /// [`reject_senders`](ApplySnapshotChunk::reject_senders) as appropriate.
34    Retry = 3,
35    /// Restart this snapshot from
36    /// [`OfferSnapshot`](super::super::request::OfferSnapshot),
37    /// reusing chunks unless instructed otherwise.
38    RetrySnapshot = 4,
39    /// Reject this snapshot, try a different one.
40    RejectSnapshot = 5,
41}
42
43impl Default for ApplySnapshotChunkResult {
44    fn default() -> Self {
45        Self::Unknown
46    }
47}
48
49// =============================================================================
50// Protobuf conversions
51// =============================================================================
52
53tendermint_pb_modules! {
54    use super::{ApplySnapshotChunk, ApplySnapshotChunkResult};
55
56    impl From<ApplySnapshotChunk> for pb::abci::ResponseApplySnapshotChunk {
57        fn from(apply_snapshot_chunk: ApplySnapshotChunk) -> Self {
58            Self {
59                result: apply_snapshot_chunk.result as i32,
60                refetch_chunks: apply_snapshot_chunk.refetch_chunks,
61                reject_senders: apply_snapshot_chunk.reject_senders,
62            }
63        }
64    }
65
66    impl TryFrom<pb::abci::ResponseApplySnapshotChunk> for ApplySnapshotChunk {
67        type Error = crate::Error;
68
69        fn try_from(apply_snapshot_chunk: pb::abci::ResponseApplySnapshotChunk) -> Result<Self, Self::Error> {
70            let result = match apply_snapshot_chunk.result {
71                0 => ApplySnapshotChunkResult::Unknown,
72                1 => ApplySnapshotChunkResult::Accept,
73                2 => ApplySnapshotChunkResult::Abort,
74                3 => ApplySnapshotChunkResult::Retry,
75                4 => ApplySnapshotChunkResult::RetrySnapshot,
76                5 => ApplySnapshotChunkResult::RejectSnapshot,
77                _ => return Err(crate::Error::unsupported_apply_snapshot_chunk_result()),
78            };
79            Ok(Self {
80                result,
81                refetch_chunks: apply_snapshot_chunk.refetch_chunks,
82                reject_senders: apply_snapshot_chunk.reject_senders,
83            })
84        }
85    }
86
87    impl Protobuf<pb::abci::ResponseApplySnapshotChunk> for ApplySnapshotChunk {}
88}