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

Race condition fix + Reliability improvements around forks pruning #1132

Merged
merged 3 commits into from
May 16, 2020

Conversation

adaszko
Copy link
Contributor

@adaszko adaszko commented May 11, 2020

Fixes #1109

@paulhauner paulhauner added the ready-for-review The code is ready for review label May 12, 2020
@paulhauner
Copy link
Member

paulhauner commented May 13, 2020

I'm still seeing some pruning errors when syncing Schlesi:

May 13 11:36:29.566 WARN Block pruning failed: BeaconStateError(MissingBeaconBlock(SignedBeaconBlockHash(0x48983f73d7f1e11806fbf02d3db2b50af3611b7b65debed084d915d3658b5d69))), service: freezer_db

EDIT: For clarity, I am using this branch to sync.

@paulhauner
Copy link
Member

It also seems like it's failing store-related tests on your end.

I'm guessing you know this and are looking for a preliminary review :)

Copy link
Member

@paulhauner paulhauner left a comment

Choose a reason for hiding this comment

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

Ok after reviewing I think I understand that perhaps this PR isn't necessarily supposed to solve the block pruning error.

I like the atomic operations stuff but think the iterator needs to be guarded against running forever.

I'll just leave this as a comment since I haven't done a super through review since the branch is failing tests and I assume will need further changes.

@michaelsproul I know you're busy but it might be worth just quickly throwing your eyes across the atomics here :)

.map(|result| result.map(|(_, block)| block))
// Include the block at the end slot (if any), it needs to be
// replayed in order to construct the canonical state at `end_slot`.
.filter(|result| match result {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: potentially a nice place for the recently-added map_or function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Almost. filter passes the iterator item to its closure by reference whereas map_or consumes self.

Copy link
Member

Choose a reason for hiding this comment

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

You can use result.as_ref().map_or(true, |block| ...)

Copy link
Member

@paulhauner paulhauner May 15, 2020

Choose a reason for hiding this comment

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

You can use result.as_ref().map_or(..) to avoid consuming self.

beacon_node/beacon_chain/src/migrate.rs Show resolved Hide resolved
@@ -145,6 +146,37 @@ impl<E: EthSpec> Store<E> for LevelDB<E> {
) -> Self::ForwardsBlockRootsIterator {
SimpleForwardsBlockRootsIterator::new(store, start_slot, end_state, end_block_root)
}

fn do_atomically(&self, atomic_batch: Vec<StoreOp>) -> Result<(), Error> {
Copy link
Member

Choose a reason for hiding this comment

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

This is cool!

@paulhauner paulhauner added waiting-on-author The reviewer has suggested changes and awaits thier implementation. and removed ready-for-review The code is ready for review labels May 13, 2020
@adaszko adaszko force-pushed the pruning-bugs branch 2 times, most recently from 7dc9ffd to fac0bab Compare May 13, 2020 12:29
@adaszko
Copy link
Contributor Author

adaszko commented May 13, 2020

Ok after reviewing I think I understand that perhaps this PR isn't necessarily supposed to solve the block pruning error.

I like the atomic operations stuff but think the iterator needs to be guarded against running forever.

I'll just leave this as a comment since I haven't done a super through review since the branch is failing tests and I assume will need further changes.

@michaelsproul I know you're busy but it might be worth just quickly throwing your eyes across the atomics here :)

I created this PR to eliminate stuff that might have been causing problems around forks pruning since I couldn't reproduce it on my end.

The tests are now passing and the PR is ready for review and merging.

@adaszko adaszko requested a review from paulhauner May 14, 2020 09:25
@adaszko adaszko changed the title Improve error handling in block iteration Race condition fix + Reliability improvements around forks pruning May 14, 2020
Copy link
Member

@michaelsproul michaelsproul left a comment

Choose a reason for hiding this comment

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

Looks great! I'm syncing Schlesi now to confirm that the race condition is fixed, happy to merge once that works and comments are addressed ☺️

beacon_node/store/src/lib.rs Outdated Show resolved Hide resolved
beacon_node/store/src/lib.rs Show resolved Hide resolved
} else {
let block_root = self.next_block_root;
let block = self.store.get_block(&block_root).ok()??;
let block = match self.store.get_block(&block_root)? {
Copy link
Member

Choose a reason for hiding this comment

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

This could use Option::ok_or{_else}, like:

self.store.get_block(&block_root)?.ok_or(Error::BlockNotFound(block_root))?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

beacon_node/beacon_chain/src/migrate.rs Outdated Show resolved Hide resolved
beacon_node/store/src/hot_cold_store.rs Outdated Show resolved Hide resolved
.map(|result| result.map(|(_, block)| block))
// Include the block at the end slot (if any), it needs to be
// replayed in order to construct the canonical state at `end_slot`.
.filter(|result| match result {
Copy link
Member

Choose a reason for hiding this comment

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

You can use result.as_ref().map_or(true, |block| ...)

beacon_node/store/src/hot_cold_store.rs Outdated Show resolved Hide resolved
@michaelsproul
Copy link
Member

michaelsproul commented May 15, 2020

Also, looks like CI is failing on the head_tracker tests due to the API change: https://github.com/adaszko/lighthouse/runs/674828986

Copy link
Member

@paulhauner paulhauner left a comment

Choose a reason for hiding this comment

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

Happy with the substantive content.

I'll give this an approval pending @michaelsproul's comments are addressed and don't change the actual logic.

beacon_node/beacon_chain/src/migrate.rs Show resolved Hide resolved
@@ -1522,6 +1524,9 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
);
});

self.head_tracker
Copy link
Member

Choose a reason for hiding this comment

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

This was a great pickup, nice work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks :)

@adaszko adaszko force-pushed the pruning-bugs branch 2 times, most recently from d275911 to 48d89e6 Compare May 15, 2020 07:42
An invariant was violated:  For every block hash in head_tracker, that
block is accessible from the store.
Copy link
Member

@michaelsproul michaelsproul left a comment

Choose a reason for hiding this comment

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

Perfect! Let’s get this merged! (I’ll let @paulhauner choose a merge ordering)

@michaelsproul michaelsproul added ready-to-squerge and removed waiting-on-author The reviewer has suggested changes and awaits thier implementation. labels May 16, 2020
@paulhauner
Copy link
Member

Thanks for squashing a killer bug @adaszko!

@paulhauner paulhauner merged commit 59ead67 into sigp:master May 16, 2020
@dapplion dapplion mentioned this pull request Jun 10, 2024
3 tasks
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.

Block pruning warnings
3 participants