Exemple #1
0
        public async Task InitializeAsync(string workFolderPath, Network network)
        {
            using (BenchmarkLogger.Measure())
            {
                WorkFolderPath = Guard.NotNullOrEmptyOrWhitespace(nameof(workFolderPath), workFolderPath, trim: true);
                IoHelpers.EnsureDirectoryExists(WorkFolderPath);

                Network = Guard.NotNull(nameof(network), network);

                IndexStore       = new IndexStore();
                TransactionStore = new AllTransactionStore();
                var networkWorkFolderPath = Path.Combine(WorkFolderPath, Network.ToString());
                var indexStoreFolderPath  = Path.Combine(networkWorkFolderPath, "IndexStore");
                HashChain      = new HashChain();
                MempoolService = new MempoolService();

                var initTasks = new[]
                {
                    IndexStore.InitializeAsync(indexStoreFolderPath, Network, HashChain),
                    TransactionStore.InitializeAsync(networkWorkFolderPath, Network)
                };

                await Task.WhenAll(initTasks).ConfigureAwait(false);

                IsInitialized = true;
            }
        }
Exemple #2
0
 private void ProcessFilter(FilterModel filter, bool enqueue)
 {
     if (enqueue)
     {
         ImmatureFilters.Add(filter);
     }
     HashChain.AddOrReplace(filter.BlockHeight.Value, filter.BlockHash);
 }
        public async Task InitializeAsync(string workFolderPath, Network network)
        {
            WorkFolderPath = Guard.NotNullOrEmptyOrWhitespace(nameof(workFolderPath), workFolderPath, trim: true);
            IoHelpers.EnsureDirectoryExists(WorkFolderPath);

            Network = Guard.NotNull(nameof(network), network);

            IndexStore = new IndexStore();
            var indexStoreFolderPath = Path.Combine(WorkFolderPath, Network.ToString());

            HashChain = new HashChain();
            await IndexStore.InitializeAsync(indexStoreFolderPath, Network, HashChain);
        }
Exemple #4
0
        public async Task InitializeAsync(string workFolderPath, Network network, HashChain hashChain)
        {
            WorkFolderPath = Guard.NotNullOrEmptyOrWhitespace(nameof(workFolderPath), workFolderPath, trim: true);
            Network        = Guard.NotNull(nameof(network), network);
            HashChain      = Guard.NotNull(nameof(hashChain), hashChain);
            var indexFilePath = Path.Combine(WorkFolderPath, "MatureIndex.dat");

            MatureIndexFileManager = new IoManager(indexFilePath, digestRandomIndex: -1);
            var immatureIndexFilePath = Path.Combine(WorkFolderPath, "ImmatureIndex.dat");

            ImmatureIndexFileManager = new IoManager(immatureIndexFilePath, digestRandomIndex: -1);

            StartingFilter = StartingFilters.GetStartingFilter(Network);
            StartingHeight = StartingFilters.GetStartingHeight(Network);

            ImmatureFilters = new List <FilterModel>(150);

            IndexLock = new AsyncLock();

            using (await IndexLock.LockAsync())
            {
                using (await MatureIndexFileManager.Mutex.LockAsync())
                    using (await ImmatureIndexFileManager.Mutex.LockAsync())
                    {
                        IoHelpers.EnsureDirectoryExists(WorkFolderPath);

                        await TryEnsureBackwardsCompatibilityAsync();

                        if (Network == Network.RegTest)
                        {
                            MatureIndexFileManager.DeleteMe();                     // RegTest is not a global ledger, better to delete it.
                            ImmatureIndexFileManager.DeleteMe();
                        }

                        if (!MatureIndexFileManager.Exists())
                        {
                            await MatureIndexFileManager.WriteAllLinesAsync(new[] { StartingFilter.ToHeightlessLine() });
                        }

                        await InitializeFiltersAsync();
                    }
            }
        }
Exemple #5
0
        public async Task <FilterModel> RemoveLastFilterAsync(CancellationToken cancel)
        {
            FilterModel filter = null;

            using (await IndexLock.LockAsync())
            {
                filter = ImmatureFilters.Last();
                ImmatureFilters.RemoveLast();
                if (HashChain.TipHeight != filter.BlockHeight.Value)
                {
                    throw new InvalidOperationException("HashChain and ImmatureFilters are not in sync.");
                }
                HashChain.RemoveLast();
            }

            Reorged?.Invoke(this, filter);

            _ = TryCommitToFileAsync(TimeSpan.FromSeconds(3), cancel);

            return(filter);
        }