Skip to content

Commit

Permalink
chore: update libp2p modules
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed Apr 29, 2021
1 parent caf0f4a commit d1b89a1
Show file tree
Hide file tree
Showing 23 changed files with 3,410 additions and 3,744 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2-beta
with:
node-version: "12.14.1"
node-version: "14.16.1"
- name: Restore dependencies
uses: actions/cache@master
id: cache-deps
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
- name: Setup Nodejs
uses: actions/setup-node@v1
with:
node-version: "12.x"
node-version: "14.x"
registry-url: "https://registry.npmjs.org"

- name: Restore dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-sim.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2-beta
with:
node-version: "12.14.1"
node-version: "14.16.1"
- name: Restore dependencies
uses: actions/cache@master
id: cache-deps
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2-beta
with:
node-version: "12.14.1"
node-version: "14.16.1"
# As of October 2020, runner has +8GB of free space w/out this script (takes 1m30s to run)
# - run: ./scripts/free-disk-space.sh
- name: Restore dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2-beta
with:
node-version: "12.14.1"
node-version: "14.16.1"
- name: Restore dependencies
uses: actions/cache@master
id: cache-deps
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"@chainsafe/bls-keygen": "^0.3.0",
"@chainsafe/bls-keystore": "2.0.0",
"@chainsafe/blst": "^0.2.0",
"@chainsafe/discv5": "^0.5.1",
"@chainsafe/discv5": "vasco-santos/discv5#chore/update-deps-with-dist",
"@chainsafe/lodestar": "^0.20.0",
"@chainsafe/lodestar-beacon-state-transition": "^0.20.0",
"@chainsafe/lodestar-config": "^0.20.0",
Expand Down
1 change: 1 addition & 0 deletions packages/db/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"@chainsafe/lodestar-config": "^0.20.0",
"@chainsafe/lodestar-utils": "^0.20.0",
"@chainsafe/ssz": "^0.8.2",
"@types/levelup": "^4.3.1",
"it-all": "^1.0.2",
"level": "^6.0.1",
"levelup": "^4.4.0"
Expand Down
21 changes: 10 additions & 11 deletions packages/lodestar/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
},
"dependencies": {
"@chainsafe/bls": "6.0.0",
"@chainsafe/discv5": "^0.5.1",
"@chainsafe/discv5": "vasco-santos/discv5#chore/update-deps-with-dist",
"@chainsafe/lodestar-beacon-state-transition": "^0.20.0",
"@chainsafe/lodestar-config": "^0.20.0",
"@chainsafe/lodestar-db": "^0.20.0",
Expand All @@ -59,30 +59,29 @@
"@chainsafe/snappy-stream": "3.0.5",
"@chainsafe/ssz": "^0.8.2",
"@ethersproject/abi": "^5.0.0",
"@types/datastore-level": "^1.1.1",
"abort-controller": "^3.0.0",
"bl": "^4.0.2",
"cross-fetch": "^3.0.6",
"datastore-level": "^2.0.0",
"datastore-level": "^5.0.1",
"deepmerge": "^3.2.0",
"es6-promisify": "6.0.2",
"fastify": "2.15.3",
"fastify-cors": "^3.0.3",
"fastify-sse-v2": "^1.0.7",
"gc-stats": "^1.4.0",
"http-terminator": "^2.0.3",
"interface-datastore": "^2.0.0",
"interface-datastore": "^4.0.0",
"it-all": "^1.0.2",
"it-pipe": "^1.1.0",
"libp2p": "^0.30.2",
"libp2p-bootstrap": "^0.12.1",
"libp2p-gossipsub": "^0.8.0",
"libp2p-interfaces": "^0.8.3",
"libp2p-mdns": "^0.15.0",
"libp2p": "libp2p/js-libp2p#fix/event-emitter-types-with-local-types-dist",
"libp2p-bootstrap": "^0.12.3",
"libp2p-gossipsub": "ChainSafe/js-libp2p-gossipsub#test/interfaces-fix",
"libp2p-interfaces": "libp2p/js-libp2p-interfaces#fix/event-emitter-with-local-types-dist",
"libp2p-mdns": "^0.16.0",
"libp2p-mplex": "^0.10.1",
"libp2p-noise": "^2.0.5",
"libp2p-noise": "^3.0.0",
"libp2p-tcp": "^0.15.3",
"multiaddr": "^8.1.2",
"multiaddr": "^9.0.0",
"peer-id": "^0.14.3",
"prom-client": "^13.1.0",
"prometheus-gc-stats": "^0.6.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/lodestar/src/network/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import {Connection} from "libp2p";
import {ENR} from "@chainsafe/discv5/lib";
import Multiaddr from "multiaddr";
import { Multiaddr } from "multiaddr";
import PeerId from "peer-id";
import {INetworkEventBus} from "./events";
import {Eth2Gossipsub} from "./gossip";
Expand Down
2 changes: 1 addition & 1 deletion packages/lodestar/src/network/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import LibP2p, {Connection} from "libp2p";
import PeerId from "peer-id";
import Multiaddr from "multiaddr";
import { Multiaddr } from "multiaddr";
import {IBeaconConfig} from "@chainsafe/lodestar-config";
import {ILogger} from "@chainsafe/lodestar-utils";
import {IMetrics} from "../metrics";
Expand Down
4 changes: 2 additions & 2 deletions packages/lodestar/src/network/nodejs/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Bootstrap from "libp2p-bootstrap";
import MDNS from "libp2p-mdns";
import PeerId from "peer-id";
import {ENRInput, Discv5Discovery} from "@chainsafe/discv5";
import {Adapter} from "interface-datastore";
import { Datastore } from "interface-datastore";

export interface ILibp2pOptions {
peerId: PeerId;
Expand All @@ -19,7 +19,7 @@ export interface ILibp2pOptions {
announce?: string[];
noAnnounce?: string[];
};
datastore?: Adapter;
datastore?: Datastore;
discv5: {
bindAddr: string;
enr: ENRInput;
Expand Down
24 changes: 0 additions & 24 deletions packages/lodestar/src/network/reqresp/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,3 @@ export type RequestOrResponseType = Exclude<
>;

export type RequestOrResponseBody = phase0.ResponseBody | phase0.RequestBody;

/**
* Stream types from libp2p.dialProtocol are too vage and cause compilation type issues
* These source and sink types are more precise to our usage
*/
export interface ILibP2pStream {
source: AsyncIterable<Buffer>;
sink: (source: AsyncIterable<Buffer>) => Promise<void>;
/**
* `libp2p-mplex`: Close for reading
* ```ts
* () => stream.source.end()
* ```
*/
close: () => void;
/**
* `libp2p-mplex`: Close immediately for reading and writing (remote error)
*/
reset: () => void;
/**
* `libp2p-mplex`: Close for reading and writing (local error)
*/
abort: (err: Error) => void;
}
6 changes: 3 additions & 3 deletions packages/lodestar/src/network/reqresp/reqResp.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/**
* @module network
*/
import {Connection} from "libp2p";
import {HandlerProps} from "libp2p";
import {IBeaconConfig} from "@chainsafe/lodestar-config";
import {phase0} from "@chainsafe/lodestar-types";
import {ILogger} from "@chainsafe/lodestar-utils";
import {AbortController} from "abort-controller";
import LibP2p from "libp2p";
import PeerId from "peer-id";
import {IReqResp, IReqRespModules, ILibP2pStream} from "./interface";
import {IReqResp, IReqRespModules} from "./interface";
import {sendRequest} from "./request";
import {handleRequest} from "./response";
import {Method, ReqRespEncoding, timeoutOptions} from "../../constants";
Expand Down Expand Up @@ -59,7 +59,7 @@ export class ReqResp implements IReqResp {
for (const encoding of Object.values(ReqRespEncoding)) {
this.libp2p.handle(
createRpcProtocol(method, encoding),
async ({connection, stream}: {connection: Connection; stream: ILibP2pStream}) => {
async ({ connection, stream }: HandlerProps) => {
const peerId = connection.remotePeer;

// TODO: Do we really need this now that there is only one encoding?
Expand Down
10 changes: 5 additions & 5 deletions packages/lodestar/src/network/reqresp/request/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import LibP2p, {Connection} from "libp2p";
import LibP2p from "libp2p";
import {AbortSignal} from "abort-controller";
import pipe from "it-pipe";
import PeerId from "peer-id";
Expand All @@ -10,7 +10,7 @@ import {createRpcProtocol, getAgentVersionFromPeerStore, prettyPrintPeerId} from
import {ResponseError} from "../response";
import {requestEncode} from "../encoders/requestEncode";
import {responseDecode} from "../encoders/responseDecode";
import {ILibP2pStream} from "../interface";
import {MuxedStream} from "libp2p-interfaces/src/stream-muxer/types";
import {collectResponses} from "./collectResponses";
import {maxTotalResponseTimeout, responseTimeoutsHandler} from "./responseTimeoutsHandler";
import {
Expand Down Expand Up @@ -72,11 +72,11 @@ export async function sendRequest<T extends phase0.ResponseBody | phase0.Respons
// DIAL_TIMEOUT: Non-spec timeout from dialing protocol until stream opened
const stream = await withTimeout(
async (timeoutAndParentSignal) => {
const conn = (await libp2p.dialProtocol(peerId, protocol, {signal: timeoutAndParentSignal})) as Connection;
const conn = (await libp2p.dialProtocol(peerId, protocol, {signal: timeoutAndParentSignal}));
if (!conn) throw Error("dialProtocol timeout");
// TODO: libp2p-ts type Stream does not declare .abort() and requires casting to unknown here
// Remove when https://github.com/ChainSafe/lodestar/issues/2167
return ((conn as unknown) as {stream: ILibP2pStream}).stream;
return ((conn as unknown) as { stream: MuxedStream}).stream;
},
DIAL_TIMEOUT,
signal
Expand All @@ -101,7 +101,7 @@ export async function sendRequest<T extends phase0.ResponseBody | phase0.Respons
signal
).catch((e) => {
// Must close the stream read side (stream.source) manually AND the write side
stream.abort(e);
stream.abort();

if (e instanceof TimeoutError) {
throw new RequestInternalError({code: RequestErrorCode.REQUEST_TIMEOUT});
Expand Down
10 changes: 5 additions & 5 deletions packages/lodestar/src/network/reqresp/response/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {Context, ILogger, TimeoutError, withTimeout} from "@chainsafe/lodestar-u
import {phase0} from "@chainsafe/lodestar-types";
import {Method, ReqRespEncoding, REQUEST_TIMEOUT, RpcResponseStatus} from "../../../constants";
import {onChunk} from "../utils/onChunk";
import {ILibP2pStream} from "../interface";
import {MuxedStream} from "libp2p-interfaces/src/stream-muxer/types";
import {requestDecode} from "../encoders/requestDecode";
import {responseEncodeError, responseEncodeSuccess} from "../encoders/responseEncode";
import {ResponseError} from "./errors";
Expand Down Expand Up @@ -34,7 +34,7 @@ export type PerformRequestHandler = (
export async function handleRequest(
{config, logger, libp2p}: {config: IBeaconConfig; logger: ILogger; libp2p: Libp2p},
performRequestHandler: PerformRequestHandler,
stream: ILibP2pStream,
stream: MuxedStream,
peerId: PeerId,
method: Method,
encoding: ReqRespEncoding,
Expand All @@ -51,7 +51,7 @@ export async function handleRequest(
// in case request whose body is a List fails at chunk_i > 0, without breaking out of the for..await..of
(async function* () {
try {
const requestBody = await withTimeout(
const requestBody = (await withTimeout(
() => pipe(stream.source, requestDecode(config, method, encoding)),
REQUEST_TIMEOUT,
signal
Expand All @@ -61,9 +61,9 @@ export async function handleRequest(
} else {
throw new ResponseError(RpcResponseStatus.INVALID_REQUEST, (e as Error).message);
}
});
})) as phase0.BeaconBlocksByRootRequest;

logger.debug("Resp received request", {...logCtx, requestBody} as Context);
logger.debug("Resp received request", { ...logCtx, requestBody } as unknown as Context);

yield* pipe(
performRequestHandler(method, requestBody, peerId),
Expand Down
6 changes: 5 additions & 1 deletion packages/lodestar/src/network/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import PeerId from "peer-id";
import {Method, MethodResponseType, Methods, ReqRespEncoding, RequestId} from "../constants";
import Multiaddr from "multiaddr";
import { Multiaddr } from "multiaddr";
import {networkInterfaces} from "os";
import {ENR} from "@chainsafe/discv5";
import MetadataBook from "libp2p/src/peer-store/metadata-book";
Expand Down Expand Up @@ -77,6 +77,10 @@ export function isLocalMultiAddr(multiaddr: Multiaddr | undefined): boolean {
const family = isIPv4 ? "IPv4" : "IPv6";
const ip = tuples[0][1];

if (!ip) {
return false
}

const ipStr = isIPv4
? Array.from(ip).join(".")
: Array.from(Uint16Array.from(ip))
Expand Down
Loading

0 comments on commit d1b89a1

Please sign in to comment.