Skip to content

Commit

Permalink
feat(Store Validator): use thiserror + minor updates (#2848)
Browse files Browse the repository at this point in the history
- DBCol is iterable by strum
- save_chunk and save_partial_chunk are safe from incorrect writing
- StoreValidator error usage refactoring, using thiserror crate
- sanity tests for StoreValidator errors are added
- check_discrepancy and check_cached macro for quick validations
- get_block_shard_id_rev not panics for invalid keys
- minor updates
  • Loading branch information
Kouprin authored Jun 15, 2020
1 parent eca04c2 commit bf5f272
Show file tree
Hide file tree
Showing 11 changed files with 355 additions and 279 deletions.
7 changes: 6 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions chain/chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ cached = "0.12"
lazy_static = "1.4"
num-rational = "0.2.4"
tracing = "0.1.13"
thiserror = "1.0"
strum = "0.18"

borsh = "0.6.2"

Expand Down
4 changes: 2 additions & 2 deletions chain/chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ impl Chain {
Err(err) => match err.kind() {
ErrorKind::DBNotFoundErr(_) => {
for chunk in genesis_chunks {
store_update.save_chunk(&chunk.chunk_hash, chunk.clone());
store_update.save_chunk(chunk.clone());
}
runtime_adapter.add_validator_proposals(BlockHeaderInfo::new(
&genesis.header(),
Expand Down Expand Up @@ -3387,7 +3387,7 @@ impl<'a> ChainUpdate<'a> {
let (outcome_root, outcome_proofs) =
ApplyTransactionResult::compute_outcomes_proof(&apply_result.outcomes);

self.chain_store_update.save_chunk(&chunk.chunk_hash, chunk.clone());
self.chain_store_update.save_chunk(chunk.clone());

self.chain_store_update.save_trie_changes(apply_result.trie_changes);
let chunk_extra = ChunkExtra::new(
Expand Down
14 changes: 6 additions & 8 deletions chain/chain/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1652,16 +1652,14 @@ impl<'a> ChainStoreUpdate<'a> {
self.chain_store_cache_update.chunk_extras.insert((*block_hash, shard_id), chunk_extra);
}

pub fn save_chunk(&mut self, chunk_hash: &ChunkHash, chunk: ShardChunk) {
self.chain_store_cache_update.chunks.insert(chunk_hash.clone(), chunk);
pub fn save_chunk(&mut self, chunk: ShardChunk) {
self.chain_store_cache_update.chunks.insert(chunk.chunk_hash.clone(), chunk);
}

pub fn save_partial_chunk(
&mut self,
chunk_hash: &ChunkHash,
partial_chunk: PartialEncodedChunk,
) {
self.chain_store_cache_update.partial_chunks.insert(chunk_hash.clone(), partial_chunk);
pub fn save_partial_chunk(&mut self, partial_chunk: PartialEncodedChunk) {
self.chain_store_cache_update
.partial_chunks
.insert(partial_chunk.header.hash.clone(), partial_chunk);
}

pub fn save_block_merkle_tree(
Expand Down
Loading

0 comments on commit bf5f272

Please sign in to comment.