Skip to content
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

Merged
merged 14 commits into from Jun 26, 2020
Merged

Conversation

iulianpascalau
Copy link
Contributor

  • 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
@iulianpascalau iulianpascalau self-assigned this Jun 24, 2020
@iulianpascalau iulianpascalau added the type:feature New feature or request label Jun 24, 2020
@sasurobert sasurobert self-requested a review June 24, 2020 13:15
cmd/node/config/ratings.toml Outdated Show resolved Hide resolved
consensus/spos/constants.go Show resolved Hide resolved
process/errors.go Show resolved Hide resolved
process/rating/peerHonesty/peerScore_test.go Outdated Show resolved Hide resolved
process/rating/peerHonesty/peerScore.go Outdated Show resolved Hide resolved
process/rating/peerHonesty/peerScore.go Outdated Show resolved Hide resolved
process/rating/peerHonesty/peerScore.go Outdated Show resolved Hide resolved
process/rating/peerHonesty/peerScore.go Outdated Show resolved Hide resolved
@andreibancioiu andreibancioiu self-requested a review June 24, 2020 18:38
Copy link
Collaborator

@andreibancioiu andreibancioiu left a 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
Copy link
Collaborator

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)
Copy link
Collaborator

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?

Copy link
Contributor Author

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)
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, remoed

phhs.IncreaseCalled(pk, topic, value)
return
}
ChangeScoreCalled func(pk string, topic string, units int)
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved

@@ -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
Copy link
Collaborator

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.

Copy link
Contributor Author

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) {
Copy link
Collaborator

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).

Copy link
Contributor Author

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,
Copy link
Collaborator

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?

Copy link
Contributor Author

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) {
Copy link
Collaborator

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.

Copy link
Contributor Author

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
Copy link
Collaborator

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()
Copy link
Collaborator

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Base automatically changed from add-new-deny-peer-cache to development June 24, 2020 21:51
sasurobert
sasurobert previously approved these changes Jun 25, 2020
andreibancioiu
andreibancioiu previously approved these changes Jun 25, 2020
Copy link
Contributor

@LucianMincu LucianMincu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

System tests passed.

@LucianMincu LucianMincu merged commit 9bf6294 into development Jun 26, 2020
@LucianMincu LucianMincu deleted the peer-honesty-implementation branch June 26, 2020 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants