Skip to content

Commit 4b1f0c2

Browse files
author
Bowen Wang
committed
fix(gc): properly update chunk tail
1 parent 86e4397 commit 4b1f0c2

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

chain/chain/src/store.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1899,7 +1899,9 @@ impl<'a> ChainStoreUpdate<'a> {
18991899

19001900
pub fn update_tail(&mut self, height: BlockHeight) {
19011901
self.tail = Some(height);
1902-
if self.chunk_tail.is_none() {
1902+
let genesis_height = self.get_genesis_height();
1903+
let chunk_tail = self.chunk_tail().unwrap_or_else(|_| genesis_height);
1904+
if chunk_tail == genesis_height {
19031905
// For consistency, Chunk Tail should be set if Tail is set
19041906
self.chunk_tail = Some(self.get_genesis_height());
19051907
}

chain/client/tests/process_blocks.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,21 @@ fn test_gc_block_skips() {
875875
}
876876
}
877877

878+
#[test]
879+
fn test_gc_chunk_tail() {
880+
let mut chain_genesis = ChainGenesis::test();
881+
let epoch_length = 100;
882+
chain_genesis.epoch_length = epoch_length;
883+
let mut env = TestEnv::new(chain_genesis.clone(), 1, 1);
884+
let mut chunk_tail = 0;
885+
for i in (1..10).chain(101..epoch_length * 6) {
886+
env.produce_block(0, i);
887+
let cur_chunk_tail = env.clients[0].chain.store().chunk_tail().unwrap();
888+
assert!(cur_chunk_tail >= chunk_tail);
889+
chunk_tail = cur_chunk_tail;
890+
}
891+
}
892+
878893
#[test]
879894
fn test_gc_execution_outcome() {
880895
let epoch_length = 5;

0 commit comments

Comments
 (0)