-
Notifications
You must be signed in to change notification settings - Fork 0
Fix: Register all BFT sub-protocols during IBFT2→QBFT consensus migration #1
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,6 +49,8 @@ | |
| import org.hyperledger.besu.ethereum.mainnet.BalConfiguration; | ||
| import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; | ||
| import org.hyperledger.besu.ethereum.p2p.config.SubProtocolConfiguration; | ||
| import org.hyperledger.besu.ethereum.p2p.network.ProtocolManager; | ||
| import org.hyperledger.besu.ethereum.p2p.rlpx.wire.SubProtocol; | ||
| import org.hyperledger.besu.ethereum.storage.StorageProvider; | ||
| import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration; | ||
| import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; | ||
|
|
@@ -225,9 +227,37 @@ protected JsonRpcMethods createAdditionalJsonRpcMethodFactory( | |
| protected SubProtocolConfiguration createSubProtocolConfiguration( | ||
| final EthProtocolManager ethProtocolManager, | ||
| final Optional<SnapProtocolManager> maybeSnapProtocolManager) { | ||
| return besuControllerBuilderSchedule | ||
| .get(besuControllerBuilderSchedule.keySet().stream().skip(1).findFirst().orElseThrow()) | ||
| .createSubProtocolConfiguration(ethProtocolManager, maybeSnapProtocolManager); | ||
| // During consensus migration, we need BOTH wire protocols registered. | ||
| // This allows nodes to communicate before AND after the migration block. | ||
| // Previously used .skip(1) which was non-deterministic with HashMap ordering. | ||
| // | ||
| // We merge all sub-protocol configurations, which registers both: | ||
| // - IBF/1 (IBFT2) for pre-migration communication | ||
| // - istanbul/100 (QBFT) for post-migration communication | ||
| final SubProtocolConfiguration mergedConfig = new SubProtocolConfiguration(); | ||
| final java.util.Set<String> addedProtocolNames = new java.util.HashSet<>(); | ||
|
|
||
| // Add sub-protocols from each consensus builder (sorted by block number for determinism) | ||
| besuControllerBuilderSchedule.entrySet().stream() | ||
| .sorted(Map.Entry.comparingByKey()) | ||
| .forEach( | ||
| entry -> { | ||
| final SubProtocolConfiguration builderConfig = | ||
| entry.getValue().createSubProtocolConfiguration(ethProtocolManager, maybeSnapProtocolManager); | ||
| final List<SubProtocol> subProtocols = builderConfig.getSubProtocols(); | ||
| final List<ProtocolManager> protocolManagers = builderConfig.getProtocolManagers(); | ||
| for (int i = 0; i < subProtocols.size(); i++) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code assumes that if (subProtocols.size() != protocolManagers.size()) {
throw new IllegalStateException("Sub-protocols and protocol managers lists must have the same size.");
} |
||
| final SubProtocol subProtocol = subProtocols.get(i); | ||
| final ProtocolManager protocolManager = protocolManagers.get(i); | ||
| // Only add if not already present (avoid duplicates like EthProtocol) | ||
| if (!addedProtocolNames.contains(subProtocol.getName())) { | ||
| mergedConfig.withSubProtocol(subProtocol, protocolManager); | ||
| addedProtocolNames.add(subProtocol.getName()); | ||
| } | ||
|
Comment on lines
+253
to
+256
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logic to check for an element's presence in a if (addedProtocolNames.add(subProtocol.getName())) {
mergedConfig.withSubProtocol(subProtocol, protocolManager);
} |
||
| } | ||
| }); | ||
|
|
||
| return mergedConfig; | ||
| } | ||
|
|
||
| @Override | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.