public RecordStorageEngine(DatabaseLayout databaseLayout, Config config, PageCache pageCache, FileSystemAbstraction fs, LogProvider logProvider, LogProvider userLogProvider, TokenHolders tokenHolders, SchemaState schemaState, ConstraintSemantics constraintSemantics, JobScheduler scheduler, TokenNameLookup tokenNameLookup, LockService lockService, IndexProviderMap indexProviderMap, IndexingService.Monitor indexingServiceMonitor, DatabaseHealth databaseHealth, ExplicitIndexProvider explicitIndexProvider, IndexConfigStore indexConfigStore, IdOrderingQueue explicitIndexTransactionOrdering, IdGeneratorFactory idGeneratorFactory, IdController idController, Monitors monitors, RecoveryCleanupWorkCollector recoveryCleanupWorkCollector, OperationalMode operationalMode, VersionContextSupplier versionContextSupplier) { this._tokenHolders = tokenHolders; this._schemaState = schemaState; this._lockService = lockService; this._databaseHealth = databaseHealth; this._explicitIndexProviderLookup = explicitIndexProvider; this._indexConfigStore = indexConfigStore; this._constraintSemantics = constraintSemantics; this._explicitIndexTransactionOrdering = explicitIndexTransactionOrdering; this._idController = idController; StoreFactory factory = new StoreFactory(databaseLayout, config, idGeneratorFactory, pageCache, fs, logProvider, versionContextSupplier); _neoStores = factory.OpenAllNeoStores(true); try { _schemaCache = new SchemaCache(constraintSemantics, Collections.emptyList(), indexProviderMap); _schemaStorage = new SchemaStorage(_neoStores.SchemaStore); NeoStoreIndexStoreView neoStoreIndexStoreView = new NeoStoreIndexStoreView(lockService, _neoStores); bool readOnly = config.Get(GraphDatabaseSettings.read_only) && operationalMode == OperationalMode.single; monitors.AddMonitorListener(new LoggingMonitor(logProvider.GetLog(typeof(NativeLabelScanStore)))); _labelScanStore = new NativeLabelScanStore(pageCache, databaseLayout, fs, new FullLabelStream(neoStoreIndexStoreView), readOnly, monitors, recoveryCleanupWorkCollector); _indexStoreView = new DynamicIndexStoreView(neoStoreIndexStoreView, _labelScanStore, lockService, _neoStores, logProvider); this._indexProviderMap = indexProviderMap; _indexingService = IndexingServiceFactory.createIndexingService(config, scheduler, indexProviderMap, _indexStoreView, tokenNameLookup, Iterators.asList(_schemaStorage.loadAllSchemaRules()), logProvider, userLogProvider, indexingServiceMonitor, schemaState, readOnly); _integrityValidator = new IntegrityValidator(_neoStores, _indexingService); _cacheAccess = new BridgingCacheAccess(_schemaCache, schemaState, tokenHolders); _explicitIndexApplierLookup = new Org.Neo4j.Kernel.Impl.Api.ExplicitIndexApplierLookup_Direct(explicitIndexProvider); _labelScanStoreSync = new WorkSync <Supplier <LabelScanWriter>, LabelUpdateWork>(_labelScanStore.newWriter); _commandReaderFactory = new RecordStorageCommandReaderFactory(); _indexUpdatesSync = new WorkSync <IndexingUpdateService, IndexUpdatesWork>(_indexingService); _denseNodeThreshold = config.Get(GraphDatabaseSettings.dense_node_threshold); _recordIdBatchSize = config.Get(GraphDatabaseSettings.record_id_batch_size); } catch (Exception failure) { _neoStores.close(); throw failure; } }
internal TransactionRecordState(NeoStores neoStores, IntegrityValidator integrityValidator, RecordChangeSet recordChangeSet, long lastCommittedTxWhenTransactionStarted, ResourceLocker locks, RelationshipCreator relationshipCreator, RelationshipDeleter relationshipDeleter, PropertyCreator propertyCreator, PropertyDeleter propertyDeleter) { this._neoStores = neoStores; this._nodeStore = neoStores.NodeStore; this._relationshipStore = neoStores.RelationshipStore; this._propertyStore = neoStores.PropertyStore; this._relationshipGroupStore = neoStores.RelationshipGroupStore; this._metaDataStore = neoStores.MetaDataStore; this._schemaStore = neoStores.SchemaStore; this._integrityValidator = integrityValidator; this._recordChangeSet = recordChangeSet; this._lastCommittedTxWhenTransactionStarted = lastCommittedTxWhenTransactionStarted; this._locks = locks; this._relationshipCreator = relationshipCreator; this._relationshipDeleter = relationshipDeleter; this._propertyCreator = propertyCreator; this._propertyDeleter = propertyDeleter; }
/// <summary> /// Creates the consensus manager used by <see cref="PosCoinViewRuleFailsAsync"/>. /// </summary> /// <param name="unspentOutputs">The dictionary used to mock up the <see cref="ICoinView"/>.</param> /// <returns>The constructed consensus manager.</returns> private async Task <ConsensusManager> CreateConsensusManagerAsync(Dictionary <OutPoint, UnspentOutput> unspentOutputs) { this.consensusSettings = new ConsensusSettings(Configuration.NodeSettings.Default(this.network)); var initialBlockDownloadState = new InitialBlockDownloadState(this.chainState.Object, this.network, this.consensusSettings, new Checkpoints(), DateTimeProvider.Default); var signals = new Signals.Signals(this.loggerFactory.Object, null); var asyncProvider = new AsyncProvider(this.loggerFactory.Object, signals); var consensusRulesContainer = new ConsensusRulesContainer(); foreach (var ruleType in this.network.Consensus.ConsensusRules.FullValidationRules) { consensusRulesContainer.FullValidationRules.Add(Activator.CreateInstance(ruleType) as FullValidationConsensusRule); } // Register POS consensus rules. // new FullNodeBuilderConsensusExtension.PosConsensusRulesRegistration().RegisterRules(this.network.Consensus); var consensusRuleEngine = new PosConsensusRuleEngine(this.network, this.loggerFactory.Object, DateTimeProvider.Default, this.ChainIndexer, this.nodeDeployments, this.consensusSettings, this.checkpoints.Object, this.coinView.Object, this.stakeChain.Object, this.stakeValidator.Object, this.chainState.Object, new InvalidBlockHashStore(this.dateTimeProvider.Object), new Mock <INodeStats>().Object, this.rewindDataIndexStore.Object, this.asyncProvider, consensusRulesContainer) .SetupRulesEngineParent(); var headerValidator = new HeaderValidator(consensusRuleEngine, this.loggerFactory.Object); var integrityValidator = new IntegrityValidator(consensusRuleEngine, this.loggerFactory.Object); var partialValidator = new PartialValidator(asyncProvider, consensusRuleEngine, this.loggerFactory.Object); var fullValidator = new FullValidator(consensusRuleEngine, this.loggerFactory.Object); // Create the chained header tree. var chainedHeaderTree = new ChainedHeaderTree(this.network, this.loggerFactory.Object, headerValidator, this.checkpoints.Object, this.chainState.Object, new Mock <IFinalizedBlockInfoRepository>().Object, this.consensusSettings, new InvalidBlockHashStore(new DateTimeProvider()), new ChainWorkComparer()); // Create consensus manager. var consensus = new ConsensusManager(chainedHeaderTree, this.network, this.loggerFactory.Object, this.chainState.Object, integrityValidator, partialValidator, fullValidator, consensusRuleEngine, new Mock <IFinalizedBlockInfoRepository>().Object, signals, new Mock <IPeerBanning>().Object, initialBlockDownloadState, this.ChainIndexer, new Mock <IBlockPuller>().Object, new Mock <IBlockStore>().Object, new Mock <IConnectionManager>().Object, new Mock <INodeStats>().Object, new Mock <INodeLifetime>().Object, this.consensusSettings, this.dateTimeProvider.Object); // Mock the coinviews "FetchCoinsAsync" method. We will use the "unspentOutputs" dictionary to track spendable outputs. this.coinView.Setup(d => d.FetchCoins(It.IsAny <OutPoint[]>())) .Returns((OutPoint[] txIds) => { var result = new FetchCoinsResponse(); for (int i = 0; i < txIds.Length; i++) { unspentOutputs.TryGetValue(txIds[i], out UnspentOutput unspent); result.UnspentOutputs.Add(txIds[i], unspent); } return(result); }); // Mock the coinviews "GetTipHashAsync" method. this.coinView.Setup(d => d.GetTipHash()).Returns(() => { return(new HashHeightPair(this.ChainIndexer.Tip)); }); // Since we are mocking the stake validator ensure that GetNextTargetRequired returns something sensible. Otherwise we get the "bad-diffbits" error. this.stakeValidator.Setup(s => s.GetNextTargetRequired(It.IsAny <IStakeChain>(), It.IsAny <ChainedHeader>(), It.IsAny <IConsensus>(), It.IsAny <bool>())) .Returns(this.network.Consensus.PowLimit); // Skip validation of signature in the proven header this.stakeValidator.Setup(s => s.VerifySignature(It.IsAny <UnspentOutput>(), It.IsAny <Transaction>(), 0, It.IsAny <ScriptVerify>())) .Returns(true); // Skip validation of stake kernel this.stakeValidator.Setup(s => s.CheckStakeKernelHash(It.IsAny <PosRuleContext>(), It.IsAny <uint>(), It.IsAny <uint256>(), It.IsAny <UnspentOutput>(), It.IsAny <OutPoint>(), It.IsAny <uint>())) .Returns(true); // Since we are mocking the stakechain ensure that the Get returns a BlockStake. Otherwise this results in "previous stake is not found". this.stakeChain.Setup(d => d.Get(It.IsAny <uint256>())).Returns(new BlockStake() { Flags = BlockFlag.BLOCK_PROOF_OF_STAKE, StakeModifierV2 = 0, StakeTime = (this.ChainIndexer.Tip.Header.Time + 60) & ~PosConsensusOptions.StakeTimestampMask }); // Since we are mocking the chainState ensure that the BlockStoreTip returns a usable value. this.chainState.Setup(d => d.BlockStoreTip).Returns(this.ChainIndexer.Tip); // Since we are mocking the chainState ensure that the ConsensusTip returns a usable value. this.chainState.Setup(d => d.ConsensusTip).Returns(this.ChainIndexer.Tip); // Initialize the consensus manager. await consensus.InitializeAsync(this.ChainIndexer.Tip); return(consensus); }