This repository has been archived by the owner on Dec 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 436
block stats / last block #174
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,6 +91,21 @@ module.exports = function(logger, portalConfig, poolConfigs){ | |
}); | ||
} | ||
|
||
// For block stats | ||
this.getBlocksStats = function (cback) { | ||
var client = redisClients[0].client; | ||
client.hgetall("Allblocks", function (error, data) { | ||
if (error) { | ||
logger.log("error:-" + error); | ||
cback(""); | ||
return; | ||
} | ||
|
||
cback(data); | ||
|
||
}); | ||
}; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Results in the same JSON output without adding the
Please give it a try. Note, I changed the function name. |
||
function gatherStatHistory(){ | ||
var retentionTime = (((Date.now() / 1000) - portalConfig.website.stats.historicalRetention) | 0).toString(); | ||
redisStats.zrangebyscore(['statHistory', retentionTime, '+inf'], function(err, replies){ | ||
|
@@ -373,11 +388,13 @@ module.exports = function(logger, portalConfig, poolConfigs){ | |
/* show all pending blocks */ | ||
pending: { | ||
blocks: replies[i + 6].sort(sortBlocks), | ||
lastblock: replies[i + 6].sort(sortBlocks).slice(0,1), | ||
confirms: (replies[i + 9] || {}) | ||
}, | ||
/* show last 5 found blocks */ | ||
confirmed: { | ||
blocks: replies[i + 7].sort(sortBlocks).slice(0,5) | ||
lastblock: replies[i + 7].sort(sortBlocks).slice(0,1) | ||
}, | ||
payments: [], | ||
currentRoundShares: (replies[i + 8] || {}), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like duplicate data in redis that is not required.
To get the last mined block without this duplicate data being stored in redis.
Since pending/confirmed blocks are sorted in newest first order, the last mined block is always first in the array. https://github.com/z-classic/z-nomp/blob/master/libs/stats.js#L375
it.stats.pools[pool].pending.blocks[0]
orit.stats.pools[pool].confirmed.blocks[0]
Example
Some additional checks may be required in case
it.stats.pools[pool].confirmed.blocks
orit.stats.pools[pool].pending.blocks
is undefined. (No pending blocks, etc.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't needed for last block mined, it was something I added to get all blocks from a single api call
The last block is just sort/slice of it.stats.pools[pool.]pending.blocks and confirmed.blocks Didn't think about the if no pending
https://github.com/madbuda/z-nomp-mb/blob/25c761865b1a30cd1a7f286a71fc32cd5f2c364a/libs/stats.js#L391
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is a better way to implement
this.getBlocksStats
api call without double saving the block data in redis. I may have a little time to look at it tonight...