Пример #1
0
        public IndexStore(string workFolderPath, Network network, SmartHeaderChain hashChain)
        {
            WorkFolderPath = Guard.NotNullOrEmptyOrWhitespace(nameof(workFolderPath), workFolderPath, trim: true);
            IoHelpers.EnsureDirectoryExists(WorkFolderPath);
            var indexFilePath = Path.Combine(WorkFolderPath, "MatureIndex.dat");

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

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

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

            StartingFilter = StartingFilters.GetStartingFilter(Network);

            SmartHeaderChain = Guard.NotNull(nameof(hashChain), hashChain);
        }
Пример #2
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();
                    }
            }
        }
Пример #3
0
        public async Task InitializeAsync(string workFolderPath, Network network, SmartHeaderChain hashChain)
        {
            using (BenchmarkLogger.Measure())
            {
                WorkFolderPath   = Guard.NotNullOrEmptyOrWhitespace(nameof(workFolderPath), workFolderPath, trim: true);
                Network          = Guard.NotNull(nameof(network), network);
                SmartHeaderChain = Guard.NotNull(nameof(hashChain), hashChain);
                var indexFilePath = Path.Combine(WorkFolderPath, "MatureIndex.dat");
                MatureIndexFileManager = new DigestableSafeMutexIoManager(indexFilePath, digestRandomIndex: -1);
                var immatureIndexFilePath = Path.Combine(WorkFolderPath, "ImmatureIndex.dat");
                ImmatureIndexFileManager = new DigestableSafeMutexIoManager(immatureIndexFilePath, digestRandomIndex: -1);

                StartingFilter = StartingFilters.GetStartingFilter(Network);
                StartingHeight = StartingFilter.Header.Height;

                ImmatureFilters = new List <FilterModel>(150);

                IndexLock = new AsyncLock();

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

                            await EnsureBackwardsCompatibilityAsync().ConfigureAwait(false);

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

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

                            await InitializeFiltersAsync().ConfigureAwait(false);
                        }
            }
        }
Пример #4
0
        public async Task InitializeAsync()
        {
            using (BenchmarkLogger.Measure())
            {
                var indexFilePath = Path.Combine(WorkFolderPath, "MatureIndex.dat");
                MatureIndexFileManager = new DigestableSafeMutexIoManager(indexFilePath, digestRandomIndex: -1);
                var immatureIndexFilePath = Path.Combine(WorkFolderPath, "ImmatureIndex.dat");
                ImmatureIndexFileManager = new DigestableSafeMutexIoManager(immatureIndexFilePath, digestRandomIndex: -1);

                StartingFilter = StartingFilters.GetStartingFilter(Network);
                StartingHeight = StartingFilter.Header.Height;

                ImmatureFilters = new List <FilterModel>(150);

                IndexLock = new AsyncLock();

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

                            await EnsureBackwardsCompatibilityAsync().ConfigureAwait(false);

                            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.ToLine() }).ConfigureAwait(false);
                            }

                            await InitializeFiltersAsync().ConfigureAwait(false);
                        }
            }
        }