@ -107,178 +107,358 @@ import java.util.function.Supplier;
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
/** The Besu controller builder that builds Besu Controller. */
public abstract class BesuControllerBuilder implements MiningParameterOverrides {
private static final Logger LOG = LoggerFactory . getLogger ( BesuControllerBuilder . class ) ;
private GenesisConfigFile genesisConfig ;
private Map < String , String > genesisConfigOverrides = Collections . emptyMap ( ) ;
/** The Config options supplier. */
protected Supplier < GenesisConfigOptions > configOptionsSupplier =
( ) - >
Optional . ofNullable ( genesisConfig )
. map ( conf - > conf . getConfigOptions ( genesisConfigOverrides ) )
. orElseGet ( genesisConfig : : getConfigOptions ) ;
/** The Sync config. */
protected SynchronizerConfiguration syncConfig ;
/** The Ethereum wire protocol configuration. */
protected EthProtocolConfiguration ethereumWireProtocolConfiguration ;
/** The Transaction pool configuration. */
protected TransactionPoolConfiguration transactionPoolConfiguration ;
/** The Network id. */
protected BigInteger networkId ;
/** The Mining parameters. */
protected MiningParameters miningParameters ;
/** The Metrics system. */
protected ObservableMetricsSystem metricsSystem ;
/** The Privacy parameters. */
protected PrivacyParameters privacyParameters ;
/** The Pki block creation configuration. */
protected Optional < PkiBlockCreationConfiguration > pkiBlockCreationConfiguration =
Optional . empty ( ) ;
/** The Data directory. */
protected Path dataDirectory ;
/** The Clock. */
protected Clock clock ;
/** The Node key. */
protected NodeKey nodeKey ;
/** The Is revert reason enabled. */
protected boolean isRevertReasonEnabled ;
/** The Gas limit calculator. */
GasLimitCalculator gasLimitCalculator ;
/** The Storage provider. */
protected StorageProvider storageProvider ;
/** The Is pruning enabled. */
protected boolean isPruningEnabled ;
/** The Pruner configuration. */
protected PrunerConfiguration prunerConfiguration ;
/** The Required blocks. */
protected Map < Long , Hash > requiredBlocks = Collections . emptyMap ( ) ;
/** The Reorg logging threshold. */
protected long reorgLoggingThreshold ;
/** The Data storage configuration. */
protected DataStorageConfiguration dataStorageConfiguration =
DataStorageConfiguration . DEFAULT_CONFIG ;
/** The Message permissioning providers. */
protected List < NodeMessagePermissioningProvider > messagePermissioningProviders =
Collections . emptyList ( ) ;
/** The Evm configuration. */
protected EvmConfiguration evmConfiguration ;
/** The Max peers. */
protected int maxPeers ;
/** The Chain pruner configuration. */
protected ChainPrunerConfiguration chainPrunerConfiguration = ChainPrunerConfiguration . DEFAULT ;
/ * *
* Storage provider besu controller builder .
*
* @param storageProvider the storage provider
* @return the besu controller builder
* /
public BesuControllerBuilder storageProvider ( final StorageProvider storageProvider ) {
this . storageProvider = storageProvider ;
return this ;
}
/ * *
* Genesis config file besu controller builder .
*
* @param genesisConfig the genesis config
* @return the besu controller builder
* /
public BesuControllerBuilder genesisConfigFile ( final GenesisConfigFile genesisConfig ) {
this . genesisConfig = genesisConfig ;
return this ;
}
/ * *
* Synchronizer configuration besu controller builder .
*
* @param synchronizerConfig the synchronizer config
* @return the besu controller builder
* /
public BesuControllerBuilder synchronizerConfiguration (
final SynchronizerConfiguration synchronizerConfig ) {
this . syncConfig = synchronizerConfig ;
return this ;
}
/ * *
* Eth protocol configuration besu controller builder .
*
* @param ethProtocolConfiguration the eth protocol configuration
* @return the besu controller builder
* /
public BesuControllerBuilder ethProtocolConfiguration (
final EthProtocolConfiguration ethProtocolConfiguration ) {
this . ethereumWireProtocolConfiguration = ethProtocolConfiguration ;
return this ;
}
/ * *
* Network id besu controller builder .
*
* @param networkId the network id
* @return the besu controller builder
* /
public BesuControllerBuilder networkId ( final BigInteger networkId ) {
this . networkId = networkId ;
return this ;
}
/ * *
* Mining parameters besu controller builder .
*
* @param miningParameters the mining parameters
* @return the besu controller builder
* /
public BesuControllerBuilder miningParameters ( final MiningParameters miningParameters ) {
this . miningParameters = miningParameters ;
return this ;
}
/ * *
* Message permissioning providers besu controller builder .
*
* @param messagePermissioningProviders the message permissioning providers
* @return the besu controller builder
* /
public BesuControllerBuilder messagePermissioningProviders (
final List < NodeMessagePermissioningProvider > messagePermissioningProviders ) {
this . messagePermissioningProviders = messagePermissioningProviders ;
return this ;
}
/ * *
* Node key besu controller builder .
*
* @param nodeKey the node key
* @return the besu controller builder
* /
public BesuControllerBuilder nodeKey ( final NodeKey nodeKey ) {
this . nodeKey = nodeKey ;
return this ;
}
/ * *
* Metrics system besu controller builder .
*
* @param metricsSystem the metrics system
* @return the besu controller builder
* /
public BesuControllerBuilder metricsSystem ( final ObservableMetricsSystem metricsSystem ) {
this . metricsSystem = metricsSystem ;
return this ;
}
/ * *
* Privacy parameters besu controller builder .
*
* @param privacyParameters the privacy parameters
* @return the besu controller builder
* /
public BesuControllerBuilder privacyParameters ( final PrivacyParameters privacyParameters ) {
this . privacyParameters = privacyParameters ;
return this ;
}
/ * *
* Pki block creation configuration besu controller builder .
*
* @param pkiBlockCreationConfiguration the pki block creation configuration
* @return the besu controller builder
* /
public BesuControllerBuilder pkiBlockCreationConfiguration (
final Optional < PkiBlockCreationConfiguration > pkiBlockCreationConfiguration ) {
this . pkiBlockCreationConfiguration = pkiBlockCreationConfiguration ;
return this ;
}
/ * *
* Data directory besu controller builder .
*
* @param dataDirectory the data directory
* @return the besu controller builder
* /
public BesuControllerBuilder dataDirectory ( final Path dataDirectory ) {
this . dataDirectory = dataDirectory ;
return this ;
}
/ * *
* Clock besu controller builder .
*
* @param clock the clock
* @return the besu controller builder
* /
public BesuControllerBuilder clock ( final Clock clock ) {
this . clock = clock ;
return this ;
}
/ * *
* Transaction pool configuration besu controller builder .
*
* @param transactionPoolConfiguration the transaction pool configuration
* @return the besu controller builder
* /
public BesuControllerBuilder transactionPoolConfiguration (
final TransactionPoolConfiguration transactionPoolConfiguration ) {
this . transactionPoolConfiguration = transactionPoolConfiguration ;
return this ;
}
/ * *
* Is revert reason enabled besu controller builder .
*
* @param isRevertReasonEnabled the is revert reason enabled
* @return the besu controller builder
* /
public BesuControllerBuilder isRevertReasonEnabled ( final boolean isRevertReasonEnabled ) {
this . isRevertReasonEnabled = isRevertReasonEnabled ;
return this ;
}
/ * *
* Is pruning enabled besu controller builder .
*
* @param isPruningEnabled the is pruning enabled
* @return the besu controller builder
* /
public BesuControllerBuilder isPruningEnabled ( final boolean isPruningEnabled ) {
this . isPruningEnabled = isPruningEnabled ;
return this ;
}
/ * *
* Pruning configuration besu controller builder .
*
* @param prunerConfiguration the pruner configuration
* @return the besu controller builder
* /
public BesuControllerBuilder pruningConfiguration ( final PrunerConfiguration prunerConfiguration ) {
this . prunerConfiguration = prunerConfiguration ;
return this ;
}
/ * *
* Genesis config overrides besu controller builder .
*
* @param genesisConfigOverrides the genesis config overrides
* @return the besu controller builder
* /
public BesuControllerBuilder genesisConfigOverrides (
final Map < String , String > genesisConfigOverrides ) {
this . genesisConfigOverrides = genesisConfigOverrides ;
return this ;
}
/ * *
* Gas limit calculator besu controller builder .
*
* @param gasLimitCalculator the gas limit calculator
* @return the besu controller builder
* /
public BesuControllerBuilder gasLimitCalculator ( final GasLimitCalculator gasLimitCalculator ) {
this . gasLimitCalculator = gasLimitCalculator ;
return this ;
}
/ * *
* Required blocks besu controller builder .
*
* @param requiredBlocks the required blocks
* @return the besu controller builder
* /
public BesuControllerBuilder requiredBlocks ( final Map < Long , Hash > requiredBlocks ) {
this . requiredBlocks = requiredBlocks ;
return this ;
}
/ * *
* Reorg logging threshold besu controller builder .
*
* @param reorgLoggingThreshold the reorg logging threshold
* @return the besu controller builder
* /
public BesuControllerBuilder reorgLoggingThreshold ( final long reorgLoggingThreshold ) {
this . reorgLoggingThreshold = reorgLoggingThreshold ;
return this ;
}
/ * *
* Data storage configuration besu controller builder .
*
* @param dataStorageConfiguration the data storage configuration
* @return the besu controller builder
* /
public BesuControllerBuilder dataStorageConfiguration (
final DataStorageConfiguration dataStorageConfiguration ) {
this . dataStorageConfiguration = dataStorageConfiguration ;
return this ;
}
/ * *
* Evm configuration besu controller builder .
*
* @param evmConfiguration the evm configuration
* @return the besu controller builder
* /
public BesuControllerBuilder evmConfiguration ( final EvmConfiguration evmConfiguration ) {
this . evmConfiguration = evmConfiguration ;
return this ;
}
/ * *
* Max peers besu controller builder .
*
* @param maxPeers the max peers
* @return the besu controller builder
* /
public BesuControllerBuilder maxPeers ( final int maxPeers ) {
this . maxPeers = maxPeers ;
return this ;
}
/ * *
* Chain pruning configuration besu controller builder .
*
* @param chainPrunerConfiguration the chain pruner configuration
* @return the besu controller builder
* /
public BesuControllerBuilder chainPruningConfiguration (
final ChainPrunerConfiguration chainPrunerConfiguration ) {
this . chainPrunerConfiguration = chainPrunerConfiguration ;
return this ;
}
/ * *
* Build besu controller .
*
* @return the besu controller
* /
public BesuController build ( ) {
checkNotNull ( genesisConfig , "Missing genesis config" ) ;
checkNotNull ( syncConfig , "Missing sync config" ) ;
@ -495,6 +675,19 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides
additionalPluginServices ) ;
}
/ * *
* Create synchronizer synchronizer .
*
* @param protocolSchedule the protocol schedule
* @param worldStateStorage the world state storage
* @param protocolContext the protocol context
* @param maybePruner the maybe pruner
* @param ethContext the eth context
* @param syncState the sync state
* @param ethProtocolManager the eth protocol manager
* @param pivotBlockSelector the pivot block selector
* @return the synchronizer
* /
protected Synchronizer createSynchronizer (
final ProtocolSchedule protocolSchedule ,
final WorldStateStorage worldStateStorage ,
@ -564,6 +757,12 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides
}
}
/ * *
* Gets full sync termination condition .
*
* @param blockchain the blockchain
* @return the full sync termination condition
* /
protected SyncTerminationCondition getFullSyncTerminationCondition ( final Blockchain blockchain ) {
return configOptionsSupplier
. get ( )
@ -572,13 +771,27 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides
. orElse ( SyncTerminationCondition . never ( ) ) ;
}
/** Prep for build. */
protected void prepForBuild ( ) { }
/ * *
* Create additional json rpc method factory json rpc methods .
*
* @param protocolContext the protocol context
* @return the json rpc methods
* /
protected JsonRpcMethods createAdditionalJsonRpcMethodFactory (
final ProtocolContext protocolContext ) {
return apis - > Collections . emptyMap ( ) ;
}
/ * *
* Create sub protocol configuration sub protocol configuration .
*
* @param ethProtocolManager the eth protocol manager
* @param maybeSnapProtocolManager the maybe snap protocol manager
* @return the sub protocol configuration
* /
protected SubProtocolConfiguration createSubProtocolConfiguration (
final EthProtocolManager ethProtocolManager ,
final Optional < SnapProtocolManager > maybeSnapProtocolManager ) {
@ -591,6 +804,17 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides
return subProtocolConfiguration ;
}
/ * *
* Create mining coordinator mining coordinator .
*
* @param protocolSchedule the protocol schedule
* @param protocolContext the protocol context
* @param transactionPool the transaction pool
* @param miningParameters the mining parameters
* @param syncState the sync state
* @param ethProtocolManager the eth protocol manager
* @return the mining coordinator
* /
protected abstract MiningCoordinator createMiningCoordinator (
ProtocolSchedule protocolSchedule ,
ProtocolContext protocolContext ,
@ -599,19 +823,57 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides
SyncState syncState ,
EthProtocolManager ethProtocolManager ) ;
/ * *
* Create protocol schedule protocol schedule .
*
* @return the protocol schedule
* /
protected abstract ProtocolSchedule createProtocolSchedule ( ) ;
/ * *
* Validate context .
*
* @param context the context
* /
protected void validateContext ( final ProtocolContext context ) { }
/ * *
* Create consensus context consensus context .
*
* @param blockchain the blockchain
* @param worldStateArchive the world state archive
* @param protocolSchedule the protocol schedule
* @return the consensus context
* /
protected abstract ConsensusContext createConsensusContext (
Blockchain blockchain ,
WorldStateArchive worldStateArchive ,
ProtocolSchedule protocolSchedule ) ;
/ * *
* Gets supported protocol .
*
* @return the supported protocol
* /
protected String getSupportedProtocol ( ) {
return EthProtocol . NAME ;
}
/ * *
* Create eth protocol manager eth protocol manager .
*
* @param protocolContext the protocol context
* @param synchronizerConfiguration the synchronizer configuration
* @param transactionPool the transaction pool
* @param ethereumWireProtocolConfiguration the ethereum wire protocol configuration
* @param ethPeers the eth peers
* @param ethContext the eth context
* @param ethMessages the eth messages
* @param scheduler the scheduler
* @param peerValidators the peer validators
* @param mergePeerFilter the merge peer filter
* @return the eth protocol manager
* /
protected EthProtocolManager createEthProtocolManager (
final ProtocolContext protocolContext ,
final SynchronizerConfiguration synchronizerConfiguration ,
@ -640,6 +902,15 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides
genesisConfig . getForkTimestamps ( ) ) ;
}
/ * *
* Create protocol context protocol context .
*
* @param blockchain the blockchain
* @param worldStateArchive the world state archive
* @param protocolSchedule the protocol schedule
* @param consensusContextFactory the consensus context factory
* @return the protocol context
* /
protected ProtocolContext createProtocolContext (
final MutableBlockchain blockchain ,
final WorldStateArchive worldStateArchive ,
@ -695,6 +966,12 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides
metricsSystem ) ) ;
}
/ * *
* Create peer validators list .
*
* @param protocolSchedule the protocol schedule
* @return the list
* /
protected List < PeerValidator > createPeerValidators ( final ProtocolSchedule protocolSchedule ) {
final List < PeerValidator > validators = new ArrayList < > ( ) ;
@ -732,6 +1009,13 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides
return validators ;
}
/ * *
* Create additional plugin services plugin service factory .
*
* @param blockchain the blockchain
* @param protocolContext the protocol context
* @return the plugin service factory
* /
protected abstract PluginServiceFactory createAdditionalPluginServices (
final Blockchain blockchain , final ProtocolContext protocolContext ) ;
}