// every round must last around 5 seconds // when round ends following things will happen: // 1. Shard Leader will send block with information about Transactions Registry Block collected most votes // 2. Winning Transactions Registry Block will be saved to local database and will be sent to Storage Layer // 3. It will be created Combined Block that will hold information about winning Transactions Registry Block private void RoundEndedHandler(RoundDescriptor roundDescriptor) { if (roundDescriptor == null) { return; } }
public void AddVotingBlock(RegistryConfidenceBlock confidenceBlock) { if (confidenceBlock == null) { throw new ArgumentNullException(nameof(confidenceBlock)); } _logger.Debug($"AddVotingBlock - Adding ConfidenceBlock of round {confidenceBlock.BlockHeight} with BitMask {confidenceBlock.BitMask.ToHexString()}"); //if (confidenceBlock.SyncBlockHeight <= _lastCompletedSyncHeight) if (_lastCompletedRound > 1 && confidenceBlock.BlockHeight <= _lastCompletedRound && confidenceBlock.BlockHeight != 1 || _lastCompletedRound == 1 && confidenceBlock.BlockHeight == 1) { _logger.Error($"AddVotingBlock - Received ConfidenceBlock with Round {confidenceBlock.BlockHeight} violates last completed Round {_lastCompletedRound}. BitMask: {confidenceBlock.BitMask.ToHexString()}"); return; } lock (_syncRound) { if (!_roundDescriptors.ContainsKey(confidenceBlock.BlockHeight)) { RoundDescriptor roundDescriptor = new RoundDescriptor(_transactionHashKey); roundDescriptor.AddVotingBlock(confidenceBlock); _roundDescriptors.Add(confidenceBlock.BlockHeight, roundDescriptor); } else { _roundDescriptors[confidenceBlock.BlockHeight].AddVotingBlock(confidenceBlock); } _logger.Debug($"AddVotingBlock - Number of voting blocks for round {confidenceBlock.BlockHeight} = {_roundDescriptors[confidenceBlock.BlockHeight].VotingBlocks.Count}"); } }
public RegistryFullBlock GetMostConfidentFullBlock(ulong round) { if (!_roundDescriptors.ContainsKey(round)) { _logger.Error($"No RoundDescriptor with index {round}"); return(null); } RoundDescriptor roundDescriptor = _roundDescriptors[round]; foreach (var confidenceBlock in roundDescriptor.VotingBlocks) { IKey key = _transactionHashKey.GetKey(confidenceBlock.ReferencedBlockHash); if (roundDescriptor.CandidateVotes.ContainsKey(key)) { long sum = GetConfidence(confidenceBlock.BitMask); roundDescriptor.CandidateVotes[key] += (int)sum; } } RegistryFullBlock transactionsFullBlockMostConfident = roundDescriptor.CandidateBlocks?.Values?.FirstOrDefault(); //if (roundDescriptor.CandidateVotes?.Count > 0 ) //{ // IKey mostConfidentKey = roundDescriptor.CandidateVotes.OrderByDescending(kv => (double)kv.Value / (double)roundDescriptor.CandidateBlocks[kv.Key].TransactionHeaders.Count).First().Key; // transactionsFullBlockMostConfident = roundDescriptor.CandidateBlocks[mostConfidentKey]; //} if (transactionsFullBlockMostConfident == null) { _logger.Error($"No candidates found for round {round}"); } else { _logger.Debug($"Most confident RegistryFullBlock contains {transactionsFullBlockMostConfident.TransactionHeaders.Count} transactions"); } return(transactionsFullBlockMostConfident); }
public void AddCandidateBlock(RegistryFullBlock transactionsFullBlock) { if (transactionsFullBlock == null) { throw new ArgumentNullException(nameof(transactionsFullBlock)); } _logger.Debug($"Adding candidate block of round {transactionsFullBlock.BlockHeight} with {transactionsFullBlock.TransactionHeaders.Count} transactions"); _logger.Debug($"{nameof(SyncRegistryMemPool)} - adding candidate block {transactionsFullBlock.RawData.ToHexString()}"); if (_lastCompletedRound > 1 && transactionsFullBlock.BlockHeight <= _lastCompletedRound && transactionsFullBlock.BlockHeight != 1 || _lastCompletedRound == 1 && transactionsFullBlock.BlockHeight == 1) { _logger.Error($"Received FullBlock with Round {transactionsFullBlock.BlockHeight} violates last completed Round {_lastCompletedRound}. Number of transactions: {transactionsFullBlock.TransactionHeaders.Count}"); return; } else { _logger.Debug($"Received FullBlock with Round {transactionsFullBlock.BlockHeight} matches completed Round {_lastCompletedRound}"); } lock (_syncRound) { if (!_roundDescriptors.ContainsKey(transactionsFullBlock.BlockHeight)) { RoundDescriptor roundDescriptor = new RoundDescriptor(_transactionHashKey); roundDescriptor.AddFullBlock(transactionsFullBlock); _roundDescriptors.Add(transactionsFullBlock.BlockHeight, roundDescriptor); } else { _roundDescriptors[transactionsFullBlock.BlockHeight].AddFullBlock(transactionsFullBlock); } _logger.Debug($"AddCandidateBlock - Number of candidate blocks for round {transactionsFullBlock.BlockHeight} = {_roundDescriptors[transactionsFullBlock.BlockHeight].CandidateBlocks.Count}"); } }