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

use latest version of ledger packages, and better use of callback delays #3944

Merged
merged 1 commit into from
Sep 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions app/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ var boot = () => {
bootP = false
return console.log('ledger client boot error: ' + ex.toString() + '\n' + ex.stack)
}
if (client.sync(callback) === true) run(random.randomInt({ min: 1, max: 10 }) * msecs.minute)
if (client.sync(callback) === true) run(random.randomInt({ min: msecs.minute, max: 10 * msecs.minute }))
getBalance()

bootP = false
Expand Down Expand Up @@ -374,7 +374,7 @@ var initialize = (onoff) => {
} catch (ex) {
return console.log('ledger client creation error: ' + ex.toString() + '\n' + ex.stack)
}
if (client.sync(callback) === true) run(random.randomInt({ min: 1, max: 10 }) * msecs.minute)
if (client.sync(callback) === true) run(random.randomInt({ min: msecs.minute, max: 10 * msecs.minute }))
cacheRuleSet(state.ruleset)

// Make sure bravery props are up-to-date with user settings
Expand Down Expand Up @@ -850,7 +850,7 @@ var callback = (err, result, delayTime) => {
console.log('ledger client error(1): ' + JSON.stringify(err, null, 2) + (err.stack ? ('\n' + err.stack) : ''))
if (!client) return

if (typeof delayTime === 'undefined') delayTime = random.randomInt({ min: 1 * msecs.minute, max: 10 * msecs.minute })
if (typeof delayTime === 'undefined') delayTime = random.randomInt({ min: msecs.minute, max: 10 * msecs.minute })
}

if (!result) return run(delayTime)
Expand All @@ -863,7 +863,8 @@ var callback = (err, result, delayTime) => {
}
cacheRuleSet(result.ruleset)

syncWriter(pathName(statePath), result, () => { run(delayTime) })
syncWriter(pathName(statePath), result, () => {})
run(delayTime)
}

var roundtrip = (params, options, callback) => {
Expand Down Expand Up @@ -937,7 +938,7 @@ var roundtrip = (params, options, callback) => {
var runTimeoutId = false

var run = (delayTime) => {
// if (clientOptions.verboseP) console.log('\nledger client run: clientP=' + (!!client) + ' delayTime=' + delayTime)
if (clientOptions.verboseP) console.log('\nledger client run: clientP=' + (!!client) + ' delayTime=' + delayTime)

if ((typeof delayTime === 'undefined') || (!client)) return

Expand Down Expand Up @@ -967,13 +968,13 @@ var run = (delayTime) => {
} catch (ex) {
delayTime = false
}
if (delayTime === false) delayTime = random.randomInt({ min: 1, max: 10 }) * msecs.minute
if (delayTime === false) delayTime = random.randomInt({ min: msecs.minute, max: 10 * msecs.minute })
}
if (delayTime > 0) {
if (runTimeoutId) return console.log('\ninterception')

active = client
if (delayTime > msecs.day) delayTime = msecs.day
if (delayTime > (1 * msecs.hour)) delayTime = random.randomInt({ min: 3 * msecs.minute, max: msecs.hour })

runTimeoutId = setTimeout(() => {
runTimeoutId = false
Expand Down Expand Up @@ -1166,11 +1167,11 @@ var cacheReturnValue = () => {
* low-level utilities
*/

var syncP = {}
var syncingP = {}

var syncWriter = (path, obj, options, cb) => {
if (syncP[path]) return
syncP[path] = true
if (syncingP[path]) return
syncingP[path] = true

if (typeof options === 'function') {
cb = options
Expand All @@ -1179,7 +1180,7 @@ var syncWriter = (path, obj, options, cb) => {
options = underscore.defaults(options || {}, { encoding: 'utf8', mode: parseInt('644', 8) })

fs.writeFile(path, JSON.stringify(obj, null, 2), options, (err) => {
syncP[path] = false
delete syncingP[path]

if (err) console.log('write error: ' + err.toString())

Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@
"immutablepatch": "^0.2.2",
"keytar": "^3.0.0",
"l20n": "^3.5.1",
"ledger-balance": "^0.8.46",
"ledger-client": "^0.8.59",
"ledger-geoip": "https://github.com/brave/ledger-geoip.git",
"ledger-publisher": "^0.8.61",
"ledger-balance": "^0.8.60",
"ledger-client": "^0.8.70",
"ledger-geoip": "^0.8.70",
"ledger-publisher": "^0.8.63",
"lru_cache": "^1.0.0",
"qr-image": "^3.1.0",
"random-lib": "2.1.0",
Expand Down