Skip to content
This repository has been archived by the owner on Jun 6, 2019. It is now read-only.

Commit

Permalink
Sanity check on reconcileStamp (#53)
Browse files Browse the repository at this point in the history
* 2.1.4: if reconcileStamp is no longer a number...

…recover it. Also ensure that `_fuzzing` doesn’t nullify it!

* Add a comment

* Simplify logic

After thinking about the comment from @NejcZdovc, I have concluded that
simpler is better in this recovery case.

* Missing the right parameter to setTimeUntilReconcile

Thanks @NejcZdovc !

* Add memo-ization

* Commit package-lock.json

Fixes #51

* Initial package-lock.json

* Adds tests
  • Loading branch information
mrose17 authored Apr 11, 2018
1 parent 3f42033 commit dd36177
Show file tree
Hide file tree
Showing 5 changed files with 10,522 additions and 7 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,5 @@ node_modules
# Optional REPL history
.node_repl_history

# package lock
package-lock.json

# one-off tests
test.js
24 changes: 21 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,22 @@ Client.prototype.sync = function (callback) {
const self = this

const now = underscore.now()
let ballot, ballots, i, transaction, updateP
let ballot, ballots, i, memo, transaction, updateP

if (typeof callback !== 'function') throw new Error('sync missing callback parameter')

if (!self.state.properties) self.state.properties = {}
if ((self.state.reconcileStamp === null) || (isNaN(self.state.reconcileStamp))) {
console.log('day', 14 * msecs.day)
memo = { prevoiusStamp: self.state.reconcileStamp }
self.state.reconcileStamp = now + (14 * msecs.day)
memo.reconcileStamp = self.state.reconcileStamp
memo.reconcileDate = new Date(self.state.reconcileStamp)
self.memo('sync', memo)

self._log('sync', { reconcileStamp: self.state.reconcileStamp })
return self.setTimeUntilReconcile(self.state.reconcileStamp, callback)
}
// the caller is responsible for checking that the reconcileStamp is too historic...
if ((self.state.properties.days) && (self.state.reconcileStamp > (now + (self.state.properties.days * msecs.day)))) {
self._log('sync', { reconcileStamp: self.state.reconcileStamp })
Expand Down Expand Up @@ -337,7 +348,13 @@ Client.prototype.getWalletProperties = function (amount, currency, callback) {
Client.prototype.setTimeUntilReconcile = function (timestamp, callback) {
const now = underscore.now()

if ((!timestamp) || (timestamp < now)) timestamp = now + (this.state.properties.days * msecs.day)
if ((!timestamp) || (timestamp < now)) {
let days = 30
if (this.state && this.state.properties && this.state.properties.days) {
days = this.state.properties.days
}
timestamp = now + (days * msecs.day)
}
this.state.reconcileStamp = timestamp
if (this.options.verboseP) this.state.reconcileDate = new Date(this.state.reconcileStamp)

Expand Down Expand Up @@ -1527,8 +1544,9 @@ Client.prototype._fuzzing = function (synopsis) {
memo.advance1 = advance
if (advance > (3 * msecs.day)) advance = 3 * msecs.day
memo.advance2 = advance
this.state.reconcileStamp += advance
if (advance) this.state.reconcileStamp += advance
memo.reconcileStamp = this.state.reconcileStamp
memo.reconcileDate = new Date(memo.reconcileStamp)

this.memo('_fuzzing', memo)
}
Expand Down
Loading

0 comments on commit dd36177

Please sign in to comment.