Ejemplo n.º 1
0
        /// <summary>
        /// Saves the memory pool to persistent storage.
        /// </summary>
        /// <returns>Memory pool save result.</returns>
        internal MemPoolSaveResult SavePool()
        {
            if (this.mempoolPersistence == null)
            {
                this.logger.LogTrace("(-)[NON_SUCCESS]");
                return(MemPoolSaveResult.NonSuccess);
            }
            MemPoolSaveResult saveResult = this.mempoolPersistence.Save(this.network, this.memPool);

            return(saveResult);
        }
        /// <inheritdoc />
        public override void Dispose()
        {
            this.logger.LogInformation("Saving Memory Pool.");

            MemPoolSaveResult result = this.mempoolManager.SavePool();

            if (result.Succeeded)
            {
                this.logger.LogInformation($"Memory Pool Saved {result.TrxSaved} transactions");
            }
            else
            {
                this.logger.LogWarning("Memory Pool Not Saved!");
            }

            this.mempoolSignaled.Stop();
        }
Ejemplo n.º 3
0
        /// <inheritdoc />
        public override void Stop()
        {
            if (this.mempoolManager != null)
            {
                this.mempoolLogger.LogInformation("Saving Memory Pool...");

                MemPoolSaveResult result = this.mempoolManager.SavePool();
                if (result.Succeeded)
                {
                    this.mempoolLogger.LogInformation($"...Memory Pool Saved {result.TrxSaved} transactions");
                }
                else
                {
                    this.mempoolLogger.LogWarning("...Memory Pool Not Saved!");
                }
            }
        }
        /// <summary>
        /// Saves a list of memory pool transaction entries to a persistence file.
        /// </summary>
        /// <param name="network">The blockchain network.</param>
        /// <param name="toSave">List of persistence transactions to save.</param>
        /// <param name="fileName">The filename to persist transactions to.</param>
        /// <returns>The save result.</returns>
        internal MemPoolSaveResult Save(Network network, IEnumerable <MempoolPersistenceEntry> toSave, string fileName)
        {
            Guard.NotEmpty(this.dataDir, nameof(this.dataDir));
            Guard.NotEmpty(fileName, nameof(fileName));

            string filePath     = Path.Combine(this.dataDir, fileName);
            string tempFilePath = $"{fileName}.new";

            if (Directory.Exists(this.dataDir))
            {
                try
                {
                    if (!toSave.Any())
                    {
                        File.Delete(filePath);
                    }
                    else
                    {
                        using (var fs = new FileStream(tempFilePath, FileMode.Create))
                        {
                            this.DumpToStream(network, toSave, fs);
                        }
                        File.Delete(filePath);
                        File.Move(tempFilePath, filePath);
                    }
                    return(MemPoolSaveResult.Success((uint)toSave.LongCount()));
                }
                catch (Exception ex)
                {
                    this.mempoolLogger.LogError(ex.Message);
                    throw;
                }
            }

            return(MemPoolSaveResult.NonSuccess);
        }