@lodestar/beacon-node 1.36.0 → 1.37.0-dev.0c3b3f119c

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 (94) hide show
  1. package/lib/api/impl/validator/index.d.ts.map +1 -1
  2. package/lib/api/impl/validator/index.js +9 -3
  3. package/lib/api/impl/validator/index.js.map +1 -1
  4. package/lib/chain/blocks/importBlock.d.ts.map +1 -1
  5. package/lib/chain/blocks/importBlock.js +4 -2
  6. package/lib/chain/blocks/importBlock.js.map +1 -1
  7. package/lib/chain/blocks/writeBlockInputToDb.d.ts.map +1 -1
  8. package/lib/chain/blocks/writeBlockInputToDb.js +14 -1
  9. package/lib/chain/blocks/writeBlockInputToDb.js.map +1 -1
  10. package/lib/chain/prepareNextSlot.d.ts.map +1 -1
  11. package/lib/chain/prepareNextSlot.js +2 -1
  12. package/lib/chain/prepareNextSlot.js.map +1 -1
  13. package/lib/chain/produceBlock/produceBlockBody.d.ts.map +1 -1
  14. package/lib/chain/produceBlock/produceBlockBody.js +2 -1
  15. package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
  16. package/lib/chain/seenCache/seenGossipBlockInput.d.ts +11 -1
  17. package/lib/chain/seenCache/seenGossipBlockInput.d.ts.map +1 -1
  18. package/lib/chain/seenCache/seenGossipBlockInput.js +30 -1
  19. package/lib/chain/seenCache/seenGossipBlockInput.js.map +1 -1
  20. package/lib/chain/validation/blobSidecar.d.ts.map +1 -1
  21. package/lib/chain/validation/blobSidecar.js +29 -22
  22. package/lib/chain/validation/blobSidecar.js.map +1 -1
  23. package/lib/chain/validation/block.d.ts.map +1 -1
  24. package/lib/chain/validation/block.js +10 -7
  25. package/lib/chain/validation/block.js.map +1 -1
  26. package/lib/chain/validation/dataColumnSidecar.d.ts.map +1 -1
  27. package/lib/chain/validation/dataColumnSidecar.js +33 -26
  28. package/lib/chain/validation/dataColumnSidecar.js.map +1 -1
  29. package/lib/network/gossip/encoding.d.ts +4 -2
  30. package/lib/network/gossip/encoding.d.ts.map +1 -1
  31. package/lib/network/gossip/encoding.js +9 -3
  32. package/lib/network/gossip/encoding.js.map +1 -1
  33. package/lib/network/gossip/gossipsub.d.ts.map +1 -1
  34. package/lib/network/gossip/gossipsub.js +6 -5
  35. package/lib/network/gossip/gossipsub.js.map +1 -1
  36. package/lib/network/gossip/metrics.d.ts +8 -0
  37. package/lib/network/gossip/metrics.d.ts.map +1 -1
  38. package/lib/network/gossip/metrics.js +12 -0
  39. package/lib/network/gossip/metrics.js.map +1 -1
  40. package/lib/network/interface.d.ts +3 -3
  41. package/lib/network/interface.d.ts.map +1 -1
  42. package/lib/network/network.d.ts +3 -3
  43. package/lib/network/network.d.ts.map +1 -1
  44. package/lib/network/network.js +3 -3
  45. package/lib/network/network.js.map +1 -1
  46. package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
  47. package/lib/network/processor/gossipHandlers.js +2 -0
  48. package/lib/network/processor/gossipHandlers.js.map +1 -1
  49. package/lib/network/reqresp/utils/collect.d.ts +3 -3
  50. package/lib/network/reqresp/utils/collect.d.ts.map +1 -1
  51. package/lib/network/reqresp/utils/collect.js +7 -3
  52. package/lib/network/reqresp/utils/collect.js.map +1 -1
  53. package/lib/network/reqresp/utils/collectSequentialBlocksInRange.d.ts +3 -2
  54. package/lib/network/reqresp/utils/collectSequentialBlocksInRange.d.ts.map +1 -1
  55. package/lib/network/reqresp/utils/collectSequentialBlocksInRange.js +5 -3
  56. package/lib/network/reqresp/utils/collectSequentialBlocksInRange.js.map +1 -1
  57. package/lib/sync/backfill/backfill.d.ts.map +1 -1
  58. package/lib/sync/backfill/backfill.js +37 -14
  59. package/lib/sync/backfill/backfill.js.map +1 -1
  60. package/lib/sync/backfill/verify.d.ts +4 -4
  61. package/lib/sync/backfill/verify.d.ts.map +1 -1
  62. package/lib/sync/backfill/verify.js +6 -6
  63. package/lib/sync/backfill/verify.js.map +1 -1
  64. package/lib/sync/utils/downloadByRange.js +1 -1
  65. package/lib/sync/utils/downloadByRange.js.map +1 -1
  66. package/lib/sync/utils/downloadByRoot.js +1 -1
  67. package/lib/sync/utils/downloadByRoot.js.map +1 -1
  68. package/package.json +14 -19
  69. package/src/api/impl/validator/index.ts +9 -2
  70. package/src/chain/blocks/importBlock.ts +5 -1
  71. package/src/chain/blocks/writeBlockInputToDb.ts +13 -1
  72. package/src/chain/prepareNextSlot.ts +2 -1
  73. package/src/chain/produceBlock/produceBlockBody.ts +2 -1
  74. package/src/chain/seenCache/seenGossipBlockInput.ts +33 -2
  75. package/src/chain/validation/blobSidecar.ts +33 -24
  76. package/src/chain/validation/block.ts +11 -7
  77. package/src/chain/validation/dataColumnSidecar.ts +43 -33
  78. package/src/network/gossip/encoding.ts +9 -3
  79. package/src/network/gossip/gossipsub.ts +8 -6
  80. package/src/network/gossip/metrics.ts +12 -0
  81. package/src/network/interface.ts +2 -9
  82. package/src/network/network.ts +8 -9
  83. package/src/network/processor/gossipHandlers.ts +2 -0
  84. package/src/network/reqresp/utils/collect.ts +12 -6
  85. package/src/network/reqresp/utils/collectSequentialBlocksInRange.ts +10 -6
  86. package/src/sync/backfill/backfill.ts +40 -16
  87. package/src/sync/backfill/verify.ts +10 -10
  88. package/src/sync/utils/downloadByRange.ts +1 -1
  89. package/src/sync/utils/downloadByRoot.ts +1 -1
  90. package/lib/network/gossip/snappy_bun.d.ts +0 -3
  91. package/lib/network/gossip/snappy_bun.d.ts.map +0 -1
  92. package/lib/network/gossip/snappy_bun.js +0 -3
  93. package/lib/network/gossip/snappy_bun.js.map +0 -1
  94. package/src/network/gossip/snappy_bun.ts +0 -2
@@ -749,27 +749,33 @@ export class BackfillSync extends (EventEmitter as {new (): BackfillSyncEmitter}
749
749
  const anchorBlock = res[0];
750
750
 
751
751
  // GENESIS_SLOT doesn't has valid signature
752
- if (anchorBlock.data.message.slot === GENESIS_SLOT) return;
752
+ if (anchorBlock.message.slot === GENESIS_SLOT) return;
753
753
  await verifyBlockProposerSignature(this.chain.bls, this.chain.getHeadState(), [anchorBlock]);
754
754
 
755
755
  // We can write to the disk if this is ahead of prevFinalizedCheckpointBlock otherwise
756
756
  // we will need to go make checks on the top of sync loop before writing as it might
757
757
  // override prevFinalizedCheckpointBlock
758
- if (this.prevFinalizedCheckpointBlock.slot < anchorBlock.data.message.slot)
759
- await this.db.blockArchive.putBinary(anchorBlock.data.message.slot, anchorBlock.bytes);
758
+ if (this.prevFinalizedCheckpointBlock.slot < anchorBlock.message.slot) {
759
+ const serialized = this.chain.serializedCache.get(anchorBlock);
760
+ if (serialized) {
761
+ await this.db.blockArchive.putBinary(anchorBlock.message.slot, serialized);
762
+ } else {
763
+ await this.db.blockArchive.put(anchorBlock.message.slot, anchorBlock);
764
+ }
765
+ }
760
766
 
761
767
  this.syncAnchor = {
762
- anchorBlock: anchorBlock.data,
768
+ anchorBlock: anchorBlock,
763
769
  anchorBlockRoot,
764
- anchorSlot: anchorBlock.data.message.slot,
765
- lastBackSyncedBlock: {root: anchorBlockRoot, slot: anchorBlock.data.message.slot, block: anchorBlock.data},
770
+ anchorSlot: anchorBlock.message.slot,
771
+ lastBackSyncedBlock: {root: anchorBlockRoot, slot: anchorBlock.message.slot, block: anchorBlock},
766
772
  };
767
773
 
768
774
  this.metrics?.backfillSync.totalBlocks.inc({method: BackfillSyncMethod.blockbyroot});
769
775
 
770
776
  this.logger.verbose("Fetched new anchorBlock", {
771
777
  root: toRootHex(anchorBlockRoot),
772
- slot: anchorBlock.data.message.slot,
778
+ slot: anchorBlock.message.slot,
773
779
  });
774
780
 
775
781
  return;
@@ -825,15 +831,33 @@ export class BackfillSync extends (EventEmitter as {new (): BackfillSyncEmitter}
825
831
  nextAnchor.slot > this.prevFinalizedCheckpointBlock.slot
826
832
  ? verifiedBlocks
827
833
  : verifiedBlocks.slice(0, verifiedBlocks.length - 1);
828
- await this.db.blockArchive.batchPutBinary(
829
- blocksToPut.map((block) => ({
830
- key: block.data.message.slot,
831
- value: block.bytes,
832
- slot: block.data.message.slot,
833
- blockRoot: this.config.getForkTypes(block.data.message.slot).BeaconBlock.hashTreeRoot(block.data.message),
834
- parentRoot: block.data.message.parentRoot,
835
- }))
836
- );
834
+
835
+ const binaryPuts = [];
836
+ const nonBinaryPuts = [];
837
+
838
+ for (const block of blocksToPut) {
839
+ const serialized = this.chain.serializedCache.get(block);
840
+ const item = {
841
+ key: block.message.slot,
842
+ slot: block.message.slot,
843
+ blockRoot: this.config.getForkTypes(block.message.slot).BeaconBlock.hashTreeRoot(block.message),
844
+ parentRoot: block.message.parentRoot,
845
+ };
846
+
847
+ if (serialized) {
848
+ binaryPuts.push({...item, value: serialized});
849
+ } else {
850
+ nonBinaryPuts.push({...item, value: block});
851
+ }
852
+ }
853
+
854
+ if (binaryPuts.length > 0) {
855
+ await this.db.blockArchive.batchPutBinary(binaryPuts);
856
+ }
857
+ if (nonBinaryPuts.length > 0) {
858
+ await this.db.blockArchive.batchPut(nonBinaryPuts);
859
+ }
860
+
837
861
  this.metrics?.backfillSync.totalBlocks.inc({method: BackfillSyncMethod.rangesync}, verifiedBlocks.length);
838
862
  }
839
863
 
@@ -1,7 +1,7 @@
1
1
  import {BeaconConfig} from "@lodestar/config";
2
2
  import {GENESIS_SLOT} from "@lodestar/params";
3
3
  import {CachedBeaconStateAllForks, ISignatureSet, getBlockProposerSignatureSet} from "@lodestar/state-transition";
4
- import {Root, SignedBeaconBlock, Slot, WithBytes, ssz} from "@lodestar/types";
4
+ import {Root, SignedBeaconBlock, Slot, ssz} from "@lodestar/types";
5
5
  import {IBlsVerifier} from "../../chain/bls/index.js";
6
6
  import {BackfillSyncError, BackfillSyncErrorCode} from "./errors.js";
7
7
 
@@ -14,19 +14,19 @@ export type BackfillBlock = BackfillBlockHeader & {block: SignedBeaconBlock};
14
14
 
15
15
  export function verifyBlockSequence(
16
16
  config: BeaconConfig,
17
- blocks: WithBytes<SignedBeaconBlock>[],
17
+ blocks: SignedBeaconBlock[],
18
18
  anchorRoot: Root
19
19
  ): {
20
20
  nextAnchor: BackfillBlock | null;
21
- verifiedBlocks: WithBytes<SignedBeaconBlock>[];
21
+ verifiedBlocks: SignedBeaconBlock[];
22
22
  error?: BackfillSyncErrorCode.NOT_LINEAR;
23
23
  } {
24
24
  let nextRoot: Root = anchorRoot;
25
25
  let nextAnchor: BackfillBlock | null = null;
26
26
 
27
- const verifiedBlocks: WithBytes<SignedBeaconBlock>[] = [];
27
+ const verifiedBlocks: SignedBeaconBlock[] = [];
28
28
  for (const block of blocks.reverse()) {
29
- const blockRoot = config.getForkTypes(block.data.message.slot).BeaconBlock.hashTreeRoot(block.data.message);
29
+ const blockRoot = config.getForkTypes(block.message.slot).BeaconBlock.hashTreeRoot(block.message);
30
30
  if (!ssz.Root.equals(blockRoot, nextRoot)) {
31
31
  if (ssz.Root.equals(nextRoot, anchorRoot)) {
32
32
  throw new BackfillSyncError({code: BackfillSyncErrorCode.NOT_ANCHORED});
@@ -34,8 +34,8 @@ export function verifyBlockSequence(
34
34
  return {nextAnchor, verifiedBlocks, error: BackfillSyncErrorCode.NOT_LINEAR};
35
35
  }
36
36
  verifiedBlocks.push(block);
37
- nextAnchor = {block: block.data, slot: block.data.message.slot, root: nextRoot};
38
- nextRoot = block.data.message.parentRoot;
37
+ nextAnchor = {block: block, slot: block.message.slot, root: nextRoot};
38
+ nextRoot = block.message.parentRoot;
39
39
  }
40
40
  return {nextAnchor, verifiedBlocks};
41
41
  }
@@ -43,12 +43,12 @@ export function verifyBlockSequence(
43
43
  export async function verifyBlockProposerSignature(
44
44
  bls: IBlsVerifier,
45
45
  state: CachedBeaconStateAllForks,
46
- blocks: WithBytes<SignedBeaconBlock>[]
46
+ blocks: SignedBeaconBlock[]
47
47
  ): Promise<void> {
48
- if (blocks.length === 1 && blocks[0].data.message.slot === GENESIS_SLOT) return;
48
+ if (blocks.length === 1 && blocks[0].message.slot === GENESIS_SLOT) return;
49
49
  const signatures = blocks.reduce((sigs: ISignatureSet[], block) => {
50
50
  // genesis block doesn't have valid signature
51
- if (block.data.message.slot !== GENESIS_SLOT) sigs.push(getBlockProposerSignatureSet(state, block.data));
51
+ if (block.message.slot !== GENESIS_SLOT) sigs.push(getBlockProposerSignatureSet(state, block));
52
52
  return sigs;
53
53
  }, []);
54
54
 
@@ -254,7 +254,7 @@ export async function requestByRange({
254
254
  if (blocksRequest) {
255
255
  requests.push(
256
256
  network.sendBeaconBlocksByRange(peerIdStr, blocksRequest).then((blockResponse) => {
257
- blocks = blockResponse.map(({data}) => data);
257
+ blocks = blockResponse;
258
258
  })
259
259
  );
260
260
  }
@@ -314,7 +314,7 @@ export async function fetchAndValidateBlock({
314
314
  blockRoot,
315
315
  }: Omit<FetchByRootAndValidateBlockProps, "chain">): Promise<SignedBeaconBlock> {
316
316
  const response = await network.sendBeaconBlocksByRoot(peerIdStr, [blockRoot]);
317
- const block = response.at(0)?.data;
317
+ const block = response.at(0);
318
318
  if (!block) {
319
319
  throw new DownloadByRootError({
320
320
  code: DownloadByRootErrorCode.MISSING_BLOCK_RESPONSE,
@@ -1,3 +0,0 @@
1
- import { snappy } from "@lodestar/bun";
2
- export declare const compress: typeof snappy.compress, uncompress: typeof snappy.uncompress;
3
- //# sourceMappingURL=snappy_bun.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"snappy_bun.d.ts","sourceRoot":"","sources":["../../../src/network/gossip/snappy_bun.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,eAAe,CAAC;AACrC,eAAO,MAAO,QAAQ,0BAAE,UAAU,0BAAU,CAAC"}
@@ -1,3 +0,0 @@
1
- import { snappy } from "@lodestar/bun";
2
- export const { compress, uncompress } = snappy;
3
- //# sourceMappingURL=snappy_bun.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"snappy_bun.js","sourceRoot":"","sources":["../../../src/network/gossip/snappy_bun.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,eAAe,CAAC;AACrC,MAAM,CAAC,MAAM,EAAC,QAAQ,EAAE,UAAU,EAAC,GAAG,MAAM,CAAC"}
@@ -1,2 +0,0 @@
1
- import {snappy} from "@lodestar/bun";
2
- export const {compress, uncompress} = snappy;