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
Remove redundant P2P interfaces - Closes #4493 #4525
Conversation
As result, there is no need to sanitize any IncomingPeerInfo.
- P2PPeerInfo.sharedState becomes non-optional - wsPort field appears as non-optional field of P2PSharedState
d600920
to
4c55aca
Compare
7030c74
to
c557b47
Compare
c557b47
to
0de5dfe
Compare
} | ||
|
||
export interface P2PPeerInfo { | ||
export interface P2PBasicPeerInfo { |
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.
We are falling back to old p2p types that we removed i.e., having two 2 peer types for holding peer information
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've added P2PBasicPeerInfo
because it is handy inside the PeerBook
to get and remove peers by peer id and ip. We don't have peer info splitted into different places. P2PPeerInfo
is the only one with a proper structure.
readonly wsPort: number; | ||
// tslint:disable-next-line: no-mixed-interface | ||
readonly [key: string]: unknown; | ||
export interface P2PPeerInfo extends P2PBasicPeerInfo { |
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 is like P2PDisocveredPeerInfo
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.
Can you elaborate a bit more? P2PDiscoveredPeerInfo
doesn't exist anymore.
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 meant that we had this old types -> new types
P2PPeerInfo
-> P2PBasicPeerInfo
P2PDiscoveredInfo
-> P2PPeerInfo
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.
They weren't exactly the same. P2PPeerInfo
contains now basic, shared and internal data.
readonly fixedPeers?: ReadonlyArray<ProtocolPeerInfo>; | ||
readonly whitelistedPeers?: ReadonlyArray<ProtocolPeerInfo>; | ||
readonly previousPeers?: ReadonlyArray<ProtocolPeerInfo>; | ||
readonly sharedState: P2PSharedState; |
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.
IMO, nodeInfo
is still sounds more clear than sharedState
. Having a distinction between nodeInfo and peerInfo is important because in future if we will have more fields like advertiseAddress
then it will be hard to incorporate, maybe now they seem almost the same but still they are different
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.
What is nodeInfo
for us, we share it to the rest of peers becoming sharedState
when they receive it. I don't think there is a strong reasoning to keep this distinction. If more fields appear, sharedState
will be the place to hold this information locally, the structure to share it and also to receive it. It just looks 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.
agree with @ishantiw , This is not really shared
as mentioned above.
prefer nodeInfo
export const EVENT_FAILED_TO_SEND_MESSAGE = 'failedToSendMessage'; | ||
|
||
// Peer base | ||
export const REMOTE_SC_EVENT_RPC_REQUEST = 'rpc-request'; | ||
export const REMOTE_SC_EVENT_MESSAGE = 'remote-message'; | ||
export const REMOTE_EVENT_POST_NODE_INFO = 'postNodeInfo'; |
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.
these name cannot be changed. It's defined in the LIP
@@ -200,14 +201,14 @@ export class P2P extends EventEmitter { | |||
private readonly _bannedPeers: Set<string>; | |||
private readonly _populatorInterval: number; | |||
private _populatorIntervalId: NodeJS.Timer | undefined; | |||
private _nodeInfo: P2PNodeInfo; | |||
private _sharedState: P2PSharedState; |
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 _nodeInfo
make more sense as variable name
? this._config.maxPeerInfoSize | ||
: DEFAULT_MAX_PEER_INFO_SIZE, | ||
); | ||
public applySharedState(sharedState: P2PSharedState): void { |
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 also should be NodeInfo
. It is SharingState
not SharedState
} | ||
|
||
public get nodeInfo(): P2PNodeInfo { | ||
return this._nodeInfo; | ||
public get sharedState(): P2PSharedState { |
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 here. The meaning is opposite
@@ -546,38 +521,35 @@ export class P2P extends EventEmitter { | |||
} | |||
} | |||
|
|||
public getTriedPeers(): ReadonlyArray<ProtocolPeerInfo> { | |||
public getTriedPeers(): ReadonlyArray<P2PPeerInfo> { |
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.
we still have P2PPeerInfo
?
readonly fixedPeers?: ReadonlyArray<ProtocolPeerInfo>; | ||
readonly whitelistedPeers?: ReadonlyArray<ProtocolPeerInfo>; | ||
readonly previousPeers?: ReadonlyArray<ProtocolPeerInfo>; | ||
readonly sharedState: P2PSharedState; |
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.
agree with @ishantiw , This is not really shared
as mentioned above.
prefer nodeInfo
@@ -105,13 +106,10 @@ export interface PeerConfig { | |||
readonly maxPeerInfoSize: number; | |||
readonly maxPeerDiscoveryResponseLength: number; | |||
readonly secret: number; | |||
readonly serverNodeInfo?: P2PNodeInfo; | |||
readonly sharedState: P2PSharedState; |
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 here
this._id = peerInfo.peerId; | ||
this._info = peerInfo; | ||
this._config = peerConfig; | ||
this._sharedState = peerConfig.sharedState; |
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.
having _id
_wsPort
and _ipAddress
as parameter make sense as base peer i think
@@ -135,6 +137,7 @@ export interface PeerPoolConfig { | |||
readonly rateCalculationInterval: number; | |||
readonly secret: number; | |||
readonly peerLists: PeerLists; | |||
readonly sharedState: P2PSharedState; |
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 above
@@ -629,29 +624,32 @@ export class PeerPool extends EventEmitter { | |||
return openOutboundSlots; | |||
} | |||
|
|||
private _applyNodeInfoOnPeer(peer: Peer, nodeInfo: P2PNodeInfo): void { | |||
private _sendSharedStateToPeer(peer: Peer): void { |
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 above
How did I solve it?
P2PProtocolPeerInfo
interfaceP2PNodeInfo
with adjustedP2PSharedState
P2PBasicPeerInfo
interface asP2PPeerInfo's
parentP2PPeerLists
interfaceblacklistedPeers
byblacklistedIPs
an array of IPsadvertiseAddress
field fromP2PInternalState
interfaceHow to manually test it?
npm t
Review checklist