Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: better accounting and less logs #67

Merged
merged 1 commit into from
Nov 11, 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
19 changes: 10 additions & 9 deletions src/decision/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ module.exports = class Engine {
return Boolean(nextTask)
},
(next) => {
log('got task', nextTask)
log('got task')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no reference of the task?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already so much logging, that's fine. and this version was printing the whole struct which was complete overkill


pull(
this.blockstore.getStream(nextTask.entry.key),
Expand Down Expand Up @@ -121,18 +121,19 @@ module.exports = class Engine {
log.error(`failed to process blocks: ${err.message}`)
}

log('wantlist', Array.from(msg.wantlist.values()).map((e) => e.toString()))
const arrayWantlist = Array.from(msg.wantlist.values())
log('wantlist', arrayWantlist.map((e) => e.toString()))

if (arrayWantlist.length === 0) {
return cb()
}

pull(
pull.values(Array.from(msg.wantlist.values())),
pull.values(arrayWantlist),
pull.asyncMap((entry, cb) => {
this._processWantlist(ledger, peerId, entry, cb)
}),
pull.onEnd((err) => {
if (err) return cb(err)
this._outbox()
cb()
})
pull.onEnd(cb)
)
})
}
Expand All @@ -146,7 +147,6 @@ module.exports = class Engine {
// Check all connected peers if they want the block we received
for (let l of this.ledgerMap.values()) {
const entry = l.wantlistContains(key)

if (entry) {
this.peerRequestQueue.push(entry, l.partner)
}
Expand All @@ -170,6 +170,7 @@ module.exports = class Engine {
} else if (exists) {
log('has want %s', mh.toB58String(entry.key))
this.peerRequestQueue.push(entry.entry, peerId)
this._outbox()
}
cb()
})
Expand Down
13 changes: 7 additions & 6 deletions src/decision/peer-request-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ module.exports = class PeerRequestQueue {
log('taskMap.set', task.key, task.toString())
this.taskMap.set(task.key, task)
partner.requests ++
partner.taskQueue.update(task)
this.pQueue.update(partner)
}

// Get the task with the hightest priority from the queue
pop () {
// log('pop, empty? %s', this.pQueue.isEmpty())
// log('partners', Array.from(this.partners.values()).map((val) => [val.requests, val.taskQueue.size()]))
if (this.pQueue.isEmpty()) return
if (this.pQueue.isEmpty()) {
return
}

let partner = this.pQueue.pop()
let out
Expand All @@ -122,7 +122,6 @@ module.exports = class PeerRequestQueue {
partner.requests --
break
}
// log('pop, out', partner.taskQueue.isEmpty(), out)
this.pQueue.push(partner)
return out
}
Expand All @@ -137,7 +136,9 @@ module.exports = class PeerRequestQueue {
t.trash = true

// having canceled a block, we now account for that in the given partner
this.partners.get(peerId.toB58String()).requests --
const p = this.partners.get(peerId.toB58String())
p.requests --
this.pQueue.update(p)
}

log('taskMap', Array.from(this.taskMap.values()).map((v) => {
Expand Down
2 changes: 0 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ module.exports = class Bitwap {
}

getStream (keys) {
log('getStream', keys.length)
if (!Array.isArray(keys)) {
return this._getStreamSingle(keys)
}
Expand All @@ -180,7 +179,6 @@ module.exports = class Bitwap {
}

_getStreamSingle (key) {
log('getStreamSingle', mh.toB58String(key))
const unwantListeners = {}
const blockListeners = {}
const unwantEvent = (key) => `unwant:${key}`
Expand Down
5 changes: 3 additions & 2 deletions src/wantmanager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ module.exports = class Wantmanager {
}
}),
pull.collect((err, entries) => {
if (err) throw err
if (err) {
throw err
}
// broadcast changes
for (let p of this.peers.values()) {
p.addEntries(entries, false)
Expand Down Expand Up @@ -108,7 +110,6 @@ module.exports = class Wantmanager {

// cancel wanting all of the given keys
cancelWants (keys) {
log('keys', keys)
log('cancel wants: ', keys.map((k) => mh.toB58String(k)))
this._addEntries(keys, true)
}
Expand Down