Use Action in single_block_component_processed #5564
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue Addressed
Part of:
The job of
single_block_component_processed
is to decide what action to do in response to a block components processing result. The current code is correct, but IMO it is hard to audit to ensure that:Proposed Changes
This PR changes the current match into returning a single
Action
valueThis style achieves the goals:
lookup
to a mutable reference as the match does not call into someself.
method (not impl in this PR). We can switch from the current pattern of remove -> insert to retry / noop to drop, to get_mut -> noop to retry / remove to drop.I'd recommend looking at the final file for a better read
https://github.com/dapplion/lighthouse/blob/540f87325f132b5065379117d92fba1e308c8a02/beacon_node/network/src/sync/block_lookups/mod.rs#L798
Next steps
There are 3 other functions that could adopt this pattern:
single_lookup_response
parent_block_processed
parent_chain_processed
But if this PR is well received I would prefer to tackle each latter and separately