Skip to content

Commit

Permalink
refactor: add FlatStateDeltaMetadata::has_changes (#10647)
Browse files Browse the repository at this point in the history
This PR is a follow-up for [this
comment](https://github.com/near/nearcore/pull/10608/files#r1499133795).

This expresses the contract around `prev_block_with_changes` with a
separate function since `prev_block_with_changes.is_none()` check is
confusing
```
    /// `None` if the block itself has flat state changes.
    /// `Some` if the block has no flat state changes, and contains
    /// info of the last block with some flat state changes.
```
  • Loading branch information
pugachAG authored Feb 22, 2024
1 parent 6dfaa36 commit f051314
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
7 changes: 7 additions & 0 deletions core/store/src/flat/delta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ pub struct FlatStateDeltaMetadata {
pub prev_block_with_changes: Option<BlockWithChangesInfo>,
}

impl FlatStateDeltaMetadata {
#[inline]
pub fn has_changes(&self) -> bool {
self.prev_block_with_changes.is_none()
}
}

#[derive(BorshSerialize, BorshDeserialize, Debug)]
pub struct KeyForFlatStateDelta {
pub shard_uid: ShardUId,
Expand Down
5 changes: 1 addition & 4 deletions core/store/src/flat/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,7 @@ impl FlatStorage {
let mut deltas = HashMap::new();
for delta_metadata in deltas_metadata {
let block_hash = delta_metadata.block.hash;
let changes: CachedFlatStateChanges = if delta_metadata
.prev_block_with_changes
.is_none()
{
let changes: CachedFlatStateChanges = if delta_metadata.has_changes() {
store_helper::get_delta_changes(&store, shard_uid, block_hash)
.expect("failed to read flat state delta changes")
.unwrap_or_else(|| {
Expand Down

0 comments on commit f051314

Please sign in to comment.