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