Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
staffik committed Dec 9, 2024
1 parent f3f4c7e commit fd1b7c1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 17 deletions.
27 changes: 19 additions & 8 deletions integration-tests/src/tests/client/cold_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,12 @@ fn test_storage_after_commit_of_cold_update() {

let client = &env.clients[0];
let client_store = client.runtime_adapter.store();
let epoch_id = client.epoch_manager.get_epoch_id_from_prev_block(&last_hash).unwrap();
let epoch_id = client.epoch_manager.get_epoch_id(block.hash()).unwrap();
let shard_layout = client.epoch_manager.get_shard_layout(&epoch_id).unwrap();
update_cold_db(cold_db, &client_store, &shard_layout, &height, 4).unwrap();
let is_last_block_in_epoch =
client.epoch_manager.is_next_block_epoch_start(block.hash()).unwrap();
update_cold_db(cold_db, &client_store, &shard_layout, &height, is_last_block_in_epoch, 4)
.unwrap();

last_hash = *block.hash();
}
Expand Down Expand Up @@ -281,14 +284,22 @@ fn test_cold_db_copy_with_height_skips() {
};

let client = &env.clients[0];
let epoch_id = client.epoch_manager.get_epoch_id_from_prev_block(&last_hash).unwrap();
let hot_store = client.runtime_adapter.store();
let block_hash =
hot_store.get_ser::<CryptoHash>(DBCol::BlockHeight, &height.to_le_bytes()).unwrap();
let Some(block) = block else {
assert!(block_hash.is_none());
continue;
};
let block_hash = block_hash.unwrap();
assert!(&block_hash == block.hash());
let epoch_id = client.epoch_manager.get_epoch_id(&block_hash).unwrap();
let shard_layout = client.epoch_manager.get_shard_layout(&epoch_id).unwrap();
update_cold_db(&cold_db, &client.runtime_adapter.store(), &shard_layout, &height, 1)
let is_last_block_in_epoch =
client.epoch_manager.is_next_block_epoch_start(&block_hash).unwrap();
update_cold_db(&cold_db, hot_store, &shard_layout, &height, is_last_block_in_epoch, 1)
.unwrap();

if block.is_some() {
last_hash = *block.unwrap().hash();
}
last_hash = block_hash;
}

// We still need to filter out one chunk
Expand Down
12 changes: 11 additions & 1 deletion integration-tests/src/tests/client/process_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1464,11 +1464,21 @@ fn test_archival_gc_common(
let header = block.header();
let epoch_id = header.epoch_id();
let shard_layout = env.clients[0].epoch_manager.get_shard_layout(epoch_id).unwrap();
let is_last_block_in_epoch =
env.clients[0].epoch_manager.is_next_block_epoch_start(header.hash()).unwrap();

blocks.push(block);

if i <= max_cold_head_height {
update_cold_db(storage.cold_db().unwrap(), hot_store, &shard_layout, &i, 1).unwrap();
update_cold_db(
storage.cold_db().unwrap(),
hot_store,
&shard_layout,
&i,
is_last_block_in_epoch,
1,
)
.unwrap();
update_cold_head(storage.cold_db().unwrap(), &hot_store, &i).unwrap();
}
}
Expand Down
18 changes: 10 additions & 8 deletions tools/cold-store/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,24 +215,26 @@ fn copy_next_block(store: &NodeStorage, config: &NearConfig, epoch_manager: &Epo

// Here it should be sufficient to just read from hot storage.
// Because BlockHeight is never garbage collectable and is not even copied to cold.
let cold_head_hash = get_ser_from_store::<CryptoHash>(
let next_height_block_hash = get_ser_from_store::<CryptoHash>(
&store.get_hot_store(),
DBCol::BlockHeight,
&cold_head_height.to_le_bytes(),
&next_height.to_le_bytes(),
)
.unwrap_or_else(|| panic!("No block hash in hot storage for height {}", cold_head_height));
.unwrap_or_else(|| panic!("No block hash in hot storage for height {}", next_height));

// For copying block we need to have shard_layout.
// For that we need epoch_id.
// For that we might use prev_block_hash, and because next_hight = cold_head_height + 1,
// we use cold_head_hash.
// For that we might use the hash of the block.
let epoch_id = &epoch_manager.get_epoch_id(&next_height_block_hash).unwrap();
let shard_layout = &epoch_manager.get_shard_layout(epoch_id).unwrap();
let is_last_block_in_epoch =
epoch_manager.is_next_block_epoch_start(&next_height_block_hash).unwrap();
update_cold_db(
&*store.cold_db().unwrap(),
&store.get_hot_store(),
&epoch_manager
.get_shard_layout(&epoch_manager.get_epoch_id_from_prev_block(&cold_head_hash).unwrap())
.unwrap(),
shard_layout,
&next_height,
is_last_block_in_epoch,
1,
)
.unwrap_or_else(|_| panic!("Failed to copy block at height {} to cold db", next_height));
Expand Down

0 comments on commit fd1b7c1

Please sign in to comment.