Esempio n. 1
0
        private void ProcessBlocks(CancellationToken ct)
        {
            foreach (SynchronizationConfirmedBlock synchronizationBlock in _synchronizationBlocks.GetConsumingEnumerable(ct))
            {
                if ((_synchronizationContext.LastBlockDescriptor?.BlockHeight ?? 0) >= synchronizationBlock.BlockHeight)
                {
                    continue;
                }

                _synchronizationContext.UpdateLastSyncBlockDescriptor(new SynchronizationDescriptor(synchronizationBlock.BlockHeight, _hashCalculation.CalculateHash(synchronizationBlock.RawData), synchronizationBlock.ReportedTime, DateTime.Now, synchronizationBlock.Round));

                _chainDataService.Add(synchronizationBlock);

                IPacketProvider packetProvider = _rawPacketProvidersFactory.Create(synchronizationBlock);
                _communicationService.PostMessage(_neighborhoodState.GetAllNeighbors(), packetProvider);
            }
        }
Esempio n. 2
0
        protected override void InitializeInner()
        {
            _logger.Info("Starting Synchronization Initializer");

            try
            {
                SynchronizationConfirmedBlock synchronizationConfirmedBlock = (SynchronizationConfirmedBlock)_chainDataService.GetAllLastBlocksByType(BlockTypes.Synchronization_ConfirmedBlock).Single();

                if (synchronizationConfirmedBlock != null)
                {
                    _synchronizationContext.UpdateLastSyncBlockDescriptor(new SynchronizationDescriptor(synchronizationConfirmedBlock.BlockHeight, _hashCalculation.CalculateHash(synchronizationConfirmedBlock.RawData), synchronizationConfirmedBlock.ReportedTime, DateTime.Now, synchronizationConfirmedBlock.Round));
                }

                SynchronizationRegistryCombinedBlock combinedBlock = (SynchronizationRegistryCombinedBlock)_chainDataService.GetAllLastBlocksByType(BlockTypes.Synchronization_RegistryCombinationBlock).Single();
                if (combinedBlock != null)
                {
                    _synchronizationContext.LastRegistrationCombinedBlockHeight = combinedBlock.BlockHeight;
                }
            }
            finally
            {
                _logger.Info("Synchronization Initializer completed");
            }
        }