private void CreateAndDistributeCombinedBlock(RegistryFullBlock transactionsFullBlockMostConfident) { lock (_synchronizationContext) { SynchronizationRegistryCombinedBlock lastCombinedBlock = (SynchronizationRegistryCombinedBlock)_synchronizationChainDataService.GetAllLastBlocksByType(BlockTypes.Synchronization_RegistryCombinationBlock).Single(); byte[] prevHash = lastCombinedBlock != null?_defaultTransactionHashCalculation.CalculateHash(lastCombinedBlock.RawData) : new byte[Globals.DEFAULT_HASH_SIZE]; byte[] fullBlockHash = _defaultTransactionHashCalculation.CalculateHash(transactionsFullBlockMostConfident?.RawData ?? new byte[Globals.DEFAULT_HASH_SIZE]); //TODO: For initial POC there will be only one participant at Synchronization Layer, thus combination of FullBlocks won't be implemented fully SynchronizationRegistryCombinedBlock synchronizationRegistryCombinedBlock = new SynchronizationRegistryCombinedBlock { SyncBlockHeight = _synchronizationContext.LastBlockDescriptor?.BlockHeight ?? 0, PowHash = _powCalculation.CalculateHash(_synchronizationContext.LastBlockDescriptor?.Hash ?? new byte[Globals.DEFAULT_HASH_SIZE]), BlockHeight = ++_synchronizationContext.LastRegistrationCombinedBlockHeight, HashPrev = prevHash, ReportedTime = DateTime.Now, BlockHashes = new byte[][] { fullBlockHash } }; ISerializer combinedBlockSerializer = _signatureSupportSerializersFactory.Create(synchronizationRegistryCombinedBlock); combinedBlockSerializer.FillBodyAndRowBytes(); IEnumerable <IKey> storageLayerKeys = _nodesResolutionService.GetStorageNodeKeys(combinedBlockSerializer); _communicationService.PostMessage(storageLayerKeys, combinedBlockSerializer); _synchronizationChainDataService.Add(synchronizationRegistryCombinedBlock); } }
private void DistributeAndSaveFullBlock(RegistryFullBlock transactionsFullBlockMostConfident) { IRawPacketProvider fullBlockSerializer = _rawPacketProvidersFactory.Create(transactionsFullBlockMostConfident); IEnumerable <IKey> storageLayerKeys = _nodesResolutionService.GetStorageNodeKeys(fullBlockSerializer); _communicationService.PostMessage(storageLayerKeys, fullBlockSerializer); _registryChainDataService.Add(transactionsFullBlockMostConfident); }
private void DistributeAndSaveFullBlock(IEnumerable <RegistryFullBlock> registryFullBlocks) { if (registryFullBlocks != null) { foreach (var registryFullBlock in registryFullBlocks) { IRawPacketProvider fullBlockSerializer = _rawPacketProvidersFactory.Create(registryFullBlock); IEnumerable <IKey> storageLayerKeys = _nodesResolutionService.GetStorageNodeKeys(fullBlockSerializer); _communicationService.PostMessage(storageLayerKeys, fullBlockSerializer); _registryChainDataService.Add(registryFullBlock); } } }
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); } }
private void StoreBlock(T blockBase) { IChainDataService chainDataService = _chainDataServicesManager.GetChainDataService(blockBase.PacketType); chainDataService.Add(blockBase); }