-
Notifications
You must be signed in to change notification settings - Fork 986
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'bat/feat/list-and-offer-snapshots' (#3386)
* origin/bat/feat/list-and-offer-snapshots: rebasing tinies Added changelog
- Loading branch information
Showing
7 changed files
with
301 additions
and
42 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
.changelog/unreleased/improvements/3386-listsnapshots-loadsnapshotchunk.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
- Addresses the third point and part of the fourth point of Issue | ||
[\#3307](https://github.com/anoma/namada/issues/3307) | ||
* Adds chunking logic to snapshots | ||
* Implements the `ListSnapshots` ABCI call | ||
* Implements the `LoadSnapshotChunk` ABCI call | ||
|
||
([\#3386](https://github.com/anoma/namada/pull/3386)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use borsh_ext::BorshSerializeExt; | ||
use namada::hash::{Hash, Sha256Hasher}; | ||
use namada::state::BlockHeight; | ||
|
||
use super::{Error, Result}; | ||
use crate::facade::tendermint::abci::types::Snapshot; | ||
use crate::facade::tendermint::v0_37::abci::{ | ||
request as tm_request, response as tm_response, | ||
}; | ||
use crate::shell::Shell; | ||
use crate::storage; | ||
use crate::storage::{DbSnapshot, SnapshotMetadata}; | ||
|
||
impl Shell<storage::PersistentDB, Sha256Hasher> { | ||
/// List the snapshot files held locally. Furthermore, the number | ||
/// of chunks, as hash of each chunk, and a hash of the chunk | ||
/// metadata are provided so that syncing nodes can verify can verify | ||
/// snapshots they receive. | ||
pub fn list_snapshots(&self) -> Result<tm_response::ListSnapshots> { | ||
if self.blocks_between_snapshots.is_none() { | ||
Ok(Default::default()) | ||
} else { | ||
let snapshots = DbSnapshot::files(&self.base_dir) | ||
.map_err(Error::Snapshot)? | ||
.into_iter() | ||
.map(|SnapshotMetadata { height, chunks, .. }| { | ||
let hash = Hash::sha256(chunks.serialize_to_vec()).0; | ||
Snapshot { | ||
height: u32::try_from(height.0).unwrap().into(), | ||
format: 0, | ||
#[allow(clippy::cast_possible_truncation)] | ||
chunks: chunks.len() as u32, | ||
hash: hash.into_iter().collect(), | ||
metadata: Default::default(), | ||
} | ||
}) | ||
.collect(); | ||
|
||
Ok(tm_response::ListSnapshots { snapshots }) | ||
} | ||
} | ||
|
||
/// Load the bytes of a requested chunk and return them | ||
/// to cometbft. | ||
pub fn load_snapshot_chunk( | ||
&self, | ||
req: tm_request::LoadSnapshotChunk, | ||
) -> Result<tm_response::LoadSnapshotChunk> { | ||
let chunk = DbSnapshot::load_chunk( | ||
BlockHeight(req.height.into()), | ||
u64::from(req.chunk), | ||
&self.base_dir, | ||
) | ||
.map_err(Error::Snapshot)?; | ||
Ok(tm_response::LoadSnapshotChunk { | ||
chunk: chunk.into_iter().collect(), | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.