-
Notifications
You must be signed in to change notification settings - Fork 632
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
feat: undo-block tool #8681
feat: undo-block tool #8681
Conversation
bc89a27
to
4ebf500
Compare
let state_header_key = StateHeaderKey(shard_id, block_hash).try_to_vec()?; | ||
self.gc_col(DBCol::StateHeaders, &state_header_key); | ||
} | ||
// delete flat storage columns: FlatStateChanges and FlatStateDeltaMetadata |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pugachAG @Longarithm flat state column changes are here, please help review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I would hide multi-line code behind feature like that:
#[cfg(feature = "protocol_feature_flat_state")]
{
line1
line2
...
}
- Though
get_simple_nightshade_layout
works currently, it is technically not correct, because we may use other shard layouts once we do more reshardings. We fix shard uids and layouts for an epoch, so we need to take smth likeblock.epoch_id
and ask epoch manager for it (or runtime adapter, if our chain refactoring is not finished yet).EpochManagerAdapter::shard_id_to_uid
do the work. And I would name it justshard_uid
because it is not specific for flat storage but for the whole chain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding epoch manager, will let runtime = NightshadeRuntime::from_config(home_dir, store.clone(), &config);
give the correct runtime?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we don't need anything else. home_dir
is used to read genesis, store
- at least for reading state data, config
... for tweaking execution parameters, caching, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why the flat storage part isn't working.
The rest looks good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! The code makes sense and flat storage removals are clear, I'm not sure what doesn't work for it.
Left some comments. I think it also deserves some test. Because it could be hard to implement, we can test the following scenario:
- create chain
- process some blocks
- undo last block H
- create new chain instance, check that chain metadata (tip?) is correct
- process some other block on height H, check that it works
let state_header_key = StateHeaderKey(shard_id, block_hash).try_to_vec()?; | ||
self.gc_col(DBCol::StateHeaders, &state_header_key); | ||
} | ||
// delete flat storage columns: FlatStateChanges and FlatStateDeltaMetadata |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I would hide multi-line code behind feature like that:
#[cfg(feature = "protocol_feature_flat_state")]
{
line1
line2
...
}
- Though
get_simple_nightshade_layout
works currently, it is technically not correct, because we may use other shard layouts once we do more reshardings. We fix shard uids and layouts for an epoch, so we need to take smth likeblock.epoch_id
and ask epoch manager for it (or runtime adapter, if our chain refactoring is not finished yet).EpochManagerAdapter::shard_id_to_uid
do the work. And I would name it justshard_uid
because it is not specific for flat storage but for the whole chain.
@Longarithm create chain do you mean testing using the tool for the above scenarios? |
I mean integration test for CI, sorry for confusion. The logic is not trivial, and it could be great to have undo block scenarios covered, so that we don't break it by chain/runtime/other changes. Especially if we want to use this code during outages. Though integration tests are hard to write. I also don't see simple guidance for it, perhaps that's a good action item for core team. Let me give some introduction: Integration tests live in
This one creates
Then, extract store update and undo block:
Then drop existing env, create new one using old store and try process new blocks on it. You can test your scenarios in that framework as well!
Example of test which kinda does it is |
Makes sense to add a test for this in CI. I'll work on adding some for this tool. |
15465c1
to
31147be
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Left some more comments but approving to unblock.
The complexity of change makes me think that our current store codebase is poor :( Looking forward to further improvements, perhaps in scope of #8153.
store_update.delete(DBCol::BlockHeader, key); | ||
self.chain_store.headers.pop(key); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment: It sucks that gc_col
doesn't work here and assumes that it is called only during GC... Later we can consider renaming gc_col
to remove_key
- it doesn't remove column as one may think.
6c4d276
to
dab6b5c
Compare
@ppca what prevents us from merging this PR? |
Was testing this on a testnet validator. The test looks good this morning. Will merge it today. |
…to its previous block
…to its previous block (#8681)
…to its previous block (#8681)
undo-block tool to revert the current head of the chain to its previous block. Typically used when the state of current chain head is messed up, e.g. running a wrong binary like in the case of protocol upgrade or gas price param changes.
To use the tool:
./target/release/neard --home {path_to_config_directory} undo-block
Assuming only the head of the chain was messed up, not a long fork, then after using the tool, the node should be able to catch up and produce block (if they are block producers).
We intentionally forbid users from reverting beyond final block so that nothing is messed up for flat storage and finality is not broken.
Design doc for the tool