Skip to content

Commit

Permalink
address comments and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ppca committed Apr 6, 2023
1 parent 674d4e0 commit 6c4d276
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
10 changes: 7 additions & 3 deletions chain/chain/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1957,8 +1957,12 @@ impl<'a> ChainStoreUpdate<'a> {
self.chunk_tail = Some(height);
}

fn clear_header_data_for_heights(&mut self, start: BlockHeight, end: BlockHeight) -> Result<(), Error> {
for height in start..end+1 {
fn clear_header_data_for_heights(
&mut self,
start: BlockHeight,
end: BlockHeight,
) -> Result<(), Error> {
for height in start..=end {
let header_hashes = self.chain_store.get_all_header_hashes_by_height(height)?;
for header_hash in header_hashes {
// Delete header_hash-indexed data: block header
Expand Down Expand Up @@ -2328,7 +2332,7 @@ impl<'a> ChainStoreUpdate<'a> {
self.gc_col(DBCol::InvalidChunks, chunk_hash);
}

// 4. Delete chun, header and blocks per height
// 4. Delete chunk hashes per height
let key = index_to_bytes(height);
self.gc_col(DBCol::ChunkHashesByHeight, &key);

Expand Down
13 changes: 5 additions & 8 deletions integration-tests/src/tests/client/undo_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@ fn setup_env(
store: Store,
) -> (TestEnv, Arc<dyn RuntimeWithEpochManagerAdapter>) {
let chain_genesis = ChainGenesis::new(genesis);
let runtimes: Vec<Arc<dyn RuntimeWithEpochManagerAdapter>> =
vec![nearcore::NightshadeRuntime::test(Path::new("../../../.."), store, genesis)];
(
TestEnv::builder(chain_genesis).runtime_adapters(runtimes.clone()).build(),
runtimes[0].clone(),
)
let runtime: Arc<dyn RuntimeWithEpochManagerAdapter> =
nearcore::NightshadeRuntime::test(Path::new("../../../.."), store, genesis);
(TestEnv::builder(chain_genesis).runtime_adapters(vec![runtime.clone()]).build(), runtime)
}

// Checks that Near client can successfully undo block on given height and then produce and process block normally after restart
fn test_undo_block(epoch_length: u64, stop_height: u64) {
init_test_logger();

Expand All @@ -36,9 +34,8 @@ fn test_undo_block(epoch_length: u64, stop_height: u64) {
let store = create_test_store();
let (mut env, runtime) = setup_env(&genesis, store.clone());

for i in 1..stop_height + 1 {
for i in 1..=stop_height {
let block = env.clients[0].produce_block(i).unwrap().unwrap();
// blocks.push(block.clone());
env.process_block(0, block, Provenance::PRODUCED);
}

Expand Down

0 comments on commit 6c4d276

Please sign in to comment.