Exemple #1
0
        private void BreakContinuousMining(ref Round nextRound)
        {
            var minersCount = RealTimeMinersInformation.Count;

            if (minersCount <= 1)
            {
                return;
            }

            // First miner of next round != Extra block producer of current round
            var firstMinerOfNextRound            = nextRound.RealTimeMinersInformation.Values.First(i => i.Order == 1);
            var extraBlockProducerOfCurrentRound = GetExtraBlockProducerInformation();

            if (firstMinerOfNextRound.Pubkey == extraBlockProducerOfCurrentRound.Pubkey)
            {
                var secondMinerOfNextRound =
                    nextRound.RealTimeMinersInformation.Values.First(i => i.Order == 2);
                secondMinerOfNextRound.Order = 1;
                firstMinerOfNextRound.Order  = 2;
                var tempTimestamp = secondMinerOfNextRound.ExpectedMiningTime;
                secondMinerOfNextRound.ExpectedMiningTime = firstMinerOfNextRound.ExpectedMiningTime;
                firstMinerOfNextRound.ExpectedMiningTime  = tempTimestamp;
            }

            // Last miner of next round != Extra block producer of next round
            var lastMinerOfNextRound =
                nextRound.RealTimeMinersInformation.Values.FirstOrDefault(i => i.Order == minersCount);

            if (lastMinerOfNextRound == null)
            {
                return;
            }

            var extraBlockProducerOfNextRound = nextRound.GetExtraBlockProducerInformation();

            if (lastMinerOfNextRound.Pubkey == extraBlockProducerOfNextRound.Pubkey)
            {
                var lastButOneMinerOfNextRound =
                    nextRound.RealTimeMinersInformation.Values.First(i => i.Order == minersCount.Sub(1));
                lastButOneMinerOfNextRound.Order = minersCount;
                lastMinerOfNextRound.Order       = minersCount.Sub(1);
                var tempTimestamp = lastButOneMinerOfNextRound.ExpectedMiningTime;
                lastButOneMinerOfNextRound.ExpectedMiningTime = lastMinerOfNextRound.ExpectedMiningTime;
                lastMinerOfNextRound.ExpectedMiningTime       = tempTimestamp;
            }
        }