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
Peer honesty implementation #2008
Conversation
iulianpascalau
commented
Jun 24, 2020
- added peer honesty implementation able to black list a public key if it insists to send bad messages. This is done currently only on consensus topic, other topics will follow.
- consensus now do not count messages in antiflood instance as it does not require to do so due to the improved filtering mechanism and peer honesty tracking process
…f it insists to send bad messages. This is done currently only on consensus topic, other topics will follow. - consensus now do not count messages in antiflood instance as it does not require to do so due to the improved filtering mechanism and peer honesty tracking process
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.
Nice implementation of scoring, and good tests with high coverage.
#for the current settings, a pk will reach to value 0 after maximum 2h (if it stopped misbehaving or stopped sending good messages) | ||
DecayCoefficient = 0.9779 | ||
DecayUpdateIntervalInSeconds = 10 | ||
MaxScore = 100 |
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.
Nice that we have both positive and negative scores plus something neutral.
IncreaseCalled func(pk string, topic string, value float64) | ||
DecreaseCalled func(pk string, topic string, value float64) | ||
ChangeScoreCalled func(pk string, topic string, units int) | ||
DecreaseCalled func(pk string, topic string, value float64) |
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.
Perhaps DecreaseCalled
can be removed now?
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.
done
// ChangeScore - | ||
func (phhs *PeerHonestyHandlerStub) ChangeScore(pk string, topic string, units int) { | ||
if phhs.ChangeScoreCalled != nil { | ||
phhs.ChangeScoreCalled(pk, topic, units) |
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.
Not sure why the return statement below.
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.
done, remoed
node/mock/peerHonestyHandlerStub.go
Outdated
phhs.IncreaseCalled(pk, topic, value) | ||
return | ||
} | ||
ChangeScoreCalled func(pk string, topic string, units int) |
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.
It's possible to move the stubs to testscommon
if they are identical - although sometimes we do not want that.
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.
moved
process/errors.go
Outdated
@@ -808,3 +808,24 @@ var ErrInvalidUserNameLength = errors.New("invalid user name length") | |||
|
|||
// ErrTxValueOutOfBounds signals that transaction value is out of bounds | |||
var ErrTxValueOutOfBounds = errors.New("tx value is out of bounds") | |||
|
|||
// ErrNilBlackListedPkCache signals that a nil black listed public key cache |
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.
signals that
- comment is missing the predicate.
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.
done
return | ||
} | ||
|
||
if pph.blackListedPkCache.Has(ps.pk) { |
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.
So we do not extend the stay in the black list
period for already-blacklisted peers even if shouldBlacklist == true
, right? Well, it makes sense since a blacklisted peer can't misbehave anymore anyway - at least not with effect (I am just thinking out loud).
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.
exactly, since this is checked on each 10 seconds or so, it will prolong the blacklisted status beyond easy understanding of this mechanism
// createMockPeerHonestyConfig creates a peer honesty config with reasonable values | ||
func createMockPeerHonestyConfig() config.PeerHonestyConfig { | ||
return config.PeerHonestyConfig{ | ||
DecayCoefficient: 0.9995, |
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 know I am exaggerating here, but can you use the same value as the one from config.toml
perhaps?
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.
done
assert.Nil(t, err) | ||
} | ||
|
||
func TestP2pPeerHonesty_Close(t *testing.T) { |
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 test is not very short (in duration) - just a remark.
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 know, shortened
@@ -0,0 +1,418 @@ | |||
package peerHonesty |
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.
👍 Tests cover everything with the exception of impossible cases (bad casts etc.).
pph.Put(pks[idx], topic, initial[idx]) | ||
} | ||
|
||
pph.applyDecay() |
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.
Perhaps add an extra test that calls applyDecay
a lot of times, just to assert that all scores go to zero?
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.
done
…ndNetwork/elrond-go into peer-honesty-implementation
9a24c20
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.
System tests passed.