Skip to content

Commit 0b4317b

Browse files
yoavGrsclaude
andauthored
apollo_committer: fix revert_happy_flow test to use same-key update for block 1 (#13756)
Block 1 previously added a different class hash key than block 0, so the reversed state diff (re-applying block 0's diff) couldn't restore the tree to block 0's state with real incremental storage. Block 1 now updates the same ClassHash(1) key to CompiledClassHash(2), making its reversal (restoring ClassHash(1) to CompiledClassHash(1)) an exact inverse. Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 602095a commit 0b4317b

1 file changed

Lines changed: 28 additions & 9 deletions

File tree

crates/apollo_committer/src/committer_test.rs

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -228,28 +228,47 @@ async fn commit_idempotent_test() {
228228
/// Commits blocks 0, 1. Reverts block 1.
229229
async fn revert_happy_flow() {
230230
let mut committer = new_test_committer().await;
231-
let mut height = 0;
232-
let state_diff_1 = 1;
233-
let state_diff_2 = 2;
231+
let height_0 = 0;
232+
let height_1 = 1;
233+
let class_hash = 1_u64;
234+
let state_diff_1 = 1_u64;
235+
let state_diff_2 = 2_u64;
236+
237+
// Block 0: ClassHash(1) → CompiledClassHash(1).
234238
let state_root = committer
235-
.commit_block(commit_block_request(state_diff_1, Some(1), height))
239+
.commit_block(commit_block_request(state_diff_1, Some(state_diff_1), height_0))
236240
.await
237241
.unwrap()
238242
.global_root;
239243

240-
height = 1;
241-
committer.commit_block(commit_block_request(state_diff_2, Some(2), height)).await.unwrap();
242-
assert_eq!(committer.offset, BlockNumber(height + 1));
244+
// Block 1: ClassHash(1) → CompiledClassHash(2) (updates the same key as block 0).
245+
// Using the same key ensures that reverting block 1 (restoring ClassHash(1) to
246+
// CompiledClassHash(1)) brings the tree back to the exact state after block 0.
247+
committer
248+
.commit_block(CommitBlockRequest {
249+
state_diff: ThinStateDiff {
250+
class_hash_to_compiled_class_hash: indexmap! {
251+
ClassHash(class_hash.into()) => CompiledClassHash(state_diff_2.into()),
252+
},
253+
..Default::default()
254+
},
255+
state_diff_commitment: Some(StateDiffCommitment(PoseidonHash(state_diff_2.into()))),
256+
height: BlockNumber(height_1),
257+
})
258+
.await
259+
.unwrap();
260+
assert_eq!(committer.offset, BlockNumber(height_1 + 1));
243261

262+
// Revert block 1: restore ClassHash(1) to CompiledClassHash(1).
244263
let response =
245-
committer.revert_block(revert_block_request(state_diff_1, height)).await.unwrap();
264+
committer.revert_block(revert_block_request(state_diff_1, height_1)).await.unwrap();
246265

247266
assert_matches!(
248267
response,
249268
RevertBlockResponse::RevertedTo(reverted_state_root)
250269
if reverted_state_root == state_root
251270
);
252-
assert_eq!(committer.offset, BlockNumber(height));
271+
assert_eq!(committer.offset, BlockNumber(height_1));
253272
}
254273

255274
#[tokio::test]

0 commit comments

Comments
 (0)