/// <summary>
 /// Initializes instance of the object based on DBreeze based coinview.
 /// </summary>
 /// <param name="inner">Underlying coinview with database storage.</param>
 /// <param name="dateTimeProvider">Provider of time functions.</param>
 /// <param name="loggerFactory">Factory to be used to create logger for the puller.</param>
 /// <param name="stakeChainStore">Storage of POS block information.</param>
 public CachedCoinView(DBreezeCoinView inner, IDateTimeProvider dateTimeProvider, ILoggerFactory loggerFactory, INodeStats nodeStats, StakeChainStore stakeChainStore = null) :
     this(dateTimeProvider, loggerFactory, nodeStats, stakeChainStore)
 {
     Guard.NotNull(inner, nameof(inner));
     this.inner = inner;
 }
Exemple #2
0
 public CoinViewTester(ICoinView coinView)
 {
     this.coinView = coinView;
     this.hash     = coinView.GetTipHashAsync().Result;
 }
        public Unity3dController(ILoggerFactory loggerFactory, IAddressIndexer addressIndexer,
                                 IBlockStore blockStore, IChainState chainState, Network network, ICoinView coinView, WalletController walletController, ChainIndexer chainIndexer, INFTTransferIndexer NFTTransferIndexer,
                                 IStakeChain stakeChain = null,
                                 IContractPrimitiveSerializer primitiveSerializer = null, IStateRepositoryRoot stateRoot = null, IContractAssemblyCache contractAssemblyCache                   = null,
                                 IReceiptRepository receiptRepository             = null, ISmartContractTransactionService smartContractTransactionService = null, ILocalExecutor localExecutor = null)
        {
            Guard.NotNull(loggerFactory, nameof(loggerFactory));
            this.logger             = loggerFactory.CreateLogger(this.GetType().FullName);
            this.addressIndexer     = Guard.NotNull(addressIndexer, nameof(addressIndexer));
            this.blockStore         = Guard.NotNull(blockStore, nameof(blockStore));
            this.chainState         = Guard.NotNull(chainState, nameof(chainState));
            this.network            = Guard.NotNull(network, nameof(network));
            this.coinView           = Guard.NotNull(coinView, nameof(coinView));
            this.walletController   = Guard.NotNull(walletController, nameof(walletController));
            this.chainIndexer       = Guard.NotNull(chainIndexer, nameof(chainIndexer));
            this.stakeChain         = stakeChain;
            this.NFTTransferIndexer = NFTTransferIndexer;

            this.primitiveSerializer             = primitiveSerializer;
            this.stateRoot                       = stateRoot;
            this.contractAssemblyCache           = contractAssemblyCache;
            this.receiptRepository               = receiptRepository;
            this.smartContractTransactionService = smartContractTransactionService;
            this.localExecutor                   = localExecutor;
        }
Exemple #4
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, INodeStats nodeStats)
     : base(network, loggerFactory, dateTimeProvider, chain, nodeDeployments, consensusSettings, checkpoints, chainState, invalidBlockHashStore, nodeStats)
 {
     this.UtxoSet    = utxoSet;
     this.prefetcher = new CoinviewPrefetcher(this.UtxoSet, chain, loggerFactory);
 }
Exemple #5
0
 /// <inheritdoc />
 /// <param name="network">Specification of the network the node runs on - regtest/testnet/mainnet.</param>
 /// <param name="stakeChain">Database of stake related data for the current blockchain.</param>
 /// <param name="chainIndexer">Chain of headers.</param>
 /// <param name="coinView">Used for getting UTXOs.</param>
 /// <param name="loggerFactory">Factory for creating loggers.</param>
 public StakeValidator(Network network, IStakeChain stakeChain, ChainIndexer chainIndexer, ICoinView coinView, ILoggerFactory loggerFactory)
 {
     this.logger       = loggerFactory.CreateLogger(this.GetType().FullName);
     this.stakeChain   = stakeChain;
     this.chainIndexer = chainIndexer;
     this.coinView     = coinView;
     this.network      = network;
 }
Exemple #6
0
 public SmartContractCollateralPoARuleRegistration(Network network, IStateRepositoryRoot stateRepositoryRoot, IContractExecutorFactory executorFactory,
                                                   ICallDataSerializer callDataSerializer, ISenderRetriever senderRetriever, IReceiptRepository receiptRepository, ICoinView coinView,
                                                   IEnumerable <IContractTransactionPartialValidationRule> partialTxValidationRules, IEnumerable <IContractTransactionFullValidationRule> fullTxValidationRules,
                                                   IInitialBlockDownloadState ibdState, ISlotsManager slotsManager, ICollateralChecker collateralChecker, IDateTimeProvider dateTime)
     : base(network, stateRepositoryRoot, executorFactory, callDataSerializer, senderRetriever, receiptRepository, coinView, partialTxValidationRules, fullTxValidationRules)
 {
     this.ibdState          = ibdState;
     this.slotsManager      = slotsManager;
     this.collateralChecker = collateralChecker;
     this.dateTime          = dateTime;
 }
Exemple #7
0
 public CoinViewTester(ICoinView coinView)
 {
     this.coinView = coinView;
     this.hash     = coinView.GetTipHash();
 }
 /// <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, IRewindDataIndexStore rewindDataIndexStore)
     : base(network, loggerFactory, dateTimeProvider, chain, nodeDeployments, consensusSettings, checkpoints, utxoSet, chainState, invalidBlockHashStore, nodeStats)
 {
     this.StakeChain           = stakeChain;
     this.StakeValidator       = stakeValidator;
     this.RewindDataIndexStore = rewindDataIndexStore;
 }
        public SmartContractMempoolValidator(ITxMempool memPool, MempoolSchedulerLock mempoolLock, IDateTimeProvider dateTimeProvider, MempoolSettings mempoolSettings, ConcurrentChain chain, ICoinView coinView, ILoggerFactory loggerFactory, NodeSettings nodeSettings, IConsensusRuleEngine consensusRules, ICallDataSerializer callDataSerializer)
            : base(memPool, mempoolLock, dateTimeProvider, mempoolSettings, chain, coinView, loggerFactory, nodeSettings, consensusRules)
        {
            this.callDataSerializer = callDataSerializer;

            var p2pkhRule = new P2PKHNotContractRule();

            p2pkhRule.Parent = (ConsensusRuleEngine)consensusRules;
            p2pkhRule.Initialize();

            var scriptTypeRule = new AllowedScriptTypeRule();

            scriptTypeRule.Parent = (ConsensusRuleEngine)consensusRules;
            scriptTypeRule.Initialize();

            this.preTxRules = new List <ISmartContractMempoolRule>
            {
                new MempoolOpSpendRule(),
                new TxOutSmartContractExecRule(),
                scriptTypeRule,
                p2pkhRule
            };

            this.feeTxRules = new List <ISmartContractMempoolRule>()
            {
                new SmartContractFormatRule(callDataSerializer)
            };
        }
 public TestPosConsensusRules(Network network, ILoggerFactory loggerFactory, IDateTimeProvider dateTimeProvider, ConcurrentChain chain, NodeDeployments nodeDeployments, ConsensusSettings consensusSettings, ICheckpoints checkpoints, ICoinView uxtoSet, ILookaheadBlockPuller lookaheadBlockPuller, IStakeChain stakeChain, IStakeValidator stakeValidator)
     : base(network, loggerFactory, dateTimeProvider, chain, nodeDeployments, consensusSettings, checkpoints, uxtoSet, lookaheadBlockPuller, stakeChain, stakeValidator)
 {
 }
Exemple #11
0
 public SmartContractPowCoinviewRule(Network network, IStateRepositoryRoot stateRepositoryRoot,
                                     IContractExecutorFactory executorFactory, ICallDataSerializer callDataSerializer,
                                     ISenderRetriever senderRetriever, IReceiptRepository receiptRepository, ICoinView coinView)
     : base(network, stateRepositoryRoot, executorFactory, callDataSerializer, senderRetriever, receiptRepository, coinView)
 {
 }
        public SmartContractMempoolValidator(ITxMempool memPool, MempoolSchedulerLock mempoolLock, IDateTimeProvider dateTimeProvider, MempoolSettings mempoolSettings, ConcurrentChain chain, ICoinView coinView, ILoggerFactory loggerFactory, NodeSettings nodeSettings, IConsensusRuleEngine consensusRules, ICallDataSerializer callDataSerializer)
            : base(memPool, mempoolLock, dateTimeProvider, mempoolSettings, chain, coinView, loggerFactory, nodeSettings, consensusRules)
        {
            // Dirty hack, but due to AllowedScriptTypeRule we don't need to check for standard scripts on any network, even live.
            // TODO: Remove ASAP. Ensure RequireStandard isn't used on SC mainnets, or the StandardScripts check is modular.
            mempoolSettings.RequireStandard = false;

            this.callDataSerializer = callDataSerializer;

            var p2pkhRule = new P2PKHNotContractRule();

            p2pkhRule.Parent = (ConsensusRuleEngine)consensusRules;
            p2pkhRule.Initialize();

            var scriptTypeRule = new AllowedScriptTypeRule();

            scriptTypeRule.Parent = (ConsensusRuleEngine)consensusRules;
            scriptTypeRule.Initialize();

            this.preTxRules = new List <ISmartContractMempoolRule>
            {
                new MempoolOpSpendRule(),
                new TxOutSmartContractExecRule(),
                scriptTypeRule,
                p2pkhRule
            };

            this.feeTxRules = new List <ISmartContractMempoolRule>()
            {
                new SmartContractFormatRule(callDataSerializer)
            };
        }
Exemple #13
0
 public IEnumerable <UnspentOutputs> GetCoins(ICoinView utxo)
 {
     return(this.unspents.Select(u => u.Value).ToList());
 }
        /// <inheritdoc />
        public async Task InitializeAsync(IConsensus consensusParameters, ChainedHeader tip, ICoinView coinView)
        {
            // A temporary hack until tip manage will be introduced.
            var     breezeCoinView = (DBreezeCoinView)((CachedCoinView)coinView).Inner;
            uint256 hash           = await breezeCoinView.GetTipHashAsync().ConfigureAwait(false);

            tip = tip.FindAncestorOrSelf(hash);

            this.numberOfBlocksToKeep = (int)consensusParameters.MaxReorgLength;

            int heightToSyncTo = tip.Height > this.numberOfBlocksToKeep ? tip.Height - this.numberOfBlocksToKeep : 0;

            for (int rewindHeight = tip.Height - 1; rewindHeight >= heightToSyncTo; rewindHeight--)
            {
                RewindData rewindData = await coinView.GetRewindData(rewindHeight).ConfigureAwait(false);

                if (rewindData == null)
                {
                    throw new ConsensusException($"Rewind data of height '{rewindHeight}' was not found!");
                }

                if (rewindData.OutputsToRestore == null || rewindData.OutputsToRestore.Count == 0)
                {
                    continue;
                }

                foreach (UnspentOutputs unspent in rewindData.OutputsToRestore)
                {
                    for (int outputIndex = 0; outputIndex < unspent.Outputs.Length; outputIndex++)
                    {
                        string key = $"{unspent.TransactionId}-{outputIndex}";
                        this.items[key] = rewindHeight;
                    }
                }
            }
        }
Exemple #15
0
 public TestContractRulesEngine(Network network, ILoggerFactory loggerFactory, IDateTimeProvider dateTimeProvider, ConcurrentChain chain, NodeDeployments nodeDeployments, ConsensusSettings consensusSettings, ICheckpoints checkpoints, ICoinView utxoSet, IChainState chainState,
                                IInvalidBlockHashStore invalidBlockHashStore, INodeStats nodeStats)
     : base(network, loggerFactory, dateTimeProvider, chain, nodeDeployments, consensusSettings, checkpoints, utxoSet, chainState, invalidBlockHashStore, nodeStats)
 {
 }
 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, ConsensusRulesContainer consensusRulesContainer)
     : base(network, loggerFactory, dateTimeProvider, chainIndexer, nodeDeployments, consensusSettings, checkpoints, uxtoSet, stakeChain, stakeValidator, chainState, invalidBlockHashStore, nodeStats, rewindDataIndexCache, asyncProvider, consensusRulesContainer)
 {
     this.ruleRegistrationHelper = new RuleRegistrationHelper(this, consensusRulesContainer);
 }
 public TestContractRulesEngine(Network network, ILoggerFactory loggerFactory, IDateTimeProvider dateTimeProvider, ConcurrentChain chain, NodeDeployments nodeDeployments, ConsensusSettings consensusSettings, ICheckpoints checkpoints, ICoinView utxoSet, ILookaheadBlockPuller puller)
     : base(network, loggerFactory, dateTimeProvider, chain, nodeDeployments, consensusSettings, checkpoints, utxoSet, puller)
 {
 }
Exemple #18
0
 public SmartContractPosCoinviewRule(Network network, IStateRepositoryRoot stateRepositoryRoot,
                                     IContractExecutorFactory executorFactory, ICallDataSerializer callDataSerializer,
                                     ISenderRetriever senderRetriever, IReceiptRepository receiptRepository, ICoinView coinView,
                                     IStakeChain stakeChain, IStakeValidator stakeValidator)
     : base(network, stateRepositoryRoot, executorFactory, callDataSerializer, senderRetriever, receiptRepository, coinView)
 {
     this.consensus      = network.Consensus;
     this.stakeChain     = stakeChain;
     this.stakeValidator = stakeValidator;
 }
Exemple #19
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, ISlotsManager slotsManager, PoABlockHeaderValidator poaHeaderValidator,
                               VotingManager votingManager, IFederationManager federationManager, IAsyncProvider asyncProvider)
     : base(network, loggerFactory, dateTimeProvider, chainIndexer, nodeDeployments, consensusSettings, checkpoints, utxoSet, chainState, invalidBlockHashStore, nodeStats, asyncProvider)
 {
     this.SlotsManager       = slotsManager;
     this.PoaHeaderValidator = poaHeaderValidator;
     this.VotingManager      = votingManager;
     this.FederationManager  = federationManager;
 }
Exemple #20
0
        public SmartContractMempoolValidator(ITxMempool memPool, MempoolSchedulerLock mempoolLock, IDateTimeProvider dateTimeProvider, MempoolSettings mempoolSettings, ConcurrentChain chain, ICoinView coinView, ILoggerFactory loggerFactory, NodeSettings nodeSettings, IConsensusRules consensusRules)
            : base(memPool, mempoolLock, dateTimeProvider, mempoolSettings, chain, coinView, loggerFactory, nodeSettings, consensusRules)
        {
            var p2pkhRule = new P2PKHNotContractRule();

            p2pkhRule.Parent = (ConsensusRules)consensusRules;
            p2pkhRule.Initialize();

            this.preTxRules = new List <ISmartContractMempoolRule>
            {
                new MempoolOpSpendRule(),
                new TxOutSmartContractExecRule(),
                p2pkhRule
            };

            this.feeTxRules = new List <ISmartContractMempoolRule>()
            {
                new SmartContractFormatRule(),
            };
        }
Exemple #21
0
        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, ConsensusRulesContainer consensusRulesContainer)
            : base(network, loggerFactory, dateTimeProvider, chainIndexer, nodeDeployments, consensusSettings, checkpoints, chainState, invalidBlockHashStore, nodeStats, consensusRulesContainer)
        {
            this.logger = loggerFactory.CreateLogger(this.GetType().FullName);

            this.UtxoSet    = utxoSet;
            this.prefetcher = new CoinviewPrefetcher(this.UtxoSet, chainIndexer, loggerFactory, asyncProvider, checkpoints);
        }
 /// <summary>
 /// Initializes instance of the object based on memory based coinview.
 /// </summary>
 /// <param name="inner">Underlying coinview with memory based storage.</param>
 /// <param name="dateTimeProvider">Provider of time functions.</param>
 /// <param name="loggerFactory">Factory to be used to create logger for the puller.</param>
 /// <param name="nodeStats">The node stats.</param>
 /// <param name="stakeChainStore">Storage of POS block information.</param>
 /// <param name="rewindDataIndexCache">Rewind data index store.</param>
 /// <remarks>
 /// This is used for testing the coinview.
 /// It allows a coin view that only has in-memory entries.
 /// </remarks>
 public CachedCoinView(InMemoryCoinView inner, IDateTimeProvider dateTimeProvider, ILoggerFactory loggerFactory, INodeStats nodeStats, StakeChainStore stakeChainStore = null, IRewindDataIndexCache rewindDataIndexCache = null) :
     this(dateTimeProvider, loggerFactory, nodeStats, stakeChainStore, rewindDataIndexCache)
 {
     Guard.NotNull(inner, nameof(inner));
     this.inner = inner;
 }
Exemple #23
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();
 }