@lodestar/beacon-node 1.41.0-dev.253ed58dd1 → 1.41.0-dev.31b0dd0873

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 (170) hide show
  1. package/lib/api/impl/beacon/state/index.js +8 -8
  2. package/lib/api/impl/beacon/state/index.js.map +1 -1
  3. package/lib/api/impl/beacon/state/utils.d.ts +3 -4
  4. package/lib/api/impl/beacon/state/utils.d.ts.map +1 -1
  5. package/lib/api/impl/beacon/state/utils.js +5 -24
  6. package/lib/api/impl/beacon/state/utils.js.map +1 -1
  7. package/lib/api/impl/node/utils.d.ts +1 -1
  8. package/lib/api/impl/node/utils.d.ts.map +1 -1
  9. package/lib/api/impl/node/utils.js.map +1 -1
  10. package/lib/api/impl/validator/index.d.ts.map +1 -1
  11. package/lib/api/impl/validator/index.js +3 -5
  12. package/lib/api/impl/validator/index.js.map +1 -1
  13. package/lib/chain/archiveStore/historicalState/getHistoricalState.d.ts +5 -6
  14. package/lib/chain/archiveStore/historicalState/getHistoricalState.d.ts.map +1 -1
  15. package/lib/chain/archiveStore/historicalState/getHistoricalState.js +9 -10
  16. package/lib/chain/archiveStore/historicalState/getHistoricalState.js.map +1 -1
  17. package/lib/chain/archiveStore/historicalState/worker.js +3 -3
  18. package/lib/chain/archiveStore/historicalState/worker.js.map +1 -1
  19. package/lib/chain/bls/multithread/index.d.ts +3 -3
  20. package/lib/chain/bls/multithread/index.d.ts.map +1 -1
  21. package/lib/chain/bls/multithread/index.js +5 -5
  22. package/lib/chain/bls/multithread/index.js.map +1 -1
  23. package/lib/chain/bls/multithread/jobItem.d.ts +2 -2
  24. package/lib/chain/bls/multithread/jobItem.d.ts.map +1 -1
  25. package/lib/chain/bls/multithread/jobItem.js +2 -2
  26. package/lib/chain/bls/multithread/jobItem.js.map +1 -1
  27. package/lib/chain/bls/singleThread.d.ts +4 -4
  28. package/lib/chain/bls/singleThread.d.ts.map +1 -1
  29. package/lib/chain/bls/singleThread.js +4 -4
  30. package/lib/chain/bls/singleThread.js.map +1 -1
  31. package/lib/chain/bls/utils.d.ts +2 -2
  32. package/lib/chain/bls/utils.d.ts.map +1 -1
  33. package/lib/chain/bls/utils.js +7 -4
  34. package/lib/chain/bls/utils.js.map +1 -1
  35. package/lib/chain/chain.d.ts +4 -7
  36. package/lib/chain/chain.d.ts.map +1 -1
  37. package/lib/chain/chain.js +8 -10
  38. package/lib/chain/chain.js.map +1 -1
  39. package/lib/chain/interface.d.ts +2 -4
  40. package/lib/chain/interface.d.ts.map +1 -1
  41. package/lib/chain/interface.js.map +1 -1
  42. package/lib/chain/produceBlock/produceBlockBody.d.ts.map +1 -1
  43. package/lib/chain/produceBlock/produceBlockBody.js +8 -1
  44. package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
  45. package/lib/chain/validation/attestation.d.ts.map +1 -1
  46. package/lib/chain/validation/attestation.js +4 -1
  47. package/lib/chain/validation/attestation.js.map +1 -1
  48. package/lib/chain/validation/attesterSlashing.js +1 -1
  49. package/lib/chain/validation/attesterSlashing.js.map +1 -1
  50. package/lib/chain/validation/payloadAttestationMessage.js +8 -1
  51. package/lib/chain/validation/payloadAttestationMessage.js.map +1 -1
  52. package/lib/chain/validation/proposerSlashing.js +1 -1
  53. package/lib/chain/validation/proposerSlashing.js.map +1 -1
  54. package/lib/chain/validation/syncCommitteeContributionAndProof.js +1 -1
  55. package/lib/db/repositories/blockArchive.d.ts.map +1 -1
  56. package/lib/db/repositories/blockArchive.js +1 -2
  57. package/lib/db/repositories/blockArchive.js.map +1 -1
  58. package/lib/execution/engine/http.d.ts +1 -0
  59. package/lib/execution/engine/http.d.ts.map +1 -1
  60. package/lib/execution/engine/http.js +3 -0
  61. package/lib/execution/engine/http.js.map +1 -1
  62. package/lib/metrics/metrics/lodestar.d.ts +3 -0
  63. package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
  64. package/lib/metrics/metrics/lodestar.js +5 -0
  65. package/lib/metrics/metrics/lodestar.js.map +1 -1
  66. package/lib/monitoring/service.d.ts +2 -2
  67. package/lib/monitoring/service.d.ts.map +1 -1
  68. package/lib/monitoring/service.js +3 -2
  69. package/lib/monitoring/service.js.map +1 -1
  70. package/lib/network/core/networkCore.d.ts +3 -3
  71. package/lib/network/core/networkCore.d.ts.map +1 -1
  72. package/lib/network/core/networkCore.js.map +1 -1
  73. package/lib/network/core/networkCoreWorkerHandler.d.ts +3 -3
  74. package/lib/network/core/networkCoreWorkerHandler.d.ts.map +1 -1
  75. package/lib/network/core/types.d.ts +2 -2
  76. package/lib/network/core/types.d.ts.map +1 -1
  77. package/lib/network/events.d.ts +2 -1
  78. package/lib/network/events.d.ts.map +1 -1
  79. package/lib/network/events.js.map +1 -1
  80. package/lib/network/gossip/encoding.d.ts +3 -3
  81. package/lib/network/gossip/encoding.d.ts.map +1 -1
  82. package/lib/network/gossip/encoding.js.map +1 -1
  83. package/lib/network/gossip/gossipsub.d.ts +13 -4
  84. package/lib/network/gossip/gossipsub.d.ts.map +1 -1
  85. package/lib/network/gossip/gossipsub.js +47 -20
  86. package/lib/network/gossip/gossipsub.js.map +1 -1
  87. package/lib/network/gossip/interface.d.ts +3 -3
  88. package/lib/network/gossip/interface.d.ts.map +1 -1
  89. package/lib/network/gossip/scoringParameters.d.ts +1 -1
  90. package/lib/network/gossip/scoringParameters.d.ts.map +1 -1
  91. package/lib/network/gossip/scoringParameters.js +1 -1
  92. package/lib/network/gossip/scoringParameters.js.map +1 -1
  93. package/lib/network/interface.d.ts +3 -3
  94. package/lib/network/interface.d.ts.map +1 -1
  95. package/lib/network/libp2p/index.d.ts +1 -1
  96. package/lib/network/libp2p/index.d.ts.map +1 -1
  97. package/lib/network/libp2p/index.js +29 -9
  98. package/lib/network/libp2p/index.js.map +1 -1
  99. package/lib/network/network.d.ts +2 -2
  100. package/lib/network/network.d.ts.map +1 -1
  101. package/lib/network/network.js.map +1 -1
  102. package/lib/network/options.d.ts.map +1 -1
  103. package/lib/network/options.js +3 -0
  104. package/lib/network/options.js.map +1 -1
  105. package/lib/network/peers/datastore.d.ts +7 -5
  106. package/lib/network/peers/datastore.d.ts.map +1 -1
  107. package/lib/network/peers/datastore.js +10 -10
  108. package/lib/network/peers/datastore.js.map +1 -1
  109. package/lib/network/peers/peerManager.d.ts +3 -0
  110. package/lib/network/peers/peerManager.d.ts.map +1 -1
  111. package/lib/network/peers/peerManager.js +103 -53
  112. package/lib/network/peers/peerManager.js.map +1 -1
  113. package/lib/network/peers/utils/prioritizePeers.d.ts +3 -3
  114. package/lib/network/peers/utils/prioritizePeers.d.ts.map +1 -1
  115. package/lib/network/processor/gossipValidatorFn.js +1 -1
  116. package/lib/network/processor/types.d.ts +1 -1
  117. package/lib/network/processor/types.d.ts.map +1 -1
  118. package/lib/network/reqresp/score.d.ts.map +1 -1
  119. package/lib/network/reqresp/score.js +0 -1
  120. package/lib/network/reqresp/score.js.map +1 -1
  121. package/lib/network/util.js +2 -2
  122. package/lib/network/util.js.map +1 -1
  123. package/lib/node/nodejs.d.ts +3 -5
  124. package/lib/node/nodejs.d.ts.map +1 -1
  125. package/lib/node/nodejs.js +6 -4
  126. package/lib/node/nodejs.js.map +1 -1
  127. package/package.json +38 -41
  128. package/src/api/impl/beacon/state/index.ts +8 -8
  129. package/src/api/impl/beacon/state/utils.ts +15 -29
  130. package/src/api/impl/node/utils.ts +3 -3
  131. package/src/api/impl/validator/index.ts +3 -4
  132. package/src/chain/archiveStore/historicalState/getHistoricalState.ts +10 -11
  133. package/src/chain/archiveStore/historicalState/worker.ts +3 -3
  134. package/src/chain/bls/multithread/index.ts +7 -7
  135. package/src/chain/bls/multithread/jobItem.ts +3 -3
  136. package/src/chain/bls/singleThread.ts +5 -5
  137. package/src/chain/bls/utils.ts +8 -5
  138. package/src/chain/chain.ts +10 -15
  139. package/src/chain/interface.ts +2 -9
  140. package/src/chain/produceBlock/produceBlockBody.ts +9 -2
  141. package/src/chain/validation/attestation.ts +4 -1
  142. package/src/chain/validation/attesterSlashing.ts +1 -1
  143. package/src/chain/validation/payloadAttestationMessage.ts +9 -1
  144. package/src/chain/validation/proposerSlashing.ts +1 -1
  145. package/src/chain/validation/syncCommitteeContributionAndProof.ts +1 -1
  146. package/src/db/repositories/blockArchive.ts +1 -2
  147. package/src/execution/engine/http.ts +3 -0
  148. package/src/metrics/metrics/lodestar.ts +5 -0
  149. package/src/monitoring/service.ts +3 -2
  150. package/src/network/core/networkCore.ts +3 -3
  151. package/src/network/core/networkCoreWorkerHandler.ts +3 -3
  152. package/src/network/core/types.ts +2 -2
  153. package/src/network/events.ts +2 -1
  154. package/src/network/gossip/encoding.ts +3 -3
  155. package/src/network/gossip/gossipsub.ts +86 -25
  156. package/src/network/gossip/interface.ts +3 -3
  157. package/src/network/gossip/scoringParameters.ts +4 -4
  158. package/src/network/interface.ts +3 -3
  159. package/src/network/libp2p/index.ts +33 -10
  160. package/src/network/network.ts +3 -3
  161. package/src/network/options.ts +3 -0
  162. package/src/network/peers/datastore.ts +13 -10
  163. package/src/network/peers/peerManager.ts +118 -54
  164. package/src/network/peers/utils/prioritizePeers.ts +3 -3
  165. package/src/network/processor/gossipValidatorFn.ts +1 -1
  166. package/src/network/processor/types.ts +1 -1
  167. package/src/network/reqresp/score.ts +0 -1
  168. package/src/network/util.ts +2 -2
  169. package/src/node/nodejs.ts +8 -9
  170. package/src/util/workerEvents.ts +1 -1
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "bugs": {
12
12
  "url": "https://github.com/ChainSafe/lodestar/issues"
13
13
  },
14
- "version": "1.41.0-dev.253ed58dd1",
14
+ "version": "1.41.0-dev.31b0dd0873",
15
15
  "type": "module",
16
16
  "exports": {
17
17
  ".": {
@@ -110,10 +110,9 @@
110
110
  "dependencies": {
111
111
  "@chainsafe/as-sha256": "^1.2.0",
112
112
  "@chainsafe/blst": "^2.2.0",
113
- "@chainsafe/discv5": "^11.0.4",
114
- "@chainsafe/enr": "^5.0.1",
115
- "@chainsafe/libp2p-gossipsub": "^14.1.2",
116
- "@chainsafe/libp2p-noise": "^16.1.5",
113
+ "@chainsafe/discv5": "^12.0.0",
114
+ "@chainsafe/enr": "^6.0.0",
115
+ "@chainsafe/libp2p-noise": "^17.0.0",
117
116
  "@chainsafe/persistent-merkle-tree": "^1.2.1",
118
117
  "@chainsafe/prometheus-gc-stats": "^1.0.0",
119
118
  "@chainsafe/pubkey-index-map": "^3.0.0",
@@ -125,39 +124,38 @@
125
124
  "@fastify/cors": "^10.0.1",
126
125
  "@fastify/swagger": "^9.0.0",
127
126
  "@fastify/swagger-ui": "^5.0.1",
128
- "@libp2p/bootstrap": "^11.0.32",
129
- "@libp2p/crypto": "^5.0.15",
130
- "@libp2p/identify": "^3.0.27",
131
- "@libp2p/interface": "^2.7.0",
132
- "@libp2p/mdns": "^11.0.32",
133
- "@libp2p/mplex": "^11.0.32",
134
- "@libp2p/peer-id": "^5.1.0",
135
- "@libp2p/prometheus-metrics": "^4.3.15",
136
- "@libp2p/tcp": "^10.1.8",
137
- "@lodestar/api": "^1.41.0-dev.253ed58dd1",
138
- "@lodestar/config": "^1.41.0-dev.253ed58dd1",
139
- "@lodestar/db": "^1.41.0-dev.253ed58dd1",
140
- "@lodestar/fork-choice": "^1.41.0-dev.253ed58dd1",
141
- "@lodestar/light-client": "^1.41.0-dev.253ed58dd1",
142
- "@lodestar/logger": "^1.41.0-dev.253ed58dd1",
143
- "@lodestar/params": "^1.41.0-dev.253ed58dd1",
144
- "@lodestar/reqresp": "^1.41.0-dev.253ed58dd1",
145
- "@lodestar/state-transition": "^1.41.0-dev.253ed58dd1",
146
- "@lodestar/types": "^1.41.0-dev.253ed58dd1",
147
- "@lodestar/utils": "^1.41.0-dev.253ed58dd1",
148
- "@lodestar/validator": "^1.41.0-dev.253ed58dd1",
149
- "@multiformats/multiaddr": "^12.1.3",
150
- "datastore-core": "^10.0.2",
151
- "datastore-fs": "^10.0.6",
152
- "datastore-level": "^11.0.3",
127
+ "@libp2p/bootstrap": "^12.0.11",
128
+ "@libp2p/crypto": "^5.1.13",
129
+ "@libp2p/gossipsub": "^15.0.12",
130
+ "@libp2p/identify": "^4.0.10",
131
+ "@libp2p/interface": "^3.1.0",
132
+ "@libp2p/mdns": "^12.0.11",
133
+ "@libp2p/mplex": "^12.0.11",
134
+ "@libp2p/peer-id": "^6.0.4",
135
+ "@libp2p/prometheus-metrics": "^5.0.10",
136
+ "@libp2p/tcp": "^11.0.10",
137
+ "@lodestar/api": "^1.41.0-dev.31b0dd0873",
138
+ "@lodestar/config": "^1.41.0-dev.31b0dd0873",
139
+ "@lodestar/db": "^1.41.0-dev.31b0dd0873",
140
+ "@lodestar/fork-choice": "^1.41.0-dev.31b0dd0873",
141
+ "@lodestar/light-client": "^1.41.0-dev.31b0dd0873",
142
+ "@lodestar/logger": "^1.41.0-dev.31b0dd0873",
143
+ "@lodestar/params": "^1.41.0-dev.31b0dd0873",
144
+ "@lodestar/reqresp": "^1.41.0-dev.31b0dd0873",
145
+ "@lodestar/state-transition": "^1.41.0-dev.31b0dd0873",
146
+ "@lodestar/types": "^1.41.0-dev.31b0dd0873",
147
+ "@lodestar/utils": "^1.41.0-dev.31b0dd0873",
148
+ "@lodestar/validator": "^1.41.0-dev.31b0dd0873",
149
+ "@multiformats/multiaddr": "^13.0.1",
150
+ "datastore-core": "^11.0.2",
151
+ "datastore-fs": "^11.0.2",
152
+ "datastore-level": "^12.0.2",
153
153
  "deepmerge": "^4.3.1",
154
154
  "fastify": "^5.7.4",
155
- "interface-datastore": "^8.3.0",
156
- "it-all": "^3.0.4",
157
- "it-pipe": "^3.0.1",
155
+ "interface-datastore": "^9.0.2",
158
156
  "jwt-simple": "0.5.6",
159
- "libp2p": "2.9.0",
160
- "multiformats": "^11.0.1",
157
+ "libp2p": "3.1.3",
158
+ "multiformats": "^13.4.2",
161
159
  "prom-client": "^15.1.0",
162
160
  "qs": "^6.11.1",
163
161
  "strict-event-emitter-types": "^2.0.0",
@@ -167,14 +165,13 @@
167
165
  },
168
166
  "devDependencies": {
169
167
  "@chainsafe/swap-or-not-shuffle": "^1.2.1",
170
- "@libp2p/interface-internal": "^2.3.18",
171
- "@libp2p/logger": "^5.1.21",
172
- "@lodestar/spec-test-util": "^1.41.0-dev.253ed58dd1",
168
+ "@libp2p/interface-internal": "^3.0.10",
169
+ "@libp2p/logger": "^6.2.2",
170
+ "@libp2p/utils": "^7.0.10",
171
+ "@lodestar/spec-test-util": "^1.41.0-dev.31b0dd0873",
173
172
  "@types/js-yaml": "^4.0.5",
174
173
  "@types/qs": "^6.9.7",
175
174
  "@types/tmp": "^0.2.3",
176
- "it-drain": "^3.0.3",
177
- "it-pair": "^2.0.6",
178
175
  "js-yaml": "^4.1.0",
179
176
  "rewiremock": "^3.14.5",
180
177
  "rimraf": "^4.4.1",
@@ -188,5 +185,5 @@
188
185
  "beacon",
189
186
  "blockchain"
190
187
  ],
191
- "gitHead": "955562055aac01532d6386c0da7fe5d6af417c03"
188
+ "gitHead": "26049a9783f70410f123d337a12f3fbeada614f9"
192
189
  }
@@ -95,14 +95,14 @@ export function getBeaconStateApi({
95
95
  const {state, executionOptimistic, finalized} = await getState(stateId);
96
96
  const currentEpoch = getCurrentEpoch(state);
97
97
  const {validators, balances} = state; // Get the validators sub tree once for all the loop
98
- const {pubkey2index} = chain;
98
+ const {pubkeyCache} = chain;
99
99
 
100
100
  const validatorResponses: routes.beacon.ValidatorResponse[] = [];
101
101
  if (validatorIds.length) {
102
102
  assertUniqueItems(validatorIds, "Duplicate validator IDs provided");
103
103
 
104
104
  for (const id of validatorIds) {
105
- const resp = getStateValidatorIndex(id, state, pubkey2index);
105
+ const resp = getStateValidatorIndex(id, state, pubkeyCache);
106
106
  if (resp.valid) {
107
107
  const validatorIndex = resp.validatorIndex;
108
108
  const validator = validators.getReadonly(validatorIndex);
@@ -127,7 +127,7 @@ export function getBeaconStateApi({
127
127
  if (statuses.length) {
128
128
  assertUniqueItems(statuses, "Duplicate statuses provided");
129
129
 
130
- const validatorsByStatus = filterStateValidatorsByStatus(statuses, state, pubkey2index, currentEpoch);
130
+ const validatorsByStatus = filterStateValidatorsByStatus(statuses, state, pubkeyCache, currentEpoch);
131
131
  return {
132
132
  data: validatorsByStatus,
133
133
  meta: {executionOptimistic, finalized},
@@ -154,7 +154,7 @@ export function getBeaconStateApi({
154
154
 
155
155
  async postStateValidatorIdentities({stateId, validatorIds = []}) {
156
156
  const {state, executionOptimistic, finalized} = await getState(stateId);
157
- const {pubkey2index} = chain;
157
+ const {pubkeyCache} = chain;
158
158
 
159
159
  let validatorIdentities: routes.beacon.ValidatorIdentities;
160
160
 
@@ -163,7 +163,7 @@ export function getBeaconStateApi({
163
163
 
164
164
  validatorIdentities = [];
165
165
  for (const id of validatorIds) {
166
- const resp = getStateValidatorIndex(id, state, pubkey2index);
166
+ const resp = getStateValidatorIndex(id, state, pubkeyCache);
167
167
  if (resp.valid) {
168
168
  const index = resp.validatorIndex;
169
169
  const {pubkey, activationEpoch} = state.validators.getReadonly(index);
@@ -187,9 +187,9 @@ export function getBeaconStateApi({
187
187
 
188
188
  async getStateValidator({stateId, validatorId}) {
189
189
  const {state, executionOptimistic, finalized} = await getState(stateId);
190
- const {pubkey2index} = chain;
190
+ const {pubkeyCache} = chain;
191
191
 
192
- const resp = getStateValidatorIndex(validatorId, state, pubkey2index);
192
+ const resp = getStateValidatorIndex(validatorId, state, pubkeyCache);
193
193
  if (!resp.valid) {
194
194
  throw new ApiError(resp.code, resp.reason);
195
195
  }
@@ -214,7 +214,7 @@ export function getBeaconStateApi({
214
214
 
215
215
  const balances: routes.beacon.ValidatorBalance[] = [];
216
216
  for (const id of validatorIds) {
217
- const resp = getStateValidatorIndex(id, state, chain.pubkey2index);
217
+ const resp = getStateValidatorIndex(id, state, chain.pubkeyCache);
218
218
 
219
219
  if (resp.valid) {
220
220
  balances.push({
@@ -1,9 +1,17 @@
1
- import {PubkeyIndexMap} from "@chainsafe/pubkey-index-map";
2
1
  import {routes} from "@lodestar/api";
3
2
  import {CheckpointWithHex, IForkChoice} from "@lodestar/fork-choice";
4
3
  import {GENESIS_SLOT} from "@lodestar/params";
5
- import {BeaconStateAllForks, CachedBeaconStateAllForks} from "@lodestar/state-transition";
6
- import {BLSPubkey, Epoch, RootHex, Slot, ValidatorIndex, getValidatorStatus, phase0} from "@lodestar/types";
4
+ import {BeaconStateAllForks, CachedBeaconStateAllForks, PubkeyCache} from "@lodestar/state-transition";
5
+ import {
6
+ BLSPubkey,
7
+ Epoch,
8
+ RootHex,
9
+ Slot,
10
+ ValidatorIndex,
11
+ getValidatorStatus,
12
+ mapToGeneralStatus,
13
+ phase0,
14
+ } from "@lodestar/types";
7
15
  import {fromHex} from "@lodestar/utils";
8
16
  import {IBeaconChain} from "../../../../chain/index.js";
9
17
  import {ApiError, ValidationError} from "../../errors.js";
@@ -65,28 +73,6 @@ export async function getStateResponseWithRegen(
65
73
  return res;
66
74
  }
67
75
 
68
- type GeneralValidatorStatus = "active" | "pending" | "exited" | "withdrawal";
69
-
70
- function mapToGeneralStatus(subStatus: routes.beacon.ValidatorStatus): GeneralValidatorStatus {
71
- switch (subStatus) {
72
- case "active_ongoing":
73
- case "active_exiting":
74
- case "active_slashed":
75
- return "active";
76
- case "pending_initialized":
77
- case "pending_queued":
78
- return "pending";
79
- case "exited_slashed":
80
- case "exited_unslashed":
81
- return "exited";
82
- case "withdrawal_possible":
83
- case "withdrawal_done":
84
- return "withdrawal";
85
- default:
86
- throw new Error(`Unknown substatus: ${subStatus}`);
87
- }
88
- }
89
-
90
76
  export function toValidatorResponse(
91
77
  index: ValidatorIndex,
92
78
  validator: phase0.Validator,
@@ -104,7 +90,7 @@ export function toValidatorResponse(
104
90
  export function filterStateValidatorsByStatus(
105
91
  statuses: string[],
106
92
  state: BeaconStateAllForks,
107
- pubkey2index: PubkeyIndexMap,
93
+ pubkeyCache: PubkeyCache,
108
94
  currentEpoch: Epoch
109
95
  ): routes.beacon.ValidatorResponse[] {
110
96
  const responses: routes.beacon.ValidatorResponse[] = [];
@@ -115,7 +101,7 @@ export function filterStateValidatorsByStatus(
115
101
  const validatorStatus = getValidatorStatus(validator, currentEpoch);
116
102
  const generalStatus = mapToGeneralStatus(validatorStatus);
117
103
 
118
- const resp = getStateValidatorIndex(validator.pubkey, state, pubkey2index);
104
+ const resp = getStateValidatorIndex(validator.pubkey, state, pubkeyCache);
119
105
  if (resp.valid && (statusSet.has(validatorStatus) || statusSet.has(generalStatus))) {
120
106
  responses.push(
121
107
  toValidatorResponse(resp.validatorIndex, validator, state.balances.get(resp.validatorIndex), currentEpoch)
@@ -132,7 +118,7 @@ type StateValidatorIndexResponse =
132
118
  export function getStateValidatorIndex(
133
119
  id: routes.beacon.ValidatorId | BLSPubkey,
134
120
  state: BeaconStateAllForks,
135
- pubkey2index: PubkeyIndexMap
121
+ pubkeyCache: PubkeyCache
136
122
  ): StateValidatorIndexResponse {
137
123
  if (typeof id === "string") {
138
124
  // mutate `id` and fallthrough to below
@@ -160,7 +146,7 @@ export function getStateValidatorIndex(
160
146
  }
161
147
 
162
148
  // typeof id === Uint8Array
163
- const validatorIndex = pubkey2index.get(id);
149
+ const validatorIndex = pubkeyCache.getIndex(id);
164
150
  if (validatorIndex === null) {
165
151
  return {valid: false, code: 404, reason: "Validator pubkey not found in state"};
166
152
  }
@@ -1,4 +1,4 @@
1
- import {Connection, StreamStatus} from "@libp2p/interface";
1
+ import type {Connection, ConnectionStatus} from "@libp2p/interface";
2
2
  import {routes} from "@lodestar/api";
3
3
 
4
4
  /**
@@ -24,7 +24,7 @@ export function formatNodePeer(peerIdStr: string, connections: Connection[]): ro
24
24
  * - Otherwise, the first closed connection
25
25
  */
26
26
  export function getRelevantConnection(connections: Connection[]): Connection | null {
27
- const byStatus = new Map<StreamStatus, Connection>();
27
+ const byStatus = new Map<ConnectionStatus, Connection>();
28
28
  for (const conn of connections) {
29
29
  if (conn.status === "open") return conn;
30
30
  if (!byStatus.has(conn.status)) byStatus.set(conn.status, conn);
@@ -37,7 +37,7 @@ export function getRelevantConnection(connections: Connection[]): Connection | n
37
37
  * Map libp2p connection status to the API's peer state notation
38
38
  * @param status
39
39
  */
40
- function getPeerState(status: StreamStatus): routes.node.PeerState {
40
+ function getPeerState(status: ConnectionStatus): routes.node.PeerState {
41
41
  switch (status) {
42
42
  case "open":
43
43
  return "connected";
@@ -1,4 +1,3 @@
1
- import {PubkeyIndexMap} from "@chainsafe/pubkey-index-map";
2
1
  import {routes} from "@lodestar/api";
3
2
  import {ApplicationMethods} from "@lodestar/api/server";
4
3
  import {ExecutionStatus, ProtoBlock} from "@lodestar/fork-choice";
@@ -27,6 +26,7 @@ import {
27
26
  computeStartSlotAtEpoch,
28
27
  computeTimeAtSlot,
29
28
  createCachedBeaconState,
29
+ createPubkeyCache,
30
30
  getBlockRootAtSlot,
31
31
  getCurrentSlot,
32
32
  loadState,
@@ -1123,8 +1123,7 @@ export function getValidatorApi(
1123
1123
  {
1124
1124
  config: chain.config,
1125
1125
  // Not required to compute proposers
1126
- pubkey2index: new PubkeyIndexMap(),
1127
- index2pubkey: [],
1126
+ pubkeyCache: createPubkeyCache(),
1128
1127
  },
1129
1128
  {skipSyncPubkeys: true, skipSyncCommitteeCache: true}
1130
1129
  );
@@ -1585,7 +1584,7 @@ export function getValidatorApi(
1585
1584
 
1586
1585
  const filteredRegistrations = registrations.filter((registration) => {
1587
1586
  const {pubkey} = registration.message;
1588
- const validatorIndex = chain.pubkey2index.get(pubkey);
1587
+ const validatorIndex = chain.pubkeyCache.getIndex(pubkey);
1589
1588
  if (validatorIndex === null) return false;
1590
1589
 
1591
1590
  const validator = headState.validators.getReadonly(validatorIndex);
@@ -1,10 +1,10 @@
1
- import {PubkeyIndexMap} from "@chainsafe/pubkey-index-map";
2
1
  import {BeaconConfig} from "@lodestar/config";
3
2
  import {
4
3
  BeaconStateAllForks,
5
4
  CachedBeaconStateAllForks,
6
5
  DataAvailabilityStatus,
7
6
  ExecutionPayloadStatus,
7
+ PubkeyCache,
8
8
  createCachedBeaconState,
9
9
  stateTransition,
10
10
  } from "@lodestar/state-transition";
@@ -15,16 +15,16 @@ import {HistoricalStateRegenMetrics} from "./metrics.js";
15
15
  import {RegenErrorType} from "./types.js";
16
16
 
17
17
  /**
18
- * Populate a PubkeyIndexMap with any new entries based on a BeaconState
18
+ * Populate a PubkeyCache with any new entries based on a BeaconState
19
19
  */
20
- export function syncPubkeyCache(state: BeaconStateAllForks, pubkey2index: PubkeyIndexMap): void {
20
+ export function syncPubkeyCache(state: BeaconStateAllForks, pubkeyCache: PubkeyCache): void {
21
21
  // Get the validators sub tree once for all the loop
22
22
  const validators = state.validators;
23
23
 
24
24
  const newCount = state.validators.length;
25
- for (let i = pubkey2index.size; i < newCount; i++) {
25
+ for (let i = pubkeyCache.size; i < newCount; i++) {
26
26
  const pubkey = validators.getReadonly(i).pubkey;
27
- pubkey2index.set(pubkey, i);
27
+ pubkeyCache.set(i, pubkey);
28
28
  }
29
29
  }
30
30
 
@@ -35,7 +35,7 @@ export async function getNearestState(
35
35
  slot: number,
36
36
  config: BeaconConfig,
37
37
  db: IBeaconDb,
38
- pubkey2index: PubkeyIndexMap
38
+ pubkeyCache: PubkeyCache
39
39
  ): Promise<CachedBeaconStateAllForks> {
40
40
  const stateBytesArr = await db.stateArchive.binaries({limit: 1, lte: slot, reverse: true});
41
41
  if (!stateBytesArr.length) {
@@ -44,14 +44,13 @@ export async function getNearestState(
44
44
 
45
45
  const stateBytes = stateBytesArr[0];
46
46
  const state = getStateTypeFromBytes(config, stateBytes).deserializeToViewDU(stateBytes);
47
- syncPubkeyCache(state, pubkey2index);
47
+ syncPubkeyCache(state, pubkeyCache);
48
48
 
49
49
  return createCachedBeaconState(
50
50
  state,
51
51
  {
52
52
  config,
53
- pubkey2index,
54
- index2pubkey: [],
53
+ pubkeyCache,
55
54
  },
56
55
  {
57
56
  skipSyncPubkeys: true,
@@ -66,13 +65,13 @@ export async function getHistoricalState(
66
65
  slot: number,
67
66
  config: BeaconConfig,
68
67
  db: IBeaconDb,
69
- pubkey2index: PubkeyIndexMap,
68
+ pubkeyCache: PubkeyCache,
70
69
  metrics?: HistoricalStateRegenMetrics
71
70
  ): Promise<Uint8Array> {
72
71
  const regenTimer = metrics?.regenTime.startTimer();
73
72
 
74
73
  const loadStateTimer = metrics?.loadStateTime.startTimer();
75
- let state = await getNearestState(slot, config, db, pubkey2index).catch((e) => {
74
+ let state = await getNearestState(slot, config, db, pubkeyCache).catch((e) => {
76
75
  metrics?.regenErrorCount.inc({reason: RegenErrorType.loadState});
77
76
  throw e;
78
77
  });
@@ -1,9 +1,9 @@
1
1
  import worker from "node:worker_threads";
2
- import {PubkeyIndexMap} from "@chainsafe/pubkey-index-map";
3
2
  import {Transfer, expose} from "@chainsafe/threads/worker";
4
3
  import {chainConfigFromJson, createBeaconConfig} from "@lodestar/config";
5
4
  import {LevelDbController} from "@lodestar/db/controller/level";
6
5
  import {getNodeLogger} from "@lodestar/logger/node";
6
+ import {createPubkeyCache} from "@lodestar/state-transition";
7
7
  import {BeaconDb} from "../../../db/index.js";
8
8
  import {RegistryMetricCreator, collectNodeJSMetrics} from "../../../metrics/index.js";
9
9
  import {JobFnQueue} from "../../../util/queue/fnQueue.js";
@@ -52,7 +52,7 @@ const queue = new JobFnQueue(
52
52
  queueMetrics
53
53
  );
54
54
 
55
- const pubkey2index = new PubkeyIndexMap();
55
+ const pubkeyCache = createPubkeyCache();
56
56
 
57
57
  const api: HistoricalStateWorkerApi = {
58
58
  async close() {
@@ -65,7 +65,7 @@ const api: HistoricalStateWorkerApi = {
65
65
  historicalStateRegenMetrics?.regenRequestCount.inc();
66
66
 
67
67
  const stateBytes = await queue.push<Uint8Array>(() =>
68
- getHistoricalState(slot, config, db, pubkey2index, historicalStateRegenMetrics)
68
+ getHistoricalState(slot, config, db, pubkeyCache, historicalStateRegenMetrics)
69
69
  );
70
70
  const result = Transfer(stateBytes, [stateBytes.buffer]) as unknown as Uint8Array;
71
71
 
@@ -7,7 +7,7 @@ import {Worker, spawn} from "@chainsafe/threads";
7
7
  self = undefined;
8
8
 
9
9
  import {PublicKey} from "@chainsafe/blst";
10
- import {ISignatureSet, Index2PubkeyCache} from "@lodestar/state-transition";
10
+ import {ISignatureSet, PubkeyCache} from "@lodestar/state-transition";
11
11
  import {Logger} from "@lodestar/utils";
12
12
  import {Metrics} from "../../../metrics/index.js";
13
13
  import {LinkedList} from "../../../util/array.js";
@@ -34,7 +34,7 @@ const workerDir = process.env.NODE_ENV === "test" ? "../../../../lib/chain/bls/m
34
34
  export type BlsMultiThreadWorkerPoolModules = {
35
35
  logger: Logger;
36
36
  metrics: Metrics | null;
37
- index2pubkey: Index2PubkeyCache;
37
+ pubkeyCache: PubkeyCache;
38
38
  };
39
39
 
40
40
  export type BlsMultiThreadWorkerPoolOptions = {
@@ -114,7 +114,7 @@ type WorkerDescriptor = {
114
114
  export class BlsMultiThreadWorkerPool implements IBlsVerifier {
115
115
  private readonly logger: Logger;
116
116
  private readonly metrics: Metrics | null;
117
- private readonly index2pubkey: Index2PubkeyCache;
117
+ private readonly pubkeyCache: PubkeyCache;
118
118
 
119
119
  private readonly workers: WorkerDescriptor[];
120
120
  private readonly jobs = new LinkedList<JobQueueItem>();
@@ -130,10 +130,10 @@ export class BlsMultiThreadWorkerPool implements IBlsVerifier {
130
130
  private workersBusy = 0;
131
131
 
132
132
  constructor(options: BlsMultiThreadWorkerPoolOptions, modules: BlsMultiThreadWorkerPoolModules) {
133
- const {logger, metrics, index2pubkey} = modules;
133
+ const {logger, metrics, pubkeyCache} = modules;
134
134
  this.logger = logger;
135
135
  this.metrics = metrics;
136
- this.index2pubkey = index2pubkey;
136
+ this.pubkeyCache = pubkeyCache;
137
137
  this.blsVerifyAllMultiThread = options.blsVerifyAllMultiThread ?? false;
138
138
 
139
139
  // Use compressed for herumi for now.
@@ -173,7 +173,7 @@ export class BlsMultiThreadWorkerPool implements IBlsVerifier {
173
173
  try {
174
174
  return verifySignatureSetsMaybeBatch(
175
175
  sets.map((set) => ({
176
- publicKey: getAggregatedPubkey(set, this.index2pubkey),
176
+ publicKey: getAggregatedPubkey(set, this.pubkeyCache),
177
177
  message: set.signingRoot.valueOf(),
178
178
  signature: set.signature,
179
179
  }))
@@ -398,7 +398,7 @@ export class BlsMultiThreadWorkerPool implements IBlsVerifier {
398
398
  try {
399
399
  // Note: This can throw, must be handled per-job.
400
400
  // Pubkey and signature aggregation is defered here
401
- workReq = await jobItemWorkReq(job, this.index2pubkey, this.metrics);
401
+ workReq = await jobItemWorkReq(job, this.pubkeyCache, this.metrics);
402
402
  } catch (e) {
403
403
  this.metrics?.blsThreadPool.errorAggregateSignatureSetsCount.inc({type: job.type});
404
404
 
@@ -1,5 +1,5 @@
1
1
  import {PublicKey, asyncAggregateWithRandomness} from "@chainsafe/blst";
2
- import {ISignatureSet, Index2PubkeyCache, SignatureSetType} from "@lodestar/state-transition";
2
+ import {ISignatureSet, PubkeyCache, SignatureSetType} from "@lodestar/state-transition";
3
3
  import {Metrics} from "../../../metrics/metrics.js";
4
4
  import {LinkedList} from "../../../util/array.js";
5
5
  import {VerifySignatureOpts} from "../interface.js";
@@ -50,7 +50,7 @@ export function jobItemSigSets(job: JobQueueItem): number {
50
50
  */
51
51
  export async function jobItemWorkReq(
52
52
  job: JobQueueItem,
53
- index2pubkey: Index2PubkeyCache,
53
+ pubkeyCache: PubkeyCache,
54
54
  metrics: Metrics | null
55
55
  ): Promise<BlsWorkReq> {
56
56
  switch (job.type) {
@@ -59,7 +59,7 @@ export async function jobItemWorkReq(
59
59
  opts: job.opts,
60
60
  sets: job.sets.map((set) => ({
61
61
  // this can throw, handled in the consumer code
62
- publicKey: getAggregatedPubkey(set, index2pubkey, metrics).toBytes(),
62
+ publicKey: getAggregatedPubkey(set, pubkeyCache, metrics).toBytes(),
63
63
  signature: set.signature,
64
64
  message: set.signingRoot,
65
65
  })),
@@ -1,5 +1,5 @@
1
1
  import {PublicKey, Signature, aggregatePublicKeys, aggregateSignatures, verify} from "@chainsafe/blst";
2
- import {ISignatureSet, Index2PubkeyCache} from "@lodestar/state-transition";
2
+ import {ISignatureSet, PubkeyCache} from "@lodestar/state-transition";
3
3
  import {Metrics} from "../../metrics/index.js";
4
4
  import {IBlsVerifier} from "./interface.js";
5
5
  import {verifySignatureSetsMaybeBatch} from "./maybeBatch.js";
@@ -7,18 +7,18 @@ import {getAggregatedPubkey, getAggregatedPubkeysCount} from "./utils.js";
7
7
 
8
8
  export class BlsSingleThreadVerifier implements IBlsVerifier {
9
9
  private readonly metrics: Metrics | null;
10
- private readonly index2pubkey: Index2PubkeyCache;
10
+ private readonly pubkeyCache: PubkeyCache;
11
11
 
12
- constructor({metrics = null, index2pubkey}: {metrics: Metrics | null; index2pubkey: Index2PubkeyCache}) {
12
+ constructor({metrics = null, pubkeyCache}: {metrics: Metrics | null; pubkeyCache: PubkeyCache}) {
13
13
  this.metrics = metrics;
14
- this.index2pubkey = index2pubkey;
14
+ this.pubkeyCache = pubkeyCache;
15
15
  }
16
16
 
17
17
  async verifySignatureSets(sets: ISignatureSet[]): Promise<boolean> {
18
18
  this.metrics?.bls.aggregatedPubkeys.inc(getAggregatedPubkeysCount(sets));
19
19
 
20
20
  const setsAggregated = sets.map((set) => ({
21
- publicKey: getAggregatedPubkey(set, this.index2pubkey, this.metrics),
21
+ publicKey: getAggregatedPubkey(set, this.pubkeyCache, this.metrics),
22
22
  message: set.signingRoot,
23
23
  signature: set.signature,
24
24
  }));
@@ -1,22 +1,25 @@
1
1
  import {PublicKey, aggregatePublicKeys} from "@chainsafe/blst";
2
- import {ISignatureSet, Index2PubkeyCache, SignatureSetType} from "@lodestar/state-transition";
2
+ import {ISignatureSet, PubkeyCache, SignatureSetType} from "@lodestar/state-transition";
3
3
  import {Metrics} from "../../metrics/metrics.js";
4
4
 
5
5
  export function getAggregatedPubkey(
6
6
  signatureSet: ISignatureSet,
7
- index2pubkey: Index2PubkeyCache,
7
+ pubkeyCache: PubkeyCache,
8
8
  metrics: Metrics | null = null
9
9
  ): PublicKey {
10
10
  switch (signatureSet.type) {
11
11
  case SignatureSetType.single:
12
12
  return signatureSet.pubkey;
13
13
 
14
- case SignatureSetType.indexed:
15
- return index2pubkey[signatureSet.index];
14
+ case SignatureSetType.indexed: {
15
+ return pubkeyCache.getOrThrow(signatureSet.index);
16
+ }
16
17
 
17
18
  case SignatureSetType.aggregate: {
18
19
  const timer = metrics?.blsThreadPool.pubkeysAggregationMainThreadDuration.startTimer();
19
- const pubkeys = signatureSet.indices.map((i) => index2pubkey[i]);
20
+ const pubkeys = signatureSet.indices.map((i) => {
21
+ return pubkeyCache.getOrThrow(i);
22
+ });
20
23
  const aggregated = aggregatePublicKeys(pubkeys);
21
24
  timer?.();
22
25
  return aggregated;
@@ -1,6 +1,5 @@
1
1
  import path from "node:path";
2
2
  import {PrivateKey} from "@libp2p/interface";
3
- import {PubkeyIndexMap} from "@chainsafe/pubkey-index-map";
4
3
  import {CompositeTypeAny, TreeView, Type} from "@chainsafe/ssz";
5
4
  import {BeaconConfig} from "@lodestar/config";
6
5
  import {CheckpointWithHex, IForkChoice, ProtoBlock, UpdateHeadOpt} from "@lodestar/fork-choice";
@@ -21,7 +20,7 @@ import {
21
20
  CachedBeaconStateGloas,
22
21
  EffectiveBalanceIncrements,
23
22
  EpochShuffling,
24
- Index2PubkeyCache,
23
+ PubkeyCache,
25
24
  computeAnchorCheckpoint,
26
25
  computeAttestationsRewards,
27
26
  computeBlockRewards,
@@ -192,8 +191,7 @@ export class BeaconChain implements IBeaconChain {
192
191
  readonly seenBlockAttesters = new SeenBlockAttesters();
193
192
 
194
193
  // Global state caches
195
- readonly pubkey2index: PubkeyIndexMap;
196
- readonly index2pubkey: Index2PubkeyCache;
194
+ readonly pubkeyCache: PubkeyCache;
197
195
 
198
196
  readonly beaconProposerCache: BeaconProposerCache;
199
197
  readonly checkpointBalancesCache: CheckpointBalancesCache;
@@ -239,8 +237,7 @@ export class BeaconChain implements IBeaconChain {
239
237
  {
240
238
  privateKey,
241
239
  config,
242
- pubkey2index,
243
- index2pubkey,
240
+ pubkeyCache,
244
241
  db,
245
242
  dbName,
246
243
  dataDir,
@@ -256,8 +253,7 @@ export class BeaconChain implements IBeaconChain {
256
253
  }: {
257
254
  privateKey: PrivateKey;
258
255
  config: BeaconConfig;
259
- pubkey2index: PubkeyIndexMap;
260
- index2pubkey: Index2PubkeyCache;
256
+ pubkeyCache: PubkeyCache;
261
257
  db: IBeaconDb;
262
258
  dbName: string;
263
259
  dataDir: string;
@@ -289,8 +285,8 @@ export class BeaconChain implements IBeaconChain {
289
285
  const emitter = new ChainEventEmitter();
290
286
  // by default, verify signatures on both main threads and worker threads
291
287
  const bls = opts.blsVerifyAllMainThread
292
- ? new BlsSingleThreadVerifier({metrics, index2pubkey})
293
- : new BlsMultiThreadWorkerPool(opts, {logger, metrics, index2pubkey});
288
+ ? new BlsSingleThreadVerifier({metrics, pubkeyCache})
289
+ : new BlsMultiThreadWorkerPool(opts, {logger, metrics, pubkeyCache});
294
290
 
295
291
  if (!clock) clock = new Clock({config, genesisTime: this.genesisTime, signal});
296
292
 
@@ -346,8 +342,7 @@ export class BeaconChain implements IBeaconChain {
346
342
  ]);
347
343
 
348
344
  // Global cache of validators pubkey/index mapping
349
- this.pubkey2index = pubkey2index;
350
- this.index2pubkey = index2pubkey;
345
+ this.pubkeyCache = pubkeyCache;
351
346
 
352
347
  const fileDataStore = opts.nHistoricalStatesFileDataStore ?? true;
353
348
  const blockStateCache = new FIFOBlockStateCache(this.opts, {metrics});
@@ -920,7 +915,7 @@ export class BeaconChain implements IBeaconChain {
920
915
  RegenCaller.produceBlock
921
916
  );
922
917
  const proposerIndex = state.epochCtx.getBeaconProposer(slot);
923
- const proposerPubKey = this.index2pubkey[proposerIndex].toBytes();
918
+ const proposerPubKey = this.pubkeyCache.getOrThrow(proposerIndex).toBytes();
924
919
 
925
920
  const {body, produceResult, executionPayloadValue, shouldOverrideBuilder} = await produceBlockBody.call(
926
921
  this,
@@ -1536,7 +1531,7 @@ export class BeaconChain implements IBeaconChain {
1536
1531
  throw Error(`State is not in cache for slot ${slot}`);
1537
1532
  }
1538
1533
 
1539
- const rewards = await computeAttestationsRewards(this.config, this.pubkey2index, cachedState, validatorIds);
1534
+ const rewards = await computeAttestationsRewards(this.config, this.pubkeyCache, cachedState, validatorIds);
1540
1535
 
1541
1536
  return {rewards, executionOptimistic, finalized};
1542
1537
  }
@@ -1553,6 +1548,6 @@ export class BeaconChain implements IBeaconChain {
1553
1548
 
1554
1549
  preState = processSlots(preState, block.slot); // Dial preState's slot to block.slot
1555
1550
 
1556
- return computeSyncCommitteeRewards(this.config, this.index2pubkey, block, preState, validatorIds);
1551
+ return computeSyncCommitteeRewards(this.config, this.pubkeyCache, block, preState, validatorIds);
1557
1552
  }
1558
1553
  }