public ConsensusFeature(
     DBreezeCoinView dBreezeCoinView,
     Network network,
     PowConsensusValidator consensusValidator,
     ConcurrentChain chain,
     LookaheadBlockPuller blockPuller,
     CoinView coinView,
     ChainBehavior.ChainState chainState,
     ConnectionManager connectionManager,
     CancellationProvider globalCancellation,
     Signals signals,
     ConsensusLoop consensusLoop,
     NodeSettings nodeSettings,
     StakeChainStore stakeChain = null)
 {
     this.dBreezeCoinView    = dBreezeCoinView;
     this.consensusValidator = consensusValidator;
     this.chain              = chain;
     this.blockPuller        = blockPuller;
     this.coinView           = coinView;
     this.chainState         = chainState;
     this.connectionManager  = connectionManager;
     this.globalCancellation = globalCancellation;
     this.signals            = signals;
     this.network            = network;
     this.consensusLoop      = consensusLoop;
     this.nodeSettings       = nodeSettings;
     this.stakeChain         = stakeChain;
 }
Exemplo n.º 2
0
 public ConsensusFeature(
     DBreezeCoinView dBreezeCoinView,
     Network network,
     PowConsensusValidator consensusValidator,
     ConcurrentChain chain,
     LookaheadBlockPuller blockPuller,
     CoinView coinView,
     ChainBehavior.ChainState chainState,
     IConnectionManager connectionManager,
     INodeLifetime nodeLifetime,
     Signals signals,
     ConsensusLoop consensusLoop,
     NodeSettings nodeSettings,
     NodeDeployments nodeDeployments,
     StakeChainStore stakeChain = null)
 {
     this.dBreezeCoinView    = dBreezeCoinView;
     this.consensusValidator = consensusValidator;
     this.chain             = chain;
     this.blockPuller       = blockPuller;
     this.coinView          = coinView;
     this.chainState        = chainState;
     this.connectionManager = connectionManager;
     this.nodeLifetime      = nodeLifetime;
     this.signals           = signals;
     this.network           = network;
     this.consensusLoop     = consensusLoop;
     this.nodeSettings      = nodeSettings;
     this.nodeDeployments   = nodeDeployments;
     this.stakeChain        = stakeChain;
 }
        public CachedCoinView(DBreezeCoinView inner)
        {
            Guard.NotNull(inner, nameof(inner));

            _Inner   = inner;
            MaxItems = 100000;
        }
 public StakeValidator(Network network,
                       StakeChain stakeChain, ConcurrentChain chain, CoinView coinView)
 {
     this.network          = network;
     this.stakeChain       = stakeChain;
     this.chain            = chain;
     this.coinView         = coinView;
     this.consensusOptions = network.Consensus.Option <PosConsensusOptions>();
 }
        public CoinViewStack(CoinView top)
        {
            Top = top;
            var current = top;

            while (current is IBackedCoinView)
            {
                current = ((IBackedCoinView)current).Inner;
            }
            Bottom = current;
        }
        /// <summary>
        /// This is used for testing the coin view
        /// it allows a coinview that only has in memory entries
        /// </summary>
        public CachedCoinView(InMemoryCoinView inner, StakeChainStore stakeChainStore = null)
        {
            Guard.NotNull(inner, nameof(inner));

            this.inner              = inner;
            this.stakeChainStore    = stakeChainStore;
            this.MaxItems           = 100000;
            this.lockobj            = new ReaderWriterLock();
            this.unspents           = new Dictionary <uint256, CacheItem>();
            this.PerformanceCounter = new CachePerformanceCounter();
        }
Exemplo n.º 7
0
        public ConsensusLoop(ConsensusValidator validator, ConcurrentChain chain, CoinView utxoSet, LookaheadBlockPuller puller)
        {
            Guard.NotNull(validator, nameof(validator));
            Guard.NotNull(chain, nameof(chain));
            Guard.NotNull(utxoSet, nameof(utxoSet));
            Guard.NotNull(puller, nameof(puller));

            _Validator = validator;
            _Chain     = chain;
            _utxoSet   = utxoSet;
            _Puller    = puller;
        }
        public PosConsensusValidator(StakeValidator stakeValidator, Network network,
                                     StakeChain stakeChain, ConcurrentChain chain, CoinView coinView)
            : base(network)
        {
            Guard.NotNull(network.Consensus.Option <PosConsensusOptions>(), nameof(network.Consensus.Options));

            this.stakeValidator   = stakeValidator;
            this.stakeChain       = stakeChain;
            this.chain            = chain;
            this.coinView         = coinView;
            this.consensusOptions = network.Consensus.Option <PosConsensusOptions>();
        }
Exemplo n.º 9
0
        public ConsensusLoop(PowConsensusValidator validator, ConcurrentChain chain, CoinView utxoSet, LookaheadBlockPuller puller, StakeChain stakeChain = null)
        {
            Guard.NotNull(validator, nameof(validator));
            Guard.NotNull(chain, nameof(chain));
            Guard.NotNull(utxoSet, nameof(utxoSet));
            Guard.NotNull(puller, nameof(puller));

            this.Validator = validator;
            this.Chain     = chain;
            this.UTXOSet   = utxoSet;
            this.Puller    = puller;

            // chain of stake info can be null if POS is not enabled
            this.StakeChain = stakeChain;
        }
        public ConsensusStats(CoinViewStack stack, CoinView coinView, ConsensusLoop consensusLoop, ChainBehavior.ChainState chainState, ConcurrentChain chain, IConnectionManager connectionManager)
        {
            stack        = new CoinViewStack(coinView);
            this.cache   = stack.Find <CachedCoinView>();
            this.dbreeze = stack.Find <DBreezeCoinView>();
            this.bottom  = stack.Bottom;

            this.consensusLoop   = consensusLoop;
            this.lookaheadPuller = this.consensusLoop.Puller as LookaheadBlockPuller;

            this.lastSnapshot      = consensusLoop.Validator.PerformanceCounter.Snapshot();
            this.lastSnapshot2     = this.dbreeze?.PerformanceCounter.Snapshot();
            this.lastSnapshot3     = this.cache?.PerformanceCounter.Snapshot();
            this.chainState        = chainState;
            this.chain             = chain;
            this.connectionManager = connectionManager;
        }
Exemplo n.º 11
0
 public IEnumerable <UnspentOutputs> GetCoins(CoinView utxo)
 {
     return(this._Unspents.Select(u => u.Value).ToList());
 }
Exemplo n.º 12
0
        // ppcoin: total coin age spent in transaction, in the unit of coin-days.
        // Only those coins meeting minimum age requirement counts. As those
        // transactions not in main chain are not currently indexed so we
        // might not find out about their coin age. Older transactions are
        // guaranteed to be in main chain by sync-checkpoint. This rule is
        // introduced to help nodes establish a consistent view of the coin
        // age (trust score) of competing branches.
        public bool GetCoinAge(ConcurrentChain chain, CoinView coinView,
                               Transaction trx, ChainedBlock pindexPrev, out ulong nCoinAge)
        {
            BigInteger bnCentSecond = BigInteger.Zero;              // coin age in the unit of cent-seconds

            nCoinAge = 0;

            if (trx.IsCoinBase)
            {
                return(true);
            }

            foreach (var txin in trx.Inputs)
            {
                var coins = coinView.FetchCoinsAsync(new[] { txin.PrevOut.Hash }).GetAwaiter().GetResult();
                if (coins == null || coins.UnspentOutputs.Length != 1)
                {
                    continue;
                }

                var prevBlock = chain.GetBlock(coins.BlockHash);
                var prevUtxo  = coins.UnspentOutputs[0];

                // First try finding the previous transaction in database
                //Transaction txPrev = trasnactionStore.Get(txin.PrevOut.Hash);
                //if (txPrev == null)
                //	continue;  // previous transaction not in main chain
                if (trx.Time < prevUtxo.Time)
                {
                    return(false);                     // Transaction timestamp violation
                }
                if (IsProtocolV3((int)trx.Time))
                {
                    if (IsConfirmedInNPrevBlocks(prevUtxo, pindexPrev, this.consensusOptions.StakeMinConfirmations - 1))
                    {
                        //LogPrint("coinage", "coin age skip nSpendDepth=%d\n", nSpendDepth + 1);
                        continue;                         // only count coins meeting min confirmations requirement
                    }
                }
                else
                {
                    // Read block header
                    //var block = blockStore.GetBlock(txPrev.GetHash());
                    //if (block == null)
                    //	return false; // unable to read block of previous transaction
                    if (prevBlock.Header.Time + this.consensusOptions.StakeMinAge > trx.Time)
                    {
                        continue;                         // only count coins meeting min age requirement
                    }
                }

                long nValueIn   = prevUtxo._Outputs[txin.PrevOut.N].Value;
                var  multiplier = BigInteger.ValueOf((trx.Time - prevUtxo.Time) / Money.CENT);
                bnCentSecond = bnCentSecond.Add(BigInteger.ValueOf(nValueIn).Multiply(multiplier));
                //bnCentSecond += new BigInteger(nValueIn) * (trx.Time - txPrev.Time) / CENT;


                //LogPrint("coinage", "coin age nValueIn=%d nTimeDiff=%d bnCentSecond=%s\n", nValueIn, nTime - txPrev.nTime, bnCentSecond.ToString());
            }

            BigInteger bnCoinDay = bnCentSecond.Multiply(BigInteger.ValueOf(Money.CENT / Money.COIN / (24 * 60 * 60)));

            //BigInteger bnCoinDay = bnCentSecond * CENT / COIN / (24 * 60 * 60);

            //LogPrint("coinage", "coin age bnCoinDay=%s\n", bnCoinDay.ToString());
            nCoinAge = new Target(bnCoinDay).ToCompact();

            return(true);
        }