Ejemplo n.º 1
0
        public static IFullNodeBuilder CheckForPoAMembersCollateral(this IFullNodeBuilder fullNodeBuilder)
        {
            fullNodeBuilder.ConfigureFeature(features =>
            {
                features.AddFeature <CollateralFeature>()
                .DependOn <CounterChainFeature>()
                .DependOn <PoAFeature>()
                .FeatureServices(services =>
                {
                    services.AddSingleton <IFederationManager, CollateralFederationManager>();
                    services.AddSingleton <ICollateralChecker, CollateralChecker>();
                    services.AddSingleton <CollateralVotingController>();

                    services.AddSingleton <IRuleRegistration, SmartContractCollateralPoARuleRegistration>();
                    services.AddSingleton <IConsensusRuleEngine>(f =>
                    {
                        PoAConsensusRuleEngine concreteRuleEngine = f.GetService <PoAConsensusRuleEngine>();
                        IRuleRegistration ruleRegistration        = f.GetService <IRuleRegistration>();

                        return(new DiConsensusRuleEngine(concreteRuleEngine, ruleRegistration));
                    });
                });
            });

            return(fullNodeBuilder);
        }
        public override void Initialize()
        {
            this.votingDataEncoder = new VotingDataEncoder();
            this.ruleEngine        = (PoAConsensusRuleEngine)this.Parent;
            this.federationManager = this.ruleEngine.FederationManager;
            this.federationHistory = this.ruleEngine.FederationHistory;

            base.Initialize();
        }
Ejemplo n.º 3
0
        public override void Initialize()
        {
            this.votingDataEncoder = new VotingDataEncoder(this.Parent.LoggerFactory);
            this.ruleEngine        = (PoAConsensusRuleEngine)this.Parent;
            this.federationManager = this.ruleEngine.FederationManager;
            this.votingManager     = this.ruleEngine.VotingManager;
            this.slotsManager      = this.ruleEngine.SlotsManager;

            base.Initialize();
        }
        public override void Initialize()
        {
            this.votingDataEncoder = new VotingDataEncoder(this.Parent.LoggerFactory);
            this.ruleEngine        = (PoAConsensusRuleEngine)this.Parent;
            this.loggerFactory     = this.Parent.LoggerFactory;
            this.logger            = this.loggerFactory.CreateLogger(this.GetType().FullName);
            this.network           = this.Parent.Network;
            this.federationManager = this.ruleEngine.FederationManager;
            this.slotsManager      = this.ruleEngine.SlotsManager;
            this.consensusFactory  = (CollateralPoAConsensusFactory)this.network.Consensus.ConsensusFactory;

            base.Initialize();
        }
Ejemplo n.º 5
0
        /// <inheritdoc />
        public override void Initialize()
        {
            base.Initialize();

            PoAConsensusRuleEngine engine = this.Parent as PoAConsensusRuleEngine;

            this.slotsManager      = engine.SlotsManager;
            this.validator         = engine.PoaHeaderValidator;
            this.votingManager     = engine.VotingManager;
            this.federationManager = engine.FederationManager;
            this.chainState        = engine.ChainState;

            this.maxReorg      = this.Parent.Network.Consensus.MaxReorgLength;
            this.votingEnabled = ((PoAConsensusOptions)this.Parent.Network.Consensus.Options).VotingEnabled;
        }
Ejemplo n.º 6
0
        public PoATestsBase(TestPoANetwork network = null)
        {
            this.loggerFactory     = new LoggerFactory();
            this.signals           = new Signals.Signals(this.loggerFactory, null);
            this.network           = network == null ? new TestPoANetwork() : network;
            this.consensusOptions  = this.network.ConsensusOptions;
            this.dBreezeSerializer = new DBreezeSerializer(this.network.Consensus.ConsensusFactory);

            this.ChainIndexer = new ChainIndexer(this.network);
            IDateTimeProvider timeProvider = new DateTimeProvider();

            this.consensusSettings = new ConsensusSettings(NodeSettings.Default(this.network));

            this.federationManager = CreateFederationManager(this, this.network, this.loggerFactory, this.signals);

            this.chainIndexerMock = new Mock <ChainIndexer>();
            var header = new BlockHeader();

            this.chainIndexerMock.Setup(x => x.Tip).Returns(new ChainedHeader(header, header.GetHash(), 0));
            this.slotsManager = new SlotsManager(this.network, this.federationManager, this.chainIndexerMock.Object, this.loggerFactory);

            this.poaHeaderValidator = new PoABlockHeaderValidator(this.loggerFactory);
            this.asyncProvider      = new AsyncProvider(this.loggerFactory, this.signals, new Mock <INodeLifetime>().Object);

            var dataFolder         = new DataFolder(TestBase.CreateTestDir(this));
            var finalizedBlockRepo = new FinalizedBlockInfoRepository(new KeyValueRepository(dataFolder, this.dBreezeSerializer), this.loggerFactory, this.asyncProvider);

            finalizedBlockRepo.LoadFinalizedBlockInfoAsync(this.network).GetAwaiter().GetResult();

            this.resultExecutorMock = new Mock <IPollResultExecutor>();

            this.votingManager = new VotingManager(this.federationManager, this.loggerFactory, this.slotsManager, this.resultExecutorMock.Object, new NodeStats(timeProvider, this.loggerFactory),
                                                   dataFolder, this.dBreezeSerializer, this.signals, finalizedBlockRepo, this.network);

            this.votingManager.Initialize();

            this.chainState = new ChainState();


            this.rulesEngine = new PoAConsensusRuleEngine(this.network, this.loggerFactory, new DateTimeProvider(), this.ChainIndexer, new NodeDeployments(this.network, this.ChainIndexer),
                                                          this.consensusSettings, new Checkpoints(this.network, this.consensusSettings), new Mock <ICoinView>().Object, this.chainState, new InvalidBlockHashStore(timeProvider),
                                                          new NodeStats(timeProvider, this.loggerFactory), this.slotsManager, this.poaHeaderValidator, this.votingManager, this.federationManager, this.asyncProvider, new ConsensusRulesContainer());

            List <ChainedHeader> headers = ChainedHeadersHelper.CreateConsecutiveHeaders(50, null, false, null, this.network);

            this.currentHeader = headers.Last();
        }
Ejemplo n.º 7
0
        public PoATestsBase(TestPoANetwork network = null)
        {
            this.loggerFactory     = new LoggerFactory();
            this.signals           = new Signals.Signals(this.loggerFactory, null);
            this.network           = network ?? new TestPoANetwork();
            this.consensusOptions  = this.network.ConsensusOptions;
            this.dBreezeSerializer = new DBreezeSerializer(this.network.Consensus.ConsensusFactory);

            this.ChainIndexer = new ChainIndexer(this.network);
            IDateTimeProvider dateTimeProvider = new DateTimeProvider();

            this.consensusSettings = new ConsensusSettings(NodeSettings.Default(this.network));

            (this.federationManager, this.federationHistory) = CreateFederationManager(this, this.network, this.loggerFactory, this.signals);

            this.slotsManager = new SlotsManager(this.network, this.federationManager, this.federationHistory, this.ChainIndexer);

            this.poaHeaderValidator = new PoABlockHeaderValidator(this.loggerFactory);
            this.asyncProvider      = new AsyncProvider(this.loggerFactory, this.signals);

            var dataFolder = new DataFolder(TestBase.CreateTestDir(this));

            this.resultExecutorMock = new Mock <IPollResultExecutor>();

            this.votingManager = new VotingManager(this.federationManager, this.resultExecutorMock.Object, new NodeStats(dateTimeProvider, NodeSettings.Default(this.network), new Mock <IVersionProvider>().Object), dataFolder,
                                                   this.dBreezeSerializer, this.signals, this.network, this.ChainIndexer, null);

            this.votingManager.Initialize(this.federationHistory);

            this.chainState = new ChainState();

            this.rulesEngine = new PoAConsensusRuleEngine(this.network, this.loggerFactory, new DateTimeProvider(), this.ChainIndexer, new NodeDeployments(this.network, this.ChainIndexer),
                                                          this.consensusSettings, new Checkpoints(this.network, this.consensusSettings), new Mock <ICoinView>().Object, this.chainState, new InvalidBlockHashStore(dateTimeProvider),
                                                          new NodeStats(dateTimeProvider, NodeSettings.Default(this.network), new Mock <IVersionProvider>().Object), this.slotsManager, this.poaHeaderValidator, this.votingManager, this.federationManager, this.asyncProvider,
                                                          new ConsensusRulesContainer(), this.federationHistory);

            List <ChainedHeader> headers = ChainedHeadersHelper.CreateConsecutiveHeaders(50, null, false, null, this.network);

            this.currentHeader = headers.Last();
        }
Ejemplo n.º 8
0
        public PoARulesTestsBase(PoANetwork network = null)
        {
            this.loggerFactory    = new LoggerFactory();
            this.network          = network == null ? new PoANetwork() : network;
            this.consensusOptions = this.network.ConsensusOptions;

            this.chain = new ConcurrentChain(this.network);
            IDateTimeProvider timeProvider = new DateTimeProvider();

            this.consensusSettings = new ConsensusSettings(NodeSettings.Default(this.network));

            this.slotsManager = new SlotsManager(this.network, new FederationManager(NodeSettings.Default(this.network), this.network, this.loggerFactory), this.loggerFactory);

            this.poaHeaderValidator = new PoABlockHeaderValidator(this.loggerFactory);

            this.rulesEngine = new PoAConsensusRuleEngine(this.network, this.loggerFactory, new DateTimeProvider(), this.chain,
                                                          new NodeDeployments(this.network, this.chain), this.consensusSettings, new Checkpoints(this.network, this.consensusSettings), new Mock <ICoinView>().Object,
                                                          new ChainState(), new InvalidBlockHashStore(timeProvider), new NodeStats(timeProvider), this.slotsManager, this.poaHeaderValidator);

            List <ChainedHeader> headers = ChainedHeadersHelper.CreateConsecutiveHeaders(50, null, false, null, this.network);

            this.currentHeader = headers.Last();
        }