Ejemplo n.º 1
0
 public TestPosConsensusRules(Network network, ILoggerFactory loggerFactory, IDateTimeProvider dateTimeProvider, ConcurrentChain chain,
                              NodeDeployments nodeDeployments, ConsensusSettings consensusSettings, ICheckpoints checkpoints, ICoinView uxtoSet, IStakeChain stakeChain,
                              IStakeValidator stakeValidator, IChainState chainState, IInvalidBlockHashStore invalidBlockHashStore)
     : base(network, loggerFactory, dateTimeProvider, chain, nodeDeployments, consensusSettings, checkpoints, uxtoSet, stakeChain, stakeValidator, chainState, invalidBlockHashStore)
 {
     this.ruleRegistrationHelper = new RuleRegistrationHelper();
 }
Ejemplo n.º 2
0
        public void CanCheckBlockWithWitness()
        {
            var block = new Block(Encoders.Hex.DecodeData("000000202f6f6a130549473222411b5c6f54150d63b32aadf10e57f7d563cfc7010000001e28204471ef9ef11acd73543894a96a3044932b85e99889e731322a8ec28a9f9ae9fc56ffff011d0011b40202010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff2c028027266a24aa21a9ed09154465f26a2a4144739eba3e83b3e9ae6a1f69566eae7dc3747d48f1183779010effffffff0250b5062a0100000023210263ed47e995cbbf1bc560101e3b76c6bdb1b094a185450cea533781ce598ff2b6ac0000000000000000266a24aa21a9ed09154465f26a2a4144739eba3e83b3e9ae6a1f69566eae7dc3747d48f1183779012000000000000000000000000000000000000000000000000000000000000000000000000001000000000101cecd90cd38ac6858c47f2fe9f28145d6e18f9c5abc7ef1a41e2f19e6fe0362580100000000ffffffff0130b48d06000000001976a91405481b7f1d90c5a167a15b00e8af76eb6984ea5988ac0247304402206104c335e4adbb920184957f9f710b09de17d015329fde6807b9d321fd2142db02200b24ad996b4aa4ff103000348b5ad690abfd9fddae546af9e568394ed4a83113012103a65786c1a48d4167aca08cf6eb8eed081e13f45c02dc6000fd8f3bb16242579a00000000"));

            var consensusFlags = new DeploymentFlags
            {
                ScriptFlags   = ScriptVerify.Witness | ScriptVerify.P2SH | ScriptVerify.Standard,
                LockTimeFlags = LockTimeFlags.MedianTimePast,
                EnforceBIP34  = true
            };

            var context = new RuleContext
            {
                BestBlock = new ContextBlockInformation
                {
                    MedianTimePast = DateTimeOffset.Parse("2016-03-31T09:02:19+00:00", CultureInfo.InvariantCulture),
                    Height         = 10111
                },
                NextWorkRequired       = block.Header.Bits,
                Time                   = DateTimeOffset.UtcNow,
                BlockValidationContext = new BlockValidationContext {
                    Block = block
                },
                Flags = consensusFlags,
            };

            Network.Main.Consensus.Options = new PowConsensusOptions();
            ConsensusSettings consensusSettings = new ConsensusSettings(NodeSettings.Default(), this.loggerFactory);
            var validator = new PowConsensusValidator(Network.Main, new Checkpoints(Network.Main, consensusSettings), DateTimeProvider.Default, this.loggerFactory);

            //validator.CheckBlockHeader(context);
            validator.ContextualCheckBlock(context);
            validator.CheckBlock(context);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes an instance of the object.
 /// </summary>
 public PowConsensusRuleEngine(Network network, ILoggerFactory loggerFactory, IDateTimeProvider dateTimeProvider, ConcurrentChain chain,
                               NodeDeployments nodeDeployments, ConsensusSettings consensusSettings, ICheckpoints checkpoints, ICoinView utxoSet, IChainState chainState,
                               IInvalidBlockHashStore invalidBlockHashStore)
     : base(network, loggerFactory, dateTimeProvider, chain, nodeDeployments, consensusSettings, checkpoints, chainState, invalidBlockHashStore)
 {
     this.UtxoSet = utxoSet;
 }
Ejemplo n.º 4
0
 public TestPosConsensusRules(Network network, ILoggerFactory loggerFactory, IDateTimeProvider dateTimeProvider, ChainIndexer chainIndexer,
                              NodeDeployments nodeDeployments, ConsensusSettings consensusSettings, ICheckpoints checkpoints, ICoinView uxtoSet, IStakeChain stakeChain,
                              IStakeValidator stakeValidator, IChainState chainState, IInvalidBlockHashStore invalidBlockHashStore, INodeStats nodeStats, IRewindDataIndexCache rewindDataIndexCache, IAsyncProvider asyncProvider, IRewardValidator rewardValidator)
     : base(network, loggerFactory, dateTimeProvider, chainIndexer, nodeDeployments, consensusSettings, checkpoints, uxtoSet, stakeChain, stakeValidator, chainState, invalidBlockHashStore, nodeStats, rewindDataIndexCache, asyncProvider, rewardValidator)
 {
     this.ruleRegistrationHelper = new RuleRegistrationHelper();
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates test chain with a consensus loop.
        /// </summary>
        public static TestRulesContext CreateAsync(Network network, [CallerMemberName] string pathName = null)
        {
            var testRulesContext = new TestRulesContext()
            {
                Network = network
            };

            string dataDir = Path.Combine("TestData", pathName);

            Directory.CreateDirectory(dataDir);

            testRulesContext.NodeSettings  = new NodeSettings(network, args: new[] { $"-datadir={dataDir}" });
            testRulesContext.LoggerFactory = testRulesContext.NodeSettings.LoggerFactory;
            testRulesContext.LoggerFactory.AddConsoleWithFilters();
            testRulesContext.DateTimeProvider = DateTimeProvider.Default;
            network.Consensus.Options         = new ConsensusOptions();
            new FullNodeBuilderConsensusExtension.PowConsensusRulesRegistration().RegisterRules(network.Consensus);

            var consensusSettings = new ConsensusSettings(testRulesContext.NodeSettings);

            testRulesContext.Checkpoints   = new Checkpoints();
            testRulesContext.ChainIndexer  = new ChainIndexer(network);
            testRulesContext.ChainState    = new ChainState();
            testRulesContext.Signals       = new Signals.Signals(testRulesContext.LoggerFactory, null);
            testRulesContext.AsyncProvider = new AsyncProvider(testRulesContext.LoggerFactory, testRulesContext.Signals, new NodeLifetime());

            var deployments = new NodeDeployments(testRulesContext.Network, testRulesContext.ChainIndexer);

            testRulesContext.ConsensusRuleEngine = new PowConsensusRuleEngine(testRulesContext.Network, testRulesContext.LoggerFactory, testRulesContext.DateTimeProvider,
                                                                              testRulesContext.ChainIndexer, deployments, consensusSettings, testRulesContext.Checkpoints, new InMemoryCoinView(new uint256()), testRulesContext.ChainState,
                                                                              new InvalidBlockHashStore(DateTimeProvider.Default), new NodeStats(DateTimeProvider.Default), testRulesContext.AsyncProvider).Register();

            return(testRulesContext);
        }
 public SmartContractPoARuleEngine(
     ConcurrentChain chain,
     ICheckpoints checkpoints,
     ConsensusSettings consensusSettings,
     IDateTimeProvider dateTimeProvider,
     IContractExecutorFactory executorFactory,
     ILoggerFactory loggerFactory,
     Network network,
     NodeDeployments nodeDeployments,
     IStateRepositoryRoot originalStateRoot,
     IReceiptRepository receiptRepository,
     ISenderRetriever senderRetriever,
     ICoinView utxoSet,
     IChainState chainState,
     IInvalidBlockHashStore invalidBlockHashStore,
     INodeStats nodeStats,
     SlotsManager slotsManager,
     PoABlockHeaderValidator poaHeaderValidator)
     : base(network, loggerFactory, dateTimeProvider, chain, nodeDeployments, consensusSettings, checkpoints, utxoSet, chainState, invalidBlockHashStore, nodeStats, slotsManager, poaHeaderValidator)
 {
     this.ExecutorFactory   = executorFactory;
     this.OriginalStateRoot = originalStateRoot;
     this.ReceiptRepository = receiptRepository;
     this.SenderRetriever   = senderRetriever;
 }
        public CachedCoinView(Network network, ICheckpoints checkpoints, ICoindb coindb, IDateTimeProvider dateTimeProvider, ILoggerFactory loggerFactory, INodeStats nodeStats, ConsensusSettings consensusSettings, StakeChainStore stakeChainStore = null, IRewindDataIndexCache rewindDataIndexCache = null)
        {
            Guard.NotNull(coindb, nameof(CachedCoinView.coindb));

            this.coindb               = coindb;
            this.logger               = loggerFactory.CreateLogger(this.GetType().FullName);
            this.network              = network;
            this.checkpoints          = checkpoints;
            this.dateTimeProvider     = dateTimeProvider;
            this.consensusSettings    = consensusSettings;
            this.stakeChainStore      = stakeChainStore;
            this.rewindDataIndexCache = rewindDataIndexCache;
            this.lockobj              = new object();
            this.cachedUtxoItems      = new Dictionary <OutPoint, CacheItem>();
            this.performanceCounter   = new CachePerformanceCounter(this.dateTimeProvider);
            this.lastCacheFlushTime   = this.dateTimeProvider.GetUtcNow();
            this.cachedRewindData     = new Dictionary <int, RewindData>();
            this.random               = new Random();

            this.lastCheckpointHeight = this.checkpoints.GetLastCheckpointHeight();

            this.MaxCacheSizeBytes             = consensusSettings.MaxCoindbCacheInMB * 1024 * 1024;
            this.CacheFlushTimeIntervalSeconds = consensusSettings.CoindbIbdFlushMin * 60;

            if (nodeStats.DisplayBenchStats)
            {
                nodeStats.RegisterStats(this.AddBenchStats, StatsType.Benchmark, this.GetType().Name, 300);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Creates test chain with a consensus loop.
        /// </summary>
        public static TestRulesContext CreateAsync(Network network, [CallerMemberName] string pathName = null)
        {
            var testRulesContext = new TestRulesContext()
            {
                Network = network
            };

            string dataDir = Path.Combine("TestData", pathName);

            Directory.CreateDirectory(dataDir);

            testRulesContext.NodeSettings  = new NodeSettings(network, args: new[] { $"-datadir={dataDir}" });
            testRulesContext.LoggerFactory = testRulesContext.NodeSettings.LoggerFactory;
            testRulesContext.LoggerFactory.AddConsoleWithFilters();
            testRulesContext.DateTimeProvider = DateTimeProvider.Default;
            network.Consensus.Options         = new PowConsensusOptions();

            var consensusSettings = new ConsensusSettings(testRulesContext.NodeSettings);

            testRulesContext.Checkpoints = new Checkpoints();
            testRulesContext.Chain       = new ConcurrentChain(network);

            var deployments = new NodeDeployments(testRulesContext.Network, testRulesContext.Chain);

            testRulesContext.Consensus = new PowConsensusRules(testRulesContext.Network, testRulesContext.LoggerFactory, testRulesContext.DateTimeProvider, testRulesContext.Chain, deployments, consensusSettings, testRulesContext.Checkpoints, new InMemoryCoinView(new uint256()), new Mock <ILookaheadBlockPuller>().Object).Register(new FullNodeBuilderConsensusExtension.PowConsensusRulesRegistration());

            return(testRulesContext);
        }
Ejemplo n.º 9
0
        protected ConsensusRuleUnitTestBase(Network network)
        {
            this.network = network;

            this.logger        = new Mock <ILogger>();
            this.loggerFactory = new Mock <ILoggerFactory>();
            this.loggerFactory.Setup(l => l.CreateLogger(It.IsAny <string>())).Returns(new Mock <ILogger>().Object);
            this.dateTimeProvider = new Mock <IDateTimeProvider>();

            this.chainState        = new Mock <IChainState>();
            this.checkpoints       = new Mock <ICheckpoints>();
            this.concurrentChain   = new ConcurrentChain(this.network);
            this.consensusSettings = new ConsensusSettings();
            this.nodeDeployments   = new NodeDeployments(this.network, this.concurrentChain);

            this.rules            = new List <IConsensusRuleBase>();
            this.ruleRegistration = new Mock <IRuleRegistration>();

            if (network.Consensus.IsProofOfStake)
            {
                this.ruleContext = new PosRuleContext(new ValidationContext(), this.dateTimeProvider.Object.GetTimeOffset());
            }
            else
            {
                this.ruleContext = new PowRuleContext(new ValidationContext(), this.dateTimeProvider.Object.GetTimeOffset());
            }
        }
 public PoAConsensusRuleEngine(Network network, ILoggerFactory loggerFactory, IDateTimeProvider dateTimeProvider, ConcurrentChain chain,
                               NodeDeployments nodeDeployments, ConsensusSettings consensusSettings, ICheckpoints checkpoints, ICoinView utxoSet, IChainState chainState,
                               IInvalidBlockHashStore invalidBlockHashStore, INodeStats nodeStats, SlotsManager slotsManager, PoABlockHeaderValidator poaHeaderValidator)
     : base(network, loggerFactory, dateTimeProvider, chain, nodeDeployments, consensusSettings, checkpoints, utxoSet, chainState, invalidBlockHashStore, nodeStats)
 {
     this.SlotsManager       = slotsManager;
     this.poaHeaderValidator = poaHeaderValidator;
 }
Ejemplo n.º 11
0
 public void LoadConfigWithAssumeValidHexLoads()
 {
     uint256 validHexBlock = new uint256("00000000229d9fb87182d73870d53f9fdd9b76bfc02c059e6d9a6c7a3507031d");
     Network network = Network.TestNet;
     NodeSettings nodeSettings = new NodeSettings(network, args:new string[] { $"-assumevalid={validHexBlock.ToString()}" });
     ConsensusSettings settings = new ConsensusSettings().Load(nodeSettings);
     Assert.Equal(validHexBlock, settings.BlockAssumedValid);
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Creates a new instance of the <see cref="InitialBlockDownloadState" /> class.
 /// </summary>
 /// <param name="chainState">Information about node's chain.</param>
 /// <param name="network">Specification of the network the node runs on - regtest/testnet/mainnet.</param>
 /// <param name="consensusSettings">Configurable settings for the consensus feature.</param>
 /// <param name="checkpoints">Provider of block header hash checkpoints.</param>
 public InitialBlockDownloadState(IChainState chainState, Network network, ConsensusSettings consensusSettings, ICheckpoints checkpoints)
 {
     this.network           = network;
     this.consensusSettings = consensusSettings;
     this.chainState        = chainState;
     this.checkpoints       = checkpoints;
     this.dateTimeProvider  = DateTimeProvider.Default;
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Initializes a new instance of the object.
        /// </summary>
        /// <param name="network">Specification of the network the node runs on - regtest/testnet/mainnet/stratis test/main.</param>
        /// <param name="consensusSettings">Consensus settings for node - used to see if checkpoints have been disabled or not.</param>
        public Checkpoints(Network network, ConsensusSettings consensusSettings)
        {
            Guard.NotNull(network, nameof(network));
            Guard.NotNull(consensusSettings, nameof(consensusSettings));

            this.consensusSettings = consensusSettings;
            this.network           = network;
        }
Ejemplo n.º 14
0
 public void LoadConfigWithAssumeValidZeroSetsToNull()
 {
     LoggerFactory loggerFactory = new LoggerFactory();
     Network network = Network.TestNet;
     NodeSettings nodeSettings = new NodeSettings(network, args:new string[] { "-assumevalid=0" });
     ConsensusSettings settings = new ConsensusSettings().Load(nodeSettings);
     Assert.Null(settings.BlockAssumedValid);
 }
 public InitialBlockDownloadTest()
 {
     this.network           = Network.Main;
     this.consensusSettings = new ConsensusSettings().Load(NodeSettings.Default());
     this.checkpoints       = new Checkpoints(this.network, this.consensusSettings);
     this.nodeSettings      = new NodeSettings(this.network);
     this.chainState        = new ChainState(new InvalidBlockHashStore(DateTimeProvider.Default));
 }
Ejemplo n.º 16
0
 public InitialBlockDownloadTest()
 {
     this.network           = Network.PurpleMain;
     this.consensusSettings = new ConsensusSettings(NodeSettings.Default(), new ExtendedLoggerFactory());
     this.checkpoints       = new Checkpoints(this.network, this.consensusSettings);
     this.nodeSettings      = new NodeSettings("Purple", this.network);
     this.chainState        = new ChainState(new InvalidBlockHashStore(DateTimeProvider.Default));
 }
 /// <summary>
 /// Initializes an instance of the object.
 /// </summary>
 public PosConsensusRuleEngine(Network network, ILoggerFactory loggerFactory, IDateTimeProvider dateTimeProvider, ConcurrentChain chain, NodeDeployments nodeDeployments,
                               ConsensusSettings consensusSettings, ICheckpoints checkpoints, ICoinView utxoSet, IStakeChain stakeChain, IStakeValidator stakeValidator, IChainState chainState,
                               IInvalidBlockHashStore invalidBlockHashStore, INodeStats nodeStats)
     : base(network, loggerFactory, dateTimeProvider, chain, nodeDeployments, consensusSettings, checkpoints, utxoSet, chainState, invalidBlockHashStore, nodeStats)
 {
     this.StakeChain     = stakeChain;
     this.StakeValidator = stakeValidator;
 }
 /// <summary>
 /// Initializes an instance of the object.
 /// </summary>
 public PowConsensusRuleEngine(Network network, ILoggerFactory loggerFactory, IDateTimeProvider dateTimeProvider, ChainIndexer chainIndexer,
                               NodeDeployments nodeDeployments, ConsensusSettings consensusSettings, ICheckpoints checkpoints, ICoinView utxoSet, IChainState chainState,
                               IInvalidBlockHashStore invalidBlockHashStore, INodeStats nodeStats, IAsyncProvider asyncProvider)
     : base(network, loggerFactory, dateTimeProvider, chainIndexer, nodeDeployments, consensusSettings, checkpoints, chainState, invalidBlockHashStore, nodeStats)
 {
     this.UtxoSet    = utxoSet;
     this.prefetcher = new CoinviewPrefetcher(this.UtxoSet, chainIndexer, loggerFactory, asyncProvider);
 }
Ejemplo n.º 19
0
        public void LoadConfigWithAssumeValidZeroSetsToNull()
        {
            LoggerFactory     loggerFactory = new LoggerFactory();
            Network           network       = Network.PurpleTest;
            NodeSettings      nodeSettings  = new NodeSettings(network.Name, network).LoadArguments(new string[] { "-assumevalid=0" });
            ConsensusSettings settings      = new ConsensusSettings(nodeSettings, loggerFactory);

            Assert.Null(settings.BlockAssumedValid);
        }
 /// <summary>
 /// Creates a new instance of the <see cref="InitialBlockDownloadState" /> class.
 /// </summary>
 /// <param name="chainState">Information about node's chain.</param>
 /// <param name="network">Specification of the network the node runs on - regtest/testnet/mainnet.</param>
 /// <param name="consensusSettings">Configurable settings for the consensus feature.</param>
 /// <param name="checkpoints">Provider of block header hash checkpoints.</param>
 /// <param name="loggerFactory">Provides us with a logger.</param>
 public InitialBlockDownloadState(IChainState chainState, Network network, ConsensusSettings consensusSettings, ICheckpoints checkpoints, ILoggerFactory loggerFactory)
 {
     this.network           = network;
     this.consensusSettings = consensusSettings;
     this.chainState        = chainState;
     this.checkpoints       = checkpoints;
     this.dateTimeProvider  = DateTimeProvider.Default;
     this.logger            = loggerFactory.CreateLogger("Impleum.Bitcoin.Fullnode");
 }
Ejemplo n.º 21
0
        public static ConsensusManager CreateConsensusManager(Network network, string dataDir = null, ChainState chainState = null, InMemoryCoinView inMemoryCoinView = null)
        {
            string[] param = dataDir == null ? new string[] {} : new string[] { $"-datadir={dataDir}" };

            var nodeSettings = new NodeSettings(network, args: param);

            ILoggerFactory    loggerFactory    = nodeSettings.LoggerFactory;
            IDateTimeProvider dateTimeProvider = DateTimeProvider.Default;

            network.Consensus.Options = new ConsensusOptions();
            new FullNodeBuilderConsensusExtension.PowConsensusRulesRegistration().RegisterRules(network.Consensus);

            // Dont check PoW of a header in this test.
            network.Consensus.HeaderValidationRules.RemoveAll(x => x.GetType() == typeof(CheckDifficultyPowRule));

            var consensusSettings = new ConsensusSettings(nodeSettings);
            var chain             = new ConcurrentChain(network);

            if (inMemoryCoinView == null)
            {
                inMemoryCoinView = new InMemoryCoinView(chain.Tip.HashBlock);
            }

            var networkPeerFactory = new NetworkPeerFactory(network,
                                                            dateTimeProvider,
                                                            loggerFactory, new PayloadProvider().DiscoverPayloads(),
                                                            new SelfEndpointTracker(loggerFactory),
                                                            new Mock <IInitialBlockDownloadState>().Object,
                                                            new ConnectionManagerSettings());

            var peerAddressManager  = new PeerAddressManager(DateTimeProvider.Default, nodeSettings.DataFolder, loggerFactory, new SelfEndpointTracker(loggerFactory));
            var peerDiscovery       = new PeerDiscovery(new AsyncLoopFactory(loggerFactory), loggerFactory, network, networkPeerFactory, new NodeLifetime(), nodeSettings, peerAddressManager);
            var connectionSettings  = new ConnectionManagerSettings(nodeSettings);
            var selfEndpointTracker = new SelfEndpointTracker(loggerFactory);
            var connectionManager   = new ConnectionManager(dateTimeProvider, loggerFactory, network, networkPeerFactory, nodeSettings,
                                                            new NodeLifetime(), new NetworkPeerConnectionParameters(), peerAddressManager, new IPeerConnector[] { },
                                                            peerDiscovery, selfEndpointTracker, connectionSettings, new VersionProvider(), new Mock <INodeStats>().Object);

            if (chainState == null)
            {
                chainState = new ChainState();
            }
            var peerBanning = new PeerBanning(connectionManager, loggerFactory, dateTimeProvider, peerAddressManager);
            var deployments = new NodeDeployments(network, chain);
            ConsensusRuleEngine consensusRules = new PowConsensusRuleEngine(network, loggerFactory, dateTimeProvider, chain, deployments, consensusSettings, new Checkpoints(),
                                                                            inMemoryCoinView, chainState, new InvalidBlockHashStore(new DateTimeProvider())).Register();

            var tree = new ChainedHeaderTree(network, loggerFactory, new HeaderValidator(consensusRules, loggerFactory), new Checkpoints(),
                                             new ChainState(), new Mock <IFinalizedBlockInfo>().Object, consensusSettings, new InvalidBlockHashStore(new DateTimeProvider()));

            var consensus = new ConsensusManager(tree, network, loggerFactory, chainState, new IntegrityValidator(consensusRules, loggerFactory),
                                                 new PartialValidator(consensusRules, loggerFactory), new FullValidator(consensusRules, loggerFactory), consensusRules,
                                                 new Mock <IFinalizedBlockInfo>().Object, new Signals.Signals(), peerBanning, new Mock <IInitialBlockDownloadState>().Object, chain,
                                                 new Mock <IBlockPuller>().Object, new Mock <IBlockStore>().Object, new Mock <IConnectionManager>().Object, new Mock <INodeStats>().Object, new NodeLifetime());

            return(consensus);
        }
 /// <summary>
 /// Initializes an instance of the object.
 /// </summary>
 public PosConsensusRuleEngine(Network network, ILoggerFactory loggerFactory, IDateTimeProvider dateTimeProvider, ChainIndexer chainIndexer, NodeDeployments nodeDeployments,
                               ConsensusSettings consensusSettings, ICheckpoints checkpoints, ICoinView utxoSet, IStakeChain stakeChain, IStakeValidator stakeValidator, IChainState chainState,
                               IInvalidBlockHashStore invalidBlockHashStore, INodeStats nodeStats, IRewindDataIndexCache rewindDataIndexCache, IAsyncProvider asyncProvider)
     : base(network, loggerFactory, dateTimeProvider, chainIndexer, nodeDeployments, consensusSettings, checkpoints, utxoSet, chainState, invalidBlockHashStore, nodeStats, asyncProvider)
 {
     this.StakeChain           = stakeChain;
     this.StakeValidator       = stakeValidator;
     this.RewindDataIndexCache = rewindDataIndexCache;
 }
 /// <summary>
 /// Creates a new instance of the <see cref="InitialBlockDownloadState" /> class.
 /// </summary>
 /// <param name="chainState">Information about node's chain.</param>
 /// <param name="network">Specification of the network the node runs on - regtest/testnet/mainnet.</param>
 /// <param name="consensusSettings">Configurable settings for the consensus feature.</param>
 /// <param name="checkpoints">Provider of block header hash checkpoints.</param>
 /// <param name="loggerFactory">Provides us with a logger.</param>
 public InitialBlockDownloadState(IChainState chainState, Network network, ConsensusSettings consensusSettings, ICheckpoints checkpoints, ILoggerFactory loggerFactory, IDateTimeProvider dateTimeProvider)
 {
     this.network           = network;
     this.consensusSettings = consensusSettings;
     this.chainState        = chainState;
     this.checkpoints       = checkpoints;
     this.dateTimeProvider  = dateTimeProvider;
     this.logger            = loggerFactory.CreateLogger(this.GetType().FullName);
 }
Ejemplo n.º 24
0
 public InitialBlockDownloadTest()
 {
     this.network           = KnownNetworks.Main;
     this.consensusSettings = new ConsensusSettings(new NodeSettings(this.network));
     this.checkpoints       = new Checkpoints(this.network, this.consensusSettings);
     this.chainState        = new ChainState();
     this.loggerFactory     = new Mock <ILoggerFactory>();
     this.loggerFactory.Setup(x => x.CreateLogger(It.IsAny <string>())).Returns(new Mock <ILogger>().Object);
 }
Ejemplo n.º 25
0
        public void LoadConfigWithAssumeValidHexLoads()
        {
            uint256           validHexBlock = new uint256("00000000229d9fb87182d73870d53f9fdd9b76bfc02c059e6d9a6c7a3507031d");
            LoggerFactory     loggerFactory = new LoggerFactory();
            Network           network       = Network.PurpleTest;
            NodeSettings      nodeSettings  = new NodeSettings(network.Name, network).LoadArguments(new string[] { $"-assumevalid={validHexBlock.ToString()}" });
            ConsensusSettings settings      = new ConsensusSettings(nodeSettings, loggerFactory);

            Assert.Equal(validHexBlock, settings.BlockAssumedValid);
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Initializes a new instance of the object.
        /// </summary>
        /// <param name="network">Specification of the network the node runs on - regtest/testnet/mainnet/stratis test/main.</param>
        /// <param name="consensusSettings">Consensus settings for node - used to see if checkpoints have been disabled or not.</param>
        public Checkpoints(Network network, ConsensusSettings consensusSettings)
        {
            Guard.NotNull(network, nameof(network));
            Guard.NotNull(consensusSettings, nameof(consensusSettings));

            this.consensusSettings = consensusSettings;
            this.network           = network;

            this.LastCheckpointHeight = this.GetLastCheckpointHeight();
        }
Ejemplo n.º 27
0
        private uint256 ComputeMerkleRoot(List <uint256> leaves, out bool mutated)
        {
            LoggerFactory     loggerFactory     = new LoggerFactory();
            ConsensusSettings consensusSettings = new ConsensusSettings(NodeSettings.Default(), loggerFactory);

            Network.PurpleMain.Consensus.Options = new PosConsensusOptions();
            var consensusValidator = new PowConsensusValidator(Network.PurpleMain, new Checkpoints(Network.PurpleMain, consensusSettings), DateTimeProvider.Default, loggerFactory);

            return(consensusValidator.ComputeMerkleRoot(leaves, out mutated));
        }
Ejemplo n.º 28
0
 public PoAConsensusRuleEngine(Network network, ILoggerFactory loggerFactory, IDateTimeProvider dateTimeProvider, ChainIndexer chainIndexer,
                               NodeDeployments nodeDeployments, ConsensusSettings consensusSettings, ICheckpoints checkpoints, ICoinView utxoSet, IChainState chainState,
                               IInvalidBlockHashStore invalidBlockHashStore, INodeStats nodeStats, SlotsManager slotsManager, PoABlockHeaderValidator poaHeaderValidator,
                               VotingManager votingManager, FederationManager federationManager)
     : base(network, loggerFactory, dateTimeProvider, chainIndexer, nodeDeployments, consensusSettings, checkpoints, utxoSet, chainState, invalidBlockHashStore, nodeStats)
 {
     this.SlotsManager       = slotsManager;
     this.PoaHeaderValidator = poaHeaderValidator;
     this.VotingManager      = votingManager;
     this.FederationManager  = federationManager;
 }
Ejemplo n.º 29
0
 public TestChainedHeaderTree(
     Network network,
     ILoggerFactory loggerFactory,
     IHeaderValidator headerValidator,
     ICheckpoints checkpoints,
     IChainState chainState,
     IFinalizedBlockInfoRepository finalizedBlockInfo,
     ConsensusSettings consensusSettings,
     IInvalidBlockHashStore invalidHashesStore) : base(network, loggerFactory, headerValidator, checkpoints,
                                                       chainState, finalizedBlockInfo, consensusSettings, invalidHashesStore)
 {
 }
Ejemplo n.º 30
0
        /// <summary>
        /// Creates test chain with a consensus loop.
        /// </summary>
        public static async Task <TestChainContext> CreateAsync(Network network, string dataDir)
        {
            var testChainContext = new TestChainContext()
            {
                Network = network
            };

            testChainContext.NodeSettings = new NodeSettings(network, args: new string[] { $"-datadir={dataDir}" });

            if (dataDir != null)
            {
                testChainContext.NodeSettings.DataDir = dataDir;
            }

            testChainContext.ConnectionSettings = new ConnectionManagerSettings();
            testChainContext.ConnectionSettings.Load(testChainContext.NodeSettings);

            testChainContext.LoggerFactory    = testChainContext.NodeSettings.LoggerFactory;
            testChainContext.DateTimeProvider = DateTimeProvider.Default;
            network.Consensus.Options         = new PowConsensusOptions();

            ConsensusSettings consensusSettings = new ConsensusSettings().Load(testChainContext.NodeSettings);

            testChainContext.Checkpoints = new Checkpoints();

            PowConsensusValidator consensusValidator = new PowConsensusValidator(network, testChainContext.Checkpoints, testChainContext.DateTimeProvider, testChainContext.LoggerFactory);

            testChainContext.Chain = new ConcurrentChain(network);
            CachedCoinView cachedCoinView = new CachedCoinView(new InMemoryCoinView(testChainContext.Chain.Tip.HashBlock), DateTimeProvider.Default, testChainContext.LoggerFactory);

            DataFolder dataFolder = new DataFolder(TestBase.AssureEmptyDir(dataDir));

            testChainContext.PeerAddressManager = new PeerAddressManager(DateTimeProvider.Default, dataFolder, testChainContext.LoggerFactory, new SelfEndpointTracker());

            testChainContext.MockConnectionManager       = new Moq.Mock <IConnectionManager>();
            testChainContext.MockReadOnlyNodesCollection = new Moq.Mock <IReadOnlyNetworkPeerCollection>();
            testChainContext.MockConnectionManager.Setup(s => s.ConnectedPeers).Returns(testChainContext.MockReadOnlyNodesCollection.Object);
            testChainContext.MockConnectionManager.Setup(s => s.NodeSettings).Returns(testChainContext.NodeSettings);
            testChainContext.MockConnectionManager.Setup(s => s.ConnectionSettings).Returns(testChainContext.ConnectionSettings);

            testChainContext.ConnectionManager = testChainContext.MockConnectionManager.Object;

            LookaheadBlockPuller blockPuller = new LookaheadBlockPuller(testChainContext.Chain, testChainContext.ConnectionManager, testChainContext.LoggerFactory);

            testChainContext.PeerBanning = new PeerBanning(testChainContext.ConnectionManager, testChainContext.LoggerFactory, testChainContext.DateTimeProvider, testChainContext.PeerAddressManager);
            NodeDeployments deployments    = new NodeDeployments(testChainContext.Network, testChainContext.Chain);
            ConsensusRules  consensusRules = new PowConsensusRules(testChainContext.Network, testChainContext.LoggerFactory, testChainContext.DateTimeProvider, testChainContext.Chain, deployments, consensusSettings, testChainContext.Checkpoints).Register(new FullNodeBuilderConsensusExtension.PowConsensusRulesRegistration());

            testChainContext.Consensus = new ConsensusLoop(new AsyncLoopFactory(testChainContext.LoggerFactory), consensusValidator, new NodeLifetime(), testChainContext.Chain, cachedCoinView, blockPuller, new NodeDeployments(network, testChainContext.Chain), testChainContext.LoggerFactory, new ChainState(new InvalidBlockHashStore(testChainContext.DateTimeProvider)), testChainContext.ConnectionManager, testChainContext.DateTimeProvider, new Signals.Signals(), consensusSettings, testChainContext.NodeSettings, testChainContext.PeerBanning, consensusRules);
            await testChainContext.Consensus.StartAsync();

            return(testChainContext);
        }