-
Notifications
You must be signed in to change notification settings - Fork 1k
PoS checkpoint sync #4844
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
PoS checkpoint sync #4844
Changes from all commits
d31d63f
5e73c6b
1bf75c0
70bd193
acca61e
3eb7015
9b38c51
1ce3021
d6480d2
e8ecdd8
98d107a
038105e
c69f15c
fa2c745
bafebeb
8e57f86
06350eb
8a650c3
3fff7f3
4861991
03a9ec6
3190822
b5e2994
f69d296
5847166
ce85fac
defaae8
7c37113
a4d44e4
ba516c4
c74bb2b
00bc42b
69b4874
be2eb22
607e62d
6f2fef8
943aa80
ed5f29f
4658d7e
81245bd
9c194fd
6f8b6b7
858fdfc
56cfd7b
fdc0a47
a25e93b
7178173
d768c87
5926fe3
5986580
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 |
|---|---|---|
|
|
@@ -14,6 +14,8 @@ | |
| */ | ||
| package org.hyperledger.besu.controller; | ||
|
|
||
| import static org.hyperledger.besu.ethereum.eth.sync.SyncMode.isCheckpointSync; | ||
|
|
||
| import org.hyperledger.besu.cli.config.EthNetworkConfig; | ||
| import org.hyperledger.besu.config.GenesisConfigFile; | ||
| import org.hyperledger.besu.config.GenesisConfigOptions; | ||
|
|
@@ -28,6 +30,7 @@ | |
| import org.hyperledger.besu.ethereum.core.PrivacyParameters; | ||
| import org.hyperledger.besu.ethereum.core.Synchronizer; | ||
| import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; | ||
| import org.hyperledger.besu.ethereum.eth.sync.SyncMode; | ||
| import org.hyperledger.besu.ethereum.eth.sync.state.SyncState; | ||
| import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; | ||
| import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; | ||
|
|
@@ -41,6 +44,7 @@ | |
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import org.apache.tuweni.units.bigints.UInt256; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
|
|
@@ -171,24 +175,26 @@ public PluginServiceFactory getAdditionalPluginServices() { | |
|
|
||
| public static class Builder { | ||
|
|
||
| public BesuControllerBuilder fromEthNetworkConfig(final EthNetworkConfig ethNetworkConfig) { | ||
| return fromEthNetworkConfig(ethNetworkConfig, Collections.emptyMap()); | ||
| } | ||
|
|
||
| public BesuControllerBuilder fromEthNetworkConfig( | ||
| final EthNetworkConfig ethNetworkConfig, final Map<String, String> genesisConfigOverrides) { | ||
| final EthNetworkConfig ethNetworkConfig, | ||
| final Map<String, String> genesisConfigOverrides, | ||
| final SyncMode syncMode) { | ||
| return fromGenesisConfig( | ||
| GenesisConfigFile.fromConfig(ethNetworkConfig.getGenesisConfig()), | ||
| genesisConfigOverrides) | ||
| genesisConfigOverrides, | ||
| syncMode) | ||
| .networkId(ethNetworkConfig.getNetworkId()); | ||
| } | ||
|
|
||
| public BesuControllerBuilder fromGenesisConfig(final GenesisConfigFile genesisConfig) { | ||
| return fromGenesisConfig(genesisConfig, Collections.emptyMap()); | ||
| public BesuControllerBuilder fromGenesisConfig( | ||
| final GenesisConfigFile genesisConfig, final SyncMode syncMode) { | ||
| return fromGenesisConfig(genesisConfig, Collections.emptyMap(), syncMode); | ||
| } | ||
|
|
||
| BesuControllerBuilder fromGenesisConfig( | ||
| final GenesisConfigFile genesisConfig, final Map<String, String> genesisConfigOverrides) { | ||
| final GenesisConfigFile genesisConfig, | ||
| final Map<String, String> genesisConfigOverrides, | ||
| final SyncMode syncMode) { | ||
| final GenesisConfigOptions configOptions = | ||
| genesisConfig.getConfigOptions(genesisConfigOverrides); | ||
| final BesuControllerBuilder builder; | ||
|
|
@@ -213,11 +219,17 @@ BesuControllerBuilder fromGenesisConfig( | |
|
|
||
| // wrap with TransitionBesuControllerBuilder if we have a terminal total difficulty: | ||
| if (configOptions.getTerminalTotalDifficulty().isPresent()) { | ||
| // TODO this should be changed to vanilla MergeBesuControllerBuilder and the Transition* | ||
| // series of classes removed after we successfully transition to PoS | ||
| // https://github.com/hyperledger/besu/issues/2897 | ||
| return new TransitionBesuControllerBuilder(builder, new MergeBesuControllerBuilder()) | ||
| .genesisConfigFile(genesisConfig); | ||
| // Enable start with vanilla MergeBesuControllerBuilder for PoS checkpoint block | ||
| if (isCheckpointSync(syncMode) && isCheckpointPoSBlock(configOptions)) { | ||
jframe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return new MergeBesuControllerBuilder().genesisConfigFile(genesisConfig); | ||
| } else { | ||
| // TODO this should be changed to vanilla MergeBesuControllerBuilder and the Transition* | ||
| // series of classes removed after we successfully transition to PoS | ||
| // https://github.com/hyperledger/besu/issues/2897 | ||
| return new TransitionBesuControllerBuilder(builder, new MergeBesuControllerBuilder()) | ||
| .genesisConfigFile(genesisConfig); | ||
| } | ||
|
|
||
| } else return builder.genesisConfigFile(genesisConfig); | ||
| } | ||
|
|
||
|
|
@@ -258,5 +270,13 @@ private Long readQbftStartBlockConfig(final QbftConfigOptions qbftConfigOptions) | |
|
|
||
| return startBlock; | ||
| } | ||
|
|
||
| private boolean isCheckpointPoSBlock(final GenesisConfigOptions configOptions) { | ||
siladu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| final UInt256 terminalTotalDifficulty = configOptions.getTerminalTotalDifficulty().get(); | ||
|
Contributor
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. I think we cannot have empty here ? |
||
|
|
||
| return configOptions.getCheckpointOptions().isValid() | ||
|
Contributor
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. we are not already checking if it is valid here ? https://github.com/hyperledger/besu/pull/4844/files#diff-2080ac0bf38c1e492921f4191b738b729195e0b1ad82657abc9103f19ac87cd8R3368 |
||
| && (UInt256.fromHexString(configOptions.getCheckpointOptions().getTotalDifficulty().get()) | ||
| .greaterThan(terminalTotalDifficulty)); | ||
| } | ||
| } | ||
| } | ||
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 all of this check are not in the valid method of CheckpointConfigOptions ?