@lodestar/reqresp 1.8.0 → 1.9.0-dev.b90a09c997
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -7
- package/lib/ReqResp.d.ts +7 -7
- package/lib/ReqResp.js +1 -1
- package/lib/ReqResp.js.map +1 -1
- package/lib/encoders/requestDecode.d.ts +2 -2
- package/lib/encoders/requestDecode.js +3 -3
- package/lib/encoders/requestDecode.js.map +1 -1
- package/lib/encoders/requestEncode.d.ts +2 -2
- package/lib/encoders/requestEncode.js +2 -4
- package/lib/encoders/requestEncode.js.map +1 -1
- package/lib/encoders/responseDecode.d.ts +4 -4
- package/lib/encoders/responseDecode.js +7 -2
- package/lib/encoders/responseDecode.js.map +1 -1
- package/lib/encoders/responseEncode.d.ts +3 -3
- package/lib/encoders/responseEncode.js +3 -31
- package/lib/encoders/responseEncode.js.map +1 -1
- package/lib/encodingStrategies/index.d.ts +3 -3
- package/lib/encodingStrategies/index.js +2 -2
- package/lib/encodingStrategies/index.js.map +1 -1
- package/lib/encodingStrategies/sszSnappy/decode.d.ts +3 -3
- package/lib/encodingStrategies/sszSnappy/decode.js +1 -14
- package/lib/encodingStrategies/sszSnappy/decode.js.map +1 -1
- package/lib/encodingStrategies/sszSnappy/encode.d.ts +1 -2
- package/lib/encodingStrategies/sszSnappy/encode.js +2 -23
- package/lib/encodingStrategies/sszSnappy/encode.js.map +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.js.map +1 -1
- package/lib/rate_limiter/ReqRespRateLimiter.d.ts +1 -1
- package/lib/rate_limiter/ReqRespRateLimiter.js.map +1 -1
- package/lib/request/errors.d.ts +5 -14
- package/lib/request/errors.js +3 -11
- package/lib/request/errors.js.map +1 -1
- package/lib/request/index.d.ts +2 -2
- package/lib/request/index.js +12 -17
- package/lib/request/index.js.map +1 -1
- package/lib/response/index.d.ts +4 -4
- package/lib/response/index.js +10 -5
- package/lib/response/index.js.map +1 -1
- package/lib/types.d.ts +62 -79
- package/lib/types.js +0 -8
- package/lib/types.js.map +1 -1
- package/lib/utils/bufferedSource.d.ts +1 -1
- package/lib/utils/bufferedSource.js.map +1 -1
- package/lib/utils/collectExactOne.js +2 -2
- package/lib/utils/collectExactOne.js.map +1 -1
- package/lib/utils/protocolId.d.ts +2 -2
- package/lib/utils/protocolId.js.map +1 -1
- package/package.json +9 -9
- package/lib/protocols/BeaconBlockAndBlobsSidecarByRoot.d.ts +0 -4
- package/lib/protocols/BeaconBlockAndBlobsSidecarByRoot.js +0 -27
- package/lib/protocols/BeaconBlockAndBlobsSidecarByRoot.js.map +0 -1
- package/lib/protocols/BeaconBlocksByRange.d.ts +0 -5
- package/lib/protocols/BeaconBlocksByRange.js +0 -38
- package/lib/protocols/BeaconBlocksByRange.js.map +0 -1
- package/lib/protocols/BeaconBlocksByRoot.d.ts +0 -5
- package/lib/protocols/BeaconBlocksByRoot.js +0 -38
- package/lib/protocols/BeaconBlocksByRoot.js.map +0 -1
- package/lib/protocols/BlobsSidecarsByRange.d.ts +0 -4
- package/lib/protocols/BlobsSidecarsByRange.js +0 -27
- package/lib/protocols/BlobsSidecarsByRange.js.map +0 -1
- package/lib/protocols/Goodbye.d.ts +0 -4
- package/lib/protocols/Goodbye.js +0 -21
- package/lib/protocols/Goodbye.js.map +0 -1
- package/lib/protocols/LightClientBootstrap.d.ts +0 -4
- package/lib/protocols/LightClientBootstrap.js +0 -30
- package/lib/protocols/LightClientBootstrap.js.map +0 -1
- package/lib/protocols/LightClientFinalityUpdate.d.ts +0 -4
- package/lib/protocols/LightClientFinalityUpdate.js +0 -29
- package/lib/protocols/LightClientFinalityUpdate.js.map +0 -1
- package/lib/protocols/LightClientOptimisticUpdate.d.ts +0 -4
- package/lib/protocols/LightClientOptimisticUpdate.js +0 -29
- package/lib/protocols/LightClientOptimisticUpdate.js.map +0 -1
- package/lib/protocols/LightClientUpdatesByRange.d.ts +0 -4
- package/lib/protocols/LightClientUpdatesByRange.js +0 -28
- package/lib/protocols/LightClientUpdatesByRange.js.map +0 -1
- package/lib/protocols/Metadata.d.ts +0 -5
- package/lib/protocols/Metadata.js +0 -31
- package/lib/protocols/Metadata.js.map +0 -1
- package/lib/protocols/Ping.d.ts +0 -4
- package/lib/protocols/Ping.js +0 -20
- package/lib/protocols/Ping.js.map +0 -1
- package/lib/protocols/Status.d.ts +0 -4
- package/lib/protocols/Status.js +0 -24
- package/lib/protocols/Status.js.map +0 -1
- package/lib/protocols/index.d.ts +0 -13
- package/lib/protocols/index.js +0 -13
- package/lib/protocols/index.js.map +0 -1
- package/lib/protocols/utils.d.ts +0 -7
- package/lib/protocols/utils.js +0 -9
- package/lib/protocols/utils.js.map +0 -1
package/lib/request/errors.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { LodestarError } from "@lodestar/utils";
|
|
2
|
-
import { Encoding } from "../types.js";
|
|
3
2
|
import { ResponseError } from "../response/index.js";
|
|
4
3
|
import { RpcResponseStatusError } from "../interface.js";
|
|
5
4
|
export declare enum RequestErrorCode {
|
|
6
5
|
/** `<response_chunk>` had `<result>` === INVALID_REQUEST */
|
|
7
6
|
INVALID_REQUEST = "REQUEST_ERROR_INVALID_REQUEST",
|
|
7
|
+
INVALID_RESPONSE_SSZ = "REQUEST_ERROR_INVALID_RESPONSE_SSZ",
|
|
8
8
|
/** `<response_chunk>` had `<result>` === SERVER_ERROR */
|
|
9
9
|
SERVER_ERROR = "REQUEST_ERROR_SERVER_ERROR",
|
|
10
10
|
/** `<response_chunk>` had `<result>` === RESOURCE_UNAVAILABLE */
|
|
@@ -33,6 +33,9 @@ export declare enum RequestErrorCode {
|
|
|
33
33
|
type RequestErrorType = {
|
|
34
34
|
code: RequestErrorCode.INVALID_REQUEST;
|
|
35
35
|
errorMessage: string;
|
|
36
|
+
} | {
|
|
37
|
+
code: RequestErrorCode.INVALID_RESPONSE_SSZ;
|
|
38
|
+
errorMessage: string;
|
|
36
39
|
} | {
|
|
37
40
|
code: RequestErrorCode.SERVER_ERROR;
|
|
38
41
|
errorMessage: string;
|
|
@@ -64,21 +67,9 @@ type RequestErrorType = {
|
|
|
64
67
|
} | {
|
|
65
68
|
code: RequestErrorCode.REQUEST_RATE_LIMITED;
|
|
66
69
|
};
|
|
67
|
-
export
|
|
68
|
-
method: string;
|
|
69
|
-
encoding: Encoding;
|
|
70
|
-
peer: string;
|
|
71
|
-
};
|
|
72
|
-
/**
|
|
73
|
-
* Same error types as RequestError but without metadata.
|
|
74
|
-
* Top level function sendRequest() must rethrow RequestInternalError with metadata
|
|
75
|
-
*/
|
|
76
|
-
export declare class RequestInternalError extends LodestarError<RequestErrorType> {
|
|
70
|
+
export declare class RequestError extends LodestarError<RequestErrorType> {
|
|
77
71
|
constructor(type: RequestErrorType);
|
|
78
72
|
}
|
|
79
|
-
export declare class RequestError extends LodestarError<RequestErrorType & RequestErrorMetadata> {
|
|
80
|
-
constructor(type: RequestErrorType, metadata: RequestErrorMetadata);
|
|
81
|
-
}
|
|
82
73
|
/**
|
|
83
74
|
* Parse response status errors into detailed request errors for each status code for easier debugging
|
|
84
75
|
*/
|
package/lib/request/errors.js
CHANGED
|
@@ -5,6 +5,7 @@ export var RequestErrorCode;
|
|
|
5
5
|
// Declaring specific values of RpcResponseStatusError for error clarity downstream
|
|
6
6
|
/** `<response_chunk>` had `<result>` === INVALID_REQUEST */
|
|
7
7
|
RequestErrorCode["INVALID_REQUEST"] = "REQUEST_ERROR_INVALID_REQUEST";
|
|
8
|
+
RequestErrorCode["INVALID_RESPONSE_SSZ"] = "REQUEST_ERROR_INVALID_RESPONSE_SSZ";
|
|
8
9
|
/** `<response_chunk>` had `<result>` === SERVER_ERROR */
|
|
9
10
|
RequestErrorCode["SERVER_ERROR"] = "REQUEST_ERROR_SERVER_ERROR";
|
|
10
11
|
/** `<response_chunk>` had `<result>` === RESOURCE_UNAVAILABLE */
|
|
@@ -30,18 +31,9 @@ export var RequestErrorCode;
|
|
|
30
31
|
/** Request rate limited */
|
|
31
32
|
RequestErrorCode["REQUEST_RATE_LIMITED"] = "REQUEST_ERROR_RATE_LIMITED";
|
|
32
33
|
})(RequestErrorCode || (RequestErrorCode = {}));
|
|
33
|
-
/**
|
|
34
|
-
* Same error types as RequestError but without metadata.
|
|
35
|
-
* Top level function sendRequest() must rethrow RequestInternalError with metadata
|
|
36
|
-
*/
|
|
37
|
-
export class RequestInternalError extends LodestarError {
|
|
38
|
-
constructor(type) {
|
|
39
|
-
super(type);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
34
|
export class RequestError extends LodestarError {
|
|
43
|
-
constructor(type
|
|
44
|
-
super(
|
|
35
|
+
constructor(type) {
|
|
36
|
+
super(type, renderErrorMessage(type));
|
|
45
37
|
}
|
|
46
38
|
}
|
|
47
39
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/request/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/request/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAE9C,OAAO,EAAC,UAAU,EAAyB,MAAM,iBAAiB,CAAC;AAEnE,MAAM,CAAN,IAAY,gBA6BX;AA7BD,WAAY,gBAAgB;IAC1B,mFAAmF;IACnF,4DAA4D;IAC5D,qEAAiD,CAAA;IACjD,+EAA2D,CAAA;IAC3D,yDAAyD;IACzD,+DAA2C,CAAA;IAC3C,iEAAiE;IACjE,uEAAmD,CAAA;IACnD,wEAAwE;IACxE,+EAA2D,CAAA;IAC3D,4DAA4D;IAC5D,+DAA2C,CAAA;IAC3C,uCAAuC;IACvC,2DAAuC,CAAA;IACvC,iEAAiE;IACjE,qEAAiD,CAAA;IACjD,8CAA8C;IAC9C,iEAA6C,CAAA;IAC7C,mFAAmF;IACnF,uEAAmD,CAAA;IACnD,iD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I,CAAC,IAAI,CAAC;KACpB;AACH,CAAC"}
|
package/lib/request/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PeerId } from "@libp2p/interface-peer-id";
|
|
2
2
|
import { Libp2p } from "libp2p";
|
|
3
3
|
import { Logger } from "@lodestar/utils";
|
|
4
|
-
import {
|
|
4
|
+
import { MixedProtocol, ResponseIncoming } from "../types.js";
|
|
5
5
|
import { RequestError, RequestErrorCode } from "./errors.js";
|
|
6
6
|
export { RequestError, RequestErrorCode };
|
|
7
7
|
export declare const DEFAULT_DIAL_TIMEOUT: number;
|
|
@@ -34,5 +34,5 @@ type SendRequestModules = {
|
|
|
34
34
|
* - Any part of the response_chunk fails validation. Throws a typed error (see `SszSnappyError`)
|
|
35
35
|
* - The maximum number of requested chunks are read. Does not throw, returns read chunks only.
|
|
36
36
|
*/
|
|
37
|
-
export declare function sendRequest
|
|
37
|
+
export declare function sendRequest({ logger, libp2p, peerClient }: SendRequestModules, peerId: PeerId, protocols: MixedProtocol[], protocolIDs: string[], requestBody: Uint8Array, signal?: AbortSignal, opts?: SendRequestOpts, requestId?: number): AsyncIterable<ResponseIncoming>;
|
|
38
38
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/request/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { prettyPrintPeerId, abortableSource } from "../utils/index.js";
|
|
|
4
4
|
import { ResponseError } from "../response/index.js";
|
|
5
5
|
import { requestEncode } from "../encoders/requestEncode.js";
|
|
6
6
|
import { responseDecode } from "../encoders/responseDecode.js";
|
|
7
|
-
import { RequestError, RequestErrorCode,
|
|
7
|
+
import { RequestError, RequestErrorCode, responseStatusErrorToRequestError } from "./errors.js";
|
|
8
8
|
export { RequestError, RequestErrorCode };
|
|
9
9
|
// Default spec values from https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/p2p-interface.md#configuration
|
|
10
10
|
export const DEFAULT_DIAL_TIMEOUT = 5 * 1000; // 5 sec
|
|
@@ -23,7 +23,7 @@ export const DEFAULT_RESP_TIMEOUT = 10 * 1000; // 10 sec
|
|
|
23
23
|
* - The maximum number of requested chunks are read. Does not throw, returns read chunks only.
|
|
24
24
|
*/
|
|
25
25
|
export async function* sendRequest({ logger, libp2p, peerClient }, peerId, protocols, protocolIDs, requestBody, signal, opts, requestId = 0) {
|
|
26
|
-
var _a, _b, _c, _d, _e
|
|
26
|
+
var _a, _b, _c, _d, _e;
|
|
27
27
|
if (protocols.length === 0) {
|
|
28
28
|
throw Error("sendRequest must set > 0 protocols");
|
|
29
29
|
}
|
|
@@ -31,10 +31,9 @@ export async function* sendRequest({ logger, libp2p, peerClient }, peerId, proto
|
|
|
31
31
|
const REQUEST_TIMEOUT = (_b = opts === null || opts === void 0 ? void 0 : opts.requestTimeoutMs) !== null && _b !== void 0 ? _b : DEFAULT_REQUEST_TIMEOUT;
|
|
32
32
|
const TTFB_TIMEOUT = (_c = opts === null || opts === void 0 ? void 0 : opts.ttfbTimeoutMs) !== null && _c !== void 0 ? _c : DEFAULT_TTFB_TIMEOUT;
|
|
33
33
|
const RESP_TIMEOUT = (_d = opts === null || opts === void 0 ? void 0 : opts.respTimeoutMs) !== null && _d !== void 0 ? _d : DEFAULT_RESP_TIMEOUT;
|
|
34
|
-
const peerIdStr = peerId.toString();
|
|
35
34
|
const peerIdStrShort = prettyPrintPeerId(peerId);
|
|
36
|
-
const { method, encoding } = protocols[0];
|
|
37
|
-
const logCtx = { method, encoding, client: peerClient, peer: peerIdStrShort, requestId };
|
|
35
|
+
const { method, encoding, version } = protocols[0];
|
|
36
|
+
const logCtx = { method, version, encoding, client: peerClient, peer: peerIdStrShort, requestId };
|
|
38
37
|
if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
|
|
39
38
|
throw new ErrorAborted("sendRequest");
|
|
40
39
|
}
|
|
@@ -63,10 +62,10 @@ export async function* sendRequest({ logger, libp2p, peerClient }, peerId, proto
|
|
|
63
62
|
return conn;
|
|
64
63
|
}, DIAL_TIMEOUT, signal).catch((e) => {
|
|
65
64
|
if (e instanceof TimeoutError) {
|
|
66
|
-
throw new
|
|
65
|
+
throw new RequestError({ code: RequestErrorCode.DIAL_TIMEOUT });
|
|
67
66
|
}
|
|
68
67
|
else {
|
|
69
|
-
throw new
|
|
68
|
+
throw new RequestError({ code: RequestErrorCode.DIAL_ERROR, error: e });
|
|
70
69
|
}
|
|
71
70
|
});
|
|
72
71
|
// Parse protocol selected by the responder
|
|
@@ -74,7 +73,7 @@ export async function* sendRequest({ logger, libp2p, peerClient }, peerId, proto
|
|
|
74
73
|
const protocol = protocolsMap.get(protocolId);
|
|
75
74
|
if (!protocol)
|
|
76
75
|
throw Error(`dialProtocol selected unknown protocolId ${protocolId}`);
|
|
77
|
-
logger.debug("Req sending request",
|
|
76
|
+
logger.debug("Req sending request", logCtx);
|
|
78
77
|
// Spec: The requester MUST close the write side of the stream once it finishes writing the request message
|
|
79
78
|
// Impl: stream.sink is closed automatically by js-libp2p-mplex when piped source is exhausted
|
|
80
79
|
// REQUEST_TIMEOUT: Non-spec timeout from sending request until write stream closed by responder
|
|
@@ -83,10 +82,10 @@ export async function* sendRequest({ logger, libp2p, peerClient }, peerId, proto
|
|
|
83
82
|
// Must close the stream read side (stream.source) manually AND the write side
|
|
84
83
|
stream.abort(e);
|
|
85
84
|
if (e instanceof TimeoutError) {
|
|
86
|
-
throw new
|
|
85
|
+
throw new RequestError({ code: RequestErrorCode.REQUEST_TIMEOUT });
|
|
87
86
|
}
|
|
88
87
|
else {
|
|
89
|
-
throw new
|
|
88
|
+
throw new RequestError({ code: RequestErrorCode.REQUEST_ERROR, error: e });
|
|
90
89
|
}
|
|
91
90
|
});
|
|
92
91
|
logger.debug("Req request sent", logCtx);
|
|
@@ -113,11 +112,11 @@ export async function* sendRequest({ logger, libp2p, peerClient }, peerId, proto
|
|
|
113
112
|
yield* pipe(abortableSource(stream.source, [
|
|
114
113
|
{
|
|
115
114
|
signal: ttfbTimeoutController.signal,
|
|
116
|
-
getError: () => new
|
|
115
|
+
getError: () => new RequestError({ code: RequestErrorCode.TTFB_TIMEOUT }),
|
|
117
116
|
},
|
|
118
117
|
{
|
|
119
118
|
signal: respTimeoutController.signal,
|
|
120
|
-
getError: () => new
|
|
119
|
+
getError: () => new RequestError({ code: RequestErrorCode.RESP_TIMEOUT }),
|
|
121
120
|
},
|
|
122
121
|
]),
|
|
123
122
|
// Transforms `Buffer` chunks to yield `ResponseBody` chunks
|
|
@@ -149,12 +148,8 @@ export async function* sendRequest({ logger, libp2p, peerClient }, peerId, proto
|
|
|
149
148
|
}
|
|
150
149
|
catch (e) {
|
|
151
150
|
logger.verbose("Req error", logCtx, e);
|
|
152
|
-
const metadata = { method, encoding, peer: peerIdStr };
|
|
153
151
|
if (e instanceof ResponseError) {
|
|
154
|
-
throw new RequestError(responseStatusErrorToRequestError(e)
|
|
155
|
-
}
|
|
156
|
-
else if (e instanceof RequestInternalError) {
|
|
157
|
-
throw new RequestError(e.type, metadata);
|
|
152
|
+
throw new RequestError(responseStatusErrorToRequestError(e));
|
|
158
153
|
}
|
|
159
154
|
else {
|
|
160
155
|
throw e;
|
package/lib/request/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/request/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAC,MAAM,SAAS,CAAC;AAI7B,OAAO,EAAC,YAAY,EAAU,WAAW,EAAE,YAAY,EAAC,MAAM,iBAAiB,CAAC;AAEhF,OAAO,EAAC,iBAAiB,EAAE,eAAe,EAAC,MAAM,mBAAmB,CAAC;AACrE,OAAO,EAAC,aAAa,EAAC,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAC,aAAa,EAAC,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAC,cAAc,EAAC,MAAM,+BAA+B,CAAC;AAC7D,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/request/index.ts"],"names":[],"mapp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,CAAC;iBACxE;gBACD;oBACE,MAAM,EAAE,qBAAqB,CAAC,MAAM;oBACpC,QAAQ,EAAE,GAAG,EAAE,CAAC,IAAI,YAAY,CAAC,EAAC,IAAI,EAAE,gBAAgB,CAAC,YAAY,EAAC,CAAC;iBACxE;aACF,CAAC;YAEF,4DAA4D;YAC5D,cAAc,CAAC,QAAQ,EAAE;gBACvB,aAAa;oBACX,4EAA4E;oBAC5E,YAAY,CAAC,WAAW,CAAC,CAAC;oBAC1B,kBAAkB,EAAE,CAAC;gBACvB,CAAC;gBACD,oBAAoB;oBAClB,yEAAyE;oBACzE,kBAAkB,EAAE,CAAC;gBACvB,CAAC;aACF,CAAC,CACH,CAAC;YAEF,0EAA0E;YAC1E,8DAA8D;YAC9D,yEAAyE;YACzE,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,EAAC,GAAG,MAAM,EAAC,CAAC,CAAC;SAC1C;gBAAS;YACR,YAAY,CAAC,WAAW,CAAC,CAAC;YAC1B,IAAI,WAAW,KAAK,IAAI;gBAAE,YAAY,CAAC,WAAW,CAAC,CAAC;YAEpD,+GAA+G;YAC/G,8EAA8E;YAC9E,mGAAmG;YACnG,MAAM,CAAC,KAAK,EAAE,CAAC;SAChB;KACF;IAAC,OAAO,CAAC,EAAE;QACV,MAAM,CAAC,OAAO,CAAC,YAAY,EAAE,MAAM,EAAE,CAAU,CAAC,CAAC;QAEjD,IAAI,CAAC,YAAY,aAAa,EAAE;YAC9B,MAAM,IAAI,YAAY,CAAC,iCAAiC,CAAC,CAAC,CAAC,CAAC,CAAC;SAC9D;aAAM;YACL,MAAM,CAAC,CAAC;SACT;KACF;AACH,CAAC"}
|
package/lib/response/index.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { PeerId } from "@libp2p/interface-peer-id";
|
|
2
2
|
import { Stream } from "@libp2p/interface-connection";
|
|
3
3
|
import { Logger } from "@lodestar/utils";
|
|
4
|
-
import {
|
|
4
|
+
import { Protocol } from "../types.js";
|
|
5
5
|
import { ReqRespRateLimiter } from "../rate_limiter/ReqRespRateLimiter.js";
|
|
6
6
|
import { ResponseError } from "./errors.js";
|
|
7
7
|
export { ResponseError };
|
|
8
8
|
export declare const DEFAULT_REQUEST_TIMEOUT: number;
|
|
9
|
-
export interface HandleRequestOpts
|
|
9
|
+
export interface HandleRequestOpts {
|
|
10
10
|
logger: Logger;
|
|
11
11
|
stream: Stream;
|
|
12
12
|
peerId: PeerId;
|
|
13
|
-
protocol:
|
|
13
|
+
protocol: Protocol;
|
|
14
14
|
protocolID: string;
|
|
15
15
|
rateLimiter: ReqRespRateLimiter;
|
|
16
16
|
signal?: AbortSignal;
|
|
@@ -30,5 +30,5 @@ export interface HandleRequestOpts<Req, Resp> {
|
|
|
30
30
|
* 4a. Encode and write `<response_chunks>` to peer
|
|
31
31
|
* 4b. On error, encode and write an error `<response_chunk>` and stop
|
|
32
32
|
*/
|
|
33
|
-
export declare function handleRequest
|
|
33
|
+
export declare function handleRequest({ logger, stream, peerId, protocol, protocolID, rateLimiter, signal, requestId, peerClient, requestTimeoutMs, }: HandleRequestOpts): Promise<void>;
|
|
34
34
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/response/index.js
CHANGED
|
@@ -28,7 +28,7 @@ export async function handleRequest({ logger, stream, peerId, protocol, protocol
|
|
|
28
28
|
// This syntax allows to recycle stream.sink to send success and error chunks without returning
|
|
29
29
|
// in case request whose body is a List fails at chunk_i > 0, without breaking out of the for..await..of
|
|
30
30
|
(async function* requestHandlerSource() {
|
|
31
|
-
var _a, _b, _c
|
|
31
|
+
var _a, _b, _c;
|
|
32
32
|
try {
|
|
33
33
|
const requestBody = await withTimeout(() => pipe(stream.source, requestDecode(protocol)), REQUEST_TIMEOUT, signal).catch((e) => {
|
|
34
34
|
if (e instanceof TimeoutError) {
|
|
@@ -38,14 +38,19 @@ export async function handleRequest({ logger, stream, peerId, protocol, protocol
|
|
|
38
38
|
throw new ResponseError(RespStatus.INVALID_REQUEST, e.message);
|
|
39
39
|
}
|
|
40
40
|
});
|
|
41
|
-
logger.debug("Req received",
|
|
42
|
-
|
|
41
|
+
logger.debug("Req received", logCtx);
|
|
42
|
+
// Max count by request for byRange and byRoot
|
|
43
|
+
const requestCount = (_c = (_b = (_a = protocol === null || protocol === void 0 ? void 0 : protocol.inboundRateLimits) === null || _a === void 0 ? void 0 : _a.getRequestCount) === null || _b === void 0 ? void 0 : _b.call(_a, requestBody)) !== null && _c !== void 0 ? _c : 1;
|
|
43
44
|
if (!rateLimiter.allows(peerId, protocolID, requestCount)) {
|
|
44
|
-
throw new RequestError({ code: RequestErrorCode.REQUEST_RATE_LIMITED }
|
|
45
|
+
throw new RequestError({ code: RequestErrorCode.REQUEST_RATE_LIMITED });
|
|
45
46
|
}
|
|
47
|
+
const requestChunk = {
|
|
48
|
+
data: requestBody,
|
|
49
|
+
version: protocol.version,
|
|
50
|
+
};
|
|
46
51
|
yield* pipe(
|
|
47
52
|
// TODO: Debug the reason for type conversion here
|
|
48
|
-
protocol.handler(
|
|
53
|
+
protocol.handler(requestChunk, peerId),
|
|
49
54
|
// NOTE: Do not log the resp chunk contents, logs get extremely cluttered
|
|
50
55
|
// Note: Not logging on each chunk since after 1 year it hasn't add any value when debugging
|
|
51
56
|
// onChunk(() => logger.debug("Resp sending chunk", logCtx)),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/response/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAC,MAAM,SAAS,CAAC;AAI7B,OAAO,EAAS,YAAY,EAAE,WAAW,EAAC,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAC,iBAAiB,EAAC,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EAAC,aAAa,EAAC,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAC,mBAAmB,EAAE,qBAAqB,EAAC,MAAM,+BAA+B,CAAC;AACzF,OAAO,EAAC,UAAU,EAAC,MAAM,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C,OAAO;aAC1B,CAAC;YAEF,KAAK,CAAC,CAAC,IAAI;YACT,kDAAkD;YAClD,QAAQ,CAAC,OAAO,CAAC,YAAY,EAAE,MAAM,CAAC;YACtC,yEAAyE;YACzE,4FAA4F;YAC5F,6DAA6D;YAC7D,qBAAqB,CAAC,QAAQ,CAAC,CAChC,CAAC;SACH;QAAC,OAAO,CAAC,EAAE;YACV,MAAM,MAAM,GAAG,CAAC,YAAY,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,YAAY,CAAC;YAC/E,KAAK,CAAC,CAAC,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAG,CAAW,CAAC,OAAO,CAAC,CAAC;YAEnE,wFAAwF;YACxF,WAAW;YACX,aAAa,GAAG,CAAU,CAAC;SAC5B;IACH,CAAC,CAAC,EAAE,EACJ,MAAM,CAAC,IAAI,CACZ,CAAC;IAEF,+DAA+D;IAC/D,wEAAwE;IACxE,qGAAqG;IACrG,MAAM,CAAC,KAAK,EAAE,CAAC;IAEf,qFAAqF;IACrF,qFAAqF;IACrF,4EAA4E;IAC5E,+FAA+F;IAC/F,+CAA+C;IAE/C,IAAI,aAAa,KAAK,IAAI,EAAE;QAC1B,MAAM,CAAC,OAAO,CAAC,YAAY,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC;QACpD,MAAM,aAAa,CAAC;KACrB;SAAM;QACL,0EAA0E;QAC1E,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;KACrC;AACH,CAAC"}
|
package/lib/types.d.ts
CHANGED
|
@@ -1,54 +1,40 @@
|
|
|
1
1
|
import { PeerId } from "@libp2p/interface-peer-id";
|
|
2
|
-
import { BeaconConfig,
|
|
2
|
+
import { BeaconConfig, ForkDigestContext } from "@lodestar/config";
|
|
3
3
|
import { ForkName } from "@lodestar/params";
|
|
4
|
-
import { Slot } from "@lodestar/types";
|
|
5
4
|
import { LodestarError } from "@lodestar/utils";
|
|
6
5
|
import { RateLimiterQuota } from "./rate_limiter/rateLimiterGRCA.js";
|
|
6
|
+
export declare const protocolPrefix = "/eth2/beacon_chain/req";
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
|
|
10
|
-
export declare enum EncodedPayloadType {
|
|
11
|
-
ssz = 0,
|
|
12
|
-
bytes = 1
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Wrapper for the request/response payload for SSZ type data
|
|
16
|
-
*/
|
|
17
|
-
export interface EncodedPayloadSsz<T> {
|
|
18
|
-
type: EncodedPayloadType.ssz;
|
|
19
|
-
data: T;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Wrapper for the request/response payload for binary type data
|
|
8
|
+
* Available request/response encoding strategies:
|
|
9
|
+
* https://github.com/ethereum/consensus-specs/blob/v1.1.10/specs/phase0/p2p-interface.md#encoding-strategies
|
|
23
10
|
*/
|
|
24
|
-
export
|
|
25
|
-
|
|
26
|
-
bytes: Uint8Array;
|
|
27
|
-
contextBytes: ContextBytes;
|
|
11
|
+
export declare enum Encoding {
|
|
12
|
+
SSZ_SNAPPY = "ssz_snappy"
|
|
28
13
|
}
|
|
14
|
+
export declare const CONTEXT_BYTES_FORK_DIGEST_LENGTH = 4;
|
|
29
15
|
/**
|
|
30
16
|
* Wrapper for the request/response payload
|
|
31
17
|
*/
|
|
32
|
-
export type
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
18
|
+
export type ResponseIncoming = {
|
|
19
|
+
data: Uint8Array;
|
|
20
|
+
fork: ForkName;
|
|
21
|
+
protocolVersion: number;
|
|
22
|
+
};
|
|
23
|
+
export type ResponseOutgoing = {
|
|
24
|
+
data: Uint8Array;
|
|
25
|
+
fork: ForkName;
|
|
26
|
+
};
|
|
37
27
|
/**
|
|
38
|
-
*
|
|
28
|
+
* Rate limiter options for the requests
|
|
39
29
|
*/
|
|
40
|
-
export interface
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
readonly method: string;
|
|
44
|
-
/** Version counter: `1`, `2` etc */
|
|
45
|
-
readonly version: number;
|
|
46
|
-
readonly encoding: Encoding;
|
|
30
|
+
export interface ReqRespRateLimiterOpts {
|
|
31
|
+
rateLimitMultiplier?: number;
|
|
32
|
+
onRateLimit?: (peer: PeerId, method: string) => void;
|
|
47
33
|
}
|
|
48
34
|
/**
|
|
49
35
|
* Inbound rate limiter quota for the protocol
|
|
50
36
|
*/
|
|
51
|
-
export interface InboundRateLimitQuota
|
|
37
|
+
export interface InboundRateLimitQuota {
|
|
52
38
|
/**
|
|
53
39
|
* Will be tracked for the protocol per peer
|
|
54
40
|
*/
|
|
@@ -61,24 +47,44 @@ export interface InboundRateLimitQuota<Req = unknown> {
|
|
|
61
47
|
* Some requests may be counted multiple e.g. getBlocksByRange
|
|
62
48
|
* for such implement this method else `1` will be used default
|
|
63
49
|
*/
|
|
64
|
-
getRequestCount?: (req:
|
|
50
|
+
getRequestCount?: (req: Uint8Array) => number;
|
|
65
51
|
}
|
|
52
|
+
export type ReqRespRequest = {
|
|
53
|
+
data: Uint8Array;
|
|
54
|
+
version: number;
|
|
55
|
+
};
|
|
66
56
|
/**
|
|
67
|
-
*
|
|
57
|
+
* Request handler
|
|
68
58
|
*/
|
|
69
|
-
export
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
59
|
+
export type ProtocolHandler = (req: ReqRespRequest, peerId: PeerId) => AsyncIterable<ResponseOutgoing>;
|
|
60
|
+
/**
|
|
61
|
+
* ReqResp Protocol Deceleration
|
|
62
|
+
*/
|
|
63
|
+
export interface ProtocolAttributes {
|
|
64
|
+
readonly protocolPrefix: string;
|
|
65
|
+
/** Protocol name identifier `beacon_blocks_by_range` or `status` */
|
|
66
|
+
readonly method: string;
|
|
67
|
+
/** Version counter: `1`, `2` etc */
|
|
68
|
+
readonly version: number;
|
|
69
|
+
readonly encoding: Encoding;
|
|
70
|
+
}
|
|
71
|
+
export interface ProtocolDescriptor extends Omit<ProtocolAttributes, "protocolPrefix"> {
|
|
72
|
+
contextBytes: ContextBytesFactory;
|
|
73
73
|
ignoreResponse?: boolean;
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* ReqResp Protocol definition for full duplex protocols
|
|
77
|
+
*/
|
|
78
|
+
export interface Protocol extends ProtocolDescriptor {
|
|
79
|
+
handler: ProtocolHandler;
|
|
80
|
+
inboundRateLimits?: InboundRateLimitQuota;
|
|
81
|
+
requestSizes: TypeSizes | null;
|
|
82
|
+
responseSizes: (fork: ForkName) => TypeSizes;
|
|
77
83
|
}
|
|
78
84
|
/**
|
|
79
85
|
* ReqResp Protocol definition for dial only protocols
|
|
80
86
|
*/
|
|
81
|
-
export interface
|
|
87
|
+
export interface DialOnlyProtocol extends Omit<Protocol, "handler" | "inboundRateLimits" | "renderRequestBody"> {
|
|
82
88
|
handler?: never;
|
|
83
89
|
inboundRateLimits?: never;
|
|
84
90
|
renderRequestBody?: never;
|
|
@@ -86,43 +92,33 @@ export interface DialOnlyProtocolDefinition<Req = unknown, Resp = unknown> exten
|
|
|
86
92
|
/**
|
|
87
93
|
* ReqResp Protocol definition for full duplex and dial only protocols
|
|
88
94
|
*/
|
|
89
|
-
export type
|
|
95
|
+
export type MixedProtocol = DialOnlyProtocol | Protocol;
|
|
90
96
|
/**
|
|
91
97
|
* ReqResp protocol definition descriptor for full duplex and dial only protocols
|
|
92
98
|
* If handler is not provided, the protocol will be dial only
|
|
93
99
|
* If handler is provided, the protocol will be full duplex
|
|
94
100
|
*/
|
|
95
|
-
export type
|
|
101
|
+
export type MixedProtocolGenerators = <H extends ProtocolHandler | undefined = undefined>(modules: {
|
|
96
102
|
config: BeaconConfig;
|
|
97
|
-
}, handler?: H) => H extends undefined ?
|
|
103
|
+
}, handler?: H) => H extends undefined ? DialOnlyProtocol : Protocol;
|
|
98
104
|
/**
|
|
99
105
|
* ReqResp protocol definition descriptor for full duplex protocols
|
|
100
106
|
*/
|
|
101
|
-
export type
|
|
107
|
+
export type ProtocolGenerator = (modules: {
|
|
102
108
|
config: BeaconConfig;
|
|
103
|
-
}, handler:
|
|
104
|
-
export type HandlerTypeFromMessage<T> = T extends
|
|
105
|
-
export
|
|
106
|
-
/**
|
|
107
|
-
* Available request/response encoding strategies:
|
|
108
|
-
* https://github.com/ethereum/consensus-specs/blob/v1.1.10/specs/phase0/p2p-interface.md#encoding-strategies
|
|
109
|
-
*/
|
|
110
|
-
export declare enum Encoding {
|
|
111
|
-
SSZ_SNAPPY = "ssz_snappy"
|
|
112
|
-
}
|
|
113
|
-
export declare const CONTEXT_BYTES_FORK_DIGEST_LENGTH = 4;
|
|
114
|
-
export type ContextBytesFactory<Resp> = {
|
|
109
|
+
}, handler: ProtocolHandler) => Protocol;
|
|
110
|
+
export type HandlerTypeFromMessage<T> = T extends ProtocolGenerator ? ProtocolHandler : never;
|
|
111
|
+
export type ContextBytesFactory = {
|
|
115
112
|
type: ContextBytesType.Empty;
|
|
116
113
|
} | {
|
|
117
114
|
type: ContextBytesType.ForkDigest;
|
|
118
|
-
forkDigestContext: ForkDigestContext
|
|
119
|
-
forkFromResponse: (response: Resp) => ForkName;
|
|
115
|
+
forkDigestContext: ForkDigestContext;
|
|
120
116
|
};
|
|
121
117
|
export type ContextBytes = {
|
|
122
118
|
type: ContextBytesType.Empty;
|
|
123
119
|
} | {
|
|
124
120
|
type: ContextBytesType.ForkDigest;
|
|
125
|
-
|
|
121
|
+
fork: ForkName;
|
|
126
122
|
};
|
|
127
123
|
export declare enum ContextBytesType {
|
|
128
124
|
/** 0 bytes chunk, can be ignored */
|
|
@@ -138,21 +134,8 @@ export type LightClientServerErrorType = {
|
|
|
138
134
|
};
|
|
139
135
|
export declare class LightClientServerError extends LodestarError<LightClientServerErrorType> {
|
|
140
136
|
}
|
|
141
|
-
|
|
142
|
-
* Lightweight interface of ssz Type<T>
|
|
143
|
-
*/
|
|
144
|
-
export interface TypeSerializer<T> {
|
|
145
|
-
serialize(data: T): Uint8Array;
|
|
146
|
-
deserialize(bytes: Uint8Array): T;
|
|
137
|
+
export type TypeSizes = {
|
|
147
138
|
maxSize: number;
|
|
148
139
|
minSize: number;
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Rate limiter options for the requests
|
|
153
|
-
*/
|
|
154
|
-
export interface ReqRespRateLimiterOpts {
|
|
155
|
-
rateLimitMultiplier?: number;
|
|
156
|
-
onRateLimit?: (peer: PeerId, method: string) => void;
|
|
157
|
-
}
|
|
140
|
+
};
|
|
158
141
|
//# sourceMappingURL=types.d.ts.map
|
package/lib/types.js
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
1
|
import { LodestarError } from "@lodestar/utils";
|
|
2
|
-
/**
|
|
3
|
-
* The encoding of the request/response payload
|
|
4
|
-
*/
|
|
5
|
-
export var EncodedPayloadType;
|
|
6
|
-
(function (EncodedPayloadType) {
|
|
7
|
-
EncodedPayloadType[EncodedPayloadType["ssz"] = 0] = "ssz";
|
|
8
|
-
EncodedPayloadType[EncodedPayloadType["bytes"] = 1] = "bytes";
|
|
9
|
-
})(EncodedPayloadType || (EncodedPayloadType = {}));
|
|
10
2
|
export const protocolPrefix = "/eth2/beacon_chain/req";
|
|
11
3
|
/**
|
|
12
4
|
* Available request/response encoding strategies:
|
package/lib/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAG9C,MAAM,CAAC,MAAM,cAAc,GAAG,wBAAwB,CAAC;AAEvD;;;GAGG;AACH,MAAM,CAAN,IAAY,QAEX;AAFD,WAAY,QAAQ;IAClB,qCAAyB,CAAA;AAC3B,CAAC,EAFW,QAAQ,KAAR,QAAQ,QAEnB;AAED,MAAM,CAAC,MAAM,gCAAgC,GAAG,CAAC,CAAC;AAuHlD,MAAM,CAAN,IAAY,gBAKX;AALD,WAAY,gBAAgB;IAC1B,oCAAoC;IACpC,yDAAK,CAAA;IACL,iJAAiJ;IACjJ,mEAAU,CAAA;AACZ,CAAC,EALW,gBAAgB,KAAhB,gBAAgB,QAK3B;AAED,MAAM,CAAN,IAAY,0BAEX;AAFD,WAAY,0BAA0B;IACpC,2EAA6C,CAAA;AAC/C,CAAC,EAFW,0BAA0B,KAA1B,0BAA0B,QAErC;AAID,MAAM,OAAO,sBAAuB,SAAQ,aAAyC;CAAG"}
|
|
@@ -10,7 +10,7 @@ export declare class BufferedSource {
|
|
|
10
10
|
isDone: boolean;
|
|
11
11
|
private buffer;
|
|
12
12
|
private source;
|
|
13
|
-
constructor(source: AsyncGenerator<Uint8ArrayList>);
|
|
13
|
+
constructor(source: AsyncGenerator<Uint8ArrayList | Uint8Array>);
|
|
14
14
|
[Symbol.asyncIterator](): AsyncIterator<Uint8ArrayList>;
|
|
15
15
|
}
|
|
16
16
|
//# sourceMappingURL=bufferedSource.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bufferedSource.js","sourceRoot":"","sources":["../../src/utils/bufferedSource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,gBAAgB,CAAC;AAE9C;;;;;;GAMG;AACH,MAAM,OAAO,cAAc;IAKzB,YAAY,
|
|
1
|
+
{"version":3,"file":"bufferedSource.js","sourceRoot":"","sources":["../../src/utils/bufferedSource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,gBAAgB,CAAC;AAE9C;;;;;;GAMG;AACH,MAAM,OAAO,cAAc;IAKzB,YAAY,MAAmD;QAJ/D,WAAM,GAAG,KAAK,CAAC;QAKb,IAAI,CAAC,MAAM,GAAG,IAAI,cAAc,EAAE,CAAC;QACnC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,CAAC,MAAM,CAAC,aAAa,CAAC;QACpB,4DAA4D;QAC5D,MAAM,IAAI,GAAG,IAAI,CAAC;QAElB,IAAI,SAAS,GAAG,IAAI,CAAC;QAErB,OAAO;YACL,KAAK,CAAC,IAAI;gBACR,0DAA0D;gBAC1D,8DAA8D;gBAC9D,IAAI,SAAS,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;oBACvC,SAAS,GAAG,KAAK,CAAC;oBAClB,OAAO,EAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,MAAM,EAAC,CAAC;iBAC1C;gBAED,mEAAmE;gBACnE,MAAM,EAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAC,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;gBACtD,IAAI,IAAI,KAAK,IAAI,EAAE;oBACjB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;oBACnB,OAAO,EAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAC,CAAC;iBACvC;qBAAM;oBACL,qEAAqE;oBACrE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;oBAC1B,OAAO,EAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,MAAM,EAAC,CAAC;iBAC1C;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RequestErrorCode,
|
|
1
|
+
import { RequestErrorCode, RequestError } from "../request/errors.js";
|
|
2
2
|
/**
|
|
3
3
|
* Sink for `<response_chunk>*`, from
|
|
4
4
|
* ```bnf
|
|
@@ -10,6 +10,6 @@ export async function collectExactOne(source) {
|
|
|
10
10
|
for await (const response of source) {
|
|
11
11
|
return response;
|
|
12
12
|
}
|
|
13
|
-
throw new
|
|
13
|
+
throw new RequestError({ code: RequestErrorCode.EMPTY_RESPONSE });
|
|
14
14
|
}
|
|
15
15
|
//# sourceMappingURL=collectExactOne.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collectExactOne.js","sourceRoot":"","sources":["../../src/utils/collectExactOne.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAE,
|
|
1
|
+
{"version":3,"file":"collectExactOne.js","sourceRoot":"","sources":["../../src/utils/collectExactOne.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAE,YAAY,EAAC,MAAM,sBAAsB,CAAC;AAEpE;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAI,MAAwB;IAC/D,IAAI,KAAK,EAAE,MAAM,QAAQ,IAAI,MAAM,EAAE;QACnC,OAAO,QAAQ,CAAC;KACjB;IACD,MAAM,IAAI,YAAY,CAAC,EAAC,IAAI,EAAE,gBAAgB,CAAC,cAAc,EAAC,CAAC,CAAC;AAClE,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Encoding,
|
|
1
|
+
import { Encoding, ProtocolAttributes } from "../types.js";
|
|
2
2
|
/**
|
|
3
3
|
* https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/p2p-interface.md#protocol-identification
|
|
4
4
|
*/
|
|
@@ -6,5 +6,5 @@ export declare function formatProtocolID(protocolPrefix: string, method: string,
|
|
|
6
6
|
/**
|
|
7
7
|
* https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/p2p-interface.md#protocol-identification
|
|
8
8
|
*/
|
|
9
|
-
export declare function parseProtocolID(protocolId: string):
|
|
9
|
+
export declare function parseProtocolID(protocolId: string): ProtocolAttributes;
|
|
10
10
|
//# sourceMappingURL=protocolId.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocolId.js","sourceRoot":"","sources":["../../src/utils/protocolId.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,Q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