Ejemplo n.º 1
0
Archivo: DPoS.cs Proyecto: wyk125/AElf
        public async Task Update()
        {
            Helper.LogDPoSInformation(await BlockChain.GetCurrentBlockHeightAsync());

            if (ConsensusMemory == Helper.CurrentRoundNumber.Value)
            {
                return;
            }

            // Dispose previous observer.
            if (ConsensusDisposable != null)
            {
                ConsensusDisposable.Dispose();
                _logger?.Trace("Disposed previous consensus observables list. Will update DPoS information.");
            }

            // Update observer.
            var address = _nodeKeyPair.Address.DumpHex().RemoveHexPrefix();
            var miners  = Helper.Miners;

            if (!miners.Nodes.Contains(address))
            {
                return;
            }

            var blockProducerInfoOfCurrentRound = Helper[address];

            ConsensusDisposable = AElfDPoSObserver.SubscribeAElfDPoSMiningProcess(blockProducerInfoOfCurrentRound,
                                                                                  Helper.ExtraBlockTimeSlot);

            // Update current round number.
            ConsensusMemory = Helper.CurrentRoundNumber.Value;
        }
Ejemplo n.º 2
0
Archivo: DPoS.cs Proyecto: wyk125/AElf
        public async Task Start()
        {
            // Consensus information already generated.
            if (ConsensusDisposable != null)
            {
                DecrementLockNumber();
                return;
            }

            if (_consensusInitialized)
            {
                return;
            }

            _consensusInitialized = true;

            // Check whether this node contained BP list.
            if (!Miners.Nodes.Contains(_nodeKeyPair.Address.DumpHex().RemoveHexPrefix()))
            {
                return;
            }

            if (NodeConfig.Instance.ConsensusInfoGenerator && !await Helper.DPoSInformationGenerated())
            {
                AElfDPoSObserver.Initialization();
                return;
            }

            Helper.SyncMiningInterval();
            _logger?.Info($"Set AElf DPoS mining interval to: {ConsensusConfig.Instance.DPoSMiningInterval} ms.");

            if (Helper.CanRecoverDPoSInformation())
            {
                ConsensusDisposable = AElfDPoSObserver.RecoverMining();
            }
        }