From 34cb226000d394ab5c2cbe6195ffa45d625ea86d Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 1 Mar 2017 11:01:41 -0800 Subject: [PATCH] mempool: enable persistent fees. --- lib/mempool/fees.js | 21 +++++++++++++++------ lib/mempool/mempool.js | 14 +++++++++++--- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/lib/mempool/fees.js b/lib/mempool/fees.js index 792b4ef4..ad823a95 100644 --- a/lib/mempool/fees.js +++ b/lib/mempool/fees.js @@ -25,14 +25,14 @@ var Int32Array = global.Int32Array || Array; * Constants */ -var MAX_BLOCK_CONFIRMS = 25; +var MAX_BLOCK_CONFIRMS = 15; /* 25 */ var DEFAULT_DECAY = 0.998; var MIN_SUCCESS_PCT = 0.95; var UNLIKELY_PCT = 0.5; var SUFFICIENT_FEETXS = 1; var SUFFICIENT_PRITXS = 0.2; var MIN_FEERATE = 10; -var MAX_FEERATE = 1e7; +var MAX_FEERATE = 1e6; /* 1e7 */ var INF_FEERATE = consensus.MAX_MONEY; var MIN_PRIORITY = 10; var MAX_PRIORITY = 1e16; @@ -451,6 +451,14 @@ function PolicyEstimator(logger) { } } +/** + * Serialization version. + * @const {Number} + * @default + */ + +PolicyEstimator.VERSION = 0; + /** * Initialize the estimator. * @private @@ -798,9 +806,8 @@ PolicyEstimator.prototype.estimatePriority = function estimatePriority(target, s PolicyEstimator.prototype.getSize = function getSize() { var size = 0; - size += 4; + size += 5; size += encoding.sizeVarlen(this.feeStats.getSize()); - size += encoding.sizeVarlen(this.priStats.getSize()); return size; }; @@ -813,9 +820,9 @@ PolicyEstimator.prototype.toRaw = function toRaw() { var size = this.getSize(); var bw = new StaticWriter(size); + bw.writeU8(PolicyEstimator.VERSION); bw.writeU32(this.bestHeight); bw.writeVarBytes(this.feeStats.toRaw()); - bw.writeVarBytes(this.priStats.toRaw()); return bw.render(); }; @@ -830,9 +837,11 @@ PolicyEstimator.prototype.toRaw = function toRaw() { PolicyEstimator.prototype.fromRaw = function fromRaw(data) { var br = new BufferReader(data); + if (br.readU8() !== PolicyEstimator.VERSION) + throw new Error('Bad serialization version for estimator.'); + this.bestHeight = br.readU32(); this.feeStats.fromRaw(br.readVarBytes()); - this.priStats.fromRaw(br.readVarBytes()); return this; }; diff --git a/lib/mempool/mempool.js b/lib/mempool/mempool.js index bbf92f8c..e9e48f2e 100644 --- a/lib/mempool/mempool.js +++ b/lib/mempool/mempool.js @@ -220,8 +220,7 @@ Mempool.prototype._addBlock = co(function* addBlock(block, txs) { if (this.fees) { this.fees.processBlock(block.height, entries, this.chain.synced); - // Note: disable for now. - // this.cache.writeFees(this.fees); + this.cache.writeFees(this.fees); } this.cache.sync(block.hash); @@ -2326,11 +2325,20 @@ MempoolCache.prototype.getTip = co(function* getTip() { MempoolCache.prototype.getFees = co(function* getFees() { var data = yield this.db.get(layout.F); + var fees; if (!data) return; - return Fees.fromRaw(data); + try { + fees = Fees.fromRaw(data); + } catch (e) { + this.logger.warning( + 'Fee data failed deserialization: %s.', + e.message); + } + + return fees; }); MempoolCache.prototype.getEntries = function getEntries() {