mempool: enable persistent fees.

This commit is contained in:
Christopher Jeffrey 2017-03-01 11:01:41 -08:00
parent a11344db0e
commit 34cb226000
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 26 additions and 9 deletions

View File

@ -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;
};

View File

@ -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() {