コード例 #1
0
        private bool WasUtxoSelectedForStaking(Network network, int chainTipHeight, int utxoHeight)
        {
            this.network = network;
            this.network.Consensus.Options = new PosConsensusOptions();
            this.chain = GenerateChainWithBlockTimeAndHeight(2, this.network, 60, 0x1df88f6f);

            PosMinting miner = this.InitializePosMinting();

            ChainedHeader chainTip = this.chain.Tip;

            chainTip.SetPrivatePropertyValue("Height", chainTipHeight);
            chainTip.Previous.SetPrivatePropertyValue("Height", utxoHeight);

            var descriptions = new List <UtxoStakeDescription>();

            var utxoDescription = new UtxoStakeDescription();

            utxoDescription.TxOut     = new TxOut(new Money(100), new Mock <IDestination>().Object);
            utxoDescription.OutPoint  = new OutPoint(uint256.One, 0);
            utxoDescription.HashBlock = chainTip.Previous.HashBlock;

            utxoDescription.UtxoSet = new UnspentOutputs();
            utxoDescription.UtxoSet.SetPrivatePropertyValue("Time", chainTip.Header.Time);

            descriptions.Add(utxoDescription);

            List <UtxoStakeDescription> suitableCoins = miner.GetUtxoStakeDescriptionsSuitableForStakingAsync(descriptions, chainTip, chainTip.Header.Time + 64, long.MaxValue).GetAwaiter().GetResult();

            return(suitableCoins.Count == 1);
        }
コード例 #2
0
        public PosMintingTest()
        {
            this.consensusManager          = new Mock <IConsensusManager>();
            this.network                   = KnownNetworks.StratisTest;
            this.network.Consensus.Options = new ConsensusOptions();
            this.chain                     = new ConcurrentChain(this.network);
            this.dateTimeProvider          = new Mock <IDateTimeProvider>();
            this.initialBlockDownloadState = new Mock <IInitialBlockDownloadState>();
            this.nodeLifetime              = new Mock <INodeLifetime>();
            this.coinView                  = new Mock <ICoinView>();
            this.stakeChain                = new Mock <IStakeChain>();
            this.powBlocks                 = new List <uint256>();
            this.SetupStakeChain();
            this.stakeValidator        = new Mock <IStakeValidator>();
            this.mempoolSchedulerLock  = new MempoolSchedulerLock();
            this.minerSettings         = new MinerSettings(NodeSettings.Default(this.network));
            this.txMempool             = new Mock <ITxMempool>();
            this.walletManager         = new Mock <IWalletManager>();
            this.asyncLoopFactory      = new Mock <IAsyncLoopFactory>();
            this.timeSyncBehaviorState = new Mock <ITimeSyncBehaviorState>();

            this.cancellationTokenSource = new CancellationTokenSource();
            this.nodeLifetime.Setup(n => n.ApplicationStopping).Returns(this.cancellationTokenSource.Token);

            this.posMinting = this.InitializePosMinting();
        }
コード例 #3
0
 /// <summary>
 /// Initializes a new instance of the object.
 /// </summary>
 /// <param name="loggerFactory">Factory to be used to create logger for the node.</param>
 /// <param name="walletManager">The wallet manager.</param>
 /// <param name="posMinting">PoS staker or null if PoS staking is not enabled.</param>
 /// <param name="fullNode">Full Node.</param>
 public MinerController(IFullNode fullNode, ILoggerFactory loggerFactory, IWalletManager walletManager, PosMinting posMinting = null)
 {
     this.fullNode      = fullNode;
     this.logger        = loggerFactory.CreateLogger(this.GetType().FullName);
     this.walletManager = walletManager;
     this.posMinting    = posMinting;
 }
コード例 #4
0
        public PosMintingTest()
        {
            this.initialBlockSignature = Block.BlockSignature;
            this.initialTimestamp      = Transaction.TimeStamp;

            Transaction.TimeStamp = true;
            Block.BlockSignature  = true;

            this.consensusValidator = new Mock <IPosConsensusValidator>();
            this.consensusLoop      = new Mock <IConsensusLoop>();
            this.network            = Network.StratisTest;
            this.chain                     = new ConcurrentChain(this.network);
            this.connectionManager         = new Mock <IConnectionManager>();
            this.dateTimeProvider          = new Mock <IDateTimeProvider>();
            this.initialBlockDownloadState = new Mock <IInitialBlockDownloadState>();
            this.nodeLifetime              = new Mock <INodeLifetime>();
            this.coinView                  = new Mock <CoinView>();;
            this.stakeChain                = new Mock <IStakeChain>();
            this.powBlocks                 = new List <uint256>();
            this.SetupStakeChain();
            this.stakeValidator        = new Mock <IStakeValidator>();
            this.mempoolSchedulerLock  = new MempoolSchedulerLock();
            this.txMempool             = new Mock <ITxMempool>();
            this.walletManager         = new Mock <IWalletManager>();
            this.asyncLoopFactory      = new Mock <IAsyncLoopFactory>();
            this.timeSyncBehaviorState = new Mock <ITimeSyncBehaviorState>();

            this.consensusLoop.Setup(c => c.Validator).Returns(this.consensusValidator.Object);

            this.cancellationTokenSource = new CancellationTokenSource();
            this.nodeLifetime.Setup(n => n.ApplicationStopping).Returns(this.cancellationTokenSource.Token);

            this.posMinting = this.InitializePosMinting();
        }
コード例 #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="builder"></param>
 /// <param name="configuration"></param>
 /// <returns></returns>
 public static ContainerBuilder AddPosMinting(this ContainerBuilder builder, IConfiguration configuration)
 {
     builder.Register(c =>
     {
         var stakingConfigurationOptions = new StakingConfigurationOptions();
         configuration.Bind("Staking", stakingConfigurationOptions);
         var posMintingProvider = new PosMinting(c.Resolve <IGraph>(), c.Resolve <IMemoryPool>(),
                                                 c.Resolve <ISerfClient>(), c.Resolve <IUnitOfWork>(), c.Resolve <ISigning>(), c.Resolve <IValidator>(),
                                                 c.Resolve <ISync>(), stakingConfigurationOptions, c.Resolve <Serilog.ILogger>(), c.Resolve <IHostApplicationLifetime>());
         return(posMintingProvider);
     }).As <IStartable>().SingleInstance();
     return(builder);
 }
コード例 #6
0
        public void GetDifficulty_BlockNull_UsesConsensusLoopTipAndStakeValidator_FindsBlock_ReturnsDifficulty()
        {
            this.chain = WalletTestsHelpers.GenerateChainWithHeight(3, this.network);
            this.consensusManager.Setup(c => c.Tip)
            .Returns(this.chain.Tip);

            ChainedHeader chainedHeader = CreateChainedBlockWithNBits(this.network, 0x12345678);

            this.stakeValidator.Setup(s => s.GetLastPowPosChainedBlock(this.stakeChain.Object, It.Is <ChainedHeader>(c => c.HashBlock == this.chain.Tip.HashBlock), false))
            .Returns(chainedHeader);

            this.posMinting = this.InitializePosMinting();
            double result = this.posMinting.GetDifficulty(null);

            Assert.Equal(5913134931067755359633408.0, Math.Round(result, 6));
        }