diff --git a/index.js b/index.js index 45b1dde..f7a8ef0 100644 --- a/index.js +++ b/index.js @@ -696,6 +696,14 @@ Client.prototype.publishersInfo = function (publishers, callback) { this._publishersInfo(callback) } +Client.prototype.memo = function (who, args) { + if (!this.memos) this.memos = [] + if (this.memos.length > 5) this.memos.splice(0, this.memos.length - 5) + this.memos.push(JSON.stringify({ who: who, what: args || {}, when: underscore.now() })) + + this._log(who, args) +} + Client.prototype._publishersInfo = function (callback) { const self = this @@ -1443,11 +1451,14 @@ Client.prototype.credentialSubmit = function (credential, surveyor, data, callba } Client.prototype._fuzzing = function (synopsis) { - let ratio, window let duration = 0 let remaining = this.state.reconcileStamp - underscore.now() + let advance, memo, ratio, window - if ((!synopsis) || (remaining > (3 * msecs.day)) || (this.boolion(process.env.LEDGER_NO_FUZZING))) return + if ((!synopsis) || + (remaining > (3 * msecs.day)) || + (this.options && this.options.noFuzzing) || + (this.boolion(process.env.LEDGER_NO_FUZZING))) return synopsis.prune() underscore.keys(synopsis.publishers).forEach((publisher) => { @@ -1456,10 +1467,22 @@ Client.prototype._fuzzing = function (synopsis) { // at the moment hard-wired to 30 minutes every 30 days ratio = duration / (30 * msecs.minute) + memo = { duration: duration, ratio1: ratio, numFrames: synopsis.options.numFrames, frameSize: synopsis.options.frameSize } window = synopsis.options.numFrames * synopsis.options.frameSize if (window > 0) ratio *= (30 * msecs.day) / window + if (ratio >= 1.0) return + + memo.window = window + memo.ratio2 = ratio + + advance = Math.round((this.state.properties.days * msecs.day) * (1.0 - ratio)) + memo.advance1 = advance + if (advance > (3 * msecs.day)) advance = 3 * msecs.day + memo.advance2 = advance + this.state.reconcileStamp += advance + memo.reconcileStamp = this.state.reconcileStamp - if (ratio < 1.0) this.state.reconcileStamp += Math.round((this.state.properties.days * msecs.day) * (1.0 - ratio)) + this.memo('_fuzzing', memo) } /* * diff --git a/package.json b/package.json index c6caf5f..020a98c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bat-client", - "version": "2.0.11", + "version": "2.1.0", "description": "An example of client code for the BAT.", "main": "index.js", "scripts": {