public Round GenerateFirstRoundOfNewTerm(int miningInterval, Timestamp currentBlockTime, long currentRoundNumber = 0, long currentTermNumber = 0) { var sortedMiners = (from obj in Pubkeys .ToDictionary <ByteString, string, int>(miner => miner.ToHex(), miner => miner[0]) orderby obj.Value descending select obj.Key).ToList(); var round = new Consensus.AEDPoS.Round(); for (var i = 0; i < sortedMiners.Count; i++) { var minerInRound = new MinerInRound(); // The first miner will be the extra block producer of first round of each term. if (i == 0) { minerInRound.IsExtraBlockProducer = true; } minerInRound.Pubkey = sortedMiners[i]; minerInRound.Order = i + 1; minerInRound.ExpectedMiningTime = currentBlockTime.AddMilliseconds((i * miningInterval) + miningInterval); // Should be careful during validation. minerInRound.PreviousInValue = Hash.Empty; round.RealTimeMinersInformation.Add(sortedMiners[i], minerInRound); } round.RoundNumber = currentRoundNumber + 1; round.TermNumber = currentTermNumber + 1; return(round); }
/// <summary> /// Based on first actual mining time of provided miner. /// </summary> /// <param name="minerInRound"></param> /// <param name="miningInterval"></param> /// <returns></returns> private int GetNextBlockMiningLeftMillisecondsForFirstRound(MinerInRound minerInRound, int miningInterval) { var firstActualMiningTime = minerInRound.ActualMiningTimes.First(); var timeForEachBlock = miningInterval.Div(AEDPoSContractConstants.TotalTinySlots); var expectedMiningTime = firstActualMiningTime.AddMilliseconds(timeForEachBlock.Mul(minerInRound.ProducedTinyBlocks)); TuneExpectedMiningTimeForTinyBlock(miningInterval, firstActualMiningTime, ref expectedMiningTime); return((int)(expectedMiningTime - Context.CurrentBlockTime).Milliseconds()); }
private static void PerformSecretSharing(UpdateValueInput input, MinerInRound minerInRound, Round round, string publicKey) { minerInRound.EncryptedInValues.Add(input.EncryptedInValues); foreach (var decryptedPreviousInValue in input.DecryptedPreviousInValues) { round.RealTimeMinersInformation[decryptedPreviousInValue.Key].DecryptedPreviousInValues .Add(publicKey, decryptedPreviousInValue.Value); } }
protected ConsensusBehaviourProviderBase(Round currentRound, string pubkey, int maximumBlocksCount, Timestamp currentBlockTime) { CurrentRound = currentRound; Pubkey = pubkey; MaximumBlocksCount = maximumBlocksCount; CurrentBlockTime = currentBlockTime; IsTimeSlotPassed = CurrentRound.IsTimeSlotPassed(Pubkey, CurrentBlockTime); MinerInRound = CurrentRound.RealTimeMinersInformation[Pubkey]; }
internal bool IsTimeSlotPassed(string publicKey, DateTime dateTime, out MinerInRound minerInRound) { minerInRound = null; var miningInterval = GetMiningInterval(); if (!RealTimeMinersInformation.ContainsKey(publicKey)) { return(false); } minerInRound = RealTimeMinersInformation[publicKey]; return(minerInRound.ExpectedMiningTime.ToDateTime().AddMilliseconds(miningInterval) <= dateTime); }