-
Notifications
You must be signed in to change notification settings - Fork 35
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(apollo_reverts): add revert blocks functionality #3988
feat(apollo_reverts): add revert blocks functionality #3988
Conversation
9b10a88
to
9dc2f88
Compare
a81e735
to
89f9830
Compare
9dc2f88
to
77b1293
Compare
89f9830
to
219af6e
Compare
77b1293
to
d1dcbe1
Compare
219af6e
to
02ce315
Compare
d1dcbe1
to
383ab09
Compare
02ce315
to
99547a1
Compare
99547a1
to
5ae9de9
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.
Reviewed 2 of 5 files at r1, 14 of 14 files at r2, all commit messages.
Reviewable status: all files reviewed, 8 unresolved discussions (waiting on @noamsp-starkware)
crates/apollo_reverts/src/lib.rs
line 21 at r2 (raw file):
#[derive(Clone, Debug, Serialize, Deserialize, Validate, PartialEq)] pub struct RevertConfig { pub revert_on: bool,
Consider renaming to should_revert
crates/apollo_reverts/src/lib.rs
line 42 at r2 (raw file):
"revert_on", &self.revert_on, "Whether the component should revert blocks.",
add " and do nothing else" at the end of the sentence
crates/apollo_reverts/src/lib.rs
line 68 at r2 (raw file):
if current_block_number <= revert_up_to_and_including { panic!( "{component_name} current block {current_block_number} is not larger than the target \
Add 's
after {component_name}
crates/apollo_reverts/src/lib.rs
line 83 at r2 (raw file):
); info!("Reverting {component_name} block number {current_block_number}."); revert_block_fn(current_block_number).await;
(Unrelated to the PR, but let's fix it while we're at it)
Add an additional log after calling the revert function that the block was reverted successfully
crates/apollo_reverts/src/lib.rs
line 93 at r2 (raw file):
} pub fn revert_block(
Add comment or documentation stating that this will revert everything related to the block and it will succeed if there's partial information for the block
crates/apollo_reverts/src/lib.rs
line 96 at r2 (raw file):
storage_writer: &mut StorageWriter, current_block_number: BlockNumber, ) -> impl Future<Output = ()> {
Change return type to nothing and return nothing. Inside sync wrap this if needed
crates/starknet_batcher/src/batcher.rs
line 739 at r2 (raw file):
fn revert_block(&mut self, height: BlockNumber) -> papyrus_storage::StorageResult<()> { block_on(apollo_reverts::revert_block(self, height));
If you take my suggestion above there's no need to call block_on
crates/starknet_batcher/src/batcher.rs
line 739 at r2 (raw file):
fn revert_block(&mut self, height: BlockNumber) -> papyrus_storage::StorageResult<()> { block_on(apollo_reverts::revert_block(self, height));
add a use statement for revert_block
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.
+reviewer:@DvirYo-starkware +reviewer:@Yael-Starkware
Reviewable status: all files reviewed, 8 unresolved discussions (waiting on @DvirYo-starkware, @noamsp-starkware, and @Yael-Starkware)
5ae9de9
to
500bfbd
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.
Reviewable status: all files reviewed, 6 unresolved discussions (waiting on @DvirYo-starkware, @ShahakShama, and @Yael-Starkware)
crates/apollo_reverts/src/lib.rs
line 42 at r2 (raw file):
Previously, ShahakShama wrote…
add " and do nothing else" at the end of the sentence
Done.
crates/apollo_reverts/src/lib.rs
line 68 at r2 (raw file):
Previously, ShahakShama wrote…
Add
's
after {component_name}
Done.
crates/apollo_reverts/src/lib.rs
line 83 at r2 (raw file):
Previously, ShahakShama wrote…
(Unrelated to the PR, but let's fix it while we're at it)
Add an additional log after calling the revert function that the block was reverted successfully
Done.
crates/apollo_reverts/src/lib.rs
line 93 at r2 (raw file):
Previously, ShahakShama wrote…
Add comment or documentation stating that this will revert everything related to the block and it will succeed if there's partial information for the block
Done.
crates/apollo_reverts/src/lib.rs
line 96 at r2 (raw file):
Previously, ShahakShama wrote…
Change return type to nothing and return nothing. Inside sync wrap this if needed
Done.
crates/starknet_batcher/src/batcher.rs
line 739 at r2 (raw file):
Previously, ShahakShama wrote…
add a use statement for revert_block
Done.
Benchmark movements: |
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.
not sure about the name starting with apollo prefix?
will all crates use apollo prefix? if not, lets delete it from here since it is not related to the reverts.
Reviewed 9 of 14 files at r2, 5 of 5 files at r3, all commit messages.
Reviewable status: all files reviewed, 15 unresolved discussions (waiting on @DvirYo-starkware and @ShahakShama)
crates/apollo_reverts/src/lib.rs
line 93 at r2 (raw file):
Previously, noamsp-starkware wrote…
Done.
wdym partial information?
it seems to succeed in any case ( unless panics).
Suggestion:
This commit introduces the crate apollo revets, which unifies block
reverting functionality.
crates/starknet_batcher/src/batcher.rs
line 738 at r3 (raw file):
} fn revert_block(&mut self, height: BlockNumber) -> papyrus_storage::StorageResult<()> {
add a comment that this function panics if there is a storage failure to revert the block.
Suggestion:
fn revert_block(&mut self, height: BlockNumber) {
crates/starknet_consensus_manager/src/consensus_manager.rs
line 143 at r3 (raw file):
|_| panic!("Failed to revert block at height {height} in the batcher"), ) };
revert_block never fails, please add a comment that it will panic if the revert fails.
Code quote:
let revert_blocks_fn = move |height| async move {
self.batcher_client.revert_block(RevertBlockInput { height }).await.unwrap_or_else(
|_| panic!("Failed to revert block at height {height} in the batcher"),
)
};
crates/starknet_consensus_manager/src/consensus_manager_test.rs
line 61 at r3 (raw file):
#[case::equal_block(BATCHER_HEIGHT)] #[should_panic(expected = "Batcher's current block 10 is not larger than the target block 11. No \ reverts are needed.")]
lets be precise about the term since current block is confusing.
Suggestion:
#[should_panic(expected = "Batcher's storage height marker 10 is not larger than the target block 10. No \
reverts are needed.")]
#[case::equal_block(BATCHER_HEIGHT)]
#[should_panic(expected = "Batcher's storage height marker 10 is not larger than the target block 11. No \
reverts are needed.")]
crates/starknet_consensus_manager/src/consensus_manager_test.rs
line 96 at r3 (raw file):
Arc::new(MockStateSyncClient::new()), Arc::new(EmptyClassManagerClient), );
Suggestion:
let consensus_manager = ConsensusManager::new(
manager_config: ConsensusManagerConfig::default(),
Arc::new(mock_batcher),
Arc::new(MockStateSyncClient::new()),
Arc::new(EmptyClassManagerClient),
);
crates/apollo_reverts/src/lib.rs
line 52 at r3 (raw file):
"Whether the component should revert block and do nothing else.", ParamPrivacyInput::Public, ),
Suggestion:
ser_param(
"should_revert",
&self.should_revert,
"If set true, the component would revert blocks and do nothing else.",
ParamPrivacyInput::Public,
),
crates/apollo_reverts/src/lib.rs
line 66 at r3 (raw file):
Fut: Future<Output = ()>, { if current_block_number <= revert_up_to_and_including {
current block is not well defined.
Suggestion:
storage_height_marker
crates/apollo_reverts/src/lib.rs
line 68 at r3 (raw file):
if current_block_number <= revert_up_to_and_including { panic!( "{component_name}'s current block {current_block_number} is not larger than the \
Suggestion:
{component_name}'s current storage height marker {current_block_number} is not larger than the \
crates/apollo_reverts/src/lib.rs
line 96 at r3 (raw file):
/// Reverts everything related to the block, will succeed if there is partial information for the /// block. pub fn revert_block(storage_writer: &mut StorageWriter, current_block_number: BlockNumber) {
add a comment that this function panics if the storage reader fails to revert
Code quote:
pub fn revert_block(storage_writer: &mut StorageWriter, current_block_number: BlockNumber) {
500bfbd
to
2a51466
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.
Reviewable status: 9 of 14 files reviewed, 15 unresolved discussions (waiting on @DvirYo-starkware, @ShahakShama, and @Yael-Starkware)
crates/apollo_reverts/src/lib.rs
line 66 at r3 (raw file):
Previously, Yael-Starkware (YaelD) wrote…
current block is not well defined.
Done.
crates/apollo_reverts/src/lib.rs
line 96 at r3 (raw file):
Previously, Yael-Starkware (YaelD) wrote…
add a comment that this function panics if the storage reader fails to revert
Done.
crates/starknet_batcher/src/batcher.rs
line 738 at r3 (raw file):
Previously, Yael-Starkware (YaelD) wrote…
add a comment that this function panics if there is a storage failure to revert the block.
Done.
crates/starknet_consensus_manager/src/consensus_manager.rs
line 143 at r3 (raw file):
Previously, Yael-Starkware (YaelD) wrote…
revert_block never fails, please add a comment that it will panic if the revert fails.
Done.
crates/starknet_consensus_manager/src/consensus_manager_test.rs
line 61 at r3 (raw file):
Previously, Yael-Starkware (YaelD) wrote…
lets be precise about the term since current block is confusing.
Done.
-- commits
line 5 at r3:
Done.
crates/apollo_reverts/src/lib.rs
line 52 at r3 (raw file):
"Whether the component should revert block and do nothing else.", ParamPrivacyInput::Public, ),
Done.
crates/apollo_reverts/src/lib.rs
line 68 at r3 (raw file):
if current_block_number <= revert_up_to_and_including { panic!( "{component_name}'s current block {current_block_number} is not larger than the \
Done.
crates/starknet_consensus_manager/src/consensus_manager_test.rs
line 96 at r3 (raw file):
Arc::new(MockStateSyncClient::new()), Arc::new(EmptyClassManagerClient), );
Done.
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.
Reviewed 5 of 5 files at r4, all commit messages.
Reviewable status: all files reviewed, 10 unresolved discussions (waiting on @DvirYo-starkware, @noamsp-starkware, and @ShahakShama)
crates/starknet_batcher/src/batcher.rs
line 738 at r3 (raw file):
Previously, noamsp-starkware wrote…
Done.
please add the comment also to this function.
and also remove the Result return value, since this function never fails.
crates/starknet_consensus_manager/src/consensus_manager.rs
line 143 at r3 (raw file):
Previously, noamsp-starkware wrote…
Done.
the revert block should not return a result at all.
crates/starknet_consensus_manager/src/consensus_manager.rs
line 139 at r4 (raw file):
.height; // This will panic if the revert fails.
Suggestion:
This function will panic if the revert fails.
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.
Reviewable status: all files reviewed, 11 unresolved discussions (waiting on @DvirYo-starkware, @noamsp-starkware, and @ShahakShama)
crates/apollo_reverts/src/lib.rs
line 115 at r4 (raw file):
.unwrap() .commit() .unwrap();
all of these function calls succeed even if there is nothing to revert?
is there a test for this?
Code quote:
storage_writer
.begin_rw_txn()
.unwrap()
.revert_header(current_block_number)
.unwrap()
.0
.revert_body(current_block_number)
.unwrap()
.0
.revert_state_diff(current_block_number)
.unwrap()
.0
.try_revert_class_manager_marker(current_block_number)
.unwrap()
.try_revert_base_layer_marker(current_block_number)
.unwrap()
.commit()
.unwrap();
Previously, Yael-Starkware (YaelD) wrote…
Some errors can return from revert_block before calling apollo_reverts::revert_block, i suggest we print the error and panic if received. Code snippet: pub async fn revert_block(&mut self, input: RevertBlockInput) -> BatcherResult<()> {
info!("Reverting block at height {}.", input.height);
let height = self.get_height_from_storage()?.prev().ok_or(
BatcherError::StorageHeightMarkerMismatch {
marker_height: BlockNumber(0),
requested_height: input.height,
},
)?;
if height != input.height {
return Err(BatcherError::StorageHeightMarkerMismatch {
marker_height: height.unchecked_next(),
requested_height: input.height,
});
}
if let Some(height) = self.active_height {
info!("Aborting all work on height {} due to a revert request.", height);
self.abort_active_height().await;
}
self.storage_writer.revert_block(height);
STORAGE_HEIGHT.decrement(1);
Ok(())
} |
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.
Reviewable status: all files reviewed, 10 unresolved discussions (waiting on @DvirYo-starkware, @noamsp-starkware, and @ShahakShama)
crates/starknet_consensus_manager/src/consensus_manager.rs
line 143 at r3 (raw file):
Previously, noamsp-starkware wrote…
Some errors can return from revert_block before calling apollo_reverts::revert_block, i suggest we print the error and panic if received.
oh, you're right, the internal function is the one that panics, yes so please revert back to printing the errors.
2a51466
to
0a49866
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.
Reviewable status: 12 of 15 files reviewed, 10 unresolved discussions (waiting on @DvirYo-starkware, @ShahakShama, and @Yael-Starkware)
crates/apollo_reverts/src/lib.rs
line 115 at r4 (raw file):
Previously, Yael-Starkware (YaelD) wrote…
all of these function calls succeed even if there is nothing to revert?
is there a test for this?
Unless an internal storage error occurs, these should succeed (revert if a legit block number provided, otherwise do nothing and return Ok(Self))
crates/starknet_batcher/src/batcher.rs
line 738 at r3 (raw file):
Previously, Yael-Starkware (YaelD) wrote…
please add the comment also to this function.
and also remove the Result return value, since this function never fails.
Done.
crates/starknet_consensus_manager/src/consensus_manager.rs
line 143 at r3 (raw file):
Previously, Yael-Starkware (YaelD) wrote…
oh, you're right, the internal function is the one that panics, yes so please revert back to printing the errors.
Done.
crates/starknet_consensus_manager/src/consensus_manager.rs
line 139 at r4 (raw file):
.height; // This will panic if the revert fails.
Done.
0a49866
to
2613903
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.
Reviewed 5 of 5 files at r6, all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @DvirYo-starkware and @Yael-Starkware)
crates/apollo_reverts/src/lib.rs
line 93 at r2 (raw file):
Previously, Yael-Starkware (YaelD) wrote…
wdym partial information?
it seems to succeed in any case ( unless panics).
Yes. What I meant is that it will not fail. @noamsp-starkware rephrase by writing instead of "will succeed if", "will succeed even if"
This commit introduces the crate apollo reverts, which unifies block reverting functionality. This commit refactors consensus manager and batcher to adhere to the functionality introduced in apollo reverts. Revert config is now a global sequencer config, should future crates need revert functionality, they shall inherit the configurations via the global sequencer config.
2613903
to
7d46802
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.
Reviewed 1 of 1 files at r7, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @DvirYo-starkware and @Yael-Starkware)
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.
Reviewed 2 of 14 files at r2, 5 of 5 files at r6, 1 of 1 files at r7, all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on @DvirYo-starkware)
crates/apollo_reverts/src/lib.rs
line 115 at r4 (raw file):
Previously, noamsp-starkware wrote…
Unless an internal storage error occurs, these should succeed (revert if a legit block number provided, otherwise do nothing and return Ok(Self))
it there a test for these function - to check that they don't fail in case that the block_number is newer than the marker? I guess there should be a test in papyrus storage.
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.
Reviewable status:
complete! all files reviewed, all discussions resolved (waiting on @DvirYo-starkware)
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.
Reviewable status:
complete! all files reviewed, all discussions resolved (waiting on @DvirYo-starkware)
crates/apollo_reverts/src/lib.rs
line 115 at r4 (raw file):
Previously, Yael-Starkware (YaelD) wrote…
it there a test for these function - to check that they don't fail in case that the block_number is newer than the marker? I guess there should be a test in papyrus storage.
Yes, these are all tested except for class_manager_marker.
I'll add a test for that in a different PR link you.
No description provided.