@lodestar/beacon-node 1.51.0-dev.8fdbd61e7e → 1.51.0-dev.90425365bb

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 (41) hide show
  1. package/lib/chain/archiveStore/utils/archiveBlocks.d.ts +12 -0
  2. package/lib/chain/archiveStore/utils/archiveBlocks.d.ts.map +1 -1
  3. package/lib/chain/archiveStore/utils/archiveBlocks.js +17 -2
  4. package/lib/chain/archiveStore/utils/archiveBlocks.js.map +1 -1
  5. package/lib/db/dataColumnStore.d.ts +3 -2
  6. package/lib/db/dataColumnStore.d.ts.map +1 -1
  7. package/lib/db/dataColumnStore.js +3 -3
  8. package/lib/db/dataColumnStore.js.map +1 -1
  9. package/lib/db/flatFileStore/flatFileStore.d.ts +1 -1
  10. package/lib/db/flatFileStore/flatFileStore.d.ts.map +1 -1
  11. package/lib/db/flatFileStore/flatFileStore.js +5 -4
  12. package/lib/db/flatFileStore/flatFileStore.js.map +1 -1
  13. package/lib/db/flatFileStore/interface.d.ts +2 -1
  14. package/lib/db/flatFileStore/interface.d.ts.map +1 -1
  15. package/lib/db/repositories/dataColumnSidecarArchive.d.ts +2 -1
  16. package/lib/db/repositories/dataColumnSidecarArchive.d.ts.map +1 -1
  17. package/lib/db/repositories/dataColumnSidecarArchive.js +14 -4
  18. package/lib/db/repositories/dataColumnSidecarArchive.js.map +1 -1
  19. package/lib/network/gossip/gossipsub.d.ts.map +1 -1
  20. package/lib/network/gossip/gossipsub.js +13 -6
  21. package/lib/network/gossip/gossipsub.js.map +1 -1
  22. package/lib/network/processor/gossipHandlers.js +3 -3
  23. package/lib/network/processor/gossipHandlers.js.map +1 -1
  24. package/lib/util/bitArray.d.ts +6 -6
  25. package/lib/util/bitArray.d.ts.map +1 -1
  26. package/lib/util/bitArray.js +25 -50
  27. package/lib/util/bitArray.js.map +1 -1
  28. package/lib/util/eventLoop.d.ts +5 -0
  29. package/lib/util/eventLoop.d.ts.map +1 -1
  30. package/lib/util/eventLoop.js +7 -0
  31. package/lib/util/eventLoop.js.map +1 -1
  32. package/package.json +17 -17
  33. package/src/chain/archiveStore/utils/archiveBlocks.ts +21 -2
  34. package/src/db/dataColumnStore.ts +5 -4
  35. package/src/db/flatFileStore/flatFileStore.ts +5 -4
  36. package/src/db/flatFileStore/interface.ts +2 -1
  37. package/src/db/repositories/dataColumnSidecarArchive.ts +14 -4
  38. package/src/network/gossip/gossipsub.ts +13 -6
  39. package/src/network/processor/gossipHandlers.ts +3 -3
  40. package/src/util/bitArray.ts +22 -43
  41. package/src/util/eventLoop.ts +8 -0
@@ -25,7 +25,7 @@ import {getSlotDurations} from "@lodestar/state-transition";
25
25
  import {SubnetID} from "@lodestar/types";
26
26
  import {Logger, Map2d, Map2dArr} from "@lodestar/utils";
27
27
  import {RegistryMetricCreator} from "../../metrics/index.js";
28
- import {callInNextEventLoop} from "../../util/eventLoop.js";
28
+ import {callImmediate, callInNextEventLoop} from "../../util/eventLoop.js";
29
29
  import {NetworkEvent, NetworkEventBus, NetworkEventData} from "../events.js";
30
30
  import {Libp2p} from "../interface.js";
31
31
  import {NetworkConfig} from "../networkConfig.js";
@@ -414,10 +414,7 @@ export class Eth2Gossipsub {
414
414
  const clientAgent = this.peersData.getPeerKind(peerIdStr) ?? "Unknown";
415
415
  const clientVersion = this.peersData.getAgentVersion(peerIdStr);
416
416
 
417
- // Use setTimeout to yield to the macro queue
418
- // Without this we'll have huge event loop lag
419
- // See https://github.com/ChainSafe/lodestar/issues/5604
420
- callInNextEventLoop(() => {
417
+ const emitPendingMessage = (): void => {
421
418
  this.events.emit(NetworkEvent.pendingGossipsubMessage, {
422
419
  topic,
423
420
  msg,
@@ -429,7 +426,17 @@ export class Eth2Gossipsub {
429
426
  seenTimestampSec,
430
427
  startProcessUnixSec: null,
431
428
  });
432
- });
429
+ };
430
+
431
+ // Use setTimeout to yield to the macro queue
432
+ // Without this we'll have huge event loop lag
433
+ // See https://github.com/ChainSafe/lodestar/issues/5604
434
+ // A block arrives once per slot and cannot cause that lag, so it skips the 1ms timer delay
435
+ if (topic.type === GossipType.beacon_block) {
436
+ callImmediate(emitPendingMessage);
437
+ } else {
438
+ callInNextEventLoop(emitPendingMessage);
439
+ }
433
440
  }
434
441
 
435
442
  private onValidationResult(data: NetworkEventData[NetworkEvent.gossipMessageValidationResult]): void {
@@ -89,7 +89,7 @@ import {validateGossipProposerPreferences} from "../../chain/validation/proposer
89
89
  import {OpSource} from "../../chain/validatorMonitor.js";
90
90
  import {Metrics} from "../../metrics/index.js";
91
91
  import {getBlobKzgCommitments, getDataColumnSidecarSlot} from "../../util/dataColumns.js";
92
- import {callInNextEventLoop} from "../../util/eventLoop.js";
92
+ import {callImmediate, callInNextEventLoop} from "../../util/eventLoop.js";
93
93
  import {INetworkCore} from "../core/index.js";
94
94
  import {NetworkEventBus} from "../events.js";
95
95
  import {
@@ -675,8 +675,8 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
675
675
  const signedBlock = sszDeserialize(topic, serializedData);
676
676
  try {
677
677
  const blockInput = await validateBeaconBlock(signedBlock, topic.boundary.fork, peerIdStr, seenTimestampSec);
678
- // Handler - deferred to next event loop so the validation result propagates first
679
- callInNextEventLoop(() => {
678
+ // Runs after the validation result is reported, except with `network.useWorker: false`
679
+ callImmediate(() => {
680
680
  try {
681
681
  chain.serializedCache.set(signedBlock, serializedData);
682
682
  handleValidBeaconBlock(blockInput, peerIdStr, seenTimestampSec);
@@ -22,63 +22,42 @@ export enum IntersectResult {
22
22
  * | 11110000 | 00001111 | A exclude B |
23
23
  * | 11111100 | 00111111 | A intersect B |
24
24
  *
25
- * For all bytes in BitArray:
26
- * - equals = MAYBE ONLY equals
27
- * - excludes = MUST ONLY equals
28
- * - superset = MUST superset MAYBE equal
29
- * - subset = MUST subset MAYBE equal
30
- * - intersect = any other condition
25
+ * For all bytes in BitArray, bytes missing from the shorter array count as zero:
26
+ * - equals = neither has a bit the other lacks
27
+ * - superset = only A has bits B lacks
28
+ * - subset = only B has bits A lacks
29
+ * - exclude = both have bits the other lacks, none shared
30
+ * - intersect = both have bits the other lacks, some shared
31
31
  */
32
32
  export function intersectUint8Arrays(aUA: Uint8Array, bUA: Uint8Array): IntersectResult {
33
- const len = aUA.length;
33
+ const len = Math.max(aUA.length, bUA.length);
34
34
 
35
- let someEquals = false;
36
- let someExcludes = false;
37
- let someSuperset = false;
38
- let someSubset = false;
35
+ let aHasExtra = false;
36
+ let bHasExtra = false;
37
+ let hasShared = false;
39
38
 
40
39
  for (let i = 0; i < len; i++) {
41
- const a = aUA[i];
42
- const b = bUA[i];
40
+ const a = aUA[i] ?? 0;
41
+ const b = bUA[i] ?? 0;
43
42
 
44
- if (a === 0 && b === 0) {
45
- // zero, skip
46
- } else if (a === b) {
47
- // A equals B
48
- someEquals = true;
49
- } else if ((a & b) === 0) {
50
- // A excludes B
51
- someExcludes = true;
52
- } else if ((a & b) === b) {
53
- // A superset B
54
- if (someSubset) return IntersectResult.Intersect;
55
- someSuperset = true;
56
- } else if ((a & b) === a) {
57
- // A subset B
58
- if (someSuperset) return IntersectResult.Intersect;
59
- someSubset = true;
60
- } else {
61
- // A diff B
62
- return IntersectResult.Intersect;
63
- }
43
+ if ((a & b) !== 0) hasShared = true;
44
+ if ((a & ~b) !== 0) aHasExtra = true;
45
+ if ((b & ~a) !== 0) bHasExtra = true;
46
+
47
+ if (aHasExtra && bHasExtra && hasShared) return IntersectResult.Intersect;
64
48
  }
65
49
 
66
- // equals = MAYBE ONLY equals
67
- if (!someExcludes && !someSuperset && !someSubset) return IntersectResult.Equal;
68
- // excludes = MUST ONLY equals
69
- if (!someEquals && someExcludes && !someSuperset && !someSubset) return IntersectResult.Exclusive;
70
- // superset = MUST superset MAYBE equal
71
- if (!someExcludes && someSuperset && !someSubset) return IntersectResult.Superset;
72
- // subset = MUST subset MAYBE equal
73
- if (!someExcludes && !someSuperset && someSubset) return IntersectResult.Subset;
74
- // intersect = any other condition
75
- return IntersectResult.Intersect;
50
+ if (!aHasExtra && !bHasExtra) return IntersectResult.Equal;
51
+ if (!bHasExtra) return IntersectResult.Superset;
52
+ if (!aHasExtra) return IntersectResult.Subset;
53
+ return hasShared ? IntersectResult.Intersect : IntersectResult.Exclusive;
76
54
  }
77
55
 
78
56
  /**
79
57
  * Check if first BitArray is equal to or superset of the second
80
58
  */
81
59
  export function isSuperSetOrEqual(superSet: BitArray, toCheck: BitArray): boolean {
60
+ if (superSet.bitLen !== toCheck.bitLen) return false;
82
61
  const intersectionResult = intersectUint8Arrays(superSet.uint8Array, toCheck.uint8Array);
83
62
  return intersectionResult === IntersectResult.Superset || intersectionResult === IntersectResult.Equal;
84
63
  }
@@ -20,3 +20,11 @@ export function callInNextEventLoop(callback: () => void): void {
20
20
  // Say https://nodejs.org/api/timers.html#settimeoutcallback-delay-args
21
21
  setTimeout(callback, 0);
22
22
  }
23
+
24
+ /**
25
+ * Schedules a callback for the `check` phase. Pending promise continuations run first,
26
+ * and there is no 1ms timer delay.
27
+ */
28
+ export function callImmediate(callback: () => void): void {
29
+ setImmediate(callback);
30
+ }