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

3943 stop blocks on finalized #4058

Merged
merged 9 commits into from
Jul 11, 2022

Conversation

jflo
Copy link
Contributor

@jflo jflo commented Jul 5, 2022

fixed #3943

@jflo jflo force-pushed the 3943-stop-blocks-on-finalized branch from 6604d0b to f653815 Compare July 7, 2022 17:15
@jflo jflo requested a review from garyschulte July 7, 2022 17:25
public interface ForkchoiceMessageListener {

void onNewForkchoiceMessage(
final Hash headBlockHash,

Check notice

Code scanning / CodeQL

Useless parameter

The parameter headBlockHash is unused.
void onNewForkchoiceMessage(
final Hash headBlockHash,
final Optional<Hash> maybeFinalizedBlockHash,
final Hash safeBlockHash);

Check notice

Code scanning / CodeQL

Useless parameter

The parameter safeBlockHash is unused.
Comment on lines 81 to 84
private Optional<Difficulty> powTerminalDifficulty;
private final StampedLock powTerminalDifficultyLock = new StampedLock();
private Hash lastFinalized = Hash.ZERO;
private final AtomicLong numFinalizedSeen = new AtomicLong(0);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we are leaking too much of the merge implementation details into protocol manager.

How about either:

  • extracting and encapsulate the merge specific behavior into an Optional "PeerFilterAction"
  • or subclassing a merge-specific EthProtocolManager

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Went with option 1, added an Optional peer filter.

Comment on lines 105 to 119
ConsensusContext cc = protocolContext.getConsensusContext(ConsensusContext.class);
if (cc instanceof MergeContext) {
protocolContext
.getConsensusContext(MergeContext.class)
.observeNewIsPostMergeState(ethProtocolManager);
protocolContext
.getConsensusContext(MergeContext.class)
.addNewForkchoiceMessageListener(ethProtocolManager);
}

return ethProtocolManager;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

if we passed in an Optional or however we encapsulate the merge-specific logic, we wouldn't need to do this kind of introspection on class type.

jflo added 7 commits July 10, 2022 18:32
…ks, or connecting with td > ttd

Signed-off-by: Justin Florentine <[email protected]>
Signed-off-by: Justin Florentine <[email protected]>
Signed-off-by: Justin Florentine <[email protected]>
Signed-off-by: Justin Florentine <[email protected]>
@jflo jflo force-pushed the 3943-stop-blocks-on-finalized branch from d5bcb32 to caa7e6d Compare July 10, 2022 22:32
@@ -409,4 +439,35 @@ public List<Bytes> getForkIdAsBytesList() {
? Collections.emptyList()
: chainHeadForkId.getForkIdAsBytesList();
}

private boolean isFinalized() {
return this.numFinalizedSeen.get() > 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

why does it have to be more than one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Specs say not to disconnect till the 2nd finalized epoch.

Copy link
Contributor

Choose a reason for hiding this comment

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

got it

@jflo jflo requested a review from garyschulte July 11, 2022 13:32
Copy link
Contributor

@garyschulte garyschulte left a comment

Choose a reason for hiding this comment

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

clean refactor. one clarification and/or simplification question, non-blocking

}

private boolean isFinalized() {
return this.numFinalizedSeen.get() > 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

why > 1 rather than >= 1 ? just to allow a bit more time before disconnects?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Spec describes it as waiting till the 2nd finalized block.

@jflo jflo merged commit 1a62d2a into hyperledger:main Jul 11, 2022
eum602 pushed a commit to lacchain/besu that referenced this pull request Nov 3, 2023
* adds interfaces for tracking merge state and forchoices
* after 2 finalizations from fcu, disconnect any peers sending new blocks, or connecting with td > ttd
* tests for preventing pow peers from joining
* refactored to separate out merge logic

Signed-off-by: Justin Florentine <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stop the block synchronization after the first finalized block
3 participants