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

Remove redundant P2P interfaces - Closes #4493 #4525

Closed
wants to merge 43 commits into from

Conversation

diego-G
Copy link

@diego-G diego-G commented Nov 18, 2019

How did I solve it?

  • Remove P2PProtocolPeerInfo interface
  • Replace P2PNodeInfo with adjusted P2PSharedState
  • Rename node Info concept to shared state
  • Introduce P2PBasicPeerInfo interface as P2PPeerInfo's parent
  • Rename objects inside the P2PPeerLists interface
  • Replace P2P blacklistedPeers by blacklistedIPs an array of IPs
  • Remove unused own sharedState from P2P peer selection functions
  • Remove redundant advertiseAddress field from P2PInternalState interface
  • Sanitize I/O data inside the P2P library in order to make the usage easier

How to manually test it?

npm t

Review checklist

@diego-G diego-G self-assigned this Nov 18, 2019
@diego-G diego-G changed the title Remove redundant p2p types - Closes #4493 Remove redundant P2P interfaces - Closes #4493 Nov 18, 2019
@diego-G diego-G force-pushed the 4493-remove_redundant_p2p_types branch from d600920 to 4c55aca Compare November 18, 2019 15:06
@LiskHQ LiskHQ deleted a comment from diego-G Nov 18, 2019
@valamidev valamidev self-requested a review November 21, 2019 08:33
@diego-G diego-G force-pushed the 4493-remove_redundant_p2p_types branch from 7030c74 to c557b47 Compare November 21, 2019 10:43
It is useful to receive sharedState on every Peer class from the
config and keep it updated in a separate variable.
@diego-G diego-G force-pushed the 4493-remove_redundant_p2p_types branch from c557b47 to 0de5dfe Compare November 21, 2019 10:58
}

export interface P2PPeerInfo {
export interface P2PBasicPeerInfo {
Copy link
Member

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

Copy link
Author

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 {
Copy link
Member

Choose a reason for hiding this comment

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

This is like P2PDisocveredPeerInfo

Copy link
Author

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.

Copy link
Member

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

Copy link
Author

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;
Copy link
Member

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

Copy link
Author

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.

Copy link
Member

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

elements/lisk-p2p/src/p2p_types.ts Show resolved Hide resolved
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';
Copy link
Member

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;
Copy link
Member

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 {
Copy link
Member

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 {
Copy link
Member

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> {
Copy link
Member

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;
Copy link
Member

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;
Copy link
Member

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;
Copy link
Member

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;
Copy link
Member

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 {
Copy link
Member

Choose a reason for hiding this comment

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

same as above

@diego-G diego-G closed this Nov 25, 2019
@shuse2 shuse2 deleted the 4493-remove_redundant_p2p_types branch January 17, 2020 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove interface ProtocolPeerInfo from P2P
6 participants