public unsafe void DeepChain() { var store = new ChainStore(new MemoryMappedFileSlim(MemoryMappedFile.CreateNew(null, BlockHeight * 120 + 4096 - (BlockHeight * 120) % 4096))); store.Initialize(); var watch = new Stopwatch(); watch.Start(); store.TryOpenBlock(CommittedBlockId.GenesisParent, out var ub); for (var i = 0; i < BlockHeight; i++) { var blockId = new CommittedBlockId(); for (var j = 0; j < 4; j++) { blockId.Data[j] = (byte)(j >> (i * 8)); } blockId.Data[5] = 1; // ensure non-zero store.TryCommitBlock(ub.Alias, blockId, out var cb); // Filtering to improve speed. // Only ~1ms, but we can have a million calls. if (i <= 1000) { var lineage2 = store.GetLineage(); Assert.False(lineage2.IsUncommitted(cb.Alias)); } store.TryOpenBlock(blockId, out ub); } // ~0.013ms to open & commit a new block against 500k blocks. _log.Log(LogSeverity.Info, $"{(double)watch.ElapsedMilliseconds / BlockHeight} ms per block (pure I/O)."); watch.Reset(); watch.Start(); // ~70ms against 500k blocks with orphan at zero height (when disabling 'OldestOrphanHeight'). var lastLineage = store.GetLineage(); Assert.True(lastLineage.IsUncommitted(ub.Alias)); _log.Log(LogSeverity.Info, $"{(double)watch.ElapsedMilliseconds } ms on GetLineage last block (at {BlockHeight} height)."); }
public async Task <IActionResult> Add(long?id) { if (id == null) { var s = new ChainStore(); s.Id = 0; s.TenantId = 0; if (_AbpSession.TenantId != null && (int)AbpSession.TenantId > 0) { s.TenantId = (int)_AbpSession.TenantId; } return(PartialView("_Add", s)); } List <BusinessDropDownDto> dtoList = (await _businessAppService.GetDropDown()); ViewData.Add("Business", new Microsoft.AspNetCore.Mvc.Rendering.SelectList(dtoList, "Id", "BusinessName")); var dtos = await _AppService.GetByIdAsync((long)id); return(PartialView("_Add", dtos)); }
public async Task CreateOrEditAsync(ChainStore store) { try { if (store.Id > 0) { await _Repository.UpdateAsync(store); } else { if (_AbpSession.TenantId != null) { store.TenantId = (int)_AbpSession.TenantId; } await _Repository.InsertAsync(store); } } catch (Exception e) { throw new Abp.UI.UserFriendlyException(e.Message); } }
public void SetupStores(CashDBConfig config) { var secretPath = Path.Combine(config.Layer1Path, "secret.dat"); var secretStore = new MemoryMappedFileSlim(secretPath); var secretSpan = secretStore.GetSpan(0, Constants.SecretStoreFileSize); // HACK: secret initialization (would be better isolated) if (secretSpan.ToArray().All(b => b == 0)) { var rng = RandomNumberGenerator.Create(); rng.GetBytes(secretSpan); } OutpointHash = new SipHash(secretSpan); var chainPath = Path.Combine(config.Layer1Path, "chains.dat"); ChainStore = new ChainStore(new MemoryMappedFileSlim(chainPath), _log); ChainStore.Initialize(); CoinStores = new ICoinStore[Constants.CoinControllerCount]; for (var i = 0; i < Constants.CoinControllerCount; i++) { var journalPath = Path.Combine(config.Layer1Path, $"coins-journal-{i:x2}.dat"); var journalFile = new MemoryMappedFileSlim(journalPath); var layer1CoinStorePath = Path.Combine(config.Layer1Path, $"coins-1-{i:x2}.dat"); var layer1File = new MemoryMappedFileSlim(layer1CoinStorePath); var sectorCount = (int)(layer1File.FileLength / Constants.CoinStoreLayer1SectorSize); // Last layer used for key-value store. IKeyValueStore <uint> kvStore = null; if (!string.IsNullOrEmpty(config.Layer3Path)) { var layer3CoinStorePath = Path.Combine(config.Layer3Path, $"coins-3-{i:x2}.dat"); kvStore = new LightningStore <uint>(layer3CoinStorePath, "coins"); } IPackStore packStore; if (string.IsNullOrEmpty(config.Layer2Path)) { // Layer 2 is omitted packStore = new PackStore( sectorCount, new[] { Constants.CoinStoreLayer1SectorSize }, new[] { layer1File }, journalFile, kvStore, _log); } else { // Layer 2 is included var layer2CoinStorePath = Path.Combine(config.Layer2Path, $"coins-2-{i:x2}.dat"); var layer2File = new MemoryMappedFileSlim(layer2CoinStorePath); // Sector size on layer 2 is inferred from the sector count on layer 1. if (layer2File.FileLength % sectorCount != 0) { throw new InvalidOperationException("Mismatch between sector counts across layers."); } var coinStoreLayer1SectorSize = (int)(layer2File.FileLength / sectorCount); packStore = new PackStore( sectorCount, new[] { Constants.CoinStoreLayer1SectorSize, coinStoreLayer1SectorSize }, new[] { layer1File, layer2File }, journalFile, kvStore, _log); } packStore.Initialize(); CoinStores[i] = new SozuTable(packStore, OutpointHash); } _log?.Log(LogSeverity.Info, "CashDB store initialization completed successfully."); }