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 BroadcastConfirmation(ulong height, ushort round, byte[] prevHash, ulong syncBlockHeight, byte[] powValue) { //List<SynchronizationBlockRetransmissionV1> retransmittedSyncBlocks = _synchronizationBlocksByHeight[height].Where(r => _nodeContext.SyncGroupParticipants.Any(p => p.Key == r.Key)).Select(kv => kv.Value.First()).OrderBy(s => s.ConfirmationPublicKey.ToHexString()).ToList(); SynchronizationConfirmedBlock synchronizationConfirmedBlock = new SynchronizationConfirmedBlock { BlockHeight = height, HashPrev = prevHash, //TODO: does not seems too secure SyncBlockHeight = syncBlockHeight, //TODO: does not seems too secure PowHash = powValue, //TODO: does not seems too secure Round = round, PublicKeys = new byte[0][], // retransmittedSyncBlocks.Select(b => b.ConfirmationPublicKey).ToArray(), Signatures = new byte[0][] //retransmittedSyncBlocks.Select(b => b.ConfirmationSignature).ToArray() }; ISerializer confirmationBlockSerializer = _signatureSupportSerializersFactory.Create(synchronizationConfirmedBlock); _communicationService.PostMessage(_neighborhoodState.GetAllNeighbors(), confirmationBlockSerializer); }