Skip to content

Commit

Permalink
fix a couple mempool bugs. add js debug logging
Browse files Browse the repository at this point in the history
  • Loading branch information
buck54321 authored and chappjc committed Nov 4, 2019
1 parent 203f793 commit aa01f16
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 8 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ require (
github.com/x-cray/logrus-prefixed-formatter v0.5.2 // indirect
golang.org/x/net v0.0.0-20191028085509-fe3aa8a45271
)

replace github.com/decred/dcrdata/mempool/v5 => ./mempool
1 change: 1 addition & 0 deletions mempool/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ func (p *MempoolMonitor) TxHandler(rawTx *chainjson.TxRawResult) error {
votingInfo := &p.inventory.VotingInfo
if tx.VoteInfo.ForLastBlock && !votingInfo.VotedTickets[tx.VoteInfo.TicketSpent] {
votingInfo.VotedTickets[tx.VoteInfo.TicketSpent] = true
votingInfo.TicketsVoted++
p.inventory.LikelyMineable.VoteTotal += tx.TotalOut
p.inventory.VotingInfo.Tally(tx.VoteInfo)
} else {
Expand Down
14 changes: 13 additions & 1 deletion public/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ async function createWebSocket (loc) {
ws.connect(uri)

var updateBlockData = function (event) {
console.log('Received newblock message', event)
var newBlock = JSON.parse(event)
if (window.loggingDebug) {
console.log('Block received')
console.log(newBlock)
}
newBlock.block.unixStamp = new Date(newBlock.block.time).getTime() / 1000
globalEventBus.publish('BLOCK_RECEIVED', newBlock)
}
Expand All @@ -48,4 +51,13 @@ async function createWebSocket (loc) {
})
}

// Debug logging can be enabled by entering logDebug(true) in the console.
// Your setting will persist across sessions.
window.loggingDebug = window.localStorage.getItem('loggingDebug') === '1'
window.logDebug = yes => {
window.loggingDebug = yes
window.localStorage.setItem('loggingDebug', yes ? '1' : '0')
return 'debug logging set to ' + (yes ? 'true' : 'false')
}

createWebSocket(window.location)
4 changes: 2 additions & 2 deletions public/js/controllers/connection_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class extends Controller {
this.indicatorTarget.classList.remove('hidden')

ws.registerEvtHandler('open', () => {
console.log('Connected')
if (window.loggingDebug) console.log('Connected')
this.updateConnectionStatus('Connected', true)
})

Expand All @@ -26,7 +26,7 @@ export default class extends Controller {
})

ws.registerEvtHandler('ping', (evt) => {
console.debug('ping. users online: ', evt)
if (window.loggingDebug) console.debug('ping. users online: ', evt)
})
}

Expand Down
2 changes: 1 addition & 1 deletion public/js/controllers/homepage_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default class extends Controller {
})
ws.registerEvtHandler('getmempooltxsResp', (evt) => {
var m = JSON.parse(evt)
this.mempool.mergeMempool(m)
this.mempool.replace(m)
this.setMempoolFigures()
this.renderLatestTransactions(m.latest, true)
keyNav(evt, false, true)
Expand Down
2 changes: 1 addition & 1 deletion public/js/controllers/mempool_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export default class extends Controller {
})
ws.registerEvtHandler('getmempooltxsResp', (evt) => {
var m = JSON.parse(evt)
this.mempool.mergeMempool(m)
this.mempool.replace(m)
this.handleTxsResp(m)
this.setMempoolFigures()
this.labelVotes()
Expand Down
4 changes: 2 additions & 2 deletions public/js/helpers/mempool_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ export default class Mempool {
}

initType (txType, total, count, avgSize) {
var fauxVal = total / count
var fauxVal = count === 0 ? 0 : total / count
for (var i = 0; i < count; i++) {
this.mempool.push(makeTx('', txType, fauxVal, null, avgSize))
}
}

initVotes (tallyTargets, total, count, avgSize) {
var fauxVal = total / count
var fauxVal = count === 0 ? 0 : total / count
tallyTargets.forEach((span) => {
let affirmed = parseInt(span.dataset.affirmed)
for (var i = 0; i < parseInt(span.dataset.count); i++) {
Expand Down
3 changes: 2 additions & 1 deletion public/js/services/messagesocket_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ class MessageSocket {
event: eventID,
message: message
})
console.log('send', payload)

if (window.loggingDebug) console.log('send', payload)
this.connection.send(payload)
}

Expand Down

0 comments on commit aa01f16

Please sign in to comment.