@lodestar/beacon-node 1.36.0-dev.c7f3e8d129 → 1.36.0-dev.d690a62b6c

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 (137) hide show
  1. package/lib/api/impl/beacon/blocks/index.d.ts.map +1 -1
  2. package/lib/api/impl/beacon/blocks/index.js +41 -22
  3. package/lib/api/impl/beacon/blocks/index.js.map +1 -1
  4. package/lib/api/impl/lodestar/index.d.ts +5 -0
  5. package/lib/api/impl/lodestar/index.d.ts.map +1 -1
  6. package/lib/api/impl/lodestar/index.js +35 -10
  7. package/lib/api/impl/lodestar/index.js.map +1 -1
  8. package/lib/api/impl/node/utils.js +1 -1
  9. package/lib/api/impl/node/utils.js.map +1 -1
  10. package/lib/chain/archiveStore/archiveStore.d.ts +9 -0
  11. package/lib/chain/archiveStore/archiveStore.d.ts.map +1 -1
  12. package/lib/chain/archiveStore/archiveStore.js +24 -0
  13. package/lib/chain/archiveStore/archiveStore.js.map +1 -1
  14. package/lib/chain/archiveStore/strategies/frequencyStateArchiveStrategy.d.ts +7 -0
  15. package/lib/chain/archiveStore/strategies/frequencyStateArchiveStrategy.d.ts.map +1 -1
  16. package/lib/chain/archiveStore/strategies/frequencyStateArchiveStrategy.js +31 -5
  17. package/lib/chain/archiveStore/strategies/frequencyStateArchiveStrategy.js.map +1 -1
  18. package/lib/chain/chain.d.ts +5 -2
  19. package/lib/chain/chain.d.ts.map +1 -1
  20. package/lib/chain/chain.js +32 -16
  21. package/lib/chain/chain.js.map +1 -1
  22. package/lib/chain/errors/dataColumnSidecarError.d.ts +7 -0
  23. package/lib/chain/errors/dataColumnSidecarError.d.ts.map +1 -1
  24. package/lib/chain/errors/dataColumnSidecarError.js +1 -0
  25. package/lib/chain/errors/dataColumnSidecarError.js.map +1 -1
  26. package/lib/chain/forkChoice/index.d.ts +9 -1
  27. package/lib/chain/forkChoice/index.d.ts.map +1 -1
  28. package/lib/chain/forkChoice/index.js +109 -4
  29. package/lib/chain/forkChoice/index.js.map +1 -1
  30. package/lib/chain/interface.d.ts +2 -0
  31. package/lib/chain/interface.d.ts.map +1 -1
  32. package/lib/chain/options.d.ts +0 -2
  33. package/lib/chain/options.d.ts.map +1 -1
  34. package/lib/chain/options.js +0 -1
  35. package/lib/chain/options.js.map +1 -1
  36. package/lib/chain/stateCache/datastore/db.d.ts +12 -0
  37. package/lib/chain/stateCache/datastore/db.d.ts.map +1 -1
  38. package/lib/chain/stateCache/datastore/db.js +70 -0
  39. package/lib/chain/stateCache/datastore/db.js.map +1 -1
  40. package/lib/chain/stateCache/datastore/file.d.ts +1 -0
  41. package/lib/chain/stateCache/datastore/file.d.ts.map +1 -1
  42. package/lib/chain/stateCache/datastore/file.js +7 -0
  43. package/lib/chain/stateCache/datastore/file.js.map +1 -1
  44. package/lib/chain/stateCache/datastore/types.d.ts +1 -0
  45. package/lib/chain/stateCache/datastore/types.d.ts.map +1 -1
  46. package/lib/chain/validation/dataColumnSidecar.d.ts.map +1 -1
  47. package/lib/chain/validation/dataColumnSidecar.js +14 -3
  48. package/lib/chain/validation/dataColumnSidecar.js.map +1 -1
  49. package/lib/index.d.ts +2 -0
  50. package/lib/index.d.ts.map +1 -1
  51. package/lib/index.js +2 -0
  52. package/lib/index.js.map +1 -1
  53. package/lib/metrics/metrics/lodestar.d.ts +10 -0
  54. package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
  55. package/lib/metrics/metrics/lodestar.js +15 -1
  56. package/lib/metrics/metrics/lodestar.js.map +1 -1
  57. package/lib/network/core/networkCore.d.ts.map +1 -1
  58. package/lib/network/core/networkCore.js +5 -1
  59. package/lib/network/core/networkCore.js.map +1 -1
  60. package/lib/network/core/networkCoreWorker.js +2 -7
  61. package/lib/network/core/networkCoreWorker.js.map +1 -1
  62. package/lib/network/discv5/worker.js +2 -7
  63. package/lib/network/discv5/worker.js.map +1 -1
  64. package/lib/network/gossip/encoding.js +1 -1
  65. package/lib/network/gossip/encoding.js.map +1 -1
  66. package/lib/network/gossip/snappy_bun.d.ts +3 -0
  67. package/lib/network/gossip/snappy_bun.d.ts.map +1 -0
  68. package/lib/network/gossip/snappy_bun.js +3 -0
  69. package/lib/network/gossip/snappy_bun.js.map +1 -0
  70. package/lib/network/metadata.d.ts +1 -1
  71. package/lib/network/metadata.d.ts.map +1 -1
  72. package/lib/network/metadata.js +1 -0
  73. package/lib/network/metadata.js.map +1 -1
  74. package/lib/network/options.d.ts +0 -1
  75. package/lib/network/options.d.ts.map +1 -1
  76. package/lib/network/options.js.map +1 -1
  77. package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
  78. package/lib/network/processor/gossipHandlers.js +14 -8
  79. package/lib/network/processor/gossipHandlers.js.map +1 -1
  80. package/lib/network/reqresp/handlers/beaconBlocksByRange.d.ts.map +1 -1
  81. package/lib/network/reqresp/handlers/beaconBlocksByRange.js +3 -1
  82. package/lib/network/reqresp/handlers/beaconBlocksByRange.js.map +1 -1
  83. package/lib/node/nodejs.d.ts +2 -1
  84. package/lib/node/nodejs.d.ts.map +1 -1
  85. package/lib/node/nodejs.js +2 -1
  86. package/lib/node/nodejs.js.map +1 -1
  87. package/lib/sync/range/range.d.ts.map +1 -1
  88. package/lib/sync/range/range.js +2 -1
  89. package/lib/sync/range/range.js.map +1 -1
  90. package/lib/sync/utils/remoteSyncType.d.ts +2 -1
  91. package/lib/sync/utils/remoteSyncType.d.ts.map +1 -1
  92. package/lib/sync/utils/remoteSyncType.js +19 -4
  93. package/lib/sync/utils/remoteSyncType.js.map +1 -1
  94. package/lib/util/blobs.d.ts +1 -1
  95. package/lib/util/blobs.d.ts.map +1 -1
  96. package/lib/util/blobs.js +53 -20
  97. package/lib/util/blobs.js.map +1 -1
  98. package/lib/util/profile.d.ts +6 -4
  99. package/lib/util/profile.d.ts.map +1 -1
  100. package/lib/util/profile.js +40 -3
  101. package/lib/util/profile.js.map +1 -1
  102. package/lib/util/sszBytes.d.ts +2 -0
  103. package/lib/util/sszBytes.d.ts.map +1 -1
  104. package/lib/util/sszBytes.js +25 -0
  105. package/lib/util/sszBytes.js.map +1 -1
  106. package/package.json +31 -24
  107. package/src/api/impl/beacon/blocks/index.ts +47 -25
  108. package/src/api/impl/lodestar/index.ts +42 -10
  109. package/src/api/impl/node/utils.ts +1 -1
  110. package/src/chain/archiveStore/archiveStore.ts +27 -0
  111. package/src/chain/archiveStore/strategies/frequencyStateArchiveStrategy.ts +32 -5
  112. package/src/chain/chain.ts +48 -23
  113. package/src/chain/errors/dataColumnSidecarError.ts +8 -0
  114. package/src/chain/forkChoice/index.ts +178 -2
  115. package/src/chain/interface.ts +2 -0
  116. package/src/chain/options.ts +0 -3
  117. package/src/chain/stateCache/datastore/db.ts +89 -1
  118. package/src/chain/stateCache/datastore/file.ts +8 -0
  119. package/src/chain/stateCache/datastore/types.ts +1 -0
  120. package/src/chain/validation/dataColumnSidecar.ts +21 -4
  121. package/src/index.ts +2 -0
  122. package/src/metrics/metrics/lodestar.ts +18 -1
  123. package/src/network/core/networkCore.ts +5 -1
  124. package/src/network/core/networkCoreWorker.ts +2 -7
  125. package/src/network/discv5/worker.ts +2 -7
  126. package/src/network/gossip/encoding.ts +1 -1
  127. package/src/network/gossip/snappy_bun.ts +2 -0
  128. package/src/network/metadata.ts +3 -1
  129. package/src/network/options.ts +0 -1
  130. package/src/network/processor/gossipHandlers.ts +16 -7
  131. package/src/network/reqresp/handlers/beaconBlocksByRange.ts +3 -1
  132. package/src/node/nodejs.ts +3 -0
  133. package/src/sync/range/range.ts +2 -1
  134. package/src/sync/utils/remoteSyncType.ts +23 -4
  135. package/src/util/blobs.ts +64 -20
  136. package/src/util/profile.ts +45 -3
  137. package/src/util/sszBytes.ts +30 -0
@@ -1,13 +1,32 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
1
3
  import {sleep} from "@lodestar/utils";
2
4
 
5
+ export enum ProfileThread {
6
+ MAIN = "main",
7
+ NETWORK = "network",
8
+ DISC5 = "discv5",
9
+ }
10
+
11
+ /**
12
+ * The time to take a Bun profile.
13
+ * If we increase this time it'll potentiall cause the app to crash.
14
+ * If we decrease this time, profile recorded will be fragmented and hard to analyze.
15
+ */
16
+ const BUN_PROFILE_MS = 3 * 1000;
17
+
18
+ export async function profileThread(thread: ProfileThread, durationMs: number, dirpath: string): Promise<string> {
19
+ return globalThis.Bun ? profileBun(thread, durationMs) : profileNodeJS(thread, durationMs, dirpath);
20
+ }
21
+
3
22
  /**
4
- * Take 10m profile of the current thread without promise tracking.
23
+ * Take `durationMs` profile of the current thread and return the persisted file path.
5
24
  */
6
- export async function profileNodeJS(durationMs: number): Promise<string> {
25
+ async function profileNodeJS(thread: ProfileThread, durationMs: number, dirpath: string): Promise<string> {
7
26
  const inspector = await import("node:inspector");
8
27
 
9
28
  // due to some typing issues, not able to use promisify here
10
- return new Promise<string>((resolve, reject) => {
29
+ const profile = await new Promise<string>((resolve, reject) => {
11
30
  // Start the inspector and connect to it
12
31
  const session = new inspector.Session();
13
32
  session.connect();
@@ -29,6 +48,29 @@ export async function profileNodeJS(durationMs: number): Promise<string> {
29
48
  });
30
49
  });
31
50
  });
51
+
52
+ const filePath = path.join(dirpath, `${thread}_thread_${new Date().toISOString()}.cpuprofile`);
53
+ fs.writeFileSync(filePath, profile);
54
+ return filePath;
55
+ }
56
+
57
+ /**
58
+ * Unlike NodeJS, Bun console.profile() api flush data to the inspector,
59
+ * so this api returns ms taken of this profile instead of file path.
60
+ */
61
+ async function profileBun(thread: ProfileThread, durationMs: number): Promise<string> {
62
+ const start = Date.now();
63
+ let now = Date.now();
64
+ while (now - start < durationMs) {
65
+ // biome-ignore lint/suspicious/noConsole: need to use console api to profile in Bun
66
+ console.profile(String(now));
67
+ await sleep(BUN_PROFILE_MS);
68
+ // biome-ignore lint/suspicious/noConsole: need to use console api to profile in Bun
69
+ console.profileEnd(String(now));
70
+ now = Date.now();
71
+ }
72
+
73
+ return `Successfully take Bun ${thread} thread profile in ${now - start}ms. Check your inspector to see the profile.`;
32
74
  }
33
75
 
34
76
  /**
@@ -417,6 +417,36 @@ export function getSlotFromDataColumnSidecarSerialized(data: Uint8Array): Slot |
417
417
  return getSlotFromOffset(data, SLOT_BYTES_POSITION_IN_SIGNED_DATA_COLUMN_SIDECAR);
418
418
  }
419
419
 
420
+ /**
421
+ * BeaconState of all forks (up until Electra, check with new forks)
422
+ * class BeaconState(Container):
423
+ * genesis_time: uint64 - 8 bytes
424
+ * genesis_validators_root: Root - 32 bytes
425
+ * slot: Slot - 8 bytes
426
+ * fork: Fork - 16 bytes
427
+ * latest_block_header: BeaconBlockHeader - fixed size
428
+ * slot: Slot - 8 bytes
429
+ *
430
+ */
431
+
432
+ const BLOCK_HEADER_SLOT_BYTES_POSITION_IN_BEACON_STATE = 8 + 32 + 8 + 16;
433
+ export function getLastProcessedSlotFromBeaconStateSerialized(data: Uint8Array): Slot | null {
434
+ if (data.length < BLOCK_HEADER_SLOT_BYTES_POSITION_IN_BEACON_STATE + SLOT_SIZE) {
435
+ return null;
436
+ }
437
+
438
+ return getSlotFromOffset(data, BLOCK_HEADER_SLOT_BYTES_POSITION_IN_BEACON_STATE);
439
+ }
440
+
441
+ const SLOT_BYTES_POSITION_IN_BEACON_STATE = 8 + 32;
442
+ export function getSlotFromBeaconStateSerialized(data: Uint8Array): Slot | null {
443
+ if (data.length < SLOT_BYTES_POSITION_IN_BEACON_STATE) {
444
+ return null;
445
+ }
446
+
447
+ return getSlotFromOffset(data, SLOT_BYTES_POSITION_IN_BEACON_STATE);
448
+ }
449
+
420
450
  /**
421
451
  * Read only the first 4 bytes of Slot, max value is 4,294,967,295 will be reached 1634 years after genesis
422
452
  *