示例#1
0
        /// <summary>
        /// The transaction with this method will generate on every node
        /// and executed with the same result.
        /// Otherwise, the block hash of the genesis block won't be equal.
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public override Empty FirstRound(Round input)
        {
            /* Basic checks. */

            // Ensure the execution of the current method only happened
            // at the very beginning of the consensus process.
            if (State.CurrentRoundNumber.Value != 0)
            {
                return(new Empty());
            }

            /* Initial settings. */
            State.CurrentTermNumber.Value       = 1;
            State.CurrentRoundNumber.Value      = 1;
            State.FirstRoundNumberOfEachTerm[1] = 1;
            State.MiningInterval.Value          = input.GetMiningInterval();
            SetMinerList(input.GetMinerList(), 1);

            if (!TryToAddRoundInformation(input))
            {
                Assert(false, "Failed to add round information.");
            }

            Context.LogDebug(() =>
                             $"Initial Miners: {input.RealTimeMinersInformation.Keys.Aggregate("\n", (key1, key2) => key1 + "\n" + key2)}");

            return(new Empty());
        }
        /// <summary>
        /// The transaction with this method will generate on every node
        /// and executed with the same result.
        /// Otherwise, the block hash of the genesis block won't be equal.
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public override Empty FirstRound(Round input)
        {
            /* Basic checks. */
            Assert(State.CurrentRoundNumber.Value == 0, "Already initialized.");

            /* Initial settings. */
            State.CurrentTermNumber.Value       = 1;
            State.CurrentRoundNumber.Value      = 1;
            State.FirstRoundNumberOfEachTerm[1] = 1;
            State.MiningInterval.Value          = input.GetMiningInterval();
            SetMinerList(input.GetMinerList(), 1);

            AddRoundInformation(input);

            Context.LogDebug(() =>
                             $"Initial Miners: {input.RealTimeMinersInformation.Keys.Aggregate("\n", (key1, key2) => key1 + "\n" + key2)}");

            return(new Empty());
        }