public async Task InitRpcModules() { if (_mergeConfig.Enabled) { if (_api.RpcModuleProvider is null) { throw new ArgumentNullException(nameof(_api.RpcModuleProvider)); } if (_api.BlockTree is null) { throw new ArgumentNullException(nameof(_api.BlockTree)); } if (_api.BlockchainProcessor is null) { throw new ArgumentNullException(nameof(_api.BlockchainProcessor)); } if (_api.StateProvider is null) { throw new ArgumentNullException(nameof(_api.StateProvider)); } if (_api.StateProvider is null) { throw new ArgumentNullException(nameof(_api.StateProvider)); } await _api.BlockchainProcessor.StopAsync(true); _api.Config <IJsonRpcConfig>().EnableModules(ModuleType.Consensus); IEngineRpcModule engineRpcModule = new EngineRpcModule( new AssembleBlockHandler(_api.BlockTree, _defaultBlockProductionTrigger, _manualTimestamper, _api.LogManager), new NewBlockHandler(_api.BlockTree, _api.BlockPreprocessor, _api.BlockchainProcessor, _api.StateProvider, _api.Config <IInitConfig>(), _api.LogManager), new SetHeadBlockHandler(_api.BlockTree, _api.StateProvider, _api.LogManager), new FinaliseBlockHandler(_api.BlockTree, _blockFinalizationManager, _api.LogManager), _api.LogManager); _api.RpcModuleProvider.RegisterSingle(engineRpcModule); if (_logger.IsInfo) { _logger.Info("Consensus Module has been enabled"); } } }
public Task InitRpcModules() { if (MergeEnabled) { if (_api.RpcModuleProvider is null) { throw new ArgumentNullException(nameof(_api.RpcModuleProvider)); } if (_api.BlockTree is null) { throw new ArgumentNullException(nameof(_api.BlockTree)); } if (_api.BlockchainProcessor is null) { throw new ArgumentNullException(nameof(_api.BlockchainProcessor)); } if (_api.StateProvider is null) { throw new ArgumentNullException(nameof(_api.StateProvider)); } if (_api.HeaderValidator is null) { throw new ArgumentNullException(nameof(_api.HeaderValidator)); } if (_api.EthSyncingInfo is null) { throw new ArgumentNullException(nameof(_api.EthSyncingInfo)); } if (_api.Sealer is null) { throw new ArgumentNullException(nameof(_api.Sealer)); } if (_api.BlockValidator is null) { throw new ArgumentNullException(nameof(_api.BlockValidator)); } if (_api.BlockProcessingQueue is null) { throw new ArgumentNullException(nameof(_api.BlockProcessingQueue)); } if (_api.SyncProgressResolver is null) { throw new ArgumentNullException(nameof(_api.SyncProgressResolver)); } if (_api.SpecProvider is null) { throw new ArgumentNullException(nameof(_api.SpecProvider)); } if (_api.StateReader is null) { throw new ArgumentNullException(nameof(_api.StateReader)); } if (_beaconPivot is null) { throw new ArgumentNullException(nameof(_beaconPivot)); } if (_beaconSync is null) { throw new ArgumentNullException(nameof(_beaconSync)); } if (_blockProductionTrigger is null) { throw new ArgumentNullException(nameof(_blockProductionTrigger)); } if (_peerRefresher is null) { throw new ArgumentNullException(nameof(_peerRefresher)); } if (_postMergeBlockProducer is null) { throw new ArgumentNullException(nameof(_postMergeBlockProducer)); } if (_blockProductionTrigger is null) { throw new ArgumentNullException(nameof(_blockProductionTrigger)); } // ToDo: ugly temporary hack to not receive engine API messages before end of processing of all blocks after restart. Then we will wait 5s more to ensure everything is processed while (!_api.BlockProcessingQueue.IsEmpty) { Thread.Sleep(100); } Thread.Sleep(5000); IBlockImprovementContextFactory improvementContextFactory; if (string.IsNullOrEmpty(_mergeConfig.BuilderRelayUrl)) { improvementContextFactory = new BlockImprovementContextFactory(_blockProductionTrigger, TimeSpan.FromSeconds(_mergeConfig.SecondsPerSlot)); } else { DefaultHttpClient httpClient = new(new HttpClient(), _api.EthereumJsonSerializer, _api.LogManager, retryDelayMilliseconds : 100); IBoostRelay boostRelay = new BoostRelay(httpClient, _mergeConfig.BuilderRelayUrl); BoostBlockImprovementContextFactory boostBlockImprovementContextFactory = new(_blockProductionTrigger, TimeSpan.FromSeconds(_mergeConfig.SecondsPerSlot), boostRelay, _api.StateReader); improvementContextFactory = boostBlockImprovementContextFactory; } PayloadPreparationService payloadPreparationService = new( _postMergeBlockProducer, improvementContextFactory, _api.TimerFactory, _api.LogManager, TimeSpan.FromSeconds(_mergeConfig.SecondsPerSlot)); IEngineRpcModule engineRpcModule = new EngineRpcModule( new GetPayloadV1Handler(payloadPreparationService, _api.LogManager), new NewPayloadV1Handler( _api.BlockValidator, _api.BlockTree, _api.Config <IInitConfig>(), _api.Config <ISyncConfig>(), _poSSwitcher, _beaconSync, _beaconPivot, _blockCacheService, _api.BlockProcessingQueue, _invalidChainTracker, _beaconSync, _api.SpecProvider, _api.LogManager), new ForkchoiceUpdatedV1Handler( _api.BlockTree, _blockFinalizationManager, _poSSwitcher, payloadPreparationService, _api.BlockProcessingQueue, _blockCacheService, _invalidChainTracker, _beaconSync, _beaconPivot, _peerRefresher, _api.LogManager), new ExecutionStatusHandler(_api.BlockTree), new GetPayloadBodiesV1Handler(_api.BlockTree, _api.LogManager), new ExchangeTransitionConfigurationV1Handler(_poSSwitcher, _api.LogManager), _api.LogManager); _api.RpcModuleProvider.RegisterSingle(engineRpcModule); if (_logger.IsInfo) { _logger.Info("Engine Module has been enabled"); } } return(Task.CompletedTask); }