-
Notifications
You must be signed in to change notification settings - Fork 204
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
Fix network sharding eclipse attack #1201
Fix network sharding eclipse attack #1201
Conversation
cmd/node/config/config.toml
Outdated
@@ -227,16 +227,29 @@ | |||
Size = 75000 | |||
Type = "LRU" | |||
|
|||
[PublicKeyShardId] | |||
#PublicKeyShardId represents the main cache used to map Elrond block signing public keys to their associated |
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.
PublicKeyShardId -> PublicKeyPeerID
The long explanation of the logic behind this parameter is unnecessary here, please keep it simple
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
} | ||
|
||
func (pq *pidQueue) pop() p2p.PeerID { | ||
evicted := pq.data[0] |
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.
there is no len check, this could give index out of bounds
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.
in order to keep this unexported struct as simple as possible, the check has been introduced before calling pop (UpdatePeerIdPublicKey function, L179)
@@ -76,6 +90,7 @@ func (psm *PeerShardMapper) byIDWithNodesCoordinator(pid p2p.PeerID) (shardId ui | |||
|
|||
pkBuff, ok := pkObj.([]byte) | |||
if !ok { | |||
psm.peerIdPk.Remove([]byte(pid)) |
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.
why is this getter doing a remove?
please don't change values in getters.
this change is also done without acquiring the mutex which will lead to race conditions.
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.
removed, added log.Warn as it is a programming error
@@ -99,6 +114,7 @@ func (psm *PeerShardMapper) byIDSearchingPkInFallbackCache(pkBuff []byte) (shard | |||
|
|||
shard, ok := shardObj.(uint32) | |||
if !ok { | |||
psm.fallbackPkShard.Remove(pkBuff) |
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.
same as previous comment
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.
removed, added log.Warn as it is a programming error
@@ -113,15 +129,86 @@ func (psm *PeerShardMapper) byIDSearchingPidInFallbackCache(pid p2p.PeerID) (sha | |||
|
|||
shard, ok := shardObj.(uint32) | |||
if !ok { | |||
psm.fallbackPidShard.Remove([]byte(pid)) |
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.
same as previous comment, please do not remove on getter
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.
removed, added log.Warn as it is a programming error
} | ||
|
||
idxPid := pq.indexOf(pid) | ||
if idxPid > -1 { |
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.
please create a constant for -1 e.g idxNotFound and check against that ( != idxNotFound ).
you can also use maxint and make the type unsigned.
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, added const
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.
only what Adi said.
…at should not happen
No description provided.