@lodestar/beacon-node 1.42.0-dev.7e96447c23 → 1.42.0-dev.83dedda569

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.
Files changed (64) hide show
  1. package/lib/chain/chain.d.ts +1 -0
  2. package/lib/chain/chain.d.ts.map +1 -1
  3. package/lib/chain/chain.js +14 -0
  4. package/lib/chain/chain.js.map +1 -1
  5. package/lib/chain/interface.d.ts +1 -0
  6. package/lib/chain/interface.d.ts.map +1 -1
  7. package/lib/network/gossip/topic.d.ts +2 -729
  8. package/lib/network/gossip/topic.d.ts.map +1 -1
  9. package/lib/network/interface.d.ts +3 -1
  10. package/lib/network/interface.d.ts.map +1 -1
  11. package/lib/network/libp2p/index.d.ts.map +1 -1
  12. package/lib/network/libp2p/index.js +5 -0
  13. package/lib/network/libp2p/index.js.map +1 -1
  14. package/lib/network/network.d.ts +3 -1
  15. package/lib/network/network.d.ts.map +1 -1
  16. package/lib/network/network.js +6 -0
  17. package/lib/network/network.js.map +1 -1
  18. package/lib/network/reqresp/ReqRespBeaconNode.d.ts.map +1 -1
  19. package/lib/network/reqresp/ReqRespBeaconNode.js +9 -0
  20. package/lib/network/reqresp/ReqRespBeaconNode.js.map +1 -1
  21. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRange.d.ts +8 -0
  22. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRange.d.ts.map +1 -0
  23. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRange.js +69 -0
  24. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRange.js.map +1 -0
  25. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRoot.d.ts +6 -0
  26. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRoot.d.ts.map +1 -0
  27. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRoot.js +28 -0
  28. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRoot.js.map +1 -0
  29. package/lib/network/reqresp/handlers/index.d.ts.map +1 -1
  30. package/lib/network/reqresp/handlers/index.js +11 -1
  31. package/lib/network/reqresp/handlers/index.js.map +1 -1
  32. package/lib/network/reqresp/protocols.d.ts +2 -0
  33. package/lib/network/reqresp/protocols.d.ts.map +1 -1
  34. package/lib/network/reqresp/protocols.js +10 -0
  35. package/lib/network/reqresp/protocols.js.map +1 -1
  36. package/lib/network/reqresp/rateLimit.d.ts.map +1 -1
  37. package/lib/network/reqresp/rateLimit.js +8 -0
  38. package/lib/network/reqresp/rateLimit.js.map +1 -1
  39. package/lib/network/reqresp/score.d.ts.map +1 -1
  40. package/lib/network/reqresp/score.js +2 -0
  41. package/lib/network/reqresp/score.js.map +1 -1
  42. package/lib/network/reqresp/types.d.ts +8 -2
  43. package/lib/network/reqresp/types.d.ts.map +1 -1
  44. package/lib/network/reqresp/types.js +7 -1
  45. package/lib/network/reqresp/types.js.map +1 -1
  46. package/lib/util/types.d.ts +2 -0
  47. package/lib/util/types.d.ts.map +1 -1
  48. package/lib/util/types.js +1 -0
  49. package/lib/util/types.js.map +1 -1
  50. package/package.json +16 -16
  51. package/src/chain/chain.ts +18 -0
  52. package/src/chain/interface.ts +1 -0
  53. package/src/network/interface.ts +14 -1
  54. package/src/network/libp2p/index.ts +5 -0
  55. package/src/network/network.ts +29 -1
  56. package/src/network/reqresp/ReqRespBeaconNode.ts +13 -0
  57. package/src/network/reqresp/handlers/executionPayloadEnvelopesByRange.ts +94 -0
  58. package/src/network/reqresp/handlers/executionPayloadEnvelopesByRoot.ts +43 -0
  59. package/src/network/reqresp/handlers/index.ts +12 -0
  60. package/src/network/reqresp/protocols.ts +12 -0
  61. package/src/network/reqresp/rateLimit.ts +18 -0
  62. package/src/network/reqresp/score.ts +2 -0
  63. package/src/network/reqresp/types.ts +13 -0
  64. package/src/util/types.ts +6 -0
@@ -0,0 +1,43 @@
1
+ import {ResponseOutgoing} from "@lodestar/reqresp";
2
+ import {computeEpochAtSlot} from "@lodestar/state-transition";
3
+ import {toRootHex} from "@lodestar/utils";
4
+ import {IBeaconChain} from "../../../chain/index.js";
5
+ import {IBeaconDb} from "../../../db/index.js";
6
+ import {ExecutionPayloadEnvelopesByRootRequest} from "../../../util/types.js";
7
+
8
+ export async function* onExecutionPayloadEnvelopesByRoot(
9
+ requestBody: ExecutionPayloadEnvelopesByRootRequest,
10
+ chain: IBeaconChain,
11
+ db: IBeaconDb
12
+ ): AsyncIterable<ResponseOutgoing> {
13
+ // Spec: [max(GLOAS_FORK_EPOCH, current_epoch - MIN_EPOCHS_FOR_BLOCK_REQUESTS), current_epoch]
14
+ const currentEpoch = chain.clock.currentEpoch;
15
+ const minimumRequestEpoch = Math.max(
16
+ currentEpoch - chain.config.MIN_EPOCHS_FOR_BLOCK_REQUESTS,
17
+ chain.config.GLOAS_FORK_EPOCH
18
+ );
19
+
20
+ for (const root of requestBody) {
21
+ const rootHex = toRootHex(root);
22
+ const block = chain.forkChoice.getBlockHexDefaultStatus(rootHex);
23
+ // If the block is not in fork choice, it may be finalized. Attempt to find its slot in block archive
24
+ const slot = block ? block.slot : await db.blockArchive.getSlotByRoot(root);
25
+
26
+ if (slot === null) {
27
+ continue;
28
+ }
29
+
30
+ const requestedEpoch = computeEpochAtSlot(slot);
31
+ if (requestedEpoch < minimumRequestEpoch) {
32
+ continue;
33
+ }
34
+
35
+ const envelopeBytes = await chain.getSerializedExecutionPayloadEnvelope(slot, rootHex);
36
+ if (envelopeBytes) {
37
+ yield {
38
+ data: envelopeBytes,
39
+ boundary: chain.config.getForkBoundaryAtEpoch(requestedEpoch),
40
+ };
41
+ }
42
+ }
43
+ }
@@ -6,6 +6,7 @@ import {
6
6
  BeaconBlocksByRootRequestType,
7
7
  BlobSidecarsByRootRequestType,
8
8
  DataColumnSidecarsByRootRequestType,
9
+ ExecutionPayloadEnvelopesByRootRequestType,
9
10
  } from "../../../util/types.js";
10
11
  import {GetReqRespHandlerFn, ReqRespMethod} from "../types.js";
11
12
  import {onBeaconBlocksByRange} from "./beaconBlocksByRange.js";
@@ -14,6 +15,8 @@ import {onBlobSidecarsByRange} from "./blobSidecarsByRange.js";
14
15
  import {onBlobSidecarsByRoot} from "./blobSidecarsByRoot.js";
15
16
  import {onDataColumnSidecarsByRange} from "./dataColumnSidecarsByRange.js";
16
17
  import {onDataColumnSidecarsByRoot} from "./dataColumnSidecarsByRoot.js";
18
+ import {onExecutionPayloadEnvelopesByRange} from "./executionPayloadEnvelopesByRange.js";
19
+ import {onExecutionPayloadEnvelopesByRoot} from "./executionPayloadEnvelopesByRoot.js";
17
20
  import {onLightClientBootstrap} from "./lightClientBootstrap.js";
18
21
  import {onLightClientFinalityUpdate} from "./lightClientFinalityUpdate.js";
19
22
  import {onLightClientOptimisticUpdate} from "./lightClientOptimisticUpdate.js";
@@ -62,6 +65,15 @@ export function getReqRespHandlers({db, chain}: {db: IBeaconDb; chain: IBeaconCh
62
65
  return onDataColumnSidecarsByRoot(body, chain, db, peerId, peerClient);
63
66
  },
64
67
 
68
+ [ReqRespMethod.ExecutionPayloadEnvelopesByRoot]: (req) => {
69
+ const body = ExecutionPayloadEnvelopesByRootRequestType(chain.config).deserialize(req.data);
70
+ return onExecutionPayloadEnvelopesByRoot(body, chain, db);
71
+ },
72
+ [ReqRespMethod.ExecutionPayloadEnvelopesByRange]: (req) => {
73
+ const body = ssz.gloas.ExecutionPayloadEnvelopesByRangeRequest.deserialize(req.data);
74
+ return onExecutionPayloadEnvelopesByRange(body, chain, db);
75
+ },
76
+
65
77
  [ReqRespMethod.LightClientBootstrap]: (req) => {
66
78
  const body = ssz.Root.deserialize(req.data);
67
79
  return onLightClientBootstrap(body, chain);
@@ -94,6 +94,18 @@ export const DataColumnSidecarsByRoot = toProtocol({
94
94
  contextBytesType: ContextBytesType.ForkDigest,
95
95
  });
96
96
 
97
+ export const ExecutionPayloadEnvelopesByRoot = toProtocol({
98
+ method: ReqRespMethod.ExecutionPayloadEnvelopesByRoot,
99
+ version: Version.V1,
100
+ contextBytesType: ContextBytesType.ForkDigest,
101
+ });
102
+
103
+ export const ExecutionPayloadEnvelopesByRange = toProtocol({
104
+ method: ReqRespMethod.ExecutionPayloadEnvelopesByRange,
105
+ version: Version.V1,
106
+ contextBytesType: ContextBytesType.ForkDigest,
107
+ });
108
+
97
109
  export const LightClientBootstrap = toProtocol({
98
110
  method: ReqRespMethod.LightClientBootstrap,
99
111
  version: Version.V1,
@@ -73,6 +73,24 @@ export const rateLimitQuotas: (fork: ForkName, config: BeaconConfig) => Record<R
73
73
  req.reduce((total, item) => total + item.columns.length, 0)
74
74
  ),
75
75
  },
76
+ [ReqRespMethod.ExecutionPayloadEnvelopesByRoot]: {
77
+ byPeer: {quota: config.MAX_REQUEST_PAYLOADS, quotaTimeMs: 10_000},
78
+ getRequestCount: getRequestCountFn(
79
+ fork,
80
+ config,
81
+ ReqRespMethod.ExecutionPayloadEnvelopesByRoot,
82
+ (req) => req.length
83
+ ),
84
+ },
85
+ [ReqRespMethod.ExecutionPayloadEnvelopesByRange]: {
86
+ byPeer: {quota: config.MAX_REQUEST_BLOCKS_DENEB, quotaTimeMs: 10_000},
87
+ getRequestCount: getRequestCountFn(
88
+ fork,
89
+ config,
90
+ ReqRespMethod.ExecutionPayloadEnvelopesByRange,
91
+ (req) => req.count
92
+ ),
93
+ },
76
94
  [ReqRespMethod.LightClientBootstrap]: {
77
95
  // As similar in the nature of `Status` protocol so we use the same rate limits.
78
96
  byPeer: {quota: 5, quotaTimeMs: 15_000},
@@ -46,6 +46,8 @@ export function onOutgoingReqRespError(e: RequestError, method: ReqRespMethod):
46
46
  return PeerAction.LowToleranceError;
47
47
  case ReqRespMethod.BeaconBlocksByRange:
48
48
  case ReqRespMethod.BeaconBlocksByRoot:
49
+ case ReqRespMethod.ExecutionPayloadEnvelopesByRoot:
50
+ case ReqRespMethod.ExecutionPayloadEnvelopesByRange:
49
51
  return PeerAction.MidToleranceError;
50
52
  default:
51
53
  return null;
@@ -14,6 +14,7 @@ import {
14
14
  altair,
15
15
  deneb,
16
16
  fulu,
17
+ gloas,
17
18
  phase0,
18
19
  ssz,
19
20
  sszTypesFor,
@@ -25,6 +26,8 @@ import {
25
26
  BlobSidecarsByRootRequestType,
26
27
  DataColumnSidecarsByRootRequest,
27
28
  DataColumnSidecarsByRootRequestType,
29
+ ExecutionPayloadEnvelopesByRootRequest,
30
+ ExecutionPayloadEnvelopesByRootRequestType,
28
31
  } from "../../util/types.js";
29
32
 
30
33
  export type ProtocolNoHandler = Omit<Protocol, "handler">;
@@ -42,6 +45,8 @@ export enum ReqRespMethod {
42
45
  BlobSidecarsByRoot = "blob_sidecars_by_root",
43
46
  DataColumnSidecarsByRange = "data_column_sidecars_by_range",
44
47
  DataColumnSidecarsByRoot = "data_column_sidecars_by_root",
48
+ ExecutionPayloadEnvelopesByRoot = "execution_payload_envelopes_by_root",
49
+ ExecutionPayloadEnvelopesByRange = "execution_payload_envelopes_by_range",
45
50
  LightClientBootstrap = "light_client_bootstrap",
46
51
  LightClientUpdatesByRange = "light_client_updates_by_range",
47
52
  LightClientFinalityUpdate = "light_client_finality_update",
@@ -60,6 +65,8 @@ export type RequestBodyByMethod = {
60
65
  [ReqRespMethod.BlobSidecarsByRoot]: BlobSidecarsByRootRequest;
61
66
  [ReqRespMethod.DataColumnSidecarsByRange]: fulu.DataColumnSidecarsByRangeRequest;
62
67
  [ReqRespMethod.DataColumnSidecarsByRoot]: DataColumnSidecarsByRootRequest;
68
+ [ReqRespMethod.ExecutionPayloadEnvelopesByRoot]: ExecutionPayloadEnvelopesByRootRequest;
69
+ [ReqRespMethod.ExecutionPayloadEnvelopesByRange]: gloas.ExecutionPayloadEnvelopesByRangeRequest;
63
70
  [ReqRespMethod.LightClientBootstrap]: Root;
64
71
  [ReqRespMethod.LightClientUpdatesByRange]: altair.LightClientUpdatesByRange;
65
72
  [ReqRespMethod.LightClientFinalityUpdate]: null;
@@ -78,6 +85,8 @@ type ResponseBodyByMethod = {
78
85
  [ReqRespMethod.BlobSidecarsByRoot]: deneb.BlobSidecar;
79
86
  [ReqRespMethod.DataColumnSidecarsByRange]: fulu.DataColumnSidecar;
80
87
  [ReqRespMethod.DataColumnSidecarsByRoot]: fulu.DataColumnSidecar;
88
+ [ReqRespMethod.ExecutionPayloadEnvelopesByRoot]: gloas.SignedExecutionPayloadEnvelope;
89
+ [ReqRespMethod.ExecutionPayloadEnvelopesByRange]: gloas.SignedExecutionPayloadEnvelope;
81
90
 
82
91
  [ReqRespMethod.LightClientBootstrap]: LightClientBootstrap;
83
92
  [ReqRespMethod.LightClientUpdatesByRange]: LightClientUpdate;
@@ -105,6 +114,8 @@ export const requestSszTypeByMethod: (
105
114
  [ReqRespMethod.BlobSidecarsByRoot]: BlobSidecarsByRootRequestType(fork, config),
106
115
  [ReqRespMethod.DataColumnSidecarsByRange]: ssz.fulu.DataColumnSidecarsByRangeRequest,
107
116
  [ReqRespMethod.DataColumnSidecarsByRoot]: DataColumnSidecarsByRootRequestType(config),
117
+ [ReqRespMethod.ExecutionPayloadEnvelopesByRoot]: ExecutionPayloadEnvelopesByRootRequestType(config),
118
+ [ReqRespMethod.ExecutionPayloadEnvelopesByRange]: ssz.gloas.ExecutionPayloadEnvelopesByRangeRequest,
108
119
 
109
120
  [ReqRespMethod.LightClientBootstrap]: ssz.Root,
110
121
  [ReqRespMethod.LightClientUpdatesByRange]: ssz.altair.LightClientUpdatesByRange,
@@ -137,6 +148,8 @@ export const responseSszTypeByMethod: {[K in ReqRespMethod]: ResponseTypeGetter<
137
148
  [ReqRespMethod.LightClientFinalityUpdate]: (fork) => sszTypesFor(onlyPostAltairFork(fork)).LightClientFinalityUpdate,
138
149
  [ReqRespMethod.DataColumnSidecarsByRange]: () => ssz.fulu.DataColumnSidecar,
139
150
  [ReqRespMethod.DataColumnSidecarsByRoot]: () => ssz.fulu.DataColumnSidecar,
151
+ [ReqRespMethod.ExecutionPayloadEnvelopesByRoot]: () => ssz.gloas.SignedExecutionPayloadEnvelope,
152
+ [ReqRespMethod.ExecutionPayloadEnvelopesByRange]: () => ssz.gloas.SignedExecutionPayloadEnvelope,
140
153
  [ReqRespMethod.LightClientOptimisticUpdate]: (fork) =>
141
154
  sszTypesFor(onlyPostAltairFork(fork)).LightClientOptimisticUpdate,
142
155
  };
package/src/util/types.ts CHANGED
@@ -29,3 +29,9 @@ export type BlobSidecarsByRootRequest = ValueOf<ReturnType<typeof BlobSidecarsBy
29
29
  export const DataColumnSidecarsByRootRequestType = (config: BeaconConfig) =>
30
30
  new ListCompositeType(ssz.fulu.DataColumnsByRootIdentifier, config.MAX_REQUEST_BLOCKS_DENEB);
31
31
  export type DataColumnSidecarsByRootRequest = ValueOf<ReturnType<typeof DataColumnSidecarsByRootRequestType>>;
32
+
33
+ export const ExecutionPayloadEnvelopesByRootRequestType = (config: BeaconConfig) =>
34
+ new ListCompositeType(ssz.Root, config.MAX_REQUEST_PAYLOADS);
35
+ export type ExecutionPayloadEnvelopesByRootRequest = ValueOf<
36
+ ReturnType<typeof ExecutionPayloadEnvelopesByRootRequestType>
37
+ >;