public void AddValidBlocksWithForkAllUncommitted() { _store = new ChainStore( new MemoryMappedFileSlim(MemoryMappedFile.CreateNew(null, 10000))); _store.TryOpenBlock(CommittedBlockId.GenesisParent, out var tmpBlock); // U(0) _tmpId1 = tmpBlock.BlockId; _store.TryCommitBlock(tmpBlock.Alias, CommittedBlockId.Genesis, out _); // C(0) _store.TryOpenBlock(CommittedBlockId.Genesis, out var tmp2Block); // C(0) -> U(1) Assert.Equal(tmp2Block.Alias, _1); _tmpId2 = tmp2Block.BlockId; _store.TryCommitBlock(tmp2Block.Alias, _hash1, out _); // C(0) -> C(1) _store.TryOpenBlock(_hash1, out var b1); Assert.Equal(_2, b1.Alias); _tmpId3 = b1.BlockId; // C(0) -> C(1) -> U(2) // Second child for second block _store.TryOpenBlock(_hash1, out b1); Assert.Equal(_2_1, b1.Alias); _tmpId4 = b1.BlockId; // C(0) -> C(1) -> U(2) // \-> U(2-1) }
public ChainRepository(IChainStore chainStore, ISignals signals = null) { this.chainStore = chainStore; this.signals = signals; this.logger = LogManager.GetCurrentClassLogger(); }
public ChainRepository(ILoggerFactory loggerFactory, IChainStore chainStore, Network network) { Guard.NotNull(loggerFactory, nameof(loggerFactory)); this.chainStore = chainStore; this.Network = network; this.logger = loggerFactory.CreateLogger(this.GetType().FullName); }
/// <summary> /// Set a different header store to the default <see cref="Chain.ChainStore"/>, this can be done only on genesis header (height 0). /// </summary> public void SetChainStore(IChainStore chainStore) { if (this.Height != 0) { throw new ArgumentException("IBlockHeaderStore can only be set on the genesis header."); } if (this.ChainStore != null) { chainStore.PutHeader(this.ChainStore.GetHeader(this, this.HashBlock)); } this.ChainStore = chainStore; }
public ChainController(IChainStore store, BoundedInbox inbox, BoundedInbox outbox, Action <ILineage> propagateLineage, ILog log = null) { _store = store; _inbox = inbox; _outbox = outbox; _propagateLineage = propagateLineage; _log = log; _pool = new SpanPool <byte>(GetBlockInfoResponse.SizeInBytes); _mre = new ManualResetEvent(false); RefreshAndPropagateLineage(); }
public void Setup() { var dispatchInbox = new BoundedInbox(); var chainInbox = new BoundedInbox(); var coinInboxes = new BoundedInbox[ShardCount]; for (var i = 0; i < coinInboxes.Length; i++) { coinInboxes[i] = new BoundedInbox(); } _dispatcher = new DispatchController( dispatchInbox, chainInbox, coinInboxes, new IdentityHash()); // Configure the wake-up callbacks to do nothing. _dispatcher.OnBlockMessageDispatched = () => { }; for (var i = 0; i < _dispatcher.OnCoinMessageDispatched.Length; i++) { _dispatcher.OnCoinMessageDispatched[i] = () => { } } ; _store = new VolatileChainStore(); _chainController = new ChainController( _store, chainInbox, dispatchInbox, lineage => { }); var c1 = ClientId.Next(); _clientConn = new ConnectionController(dispatchInbox, _socket, c1); _handleMask = c1.Mask; _dispatcher.AddConnection(_clientConn); _dispatcher.OnConnectionAccepted = _ => { }; _dispatcher.HandleNewConnection(); _c0 = new ClientId(0); }
public void AddBlockToCommittedParent() { _store = new ChainStore( new MemoryMappedFileSlim(MemoryMappedFile.CreateNew(null, 10000))); var status1 = _store.TryOpenBlock(CommittedBlockId.GenesisParent, out var block1); Assert.True(OpenBlockStatus.Success.Equals(status1)); var id = block1.Alias; var status2 = _store.TryCommitBlock(id, CommittedBlockId.Genesis, out _); Assert.Equal(CommitBlockStatus.Success, status2); Assert.Equal(BlockAlias.Genesis, id); var status3 = _store.TryOpenBlock(CommittedBlockId.Genesis, out _); Assert.Equal(OpenBlockStatus.Success, status3); }
public void AddValidBlocksWithFork() { _store = new ChainStore( new MemoryMappedFileSlim(MemoryMappedFile.CreateNew(null, 10000))); _store.TryOpenBlock(CommittedBlockId.GenesisParent, out var b0); var id0 = b0.Alias; // U(0) _store.TryCommitBlock(id0, CommittedBlockId.Genesis, out _); // C(0) _store.TryOpenBlock(CommittedBlockId.Genesis, out var b1); var id1 = b1.Alias; // C(0) -> U(1) _store.TryCommitBlock(id1, _hash1, out _); // C(0) -> C(1) Assert.Equal(_1, id1); _store.TryOpenBlock(_hash1, out var b2); var id2 = b2.Alias; // C(0) -> C(1) -> U(2) Assert.Equal(_2, id2); _store.TryCommitBlock(id2, _hash2, out _); // C(0) -> C(1) -> C(2) // Second child for second block _store.TryOpenBlock(_hash1, out var b21); var id21 = b21.Alias; // C(0) -> C(1) -> C(2) // \-> U(2-1) Assert.Equal(_2_1, id21); _store.TryCommitBlock(id21, _hash3, out _); // C(0) -> C(1) -> C(2) // \-> C(2-1) }
/// <summary> /// Makes the full node use all the required features - <see cref="BaseFeature"/>. /// </summary> /// <param name="fullNodeBuilder">Builder responsible for creating the node.</param> /// <returns>Full node builder's interface to allow fluent code.</returns> public static IFullNodeBuilder UseBaseFeature(this IFullNodeBuilder fullNodeBuilder, DbType dbType = DbType.Leveldb) { fullNodeBuilder.ConfigureFeature(features => { features .AddFeature <BaseFeature>() .FeatureServices(services => { services.AddSingleton(fullNodeBuilder.Network.Consensus.ConsensusFactory); services.AddSingleton <DBreezeSerializer>(); services.AddSingleton(fullNodeBuilder.NodeSettings.LoggerFactory); services.AddSingleton(fullNodeBuilder.NodeSettings.DataFolder); services.AddSingleton <INodeLifetime, NodeLifetime>(); services.AddSingleton <IPeerBanning, PeerBanning>(); services.AddSingleton <FullNodeFeatureExecutor>(); services.AddSingleton <ISignals, Signals.Signals>(); services.AddSingleton <ISubscriptionErrorHandler, DefaultSubscriptionErrorHandler>(); services.AddSingleton <FullNode>().AddSingleton((provider) => { return(provider.GetService <FullNode>() as IFullNode); }); ChainIndexer chainIndexer = new ChainIndexer(fullNodeBuilder.Network); IChainStore chainStore = null; if (dbType == DbType.Leveldb) { chainStore = new LevelDbChainStore(fullNodeBuilder.Network, fullNodeBuilder.NodeSettings.DataFolder, chainIndexer); services.AddSingleton <IKeyValueRepository, LevelDbKeyValueRepository>(); } if (dbType == DbType.RocksDb) { chainStore = new RocksDbChainStore(fullNodeBuilder.Network, fullNodeBuilder.NodeSettings.DataFolder, chainIndexer); services.AddSingleton <IKeyValueRepository, RocksDbKeyValueRepository>(); } chainIndexer[0].SetChainStore(chainStore); services.AddSingleton(chainStore); services.AddSingleton(chainIndexer); services.AddSingleton(DateTimeProvider.Default); services.AddSingleton <IInvalidBlockHashStore, InvalidBlockHashStore>(); services.AddSingleton <IChainState, ChainState>(); services.AddSingleton <IChainRepository, ChainRepository>(); services.AddSingleton <IFinalizedBlockInfoRepository, FinalizedBlockInfoRepository>(); services.AddSingleton <ITimeSyncBehaviorState, TimeSyncBehaviorState>(); services.AddSingleton <NodeDeployments>(); services.AddSingleton <IInitialBlockDownloadState, InitialBlockDownloadState>(); services.AddSingleton <ITipsManager, TipsManager>(); services.AddSingleton <IAsyncProvider, AsyncProvider>(); // Consensus services.AddSingleton <ConsensusSettings>(); services.AddSingleton <ICheckpoints, Checkpoints>(); services.AddSingleton <ConsensusRulesContainer>(); foreach (var ruleType in fullNodeBuilder.Network.Consensus.ConsensusRules.HeaderValidationRules) { services.AddSingleton(typeof(IHeaderValidationConsensusRule), ruleType); } foreach (var ruleType in fullNodeBuilder.Network.Consensus.ConsensusRules.IntegrityValidationRules) { services.AddSingleton(typeof(IIntegrityValidationConsensusRule), ruleType); } foreach (var ruleType in fullNodeBuilder.Network.Consensus.ConsensusRules.PartialValidationRules) { services.AddSingleton(typeof(IPartialValidationConsensusRule), ruleType); } foreach (var ruleType in fullNodeBuilder.Network.Consensus.ConsensusRules.FullValidationRules) { services.AddSingleton(typeof(IFullValidationConsensusRule), ruleType); } // Connection services.AddSingleton <INetworkPeerFactory, NetworkPeerFactory>(); services.AddSingleton <NetworkPeerConnectionParameters>(); services.AddSingleton <IConnectionManager, ConnectionManager>(); services.AddSingleton <ConnectionManagerSettings>(); services.AddSingleton(new PayloadProvider().DiscoverPayloads()); services.AddSingleton <IVersionProvider, VersionProvider>(); services.AddSingleton <IBlockPuller, BlockPuller>(); // Peer address manager services.AddSingleton <IPeerAddressManager, PeerAddressManager>(); services.AddSingleton <IPeerConnector, PeerConnectorAddNode>(); services.AddSingleton <IPeerConnector, PeerConnectorConnectNode>(); services.AddSingleton <IPeerConnector, PeerConnectorDiscovery>(); services.AddSingleton <IPeerDiscovery, PeerDiscovery>(); services.AddSingleton <ISelfEndpointTracker, SelfEndpointTracker>(); // Consensus // Consensus manager is created like that due to CM's constructor being internal. This is done // in order to prevent access to CM creation and CHT usage from another features. CHT is supposed // to be used only by CM and no other component. services.AddSingleton <IConsensusManager>(provider => new ConsensusManager( chainedHeaderTree: provider.GetService <IChainedHeaderTree>(), network: provider.GetService <Network>(), loggerFactory: provider.GetService <ILoggerFactory>(), chainState: provider.GetService <IChainState>(), integrityValidator: provider.GetService <IIntegrityValidator>(), partialValidator: provider.GetService <IPartialValidator>(), fullValidator: provider.GetService <IFullValidator>(), consensusRules: provider.GetService <IConsensusRuleEngine>(), finalizedBlockInfo: provider.GetService <IFinalizedBlockInfoRepository>(), signals: provider.GetService <ISignals>(), peerBanning: provider.GetService <IPeerBanning>(), ibdState: provider.GetService <IInitialBlockDownloadState>(), chainIndexer: provider.GetService <ChainIndexer>(), blockPuller: provider.GetService <IBlockPuller>(), blockStore: provider.GetService <IBlockStore>(), connectionManager: provider.GetService <IConnectionManager>(), nodeStats: provider.GetService <INodeStats>(), nodeLifetime: provider.GetService <INodeLifetime>(), consensusSettings: provider.GetService <ConsensusSettings>(), dateTimeProvider: provider.GetService <IDateTimeProvider>())); services.AddSingleton <IChainWorkComparer, ChainWorkComparer>(); services.AddSingleton <IChainedHeaderTree, ChainedHeaderTree>(); services.AddSingleton <IHeaderValidator, HeaderValidator>(); services.AddSingleton <IIntegrityValidator, IntegrityValidator>(); services.AddSingleton <IPartialValidator, PartialValidator>(); services.AddSingleton <IFullValidator, FullValidator>(); // Console services.AddSingleton <INodeStats, NodeStats>(); }); }); return(fullNodeBuilder); }
public ChainRepository(IChainStore chainStore) { this.chainStore = chainStore; }