Exemplo n.º 1
0
        /// <summary>
        /// Constructs an instance of the block policy estimator object.
        /// </summary>
        /// <param name="mempoolSettings">Mempool settings.</param>
        /// <param name="loggerFactory">Factory for creating loggers.</param>
        /// <param name="nodeSettings">Full node settings.</param>
        public BlockPolicyEstimator(ILoggerFactory loggerFactory, NodeSettings nodeSettings)
        {
            this.lockObject          = new object();
            this.logger              = loggerFactory.CreateLogger(this.GetType().FullName);
            this.mapMemPoolTxs       = new Dictionary <uint256, TxStatsInfo>();
            this.buckets             = new List <double>();
            this.bucketMap           = new SortedDictionary <double, int>();
            this.nBestSeenHeight     = 0;
            this.firstRecordedHeight = 0;
            this.historicalFirst     = 0;
            this.historicalBest      = 0;
            this.trackedTxs          = 0;
            this.untrackedTxs        = 0;
            int bucketIndex = 0;

            for (double bucketBoundary = nodeSettings.MinRelayTxFeeRate.FeePerK.Satoshi; bucketBoundary <= MaxBucketFeeRate; bucketBoundary *= FeeSpacing, bucketIndex++)
            {
                this.buckets.Add(bucketBoundary);
                this.bucketMap.Add(bucketBoundary, bucketIndex);
            }
            this.buckets.Add(InfFeeRate);
            this.bucketMap.Add(InfFeeRate, bucketIndex);
            Guard.Assert(this.bucketMap.Count == this.buckets.Count);

            this.feeStats = new TxConfirmStats(this.logger);
            this.feeStats.Initialize(this.buckets, this.bucketMap, MedBlockPeriods, MedDecay, MedScale);
            this.shortStats = new TxConfirmStats(this.logger);
            this.shortStats.Initialize(this.buckets, this.bucketMap, ShortBlockPeriods, ShortDecay, ShortScale);
            this.longStats = new TxConfirmStats(this.logger);
            this.longStats.Initialize(this.buckets, this.bucketMap, LongBlockPeriods, LongDecay, LongScale);
            this.fileStorage = new FileStorage <BlockPolicyData>(nodeSettings.DataFolder.WalletPath);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Read estimation data from a file.
 /// </summary>
 /// <param name="filein">Stream to read data from.</param>
 /// <param name="nFileVersion">Version number of the file.</param>
 public bool Read()
 {
     try
     {
         lock (this.lockObject)
         {
             if (!this.fileStorage.Exists(FileName))
             {
                 return(true);
             }
             var data = this.fileStorage.LoadByFileName(FileName);
             if (data == null)
             {
                 throw new ApplicationException("Corrupt estimates file or file not found");
             }
             if (data.HistoricalFirst > data.HistoricalBest || data.HistoricalBest > data.BestSeenHeight)
             {
                 throw new ApplicationException("Corrupt estimates file. Historical block range for estimates is invalid");
             }
             if (data.Buckets.Count <= 1 || data.Buckets.Count > 1000)
             {
                 throw new ApplicationException("Corrupt estimates file. Must have between 2 and 1000 feerate buckets");
             }
             this.nBestSeenHeight = data.BestSeenHeight;
             this.historicalFirst = data.HistoricalFirst;
             this.historicalBest  = data.HistoricalBest;
             this.buckets         = data.Buckets;
             this.bucketMap       = new SortedDictionary <double, int>();
             for (int i = 0; i < this.buckets.Count; i++)
             {
                 this.bucketMap.Add(this.buckets[i], i);
             }
             this.feeStats = new TxConfirmStats(this.logger);
             this.feeStats.Initialize(this.buckets, this.bucketMap, MedBlockPeriods, MedDecay, MedScale);
             this.feeStats.Read(data.MedStats);
             this.shortStats = new TxConfirmStats(this.logger);
             this.shortStats.Initialize(this.buckets, this.bucketMap, ShortBlockPeriods, ShortDecay, ShortScale);
             this.shortStats.Read(data.ShortStats);
             this.longStats = new TxConfirmStats(this.logger);
             this.longStats.Initialize(this.buckets, this.bucketMap, LongBlockPeriods, LongDecay, LongScale);
             this.longStats.Read(data.LongStats);
         }
     }
     catch (Exception e)
     {
         this.logger.LogError("Error while reading policy estimation data from file", e);
         return(false);
     }
     return(true);
 }
Exemplo n.º 3
0
        /// <summary>
        /// Constructs an instance of the block policy estimator object.
        /// </summary>
        /// <param name="mempoolSettings">Mempool settings.</param>
        /// <param name="loggerFactory">Factory for creating loggers.</param>
        /// <param name="nodeSettings">Full node settings.</param>
        public BlockPolicyEstimator(MempoolSettings mempoolSettings, ILoggerFactory loggerFactory, NodeSettings nodeSettings)
        {
            this.mapMemPoolTxs   = new Dictionary <uint256, TxStatsInfo>();
            this.mempoolSettings = mempoolSettings;
            this.nBestSeenHeight = 0;
            this.trackedTxs      = 0;
            this.untrackedTxs    = 0;
            this.logger          = loggerFactory.CreateLogger(this.GetType().FullName);

            this.minTrackedFee = nodeSettings.MinRelayTxFeeRate < new FeeRate(new Money(MinFeeRate))
                ? new FeeRate(new Money(MinFeeRate))
                : nodeSettings.MinRelayTxFeeRate;
            var vfeelist = new List <double>();

            for (double bucketBoundary = this.minTrackedFee.FeePerK.Satoshi;
                 bucketBoundary <= MaxFeeRate;
                 bucketBoundary *= FeeSpacing)
            {
                vfeelist.Add(bucketBoundary);
            }
            vfeelist.Add(InfFeeRate);
            this.feeStats = new TxConfirmStats(this.logger);
            this.feeStats.Initialize(vfeelist, MaxBlockConfirms, DefaultDecay);
        }
        public BlockPolicyEstimator(FeeRate minRelayFee, NodeSettings nodeArgs, ILoggerFactory loggerFactory)
        {
            this.mapMemPoolTxs   = new Dictionary <uint256, TxStatsInfo>();
            this.nodeArgs        = nodeArgs;
            this.nBestSeenHeight = 0;
            this.trackedTxs      = 0;
            this.untrackedTxs    = 0;
            this.logger          = loggerFactory.CreateLogger(this.GetType().FullName);

            this.minTrackedFee = minRelayFee < new FeeRate(new Money(MIN_FEERATE))
                ? new FeeRate(new Money(MIN_FEERATE))
                : minRelayFee;
            var vfeelist = new List <double>();

            for (double bucketBoundary = this.minTrackedFee.FeePerK.Satoshi;
                 bucketBoundary <= MAX_FEERATE;
                 bucketBoundary *= FEE_SPACING)
            {
                vfeelist.Add(bucketBoundary);
            }
            vfeelist.Add(INF_FEERATE);
            this.feeStats = new TxConfirmStats(this.logger);
            this.feeStats.Initialize(vfeelist, MAX_BLOCK_CONFIRMS, DEFAULT_DECAY);
        }