예제 #1
0
 private void TriggerOnTriggerBlockProduction(object?sender, BlockProductionEventArgs e)
 {
     if (_checkCondition.Invoke(e))
     {
         TriggerBlockProduction?.Invoke(this, e);
     }
 }
 private void InvokeTriggerBlockProduction(BlockProductionEventArgs e)
 {
     if (CanTriggerBlockProduction)
     {
         // if we can trigger production lets do it directly, this should be most common case
         TriggerBlockProduction?.Invoke(this, e);
     }
     else
     {
         // otherwise set delayed production task
         // we need to clone event args as its BlockProductionTask will be awaited in delayed production task
         e.BlockProductionTask = InvokeTriggerBlockProductionDelayed(e.Clone());
     }
 }
        private async Task <Block?> InvokeTriggerBlockProductionDelayed(BlockProductionEventArgs e)
        {
            CancellationToken cancellationToken = e.CancellationToken;

            // retry production until its allowed or its cancelled
            while (!CanTriggerBlockProduction && !cancellationToken.IsCancellationRequested)
            {
                if (_logger.IsDebug)
                {
                    _logger.Debug($"Delaying producing block, chain not processed yet. BlockProcessingQueue count {_blockProcessingQueue.Count}.");
                }
                await Task.Delay(ChainNotYetProcessedMillisecondsDelay, cancellationToken);
            }

            if (!cancellationToken.IsCancellationRequested)
            {
                TriggerBlockProduction?.Invoke(this, e);
            }

            return(await e.BlockProductionTask);
        }
 private void OnBlockProduction(object?sender, BlockProductionEventArgs e)
 {
     e.BlockProductionTask = TryProduceBlock(e.ParentHeader, e.CancellationToken);
 }
 private void OnInnerTriggerBlockProduction(object?sender, BlockProductionEventArgs e) =>
 TriggerBlockProduction?.Invoke(sender, e);
 private void OnTriggerBlockProduction(object?sender, BlockProductionEventArgs e) => InvokeTriggerBlockProduction(e);