-
Notifications
You must be signed in to change notification settings - Fork 11
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
heartbeat + enhanced tests + refactor #57
Conversation
0a35a6f
to
6cad255
Compare
374487c
to
d8bd899
Compare
47b1558
to
e913097
Compare
c10b0c0
to
d9c944f
Compare
d9c944f
to
f1bdb74
Compare
test/integration.js
Outdated
const { balances } = res.validatorMessages[0].msg | ||
const fakeBalances = { "publisher": "3" } | ||
// increase the state tree balance by 1 | ||
let incBalances = {} |
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.
you don't need to increment; the same balances is also a valid state transition, cause it does not violate the OUTPACE rules
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.
check out the comments for the tests: neither of the tests you've changed need to increment the balance tree; transitioning from a balance tree to the same tree is valid in OUTPACE
also heartbeat doesn't seem to be:
- sent from the leader
- checked in the test/integration
06fba82
to
a679855
Compare
routes/channel.js
Outdated
@@ -156,11 +156,14 @@ function isValidatorMsgValid(msg) { | |||
// @TODO either make this more sophisticated, or rewrite this in a type-safe lang | |||
// for example, we should validate if every value in balances is a positive integer | |||
return msg | |||
&& typeof(msg.stateRoot) === 'string' && msg.stateRoot.length == 64 | |||
&& ( | |||
(msg.stateRoot && typeof(msg.stateRoot) === 'string' && msg.stateRoot.length == 64) |
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.
msg.stateRoot check here is redudant - if it's a string and the length is 64, it's certainly truthy
services/validatorWorker/follower.js
Outdated
const producer = require('./producer') | ||
const { heartbeat } = require('./heartbeat') |
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.
should be const heartbeat = require('./heartbeat')
and heartbeat should directly expose heartbeat
, to follow the convention set by producer
, leader
, follower
services/validatorWorker/follower.js
Outdated
.then(function(res){ | ||
// send heartbeat | ||
if(res && res.nothingNew){ | ||
Promise.resolve( |
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.
the new lines here are redundant IMO,
but most importantly, why is heartbeat not returning a promise?
services/validatorWorker/follower.js
Outdated
@@ -58,7 +68,9 @@ function onNewState(adapter, {channel, balances, newMsg, approveMsg}) { | |||
return { nothingNew: true } | |||
} | |||
}) | |||
.then(function(){ | |||
.then(function(res){ | |||
if(res && res.nothingNew) return res |
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 bad, but it can be mitigated by just deleting the second .then
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.
just remove lines 70, 71
@@ -58,7 +68,9 @@ function onNewState(adapter, {channel, balances, newMsg, approveMsg}) { | |||
return { nothingNew: true } |
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.
also the res here from verify()
should be renamed to isValid
}) | ||
} | ||
|
||
module.exports = { heartbeat } |
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.
just module.exports = heartbeat
as the convention from follower/leader/etc.
services/validatorWorker/follower.js
Outdated
.then(function(res){ | ||
// send heartbeat | ||
if(res && res.nothingNew){ | ||
heartbeat(adapter, channel) |
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.
should be return heartbeat
, right?
254acb5
to
1ec4b60
Compare
Fixes #17