Skip to content

Commit afd1512

Browse files
authored
refactor(core-p2p): add internal contracts and delete obsolete ones
1 parent 0a4a659 commit afd1512

File tree

14 files changed

+67
-120
lines changed

14 files changed

+67
-120
lines changed

packages/core-kernel/src/contracts/p2p/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
export * from "./index";
22
export * from "./network-monitor";
33
export * from "./network-state";
4-
export * from "./peer-communicator";
5-
export * from "./peer-connector";
6-
export * from "./peer-processor";
74
export * from "./peer-storage";
85
export * from "./peer-verifier";
96
export * from "./peer";

packages/core-kernel/src/contracts/p2p/network-monitor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ export interface INetworkMonitor {
3535
syncWithNetwork(fromBlockHeight: number, maxParallelDownloads?: number): Promise<Interfaces.IBlockData[]>;
3636
broadcastBlock(block: Interfaces.IBlock): Promise<void>;
3737
broadcastTransactions(transactions: Interfaces.ITransaction[]): Promise<void>;
38-
getServer(): SocketCluster;
39-
setServer(server: SocketCluster): void;
38+
getServer(): SocketCluster; // remove this
39+
setServer(server: SocketCluster): void; // remove this
4040
isColdStart(): boolean;
4141
completeColdStart(): void;
4242
stopServer(): void;

packages/core-kernel/src/contracts/p2p/network-state.ts

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -12,49 +12,3 @@ export interface NetworkState {
1212
getOverHeightBlockHeaders();
1313
toJson();
1414
}
15-
16-
export interface QuorumDetails {
17-
/**
18-
* Number of peers on same height, with same block and same slot. Used for
19-
* quorum calculation.
20-
*/
21-
peersQuorum: number;
22-
23-
/**
24-
* Number of peers which do not meet the quorum requirements. Used for
25-
* quorum calculation.
26-
*/
27-
peersNoQuorum: number;
28-
29-
/**
30-
* Number of overheight peers.
31-
*/
32-
peersOverHeight: number;
33-
34-
/**
35-
* All overheight block headers grouped by id.
36-
*/
37-
peersOverHeightBlockHeaders: { [id: string]: any };
38-
39-
/**
40-
* The following properties are not mutual exclusive for a peer
41-
* and imply a peer is on the same `nodeHeight`.
42-
*/
43-
44-
/**
45-
* Number of peers that are on a different chain (forked).
46-
*/
47-
peersForked: number;
48-
49-
/**
50-
* Number of peers with a different slot.
51-
*/
52-
peersDifferentSlot: number;
53-
54-
/**
55-
* Number of peers where forging is not allowed.
56-
*/
57-
peersForgingNotAllowed: number;
58-
59-
getQuorum(): number;
60-
}

packages/core-kernel/src/contracts/p2p/peer-communicator.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.

packages/core-kernel/src/contracts/p2p/peer-connector.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

packages/core-kernel/src/contracts/p2p/peer-processor.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

packages/core-p2p/src/event-listener.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { Container, Contracts } from "@arkecosystem/core-kernel";
22

3+
import { PeerConnector } from "./peer-connector";
4+
35
// todo: review the implementation
46
@Container.injectable()
57
export class EventListener {
68
@Container.inject(Container.Identifiers.EventDispatcherService)
79
private readonly emitter!: Contracts.Kernel.Events.EventDispatcher;
810

911
@Container.inject(Container.Identifiers.PeerConnector)
10-
private readonly connector!: Contracts.P2P.PeerConnector;
12+
private readonly connector!: PeerConnector;
1113

1214
@Container.inject(Container.Identifiers.PeerStorage)
1315
private readonly storage!: Contracts.P2P.PeerStorage;

packages/core-p2p/src/network-monitor.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import SocketCluster from "socketcluster";
55

66
import { PeerData } from "./interfaces";
77
import { NetworkState } from "./network-state";
8+
import { PeerCommunicator } from "./peer-communicator";
9+
import { PeerProcessor } from "./peer-processor";
810
import { RateLimiter } from "./rate-limiter";
911
import { checkDNS, checkNTP } from "./utils";
1012
import { buildRateLimiter } from "./utils/build-rate-limiter";
@@ -29,10 +31,10 @@ export class NetworkMonitor implements Contracts.P2P.INetworkMonitor {
2931
private readonly emitter!: Contracts.Kernel.Events.EventDispatcher;
3032

3133
@Container.inject(Container.Identifiers.PeerCommunicator)
32-
private readonly communicator!: Contracts.P2P.PeerCommunicator;
34+
private readonly communicator!: PeerCommunicator;
3335

3436
@Container.inject(Container.Identifiers.PeerProcessor)
35-
private readonly processor!: Contracts.P2P.PeerProcessor;
37+
private readonly processor!: PeerProcessor;
3638

3739
@Container.inject(Container.Identifiers.PeerStorage)
3840
private readonly storage!: Contracts.P2P.PeerStorage;

packages/core-p2p/src/network-state.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,47 @@ import { Crypto, Interfaces } from "@arkecosystem/crypto";
33

44
import { NetworkStateStatus } from "./enums";
55

6-
class QuorumDetails implements Contracts.P2P.QuorumDetails {
6+
class QuorumDetails {
7+
/**
8+
* Number of peers on same height, with same block and same slot. Used for
9+
* quorum calculation.
10+
*/
711
public peersQuorum = 0;
12+
13+
/**
14+
* Number of peers which do not meet the quorum requirements. Used for
15+
* quorum calculation.
16+
*/
817
public peersNoQuorum = 0;
18+
19+
/**
20+
* Number of overheight peers.
21+
*/
922
public peersOverHeight = 0;
23+
24+
/**
25+
* All overheight block headers grouped by id.
26+
*/
1027
public peersOverHeightBlockHeaders: { [id: string]: any } = {};
28+
29+
/**
30+
* The following properties are not mutual exclusive for a peer
31+
* and imply a peer is on the same `nodeHeight`.
32+
*/
33+
34+
/**
35+
* Number of peers that are on a different chain (forked).
36+
*/
1137
public peersForked = 0;
38+
39+
/**
40+
* Number of peers with a different slot.
41+
*/
1242
public peersDifferentSlot = 0;
43+
44+
/**
45+
* Number of peers where forging is not allowed.
46+
*/
1347
public peersForgingNotAllowed = 0;
1448

1549
public getQuorum() {

packages/core-p2p/src/peer-communicator.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ import { SCClientSocket } from "socketcluster-client";
66
import { SocketErrors } from "./enums";
77
import { PeerPingTimeoutError, PeerStatusResponseError, PeerVerificationFailedError } from "./errors";
88
import { PeerConfig, PeerPingResponse } from "./interfaces";
9+
import { PeerConnector } from "./peer-connector";
910
import { PeerVerifier } from "./peer-verifier";
1011
import { createSchemas } from "./schemas";
1112
import { isValidVersion, socketEmit } from "./utils";
1213

1314
// todo: review the implementation
1415
@Container.injectable()
15-
export class PeerCommunicator implements Contracts.P2P.PeerCommunicator {
16+
export class PeerCommunicator {
1617
@Container.inject(Container.Identifiers.Application)
1718
private readonly app!: Contracts.Kernel.Application;
1819

@@ -23,7 +24,7 @@ export class PeerCommunicator implements Contracts.P2P.PeerCommunicator {
2324
private readonly emitter!: Contracts.Kernel.Events.EventDispatcher;
2425

2526
@Container.inject(Container.Identifiers.PeerConnector)
26-
private readonly connector!: Contracts.P2P.PeerConnector;
27+
private readonly connector!: PeerConnector;
2728

2829
public async downloadBlocks(peer: Contracts.P2P.Peer, fromBlockHeight: number): Promise<Interfaces.IBlockData[]> {
2930
this.logger.debug(`Downloading blocks from height ${fromBlockHeight.toLocaleString()} via ${peer.ip}`);

0 commit comments

Comments
 (0)