tendermint/abci/request/
apply_snapshot_chunk.rs

1use bytes::Bytes;
2
3// bring into scope for doc links
4#[allow(unused)]
5use super::{super::types::Snapshot, Info, LoadSnapshotChunk};
6use crate::prelude::*;
7
8/// Applies a snapshot chunk.
9///
10/// The application can choose to refetch chunks and/or ban P2P peers as
11/// appropriate. Tendermint will not do this unless instructed by the
12/// application.
13///
14/// The application may want to verify each chunk, e.g., by attaching chunk
15/// hashes in [`Snapshot::metadata`] and/or incrementally verifying contents
16/// against `app_hash`.
17///
18/// When all chunks have been accepted, Tendermint will make an ABCI [`Info`]
19/// request to verify that `last_block_app_hash` and `last_block_height` match
20/// the expected values, and record the `app_version` in the node state. It then
21/// switches to fast sync or consensus and joins the network.
22///
23/// If Tendermint is unable to retrieve the next chunk after some time (e.g.,
24/// because no suitable peers are available), it will reject the snapshot and try
25/// a different one via `OfferSnapshot`. The application should be prepared to
26/// reset and accept it or abort as appropriate.
27///
28/// [ABCI documentation](https://docs.tendermint.com/master/spec/abci/abci.html#applysnapshotchunk)
29#[derive(Clone, PartialEq, Eq, Debug)]
30pub struct ApplySnapshotChunk {
31    /// The chunk index, starting from `0`.  Tendermint applies chunks sequentially.
32    pub index: u32,
33    /// The binary chunk contents, as returned by [`LoadSnapshotChunk`].
34    pub chunk: Bytes,
35    /// The P2P ID of the node who sent this chunk.
36    pub sender: String,
37}
38
39// =============================================================================
40// Protobuf conversions
41// =============================================================================
42
43tendermint_pb_modules! {
44    use super::ApplySnapshotChunk;
45
46    impl From<ApplySnapshotChunk> for pb::abci::RequestApplySnapshotChunk {
47        fn from(apply_snapshot_chunk: ApplySnapshotChunk) -> Self {
48            Self {
49                index: apply_snapshot_chunk.index,
50                chunk: apply_snapshot_chunk.chunk,
51                sender: apply_snapshot_chunk.sender,
52            }
53        }
54    }
55
56    impl TryFrom<pb::abci::RequestApplySnapshotChunk> for ApplySnapshotChunk {
57        type Error = crate::Error;
58
59        fn try_from(apply_snapshot_chunk: pb::abci::RequestApplySnapshotChunk) -> Result<Self, Self::Error> {
60            Ok(Self {
61                index: apply_snapshot_chunk.index,
62                chunk: apply_snapshot_chunk.chunk,
63                sender: apply_snapshot_chunk.sender,
64            })
65        }
66    }
67
68    impl Protobuf<pb::abci::RequestApplySnapshotChunk> for ApplySnapshotChunk {}
69}