protected override void BuildProducer() { if (_api.EngineSigner == null) { throw new StepDependencyException(nameof(_api.EngineSigner)); } if (_api.ChainSpec == null) { throw new StepDependencyException(nameof(_api.ChainSpec)); } ILogger logger = _api.LogManager.GetClassLogger(); if (logger.IsWarn) { logger.Warn("Starting AuRa block producer & sealer"); } IAuRaStepCalculator stepCalculator = new AuRaStepCalculator(_api.ChainSpec.AuRa.StepDuration, _api.Timestamper, _api.LogManager); BlockProducerContext producerContext = GetProducerChain(); _api.BlockProducer = new AuRaBlockProducer( producerContext.TxSource, producerContext.ChainProcessor, producerContext.ReadOnlyStateProvider, _api.Sealer, _api.BlockTree, _api.BlockProcessingQueue, _api.Timestamper, stepCalculator, _api.ReportingValidator, _auraConfig, CreateGasLimitCalculator(producerContext.ReadOnlyTxProcessorSource), _api.LogManager); }
protected override void InitSealEngine() { if (_api.DbProvider == null) { throw new StepDependencyException(nameof(_api.DbProvider)); } if (_api.ChainSpec == null) { throw new StepDependencyException(nameof(_api.ChainSpec)); } if (_api.EthereumEcdsa == null) { throw new StepDependencyException(nameof(_api.EthereumEcdsa)); } if (_api.BlockTree == null) { throw new StepDependencyException(nameof(_api.BlockTree)); } _api.ValidatorStore = new ValidatorStore(_api.DbProvider.BlockInfosDb); ValidSealerStrategy validSealerStrategy = new ValidSealerStrategy(); AuRaStepCalculator auRaStepCalculator = new AuRaStepCalculator(_api.ChainSpec.AuRa.StepDuration, _api.Timestamper, _api.LogManager); _api.SealValidator = _sealValidator = new AuRaSealValidator(_api.ChainSpec.AuRa, auRaStepCalculator, _api.BlockTree, _api.ValidatorStore, validSealerStrategy, _api.EthereumEcdsa, _api.LogManager); _api.RewardCalculatorSource = AuRaRewardCalculator.GetSource(_api.ChainSpec.AuRa, _api.AbiEncoder); _api.Sealer = new AuRaSealer(_api.BlockTree, _api.ValidatorStore, auRaStepCalculator, _api.EngineSigner, validSealerStrategy, _api.LogManager); _auRaStepCalculator = auRaStepCalculator; }
public async Task after_waiting_for_next_step_timeToNextStep_should_be_close_to_stepDuration_in_seconds(int stepDuration) { var calculator = new AuRaStepCalculator(stepDuration, new Timestamper()); await TaskExt.DelayAtLeast(calculator.TimeToNextStep); calculator.TimeToNextStep.Should().BeCloseTo(TimeSpan.FromSeconds(stepDuration), TimeSpan.FromMilliseconds(100)); }
public void step_is_calculated_correctly(long milliSeconds, int stepDuration) { var time = DateTimeOffset.FromUnixTimeMilliseconds(milliSeconds); var calculator = new AuRaStepCalculator(stepDuration, new Timestamper(time.UtcDateTime)); calculator.CurrentStep.Should().Be(time.ToUnixTimeSeconds() / stepDuration); }
protected override void InitSealEngine() { if (_context.DbProvider == null) { throw new StepDependencyException(nameof(_context.DbProvider)); } if (_context.ChainSpec == null) { throw new StepDependencyException(nameof(_context.ChainSpec)); } if (_context.EthereumEcdsa == null) { throw new StepDependencyException(nameof(_context.EthereumEcdsa)); } if (_context.NodeKey == null) { throw new StepDependencyException(nameof(_context.NodeKey)); } AbiEncoder abiEncoder = new AbiEncoder(); _context.ValidatorStore = new ValidatorStore(_context.DbProvider.BlockInfosDb); IReadOnlyTransactionProcessorSource readOnlyTransactionProcessorSource = new ReadOnlyTransactionProcessorSource(_context.DbProvider, _context.BlockTree, _context.SpecProvider, _context.LogManager); IAuRaValidatorProcessorExtension validatorProcessorExtension = new AuRaValidatorProcessorFactory(_context.StateProvider, abiEncoder, _context.TransactionProcessor, readOnlyTransactionProcessorSource, _context.BlockTree, _context.ReceiptStorage, _context.ValidatorStore, _context.LogManager) .CreateValidatorProcessor(_context.ChainSpec.AuRa.Validators); AuRaStepCalculator auRaStepCalculator = new AuRaStepCalculator(_context.ChainSpec.AuRa.StepDuration, _context.Timestamper); _context.SealValidator = new AuRaSealValidator(_context.ChainSpec.AuRa, auRaStepCalculator, _context.ValidatorStore, _context.EthereumEcdsa, _context.LogManager); _context.RewardCalculatorSource = AuRaRewardCalculator.GetSource(_context.ChainSpec.AuRa, abiEncoder); _context.Sealer = new AuRaSealer(_context.BlockTree, _context.ValidatorStore, auRaStepCalculator, _context.NodeKey.Address, new BasicWallet(_context.NodeKey), new ValidSealerStrategy(), _context.LogManager); _context.AuRaBlockProcessorExtension = validatorProcessorExtension; }
protected override void BuildProducer() { if (_context.NodeKey == null) { throw new StepDependencyException(nameof(_context.NodeKey)); } if (_context.ChainSpec == null) { throw new StepDependencyException(nameof(_context.ChainSpec)); } ILogger logger = _context.LogManager.GetClassLogger(); if (logger.IsWarn) { logger.Warn("Starting AuRa block producer & sealer"); } IAuRaStepCalculator stepCalculator = new AuRaStepCalculator(_context.ChainSpec.AuRa.StepDuration, _context.Timestamper); BlockProducerContext producerContext = GetProducerChain(); var auraConfig = _context.Config <IAuraConfig>(); _context.BlockProducer = new AuRaBlockProducer( producerContext.PendingTxSelector, producerContext.ChainProcessor, producerContext.ReadOnlyStateProvider, _context.Sealer, _context.BlockTree, _context.BlockProcessingQueue, _context.Timestamper, _context.LogManager, stepCalculator, auraConfig, _context.NodeKey.Address); }
protected override void InitSealEngine() { if (_context.DbProvider == null) { throw new StepDependencyException(nameof(_context.DbProvider)); } if (_context.ChainSpec == null) { throw new StepDependencyException(nameof(_context.ChainSpec)); } if (_context.EthereumEcdsa == null) { throw new StepDependencyException(nameof(_context.EthereumEcdsa)); } if (_context.NodeKey == null) { throw new StepDependencyException(nameof(_context.NodeKey)); } _context.ValidatorStore = new ValidatorStore(_context.DbProvider.BlockInfosDb); AuRaStepCalculator auRaStepCalculator = new AuRaStepCalculator(_context.ChainSpec.AuRa.StepDuration, _context.Timestamper, _context.LogManager); _context.SealValidator = new AuRaSealValidator(_context.ChainSpec.AuRa, auRaStepCalculator, _context.ValidatorStore, _context.EthereumEcdsa, _context.LogManager); _context.RewardCalculatorSource = AuRaRewardCalculator.GetSource(_context.ChainSpec.AuRa, _context.AbiEncoder); _context.Sealer = new AuRaSealer(_context.BlockTree, _context.ValidatorStore, auRaStepCalculator, _context.NodeKey.Address, new BasicWallet(_context.NodeKey), new ValidSealerStrategy(), _context.LogManager); }
public void step_is_calculated_correctly(long milliSeconds, int stepDuration) { var time = DateTimeOffset.FromUnixTimeMilliseconds(milliSeconds); var timestamper = new ManualTimestamper(time.UtcDateTime); var calculator = new AuRaStepCalculator(GetStepDurationsForSingleStep(stepDuration), timestamper, LimboLogs.Instance); calculator.CurrentStep.Should().Be(time.ToUnixTimeSeconds() / stepDuration); }
public void after_waiting_for_next_step_timeToNextStep_should_be_close_to_stepDuration_in_seconds(int stepDuration) { var manualTimestamper = new ManualTimestamper(DateTime.Now); var calculator = new AuRaStepCalculator(GetStepDurationsForSingleStep(stepDuration), manualTimestamper, LimboLogs.Instance); manualTimestamper.Add(calculator.TimeToNextStep); calculator.TimeToNextStep.Should().BeCloseTo(TimeSpan.FromSeconds(stepDuration), TimeSpan.FromMilliseconds(200)); }
public async Task step_increases_after_timeToNextStep(int stepDuration) { var calculator = new AuRaStepCalculator(stepDuration, new Timestamper()); var step = calculator.CurrentStep; await TaskExt.DelayAtLeast(calculator.TimeToNextStep); calculator.CurrentStep.Should().Be(step + 1, calculator.TimeToNextStep.ToString()); }
public void step_increases_after_timeToNextStep(int stepDuration) { var manualTimestamper = new ManualTimestamper(DateTime.Now); var calculator = new AuRaStepCalculator(GetStepDurationsForSingleStep(stepDuration), manualTimestamper, LimboLogs.Instance); var step = calculator.CurrentStep; manualTimestamper.Add(calculator.TimeToNextStep); calculator.CurrentStep.Should().Be(step + 1, calculator.TimeToNextStep.ToString()); }
public void time_to_step_is_calculated_correctly(long milliSeconds, int stepDuration, int checkedStep) { const long currentStep = 50000030; TimeSpan timeToNextStep = TimeSpan.FromMilliseconds(1995); var time = DateTimeOffset.FromUnixTimeMilliseconds(milliSeconds); var timestamper = new ManualTimestamper(time.UtcDateTime); var calculator = new AuRaStepCalculator(GetStepDurationsForSingleStep(stepDuration), timestamper, LimboLogs.Instance); TimeSpan expected = checkedStep <= currentStep?TimeSpan.FromMilliseconds(0) : TimeSpan.FromSeconds((checkedStep - currentStep - 1) * stepDuration) + timeToNextStep; TestContext.Out.WriteLine($"Expected time to step {checkedStep} is {expected}"); calculator.TimeToStep(checkedStep).Should().Be(expected); }
public void GetBlockProcessorAndProducerIntervalHint_returns_expected_result( [ValueSource(nameof(BlockProcessorIntervalHintTestCases))] BlockProcessorIntervalHint test) { ManualTimestamper manualTimestamper = new ManualTimestamper(DateTime.Now); AuRaStepCalculator stepCalculator = new AuRaStepCalculator(new Dictionary <long, long>() { { 0, test.StepDuration } }, manualTimestamper, LimboLogs.Instance); IValidatorStore validatorStore = Substitute.For <IValidatorStore>(); validatorStore.GetValidators().Returns(new Address[test.ValidatorsCount]); IHealthHintService healthHintService = new AuraHealthHintService(stepCalculator, validatorStore); ulong?actualProcessing = healthHintService.MaxSecondsIntervalForProcessingBlocksHint(); ulong?actualProducing = healthHintService.MaxSecondsIntervalForProducingBlocksHint(); Assert.AreEqual(test.ExpectedProcessingHint, actualProcessing); Assert.AreEqual(test.ExpectedProducingHint, actualProducing); }