Skip to content

Commit 3262d88

Browse files
authored
Fix pending change after flushing RegisterView (#3133)
## Motivation <!-- Briefly describe the goal(s) of this PR. --> @afck ran into an issue where an assertion caught unexpected pending changes after voting for a block proposal. After investigating the issue, the cause seems to be that `RegisterView::flush` had an edge case where it wouldn't clear it's `update` field. ## Proposal <!-- Summarize the proposed changes and how they address the goal(s) stated above. --> Clear the `update` field after successfully flushing. ## Test Plan <!-- Explain how you made sure that the changes are correct and that they perform as intended. Please describe testing protocols (CI, manual tests, benchmarks, etc) in a way that others can reproduce the results. --> A unit test was added to reproduce the issue. ## Release Plan <!-- If this PR targets the `main` branch, **keep the applicable lines** to indicate if you recommend the changes to be picked in release branches, SDKs, and hotfixes. This generally concerns only bug fixes. Note that altering the public protocol (e.g. transaction format, WASM syscalls) or storage formats requires a new deployment. --> - These changes should be backported to the latest `devnet` branch, then - be released in a validator hotfix. - These changes should be backported to the latest `testnet` branch, then - be released in a validator hotfix. ## Links <!-- Optional section for related PRs, related issues, and other references. If needed, please create issues to track future improvements and link them here. --> - [reviewer checklist](https://github.com/linera-io/linera-protocol/blob/main/CONTRIBUTING.md#reviewer-checklist)
1 parent fbd08e9 commit 3262d88

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

linera-views/src/views/register_view.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ where
9999
self.stored_value = value;
100100
}
101101
self.delete_storage_first = false;
102+
self.update = None;
102103
Ok(delete_view)
103104
}
104105

linera-views/src/views/unit_tests/views.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,22 @@ async fn test_reentrant_collection_view_has_pending_changes_after_try_load_entri
480480
Ok(())
481481
}
482482

483+
/// Checks if a cleared [`RegisterView`] has no pending changes after flushing.
484+
#[tokio::test]
485+
async fn test_flushing_cleared_register_view() -> anyhow::Result<()> {
486+
let context = create_test_memory_context();
487+
let mut view = RegisterView::<_, bool>::load(context.clone()).await?;
488+
489+
assert!(!view.has_pending_changes().await);
490+
view.clear();
491+
assert!(view.has_pending_changes().await);
492+
493+
save_view(&context, &mut view).await?;
494+
assert!(!view.has_pending_changes().await);
495+
496+
Ok(())
497+
}
498+
483499
/// Saves a [`View`] into the [`MemoryContext<()>`] storage simulation.
484500
async fn save_view<C>(context: &C, view: &mut impl View<C>) -> anyhow::Result<()>
485501
where

0 commit comments

Comments
 (0)