Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public void SetPubKey(KeyId keyId, PubKey pubkey)
        {
            if (keyId == null)
            {
                throw new ArgumentNullException(nameof(keyId));
            }

            if (pubkey == null)
            {
                throw new ArgumentNullException(nameof(pubkey));
            }

            Pubkeys.AddOrReplace(keyId, pubkey);
        }
Exemplo n.º 3
0
        public Hash GetMinersHash()
        {
            var orderedMiners = Pubkeys.OrderBy(p => p);

            return(HashHelper.ComputeFrom(orderedMiners.Aggregate("", (current, publicKey) => current + publicKey)));
        }
Exemplo n.º 4
0
 public bool TryGetPubKey(KeyId keyId, [MaybeNullWhen(false)] out PubKey pubkey)
 => Pubkeys.TryGetValue(keyId, out pubkey);
Exemplo n.º 5
0
 public bool TryGetPubKey(KeyId keyId, out PubKey pubkey)
 => Pubkeys.TryGetValue(keyId, out pubkey);
Exemplo n.º 6
0
        public Hash GetMinersHash()
        {
            var orderedMiners = Pubkeys.OrderBy(p => p);

            return(Hash.FromString(orderedMiners.Aggregate("", (current, publicKey) => current + publicKey)));
        }