ethereumclassic / explorer

EthereumClassic Block Explorer
MIT License
263 stars 251 forks source link

Fix `app.js` crashing issues, currently crashes periodically when retrieving hashrate data from minergate #89

Closed pyskell closed 6 years ago

pyskell commented 6 years ago

This is a two-part issue:

Part of an Ecosystem Proposal

hackmod commented 6 years ago

ETC explorer already has hashrate function, routes/stats.js named getHashrate().

else if (req.body.action=="hashrate")
    getHashrate(res);

currently, getHashrate() has some bug.

/**
  Calc difficulty, hashrate from recent blocks in DB
**/
var getHashrate = function(res) {
  var hashFind = BlockStat.find({}, "difficulty blockTime")
                            .lean(true).limit(64).sort('-number');

  // highest difficulty / avg blocktime
  hashFind.exec(function (err, docs) {
    var x = docs.reduce( function(hashR, doc) {
                            return { "blockTime": hashR.blockTime + doc.blockTime,
                                     "difficulty": Math.max(hashR.difficulty, doc.difficulty) }
                                 }, {"blockTime": 0, "difficulty": 0});
    var hashrate = x.difficulty / (1000*x.blockTime / docs.length); // wrong line
    res.write(JSON.stringify({"hashrate": hashrate, "difficulty": x.difficulty}));
    res.end();
  });
}

hashrate in H/s is

    var hashrate = x.difficulty / (x.blockTime / docs.length); // fixed line

PR #91 is a try to using it.

ghost commented 6 years ago

@pyskell Yup. I use systemctl restart-on=failure option in order to solve the problem "temporary" 😄

lowskidev commented 6 years ago

There is no parameter blockTime, so it returns empty array. Last fix should have it working now with out crashing and pulling data into the front end,

hackmod commented 6 years ago

/fiat query emit Error: socket hang up sometimes and cause app.js crashing.

[1] Error: socket hang up
[1]     at createHangUpError (_http_client.js:254:15)
[1]     at Socket.socketOnEnd (_http_client.js:346:23)
[1]     at emitNone (events.js:91:20)
[1]     at Socket.emit (events.js:185:7)
[1]     at endReadableNT (_stream_readable.js:974:12)
[1]     at _combinedTickCallback (internal/process/next_tick.js:80:11)
[1]     at process._tickCallback (internal/process/next_tick.js:104:9)
pyskell commented 6 years ago

Fixed. Thanks everyone!

hackmod commented 6 years ago

There is no parameter blockTime, so it returns empty array.

and now, Block.blockTime column is not used at all.

hackmod commented 6 years ago

Fixed. Thanks everyone!

so. Who got the bounty ? who is bakon?

pyskell commented 6 years ago

Yup, bakon is ethernodeio.

Just FYI proposals are locked-in/signed up for so people avoid duplicating work/competing on changes.

But I also will have more proposals soon 🙂

I'll look into your Block.blockTime comment.