-
Notifications
You must be signed in to change notification settings - Fork 960
Replace getByBlockNumber by getByBlockHeader #5127
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
Replace getByBlockNumber by getByBlockHeader #5127
Conversation
Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com>
Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com>
Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com>
Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com>
Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com>
Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com>
Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com>
Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com>
Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com>
Change default getByBlockHeader behaviour to use dispatchFunctionAccordingToMergeState Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com>
Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com>
Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com>
* @param blockHeader the block header | ||
* @return the ProtocolSpec to be used by the provided block | ||
*/ | ||
public ProtocolSpec getByBlockHeaderForBws(final ProcessableBlockHeader blockHeader) { |
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 what a better name would be but I don't think it should encode the caller since this might change. The difference is that it calls getByBlockHeaderFromTransitionUtils but that name doesn't really capture the difference in behaviour either.
Think I would need to understand why backwards sync needs this different behaviour and whether or not it's relevant for other code paths that call getByBlockHeader...maybe a question for @gezero?
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.
After reading around a bit, wonder if getByBlockHeaderAndHandleReorgBelowTTD
makes more sense.
This appears to be the PR that introduced the extra logic: #3696
Seems super-specific and edge-casey...wonder if syncing goerli always hits this edge case though 🤔
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.
Why was using this causing the Goerli sync to fail?
@@ -159,52 +155,45 @@ public void getByBlockHeader_returnsTimestampScheduleIfPresent() { | |||
} | |||
|
|||
@Test | |||
public void getByBlockNumber_returnsTimestampScheduleIfPresent() { |
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.
Why are the getByBlockNumber tests being removed and migrated to cover getByBlockHeaderForBws?
This PR isn't removing getByBlockNumber so I think the tests should remain, we may need to duplicate some for the new method.
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.
Added back getByBlockNumber tests which are almost duplicates of the getByBlockHeader tests since that method still exists and is being used.
|
||
verifyPostMergeProtocolScheduleReturned(); | ||
} | ||
|
||
@Test | ||
public void getByBlockNumber_delegatesToPostMergeScheduleWhenTimestampScheduleDoesNotExist() { | ||
public void getByBlockHeader_delegatesToPostMergeScheduleWhenTimestampScheduleDoesNotExist() { |
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.
Test names should be updated from getByBlockHeader_... -> getByBlockHeaderForBws_...
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.
Changed these tests to use getByBlockHeader so we have test coverage for that method
|
||
verifyPreMergeProtocolScheduleReturned(); | ||
} | ||
|
||
@Test | ||
public void getByBlockNumber_delegatesToPostMergeScheduleWhenBlockNotFound() { | ||
when(blockchain.getBlockHeader(BLOCK_NUMBER)).thenReturn(Optional.empty()); | ||
public void getByBlockHeader_delegatesToPostMergeScheduleWhenBlockNotFound() { |
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 shown in the diff, but I think getByBlockHeader() is now only being covered by one unit test, for when the timestamp schedule is found. It needs at least the other branch of logic tested, which is similar to this unit test.
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.
Changed the getByBlockHeader tests to use getByBlockHeader instead of getByBlockHeaderForBws. The other tests cover the backward sync conditions.
I think there's still some cases where getByBlockNumber has not been migrated across (even though the header is available) so would like to understand those a bit more and why they weren't included in this PR (if intentional). |
besu/src/test/java/org/hyperledger/besu/controller/TransitionControllerBuilderTest.java
Outdated
Show resolved
Hide resolved
...h/src/main/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/BackwardSyncContext.java
Show resolved
Hide resolved
* @param blockHeader the block header | ||
* @return the ProtocolSpec to be used by the provided block | ||
*/ | ||
public ProtocolSpec getByBlockHeaderForBws(final ProcessableBlockHeader blockHeader) { |
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.
Why was using this causing the Goerli sync to fail?
…d use getByBlockHeader for blockHeader tests instead of getByBlockHeaderForBws Signed-off-by: Jason Frame <jason.frame@consensys.net>
…umber-by-getByBlockHeader
…andling Signed-off-by: Jason Frame <jason.frame@consensys.net>
} | ||
|
||
@Test | ||
public void getByBlockHeader_delegatesToPostMergeScheduleWhenBlockNotFound() { |
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.
How is this distinguished from the test below, getByBlockHeader_delegatesToPostMergeScheduleWhenTimestampScheduleDoesNotExist
?
Before, it was testing 'block not found' with this...
when(blockchain.getBlockHeader(BLOCK_NUMBER)).thenReturn(Optional.empty());
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.
Fixed the tests for the block not found cases for getByBlockNumber
. And have removed tests for getByBlockHeader
for the block not found cases. For getByBlockHeader
we don't need to do a blockchain.getBlockHeader()
call so we can never get the case where the block or block header doesn't exist.
Signed-off-by: Jason Frame <jason.frame@consensys.net>
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.
LGTM
Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com> Signed-off-by: Jason Frame <jason.frame@consensys.net>
Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com> Signed-off-by: Jason Frame <jason.frame@consensys.net>
PR description
This PR brings the changes introduced in #5020 + the amend to the issue spotted on #5064.
Replacing getByBlockNumber by getByBlockHeader brought issue to sync because TransitionProtocolSchedule getByBlockHeader does not have the same behaviour as getByBlockNumber.
This PR Introduced a private TransitionProtocolSchedule getByBlockHeaderForBws to restore the original behaviour of getByBlockHeader.
getByBlockHeader follows the same approach getByBlockNumber used to have which uses the dispatchFunctionAccordingToMergeState to return the pre or post merge protocolSchedule.
Syncing test done:
Fixed Issue(s)
Part of #4789
Documentation
doc-change-required
label to this PR ifupdates are required.
Acceptance Tests (Non Mainnet)
./gradlew acceptanceTestNonMainnet
locally if my PR affects non-mainnet modules.Changelog