Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
pmnoxx committed Dec 22, 2021
1 parent 2f7261f commit 29bb4b5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 14 deletions.
10 changes: 2 additions & 8 deletions chain/chain/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,10 +549,7 @@ impl ChainStore {
&self,
id: &CryptoHash,
) -> Result<Vec<ExecutionOutcomeWithIdAndProof>, Error> {
Ok(self
.store
.get_ser(ColTransactionResult, id.as_ref())?
.unwrap_or_else(std::vec::Vec::new))
Ok(self.store.get_ser(ColTransactionResult, id.as_ref())?.unwrap_or_default())
}

/// Returns a vector of Outcome ids for given block and shard id
Expand Down Expand Up @@ -1016,10 +1013,7 @@ impl ChainStoreAccess for ChainStore {
}

fn get_blocks_to_catchup(&self, hash: &CryptoHash) -> Result<Vec<CryptoHash>, Error> {
Ok(self
.store
.get_ser(ColBlocksToCatchup, hash.as_ref())?
.unwrap_or_else(std::vec::Vec::new))
Ok(self.store.get_ser(ColBlocksToCatchup, hash.as_ref())?.unwrap_or_default())
}

fn is_block_challenged(&mut self, hash: &CryptoHash) -> Result<bool, Error> {
Expand Down
8 changes: 3 additions & 5 deletions chain/chunks/src/chunk_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,8 @@ impl EncodedChunksCache {
&& height <= self.largest_seen_height + MAX_HEIGHTS_AHEAD
{
let prev_block_hash = header.prev_block_hash();
let mut block_hash_to_chunk_headers = self
.block_hash_to_chunk_headers
.cache_remove(&prev_block_hash)
.unwrap_or_else(HashMap::new);
let mut block_hash_to_chunk_headers =
self.block_hash_to_chunk_headers.cache_remove(&prev_block_hash).unwrap_or_default();
block_hash_to_chunk_headers.insert(shard_id, header);
self.block_hash_to_chunk_headers
.cache_set(prev_block_hash, block_hash_to_chunk_headers);
Expand All @@ -192,7 +190,7 @@ impl EncodedChunksCache {
&mut self,
prev_block_hash: &CryptoHash,
) -> HashMap<ShardId, ShardChunkHeader> {
self.block_hash_to_chunk_headers.cache_remove(prev_block_hash).unwrap_or_else(HashMap::new)
self.block_hash_to_chunk_headers.cache_remove(prev_block_hash).unwrap_or_default()
}

/// Returns number of chunks that are ready to be included in the next block
Expand Down
2 changes: 1 addition & 1 deletion chain/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1300,7 +1300,7 @@ impl Client {
}
}
let mut entry =
self.pending_approvals.cache_remove(&approval.inner).unwrap_or_else(HashMap::new);
self.pending_approvals.cache_remove(&approval.inner).unwrap_or_default();
entry.insert(approval.account_id.clone(), (approval.clone(), approval_type));
self.pending_approvals.cache_set(approval.inner.clone(), entry);
}
Expand Down

0 comments on commit 29bb4b5

Please # to comment.