Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reintroduce clear_resharding_data #10211

Merged
merged 3 commits into from
Nov 20, 2023
Merged

Conversation

posvyatokum
Copy link
Member

Tested on updated #10193

is_next_block_epoch_start reads BlockInfo of the first block of the epoch, which is not correct in the case of garbage collection.
The previous version of the test was passing, because that BlockInfo was still in the cache of the epoch manager (as we call is_next_block_epoch_start on every block)

Implemented safer version of is_next_block_epoch_start -- is_last_block_in_finished_epoch (didn't think too much about the name, open to suggestions).
is_last_block_in_finished_epoch works by relying on the fact that if we processed block, and it was the last block of an epoch according to is_next_block_epoch_start, then we wrote an EpochInfo with the hash of that block, and EpochInfo is not garbage collectible.

@posvyatokum posvyatokum requested a review from a team as a code owner November 17, 2023 23:13
Copy link
Contributor

@wacban wacban left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for looking into it!

chain/chain/src/chain.rs Outdated Show resolved Hide resolved
chain/epoch-manager/src/adapter.rs Outdated Show resolved Hide resolved
Comment on lines +80 to +83
/// `is_next_block_epoch_start` works even if we didn't fully process the provided block.
/// This function works even if we garbage collected `BlockInfo` of the first block of the epoch.
/// Thus, this function is better suited for use in garbage collection.
fn is_last_block_in_finished_epoch(&self, hash: &CryptoHash) -> Result<bool, EpochError>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️ the comment

@@ -475,6 +481,11 @@ impl EpochManagerAdapter for EpochManagerHandle {
epoch_manager.is_next_block_epoch_start(parent_hash)
}

fn is_last_block_in_finished_epoch(&self, hash: &CryptoHash) -> Result<bool, EpochError> {
let epoch_manager = self.read();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this do?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is impl EpochManagerAdapter for EpochManagerHandle

pub struct EpochManagerHandle {

The actual implementation of the method depends on specific EpochManager implementation of get_epoch_info. So we get EpochManager out of EpochManagerHandle and call is_last_block_in_finished_epoch there.

@@ -1086,6 +1086,20 @@ impl EpochManager {
self.is_next_block_in_next_epoch(&block_info)
}

/// Relies on the fact that last block hash of an epoch is an EpochId of next next epoch.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow I didn't know that. Nice trick!

chain/epoch-manager/src/lib.rs Outdated Show resolved Hide resolved
// self.epoch_manager.as_ref(),
// *block_hash,
// )?;
chain_store_update.clear_resharding_data(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we enable the resharding tests test_shard_layout_upgrade_gc and test_shard_layout_upgrade_gc_v2?

@posvyatokum posvyatokum disabled auto-merge November 20, 2023 12:10
Copy link
Contributor

@shreyan-gupta shreyan-gupta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you soo much for looking into this!!

@posvyatokum posvyatokum added this pull request to the merge queue Nov 20, 2023
Merged via the queue into master with commit 5fa5470 Nov 20, 2023
13 checks passed
@posvyatokum posvyatokum deleted the clear_resharding_data_safely branch November 20, 2023 12:55
VanBarbascu added a commit that referenced this pull request Dec 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants