@lodestar/beacon-node 1.45.0-dev.f2645825a8 → 1.45.0-dev.f535421f29

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 (69) hide show
  1. package/lib/api/impl/beacon/pool/index.d.ts.map +1 -1
  2. package/lib/api/impl/beacon/pool/index.js +1 -0
  3. package/lib/api/impl/beacon/pool/index.js.map +1 -1
  4. package/lib/api/impl/beacon/state/index.d.ts.map +1 -1
  5. package/lib/api/impl/beacon/state/index.js +3 -46
  6. package/lib/api/impl/beacon/state/index.js.map +1 -1
  7. package/lib/api/impl/beacon/state/utils.d.ts +2 -11
  8. package/lib/api/impl/beacon/state/utils.d.ts.map +1 -1
  9. package/lib/api/impl/beacon/state/utils.js +3 -39
  10. package/lib/api/impl/beacon/state/utils.js.map +1 -1
  11. package/lib/api/impl/validator/index.d.ts.map +1 -1
  12. package/lib/api/impl/validator/index.js +3 -9
  13. package/lib/api/impl/validator/index.js.map +1 -1
  14. package/lib/chain/blocks/importBlock.js +1 -1
  15. package/lib/chain/blocks/importBlock.js.map +1 -1
  16. package/lib/chain/chain.d.ts +2 -1
  17. package/lib/chain/chain.d.ts.map +1 -1
  18. package/lib/chain/chain.js +3 -1
  19. package/lib/chain/chain.js.map +1 -1
  20. package/lib/chain/interface.d.ts +2 -1
  21. package/lib/chain/interface.d.ts.map +1 -1
  22. package/lib/chain/interface.js.map +1 -1
  23. package/lib/chain/opPools/proposerPreferencesPool.d.ts +1 -2
  24. package/lib/chain/opPools/proposerPreferencesPool.d.ts.map +1 -1
  25. package/lib/chain/opPools/proposerPreferencesPool.js +0 -3
  26. package/lib/chain/opPools/proposerPreferencesPool.js.map +1 -1
  27. package/lib/chain/options.d.ts +0 -1
  28. package/lib/chain/options.d.ts.map +1 -1
  29. package/lib/chain/options.js +0 -1
  30. package/lib/chain/options.js.map +1 -1
  31. package/lib/chain/produceBlock/produceBlockBody.d.ts.map +1 -1
  32. package/lib/chain/produceBlock/produceBlockBody.js +12 -4
  33. package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
  34. package/lib/chain/seenCache/index.d.ts +1 -0
  35. package/lib/chain/seenCache/index.d.ts.map +1 -1
  36. package/lib/chain/seenCache/index.js +1 -0
  37. package/lib/chain/seenCache/index.js.map +1 -1
  38. package/lib/chain/seenCache/seenProposerPreferences.d.ts +16 -0
  39. package/lib/chain/seenCache/seenProposerPreferences.d.ts.map +1 -0
  40. package/lib/chain/seenCache/seenProposerPreferences.js +26 -0
  41. package/lib/chain/seenCache/seenProposerPreferences.js.map +1 -0
  42. package/lib/chain/validation/proposerPreferences.d.ts.map +1 -1
  43. package/lib/chain/validation/proposerPreferences.js +3 -11
  44. package/lib/chain/validation/proposerPreferences.js.map +1 -1
  45. package/lib/network/gossip/topic.d.ts +19 -776
  46. package/lib/network/gossip/topic.d.ts.map +1 -1
  47. package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
  48. package/lib/network/processor/gossipHandlers.js +1 -0
  49. package/lib/network/processor/gossipHandlers.js.map +1 -1
  50. package/lib/util/graffiti.d.ts +0 -15
  51. package/lib/util/graffiti.d.ts.map +1 -1
  52. package/lib/util/graffiti.js +0 -55
  53. package/lib/util/graffiti.js.map +1 -1
  54. package/package.json +14 -14
  55. package/src/api/impl/beacon/pool/index.ts +1 -0
  56. package/src/api/impl/beacon/state/index.ts +1 -52
  57. package/src/api/impl/beacon/state/utils.ts +4 -57
  58. package/src/api/impl/validator/index.ts +3 -9
  59. package/src/chain/blocks/importBlock.ts +1 -1
  60. package/src/chain/chain.ts +3 -0
  61. package/src/chain/interface.ts +2 -0
  62. package/src/chain/opPools/proposerPreferencesPool.ts +1 -5
  63. package/src/chain/options.ts +0 -2
  64. package/src/chain/produceBlock/produceBlockBody.ts +17 -9
  65. package/src/chain/seenCache/index.ts +1 -0
  66. package/src/chain/seenCache/seenProposerPreferences.ts +32 -0
  67. package/src/chain/validation/proposerPreferences.ts +3 -12
  68. package/src/network/processor/gossipHandlers.ts +1 -0
  69. package/src/util/graffiti.ts +0 -78
@@ -1,4 +1,4 @@
1
- import {RootHex, Slot, ValidatorIndex, gloas} from "@lodestar/types";
1
+ import {RootHex, Slot, gloas} from "@lodestar/types";
2
2
  import {toRootHex} from "@lodestar/utils";
3
3
 
4
4
  /**
@@ -22,10 +22,6 @@ export class ProposerPreferencesPool {
22
22
  return this.bySlot.get(slot)?.get(dependentRootHex) ?? null;
23
23
  }
24
24
 
25
- isKnown(proposalSlot: Slot, dependentRoot: RootHex, validatorIndex: ValidatorIndex): boolean {
26
- return this.get(proposalSlot, dependentRoot)?.message.validatorIndex === validatorIndex;
27
- }
28
-
29
25
  add(signed: gloas.SignedProposerPreferences): void {
30
26
  const {proposalSlot, dependentRoot} = signed.message;
31
27
  const rootHex = toRootHex(dependentRoot);
@@ -35,7 +35,6 @@ export type IChainOptions = BlockProcessOpts &
35
35
  persistOrphanedBlocksDir?: string;
36
36
  skipCreateStateCacheIfAvailable?: boolean;
37
37
  suggestedFeeRecipient: string;
38
- graffitiAppend?: boolean;
39
38
  maxSkipSlots?: number;
40
39
  /** Ensure blobs returned by the execution engine are valid */
41
40
  sanityCheckExecutionEngineBlobs?: boolean;
@@ -108,7 +107,6 @@ export const defaultChainOptions: IChainOptions = {
108
107
  computeUnrealized: true,
109
108
  fastConfirmation: false,
110
109
  suggestedFeeRecipient: defaultValidatorOptions.suggestedFeeRecipient,
111
- graffitiAppend: true,
112
110
  serveHistoricalState: false,
113
111
  assertCorrectProgressiveBalances: false,
114
112
  archiveStateEpochFrequency: 1024,
@@ -43,7 +43,6 @@ import {
43
43
  ValidatorIndex,
44
44
  Wei,
45
45
  altair,
46
- bellatrix,
47
46
  capella,
48
47
  deneb,
49
48
  electra,
@@ -831,19 +830,28 @@ export function getPayloadAttributesForSSE(
831
830
  feeRecipient,
832
831
  });
833
832
 
834
- const ssePayloadAttributes = {
833
+ let parentBlockNumber: number;
834
+ if (isForkPostGloas(fork)) {
835
+ const parentBlock = chain.forkChoice.getBlockHexAndBlockHash(
836
+ toRootHex(parentBlockRoot),
837
+ toRootHex(parentBlockHash)
838
+ );
839
+ if (parentBlock?.executionPayloadBlockHash == null) {
840
+ throw Error(`Parent block not found in fork choice root=${toRootHex(parentBlockRoot)}`);
841
+ }
842
+ parentBlockNumber = parentBlock.executionPayloadNumber;
843
+ } else {
844
+ parentBlockNumber = prepareState.payloadBlockNumber;
845
+ }
846
+
847
+ const ssePayloadAttributes: SSEPayloadAttributes = {
835
848
  proposerIndex: prepareState.getBeaconProposer(prepareSlot),
836
849
  proposalSlot: prepareSlot,
850
+ parentBlockNumber,
837
851
  parentBlockRoot,
838
852
  parentBlockHash,
839
853
  payloadAttributes,
840
- } as SSEPayloadAttributes;
841
-
842
- if (!isForkPostGloas(fork)) {
843
- // Removed in Gloas, builders can get the block number from the EL via the block hash if required
844
- (ssePayloadAttributes as bellatrix.SSEPayloadAttributes).parentBlockNumber = prepareState.payloadBlockNumber;
845
- }
846
-
854
+ };
847
855
  return ssePayloadAttributes;
848
856
  }
849
857
 
@@ -5,3 +5,4 @@ export {SeenContributionAndProof} from "./seenCommitteeContribution.js";
5
5
  export {SeenExecutionPayloadBids} from "./seenExecutionPayloadBids.js";
6
6
  export {SeenBlockInput} from "./seenGossipBlockInput.js";
7
7
  export {PayloadEnvelopeInput, SeenPayloadEnvelopeInput} from "./seenPayloadEnvelopeInput.js";
8
+ export {SeenProposerPreferences} from "./seenProposerPreferences.js";
@@ -0,0 +1,32 @@
1
+ import {RootHex, Slot, ValidatorIndex} from "@lodestar/types";
2
+ import {MapDef} from "@lodestar/utils";
3
+
4
+ /**
5
+ * Tracks signed proposer preferences we've already seen per (dependent_root, proposal_slot, validator_index).
6
+ */
7
+ export class SeenProposerPreferences {
8
+ private readonly validatorByDependentRootBySlot = new MapDef<Slot, Map<RootHex, ValidatorIndex>>(
9
+ () => new Map<RootHex, ValidatorIndex>()
10
+ );
11
+
12
+ isKnown(dependentRoot: RootHex, proposalSlot: Slot, validatorIndex: ValidatorIndex): boolean {
13
+ return this.validatorByDependentRootBySlot.get(proposalSlot)?.get(dependentRoot) === validatorIndex;
14
+ }
15
+
16
+ add(dependentRoot: RootHex, proposalSlot: Slot, validatorIndex: ValidatorIndex): void {
17
+ this.validatorByDependentRootBySlot.getOrDefault(proposalSlot).set(dependentRoot, validatorIndex);
18
+ }
19
+
20
+ /**
21
+ * Entries are only load-bearing while `proposal_slot > current_slot`. Once the slot has
22
+ * passed the `[IGNORE] proposal_slot > current_slot` gossip rule takes over, so drop them
23
+ * on each slot tick.
24
+ */
25
+ prune(currentSlot: Slot): void {
26
+ for (const slot of this.validatorByDependentRootBySlot.keys()) {
27
+ if (slot < currentSlot) {
28
+ this.validatorByDependentRootBySlot.delete(slot);
29
+ }
30
+ }
31
+ }
32
+ }
@@ -81,7 +81,7 @@ export async function validateGossipProposerPreferences(
81
81
  }
82
82
 
83
83
  // [IGNORE] First valid message for (dependent_root, proposal_slot, validator_index).
84
- if (chain.proposerPreferencesPool.isKnown(proposalSlot, dependentRootHex, validatorIndex)) {
84
+ if (chain.seenProposerPreferences.isKnown(dependentRootHex, proposalSlot, validatorIndex)) {
85
85
  throw new ProposerPreferencesError(GossipAction.IGNORE, {
86
86
  code: ProposerPreferencesErrorCode.ALREADY_KNOWN,
87
87
  proposalSlot,
@@ -105,15 +105,6 @@ export async function validateGossipProposerPreferences(
105
105
  });
106
106
  }
107
107
 
108
- // Repeated check - deals with race-condition between preferences submissions
109
- if (chain.proposerPreferencesPool.isKnown(proposalSlot, dependentRootHex, validatorIndex)) {
110
- throw new ProposerPreferencesError(GossipAction.IGNORE, {
111
- code: ProposerPreferencesErrorCode.ALREADY_KNOWN,
112
- proposalSlot,
113
- validatorIndex,
114
- dependentRoot: dependentRootHex,
115
- });
116
- }
117
-
118
- chain.proposerPreferencesPool.add(signedProposerPreferences);
108
+ // Valid
109
+ chain.seenProposerPreferences.add(dependentRootHex, proposalSlot, validatorIndex);
119
110
  }
@@ -1273,6 +1273,7 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
1273
1273
  const signedProposerPreferences = sszDeserialize(topic, serializedData);
1274
1274
  await validateGossipProposerPreferences(chain, signedProposerPreferences);
1275
1275
 
1276
+ chain.proposerPreferencesPool.add(signedProposerPreferences);
1276
1277
  chain.emitter.emit(routes.events.EventType.proposerPreferences, {
1277
1278
  version: ForkName.gloas,
1278
1279
  data: signedProposerPreferences,
@@ -37,81 +37,3 @@ export function getDefaultGraffiti(
37
37
  // No EL client info available. We still want to include CL info albeit not spec compliant
38
38
  return `${consensusClientVersion.code}${consensusClientVersion.commit.slice(0, 4)}`;
39
39
  }
40
-
41
- function appendLongestFittingSuffix(userGraffiti: string, suffixes: string[]): string {
42
- const userGraffitiBytes = Buffer.byteLength(userGraffiti, "utf8");
43
- if (userGraffitiBytes >= GRAFFITI_SIZE) {
44
- return userGraffiti;
45
- }
46
-
47
- const availableBytes = GRAFFITI_SIZE - userGraffitiBytes;
48
-
49
- for (const suffix of suffixes) {
50
- if (Buffer.byteLength(suffix, "utf8") <= availableBytes) {
51
- return `${userGraffiti}${suffix}`;
52
- }
53
- }
54
-
55
- return userGraffiti;
56
- }
57
-
58
- /**
59
- * Appends the richest available client watermark that fits after user graffiti.
60
- *
61
- * Tiers are:
62
- * - full EL/CL watermark, e.g. " BU9b0eLS80c2"
63
- * - EL/CL client codes, e.g. " BULS"
64
- * - CL client code, e.g. " LS"
65
- */
66
- export function appendClientInfoToGraffiti(
67
- userGraffiti: string,
68
- consensusClientVersion: ClientVersion,
69
- executionClientVersion: ClientVersion | null | undefined,
70
- opts: {private?: boolean} = {}
71
- ): string {
72
- if (opts.private) {
73
- return userGraffiti;
74
- }
75
-
76
- // Graffiti supplied via the beacon API is decoded from a fixed 32-byte field (see
77
- // fromGraffitiHex) and arrives right-padded with NUL bytes. Trim only trailing padding
78
- // NULs; a NUL that appears in the middle of the string is data, not padding.
79
- let end = userGraffiti.length;
80
- while (end > 0 && userGraffiti.charCodeAt(end - 1) === 0) {
81
- end--;
82
- }
83
- const graffiti = userGraffiti.slice(0, end);
84
-
85
- const fullClientInfo = getDefaultGraffiti(consensusClientVersion, executionClientVersion, {private: false});
86
- if (graffiti.length === 0) {
87
- return fullClientInfo;
88
- }
89
-
90
- const suffixes =
91
- executionClientVersion != null
92
- ? [
93
- ` ${fullClientInfo}`,
94
- ` ${executionClientVersion.code}${consensusClientVersion.code}`,
95
- ` ${consensusClientVersion.code}`,
96
- ]
97
- : [` ${fullClientInfo}`, ` ${consensusClientVersion.code}`];
98
-
99
- return appendLongestFittingSuffix(graffiti, suffixes);
100
- }
101
-
102
- export function getBlockGraffiti(
103
- userGraffiti: string | undefined,
104
- consensusClientVersion: ClientVersion,
105
- executionClientVersion: ClientVersion | null | undefined,
106
- opts: {private?: boolean; graffitiAppend?: boolean}
107
- ): string {
108
- if (userGraffiti === undefined) {
109
- return getDefaultGraffiti(consensusClientVersion, executionClientVersion, opts);
110
- }
111
-
112
- if (opts.graffitiAppend === false) {
113
- return userGraffiti;
114
- }
115
-
116
- return appendClientInfoToGraffiti(userGraffiti, consensusClientVersion, executionClientVersion, opts);
117
- }