Skip to content

Conversation

gfukushima
Copy link
Contributor

@gfukushima gfukushima commented Feb 23, 2023

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:

  • - Checkpoint Sepolia
  • - Sepolia Shanghai Upgrade
  • - Checkpoint Goerli
  • - Checkpoint Mainnet

Fixed Issue(s)

Part of #4789

Documentation

  • I thought about documentation and added the doc-change-required label to this PR if
    updates are required.

Acceptance Tests (Non Mainnet)

  • I have considered running ./gradlew acceptanceTestNonMainnet locally if my PR affects non-mainnet modules.

Changelog

gfukushima and others added 24 commits January 25, 2023 17:39
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>
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>
@gfukushima gfukushima added TeamGroot GH issues worked on by Groot Team mainnet labels Feb 23, 2023
@siladu siladu marked this pull request as ready for review February 27, 2023 01:13
* @param blockHeader the block header
* @return the ProtocolSpec to be used by the provided block
*/
public ProtocolSpec getByBlockHeaderForBws(final ProcessableBlockHeader blockHeader) {
Copy link
Contributor

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?

Copy link
Contributor

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 🤔

Copy link
Contributor

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() {
Copy link
Contributor

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.

Copy link
Contributor

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() {
Copy link
Contributor

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_...

Copy link
Contributor

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() {
Copy link
Contributor

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.

Copy link
Contributor

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.

@siladu
Copy link
Contributor

siladu commented Feb 27, 2023

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).

* @param blockHeader the block header
* @return the ProtocolSpec to be used by the provided block
*/
public ProtocolSpec getByBlockHeaderForBws(final ProcessableBlockHeader blockHeader) {
Copy link
Contributor

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?

jframe added 4 commits March 2, 2023 14:13
…d use getByBlockHeader for blockHeader tests instead of getByBlockHeaderForBws

Signed-off-by: Jason Frame <jason.frame@consensys.net>
Signed-off-by: Jason Frame <jason.frame@consensys.net>
…andling

Signed-off-by: Jason Frame <jason.frame@consensys.net>
}

@Test
public void getByBlockHeader_delegatesToPostMergeScheduleWhenBlockNotFound() {
Copy link
Contributor

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());

Copy link
Contributor

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>
Copy link
Contributor

@siladu siladu left a comment

Choose a reason for hiding this comment

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

LGTM

@jframe jframe enabled auto-merge (squash) March 3, 2023 05:02
@jframe jframe merged commit bf01981 into hyperledger:main Mar 3, 2023
@gfukushima gfukushima deleted the replace-getByBlockNumber-by-getByBlockHeader branch March 23, 2023 22:59
elenduuche pushed a commit to elenduuche/besu that referenced this pull request Aug 16, 2023
Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com>
Signed-off-by: Jason Frame <jason.frame@consensys.net>
eum602 pushed a commit to lacchain/besu that referenced this pull request Nov 3, 2023
Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com>
Signed-off-by: Jason Frame <jason.frame@consensys.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mainnet TeamGroot GH issues worked on by Groot Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants