@lodestar/beacon-node 1.39.0-dev.b6bba4cb8c → 1.39.0-dev.b6d377a93c

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 (52) hide show
  1. package/README.md +1 -1
  2. package/lib/chain/chain.d.ts +4 -7
  3. package/lib/chain/chain.d.ts.map +1 -1
  4. package/lib/chain/chain.js +1 -4
  5. package/lib/chain/chain.js.map +1 -1
  6. package/lib/chain/interface.d.ts +4 -7
  7. package/lib/chain/interface.d.ts.map +1 -1
  8. package/lib/chain/interface.js.map +1 -1
  9. package/lib/chain/produceBlock/produceBlockBody.js +1 -1
  10. package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
  11. package/lib/chain/validation/aggregateAndProof.js +9 -0
  12. package/lib/chain/validation/aggregateAndProof.js.map +1 -1
  13. package/lib/chain/validation/blobSidecar.d.ts.map +1 -1
  14. package/lib/chain/validation/blobSidecar.js +2 -3
  15. package/lib/chain/validation/blobSidecar.js.map +1 -1
  16. package/lib/chain/validation/dataColumnSidecar.d.ts.map +1 -1
  17. package/lib/chain/validation/dataColumnSidecar.js +2 -3
  18. package/lib/chain/validation/dataColumnSidecar.js.map +1 -1
  19. package/lib/network/peers/discover.d.ts.map +1 -1
  20. package/lib/network/peers/discover.js.map +1 -1
  21. package/lib/sync/backfill/backfill.d.ts.map +1 -1
  22. package/lib/sync/backfill/backfill.js +2 -2
  23. package/lib/sync/backfill/backfill.js.map +1 -1
  24. package/lib/sync/backfill/verify.d.ts +2 -2
  25. package/lib/sync/backfill/verify.d.ts.map +1 -1
  26. package/lib/sync/backfill/verify.js +2 -2
  27. package/lib/sync/backfill/verify.js.map +1 -1
  28. package/package.json +28 -20
  29. package/src/chain/chain.ts +7 -6
  30. package/src/chain/interface.ts +4 -6
  31. package/src/chain/produceBlock/produceBlockBody.ts +1 -1
  32. package/src/chain/validation/aggregateAndProof.ts +12 -0
  33. package/src/chain/validation/blobSidecar.ts +3 -3
  34. package/src/chain/validation/dataColumnSidecar.ts +3 -3
  35. package/src/network/peers/discover.ts +3 -3
  36. package/src/sync/backfill/backfill.ts +2 -14
  37. package/src/sync/backfill/verify.ts +1 -7
  38. package/lib/chain/rewards/attestationsRewards.d.ts +0 -8
  39. package/lib/chain/rewards/attestationsRewards.d.ts.map +0 -1
  40. package/lib/chain/rewards/attestationsRewards.js +0 -112
  41. package/lib/chain/rewards/attestationsRewards.js.map +0 -1
  42. package/lib/chain/rewards/blockRewards.d.ts +0 -15
  43. package/lib/chain/rewards/blockRewards.d.ts.map +0 -1
  44. package/lib/chain/rewards/blockRewards.js +0 -94
  45. package/lib/chain/rewards/blockRewards.js.map +0 -1
  46. package/lib/chain/rewards/syncCommitteeRewards.d.ts +0 -7
  47. package/lib/chain/rewards/syncCommitteeRewards.d.ts.map +0 -1
  48. package/lib/chain/rewards/syncCommitteeRewards.js +0 -36
  49. package/lib/chain/rewards/syncCommitteeRewards.js.map +0 -1
  50. package/src/chain/rewards/attestationsRewards.ts +0 -206
  51. package/src/chain/rewards/blockRewards.ts +0 -153
  52. package/src/chain/rewards/syncCommitteeRewards.ts +0 -60
@@ -245,6 +245,18 @@ async function validateAggregateAndProof(
245
245
  });
246
246
  }
247
247
 
248
+ // Same race-condition check as above for seen aggregators
249
+ if (
250
+ !skipValidationKnownAttesters &&
251
+ chain.seenAggregatedAttestations.isKnown(targetEpoch, attIndex, attDataRootHex, aggregationBits)
252
+ ) {
253
+ throw new AttestationError(GossipAction.IGNORE, {
254
+ code: AttestationErrorCode.ATTESTERS_ALREADY_KNOWN,
255
+ targetEpoch,
256
+ aggregateRoot: attDataRootHex,
257
+ });
258
+ }
259
+
248
260
  chain.seenAggregators.add(targetEpoch, aggregatorIndex);
249
261
  chain.seenAggregatedAttestations.add(
250
262
  targetEpoch,
@@ -138,8 +138,9 @@ export async function validateGossipBlobSidecar(
138
138
  const signature = blobSidecar.signedBlockHeader.signature;
139
139
  if (!chain.seenBlockInputCache.isVerifiedProposerSignature(blobSlot, blockHex, signature)) {
140
140
  const signatureSet = getBlockHeaderProposerSignatureSetByParentStateSlot(
141
+ chain.config,
141
142
  chain.index2pubkey,
142
- blockState,
143
+ blockState.slot,
143
144
  blobSidecar.signedBlockHeader
144
145
  );
145
146
  // Don't batch so verification is not delayed
@@ -243,10 +244,9 @@ export async function validateBlockBlobSidecars(
243
244
  const blockRootHex = toRootHex(blockRoot);
244
245
  const signature = firstSidecarSignedBlockHeader.signature;
245
246
  if (!chain.seenBlockInputCache.isVerifiedProposerSignature(blockSlot, blockRootHex, signature)) {
246
- const headState = await chain.getHeadState();
247
247
  const signatureSet = getBlockHeaderProposerSignatureSetByHeaderSlot(
248
+ chain.config,
248
249
  chain.index2pubkey,
249
- headState,
250
250
  firstSidecarSignedBlockHeader
251
251
  );
252
252
 
@@ -135,8 +135,9 @@ export async function validateGossipDataColumnSidecar(
135
135
  const signature = dataColumnSidecar.signedBlockHeader.signature;
136
136
  if (!chain.seenBlockInputCache.isVerifiedProposerSignature(blockHeader.slot, blockRootHex, signature)) {
137
137
  const signatureSet = getBlockHeaderProposerSignatureSetByParentStateSlot(
138
+ chain.config,
138
139
  chain.index2pubkey,
139
- blockState,
140
+ blockState.slot,
140
141
  dataColumnSidecar.signedBlockHeader
141
142
  );
142
143
 
@@ -336,10 +337,9 @@ export async function validateBlockDataColumnSidecars(
336
337
  const slot = firstSidecarSignedBlockHeader.message.slot;
337
338
  const signature = firstSidecarSignedBlockHeader.signature;
338
339
  if (!chain.seenBlockInputCache.isVerifiedProposerSignature(slot, rootHex, signature)) {
339
- const headState = await chain.getHeadState();
340
340
  const signatureSet = getBlockHeaderProposerSignatureSetByHeaderSlot(
341
+ chain.config,
341
342
  chain.index2pubkey,
342
- headState,
343
343
  firstSidecarSignedBlockHeader
344
344
  );
345
345
 
@@ -1,4 +1,4 @@
1
- import type {PeerId, PeerInfo, PrivateKey} from "@libp2p/interface";
1
+ import type {PeerId, PeerInfo, PendingDial, PrivateKey} from "@libp2p/interface";
2
2
  import {Multiaddr} from "@multiformats/multiaddr";
3
3
  import {ENR} from "@chainsafe/enr";
4
4
  import {BeaconConfig} from "@lodestar/config";
@@ -217,7 +217,7 @@ export class PeerDiscovery {
217
217
  const pendingDials = new Set(
218
218
  this.libp2p.services.components.connectionManager
219
219
  .getDialQueue()
220
- .map((pendingDial) => pendingDial.peerId?.toString())
220
+ .map((pendingDial: PendingDial) => pendingDial.peerId?.toString())
221
221
  );
222
222
  for (const [id, cachedENR] of this.cachedENRs.entries()) {
223
223
  if (
@@ -458,7 +458,7 @@ export class PeerDiscovery {
458
458
  if (
459
459
  this.libp2p.services.components.connectionManager
460
460
  .getDialQueue()
461
- .find((pendingDial) => pendingDial.peerId?.equals(peerId))
461
+ .find((pendingDial: PendingDial) => pendingDial.peerId?.equals(peerId))
462
462
  ) {
463
463
  return DiscoveredPeerStatus.already_dialing;
464
464
  }
@@ -750,13 +750,7 @@ export class BackfillSync extends (EventEmitter as {new (): BackfillSyncEmitter}
750
750
 
751
751
  // GENESIS_SLOT doesn't has valid signature
752
752
  if (anchorBlock.message.slot === GENESIS_SLOT) return;
753
- await verifyBlockProposerSignature(
754
- this.chain.config,
755
- this.chain.index2pubkey,
756
- this.chain.bls,
757
- this.chain.getHeadState(),
758
- [anchorBlock]
759
- );
753
+ await verifyBlockProposerSignature(this.chain.config, this.chain.index2pubkey, this.chain.bls, [anchorBlock]);
760
754
 
761
755
  // We can write to the disk if this is ahead of prevFinalizedCheckpointBlock otherwise
762
756
  // we will need to go make checks on the top of sync loop before writing as it might
@@ -821,13 +815,7 @@ export class BackfillSync extends (EventEmitter as {new (): BackfillSyncEmitter}
821
815
 
822
816
  // If any of the block's proposer signature fail, we can't trust this peer at all
823
817
  if (verifiedBlocks.length > 0) {
824
- await verifyBlockProposerSignature(
825
- this.chain.config,
826
- this.chain.index2pubkey,
827
- this.chain.bls,
828
- this.chain.getHeadState(),
829
- verifiedBlocks
830
- );
818
+ await verifyBlockProposerSignature(this.chain.config, this.chain.index2pubkey, this.chain.bls, verifiedBlocks);
831
819
 
832
820
  // This is bad, like super bad. Abort the backfill
833
821
  if (!nextAnchor)
@@ -1,11 +1,6 @@
1
1
  import {BeaconConfig} from "@lodestar/config";
2
2
  import {GENESIS_SLOT} from "@lodestar/params";
3
- import {
4
- CachedBeaconStateAllForks,
5
- ISignatureSet,
6
- Index2PubkeyCache,
7
- getBlockProposerSignatureSet,
8
- } from "@lodestar/state-transition";
3
+ import {ISignatureSet, Index2PubkeyCache, getBlockProposerSignatureSet} from "@lodestar/state-transition";
9
4
  import {Root, SignedBeaconBlock, Slot, ssz} from "@lodestar/types";
10
5
  import {IBlsVerifier} from "../../chain/bls/index.js";
11
6
  import {BackfillSyncError, BackfillSyncErrorCode} from "./errors.js";
@@ -49,7 +44,6 @@ export async function verifyBlockProposerSignature(
49
44
  config: BeaconConfig,
50
45
  index2pubkey: Index2PubkeyCache,
51
46
  bls: IBlsVerifier,
52
- state: CachedBeaconStateAllForks,
53
47
  blocks: SignedBeaconBlock[]
54
48
  ): Promise<void> {
55
49
  if (blocks.length === 1 && blocks[0].message.slot === GENESIS_SLOT) return;
@@ -1,8 +0,0 @@
1
- import { PubkeyIndexMap } from "@chainsafe/pubkey-index-map";
2
- import { routes } from "@lodestar/api";
3
- import { BeaconConfig } from "@lodestar/config";
4
- import { CachedBeaconStateAllForks } from "@lodestar/state-transition";
5
- import { ValidatorIndex } from "@lodestar/types";
6
- export type AttestationsRewards = routes.beacon.AttestationsRewards;
7
- export declare function computeAttestationsRewards(config: BeaconConfig, pubkey2index: PubkeyIndexMap, state: CachedBeaconStateAllForks, validatorIds?: (ValidatorIndex | string)[]): Promise<AttestationsRewards>;
8
- //# sourceMappingURL=attestationsRewards.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"attestationsRewards.d.ts","sourceRoot":"","sources":["../../../src/chain/rewards/attestationsRewards.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAC,MAAM,EAAC,MAAM,eAAe,CAAC;AACrC,OAAO,EAAC,YAAY,EAAC,MAAM,kBAAkB,CAAC;AAc9C,OAAO,EACL,yBAAyB,EAU1B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAC,cAAc,EAAC,MAAM,iBAAiB,CAAC;AAG/C,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC;AASpE,wBAAsB,0BAA0B,CAC9C,MAAM,EAAE,YAAY,EACpB,YAAY,EAAE,cAAc,EAC5B,KAAK,EAAE,yBAAyB,EAChC,YAAY,CAAC,EAAE,CAAC,cAAc,GAAG,MAAM,CAAC,EAAE,GACzC,OAAO,CAAC,mBAAmB,CAAC,CAyB9B"}
@@ -1,112 +0,0 @@
1
- import { EFFECTIVE_BALANCE_INCREMENT, ForkName, INACTIVITY_PENALTY_QUOTIENT_ALTAIR, MAX_EFFECTIVE_BALANCE, MAX_EFFECTIVE_BALANCE_ELECTRA, PARTICIPATION_FLAG_WEIGHTS, TIMELY_HEAD_FLAG_INDEX, TIMELY_SOURCE_FLAG_INDEX, TIMELY_TARGET_FLAG_INDEX, WEIGHT_DENOMINATOR, isForkPostElectra, } from "@lodestar/params";
2
- import { FLAG_ELIGIBLE_ATTESTER, FLAG_PREV_HEAD_ATTESTER_UNSLASHED, FLAG_PREV_SOURCE_ATTESTER_UNSLASHED, FLAG_PREV_TARGET_ATTESTER_UNSLASHED, beforeProcessEpoch, hasMarkers, isInInactivityLeak, } from "@lodestar/state-transition";
3
- import { fromHex } from "@lodestar/utils";
4
- const defaultAttestationsReward = { head: 0, target: 0, source: 0, inclusionDelay: 0, inactivity: 0 };
5
- const defaultAttestationsPenalty = { target: 0, source: 0 };
6
- export async function computeAttestationsRewards(config, pubkey2index, state, validatorIds) {
7
- const fork = config.getForkName(state.slot);
8
- if (fork === ForkName.phase0) {
9
- throw Error("Unsupported fork. Attestations rewards calculation is not available in phase0");
10
- }
11
- const stateAltair = state;
12
- const transitionCache = beforeProcessEpoch(stateAltair);
13
- const [idealRewards, penalties] = computeIdealAttestationsRewardsAndPenaltiesAltair(config, stateAltair, transitionCache);
14
- const totalRewards = computeTotalAttestationsRewardsAltair(config, pubkey2index, stateAltair, transitionCache, idealRewards, penalties, validatorIds);
15
- return { idealRewards, totalRewards };
16
- }
17
- function computeIdealAttestationsRewardsAndPenaltiesAltair(config, state, transitionCache) {
18
- const baseRewardPerIncrement = transitionCache.baseRewardPerIncrement;
19
- const activeBalanceByIncrement = transitionCache.totalActiveStakeByIncrement;
20
- const fork = config.getForkName(state.slot);
21
- const maxEffectiveBalance = isForkPostElectra(fork) ? MAX_EFFECTIVE_BALANCE_ELECTRA : MAX_EFFECTIVE_BALANCE;
22
- const maxEffectiveBalanceByIncrement = Math.floor(maxEffectiveBalance / EFFECTIVE_BALANCE_INCREMENT);
23
- const idealRewards = Array.from({ length: maxEffectiveBalanceByIncrement + 1 }, (_, effectiveBalanceByIncrement) => ({
24
- ...defaultAttestationsReward,
25
- effectiveBalance: effectiveBalanceByIncrement * EFFECTIVE_BALANCE_INCREMENT,
26
- }));
27
- const attestationsPenalties = Array.from({ length: maxEffectiveBalanceByIncrement + 1 }, (_, effectiveBalanceByIncrement) => ({
28
- ...defaultAttestationsPenalty,
29
- effectiveBalance: effectiveBalanceByIncrement * EFFECTIVE_BALANCE_INCREMENT,
30
- }));
31
- for (let i = 0; i < PARTICIPATION_FLAG_WEIGHTS.length; i++) {
32
- const weight = PARTICIPATION_FLAG_WEIGHTS[i];
33
- let unslashedStakeByIncrement;
34
- let flagName;
35
- switch (i) {
36
- case TIMELY_SOURCE_FLAG_INDEX: {
37
- unslashedStakeByIncrement = transitionCache.prevEpochUnslashedStake.sourceStakeByIncrement;
38
- flagName = "source";
39
- break;
40
- }
41
- case TIMELY_TARGET_FLAG_INDEX: {
42
- unslashedStakeByIncrement = transitionCache.prevEpochUnslashedStake.targetStakeByIncrement;
43
- flagName = "target";
44
- break;
45
- }
46
- case TIMELY_HEAD_FLAG_INDEX: {
47
- unslashedStakeByIncrement = transitionCache.prevEpochUnslashedStake.headStakeByIncrement;
48
- flagName = "head";
49
- break;
50
- }
51
- default: {
52
- throw Error(`Unable to retrieve unslashed stake. Unknown participation flag index: ${i}`);
53
- }
54
- }
55
- for (let effectiveBalanceByIncrement = 0; effectiveBalanceByIncrement <= maxEffectiveBalanceByIncrement; effectiveBalanceByIncrement++) {
56
- const baseReward = effectiveBalanceByIncrement * baseRewardPerIncrement;
57
- const rewardNumerator = baseReward * weight * unslashedStakeByIncrement;
58
- // Both idealReward and penalty are rounded to nearest integer. Loss of precision is minimal as unit is gwei
59
- const idealReward = Math.round(rewardNumerator / activeBalanceByIncrement / WEIGHT_DENOMINATOR);
60
- const penalty = Math.round((baseReward * weight) / WEIGHT_DENOMINATOR); // Positive number indicates penalty
61
- const idealAttestationsReward = idealRewards[effectiveBalanceByIncrement];
62
- idealAttestationsReward[flagName] = isInInactivityLeak(state) ? 0 : idealReward; // No attestations rewards during inactivity leak
63
- if (flagName !== "head") {
64
- const attestationPenalty = attestationsPenalties[effectiveBalanceByIncrement];
65
- attestationPenalty[flagName] = penalty;
66
- }
67
- }
68
- }
69
- return [idealRewards, attestationsPenalties];
70
- }
71
- // Same calculation as `getRewardsAndPenaltiesAltair` but returns the breakdown of rewards instead of aggregated
72
- function computeTotalAttestationsRewardsAltair(config, pubkey2index, state, transitionCache, idealRewards, penalties, validatorIds = []) {
73
- const rewards = [];
74
- const { flags } = transitionCache;
75
- const { epochCtx } = state;
76
- const validatorIndices = validatorIds
77
- .map((id) => (typeof id === "number" ? id : pubkey2index.get(fromHex(id))))
78
- .filter((index) => index !== undefined); // Validator indices to include in the result
79
- const inactivityPenaltyDenominator = config.INACTIVITY_SCORE_BIAS * INACTIVITY_PENALTY_QUOTIENT_ALTAIR;
80
- for (let i = 0; i < flags.length; i++) {
81
- if (validatorIndices.length && !validatorIndices.includes(i)) {
82
- continue;
83
- }
84
- const flag = flags[i];
85
- if (!hasMarkers(flag, FLAG_ELIGIBLE_ATTESTER)) {
86
- continue;
87
- }
88
- const effectiveBalanceIncrement = epochCtx.effectiveBalanceIncrements[i];
89
- const currentRewards = { ...defaultAttestationsReward, validatorIndex: i };
90
- if (hasMarkers(flag, FLAG_PREV_SOURCE_ATTESTER_UNSLASHED)) {
91
- currentRewards.source = idealRewards[effectiveBalanceIncrement].source;
92
- }
93
- else {
94
- currentRewards.source = penalties[effectiveBalanceIncrement].source * -1; // Negative reward to indicate penalty
95
- }
96
- if (hasMarkers(flag, FLAG_PREV_TARGET_ATTESTER_UNSLASHED)) {
97
- currentRewards.target = idealRewards[effectiveBalanceIncrement].target;
98
- }
99
- else {
100
- currentRewards.target = penalties[effectiveBalanceIncrement].target * -1;
101
- // Also incur inactivity penalty if not voting target correctly
102
- const inactivityPenaltyNumerator = effectiveBalanceIncrement * EFFECTIVE_BALANCE_INCREMENT * state.inactivityScores.get(i);
103
- currentRewards.inactivity = Math.floor(inactivityPenaltyNumerator / inactivityPenaltyDenominator) * -1;
104
- }
105
- if (hasMarkers(flag, FLAG_PREV_HEAD_ATTESTER_UNSLASHED)) {
106
- currentRewards.head = idealRewards[effectiveBalanceIncrement].head;
107
- }
108
- rewards.push(currentRewards);
109
- }
110
- return rewards;
111
- }
112
- //# sourceMappingURL=attestationsRewards.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"attestationsRewards.js","sourceRoot":"","sources":["../../../src/chain/rewards/attestationsRewards.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,2BAA2B,EAC3B,QAAQ,EACR,kCAAkC,EAClC,qBAAqB,EACrB,6BAA6B,EAC7B,0BAA0B,EAC1B,sBAAsB,EACtB,wBAAwB,EACxB,wBAAwB,EACxB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAIL,sBAAsB,EACtB,iCAAiC,EACjC,mCAAmC,EACnC,mCAAmC,EACnC,kBAAkB,EAClB,UAAU,E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AAG,YAAY,CAAC,yBAAyB,CAAC,CAAC,MAAM,CAAC;QACzE,CAAC;aAAM,CAAC;YACN,cAAc,CAAC,MAAM,GAAG,SAAS,CAAC,yBAAyB,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,sCAAsC;QAClH,CAAC;QAED,IAAI,UAAU,CAAC,IAAI,EAAE,mCAAmC,CAAC,EAAE,CAAC;YAC1D,cAAc,CAAC,MAAM,GAAG,YAAY,CAAC,yBAAyB,CAAC,CAAC,MAAM,CAAC;QACzE,CAAC;aAAM,CAAC;YACN,cAAc,CAAC,MAAM,GAAG,SAAS,CAAC,yBAAyB,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;YAEzE,+DAA+D;YAC/D,MAAM,0BAA0B,GAC9B,yBAAyB,GAAG,2BAA2B,GAAG,KAAK,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YAC1F,cAAc,CAAC,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,0BAA0B,GAAG,4BAA4B,CAAC,GAAG,CAAC,CAAC,CAAC;QACzG,CAAC;QAED,IAAI,UAAU,CAAC,IAAI,EAAE,iCAAiC,CAAC,EAAE,CAAC;YACxD,cAAc,CAAC,IAAI,GAAG,YAAY,CAAC,yBAAyB,CAAC,CAAC,IAAI,CAAC;QACrE,CAAC;QAED,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IAC/B,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -1,15 +0,0 @@
1
- import { routes } from "@lodestar/api";
2
- import { BeaconConfig } from "@lodestar/config";
3
- import { CachedBeaconStateAllForks } from "@lodestar/state-transition";
4
- import { BeaconBlock } from "@lodestar/types";
5
- export type BlockRewards = routes.beacon.BlockRewards;
6
- /**
7
- * Calculate total proposer block rewards given block and the beacon state of the same slot before the block is applied (preState)
8
- * postState can be passed in to read reward cache if available
9
- * Standard (Non MEV) rewards for proposing a block consists of:
10
- * 1) Including attestations from (beacon) committee
11
- * 2) Including attestations from sync committee
12
- * 3) Reporting slashable behaviours from proposer and attester
13
- */
14
- export declare function computeBlockRewards(config: BeaconConfig, block: BeaconBlock, preState: CachedBeaconStateAllForks, postState?: CachedBeaconStateAllForks): Promise<BlockRewards>;
15
- //# sourceMappingURL=blockRewards.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"blockRewards.d.ts","sourceRoot":"","sources":["../../../src/chain/rewards/blockRewards.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,eAAe,CAAC;AACrC,OAAO,EAAC,YAAY,EAAC,MAAM,kBAAkB,CAAC;AAO9C,OAAO,EACL,yBAAyB,EAK1B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAC,WAAW,EAAiB,MAAM,iBAAiB,CAAC;AAE5D,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC;AAGtD;;;;;;;GAOG;AACH,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,WAAW,EAClB,QAAQ,EAAE,yBAAyB,EACnC,SAAS,CAAC,EAAE,yBAAyB,GACpC,OAAO,CAAC,YAAY,CAAC,CAgCvB"}
@@ -1,94 +0,0 @@
1
- import { ForkName, WHISTLEBLOWER_REWARD_QUOTIENT, WHISTLEBLOWER_REWARD_QUOTIENT_ELECTRA, isForkPostElectra, } from "@lodestar/params";
2
- import { getAttesterSlashableIndices, processAttestationsAltair, } from "@lodestar/state-transition";
3
- /**
4
- * Calculate total proposer block rewards given block and the beacon state of the same slot before the block is applied (preState)
5
- * postState can be passed in to read reward cache if available
6
- * Standard (Non MEV) rewards for proposing a block consists of:
7
- * 1) Including attestations from (beacon) committee
8
- * 2) Including attestations from sync committee
9
- * 3) Reporting slashable behaviours from proposer and attester
10
- */
11
- export async function computeBlockRewards(config, block, preState, postState) {
12
- const fork = config.getForkName(block.slot);
13
- const { attestations: cachedAttestationsReward = 0, syncAggregate: cachedSyncAggregateReward = 0 } = postState?.proposerRewards ?? {};
14
- let blockAttestationReward = cachedAttestationsReward;
15
- let syncAggregateReward = cachedSyncAggregateReward;
16
- if (blockAttestationReward === 0) {
17
- blockAttestationReward =
18
- fork === ForkName.phase0
19
- ? computeBlockAttestationRewardPhase0(block, preState)
20
- : computeBlockAttestationRewardAltair(config, block, preState);
21
- }
22
- if (syncAggregateReward === 0) {
23
- syncAggregateReward = computeSyncAggregateReward(block, preState);
24
- }
25
- const blockProposerSlashingReward = computeBlockProposerSlashingReward(fork, block, preState);
26
- const blockAttesterSlashingReward = computeBlockAttesterSlashingReward(fork, block, preState);
27
- const total = blockAttestationReward + syncAggregateReward + blockProposerSlashingReward + blockAttesterSlashingReward;
28
- return {
29
- proposerIndex: block.proposerIndex,
30
- total,
31
- attestations: blockAttestationReward,
32
- syncAggregate: syncAggregateReward,
33
- proposerSlashings: blockProposerSlashingReward,
34
- attesterSlashings: blockAttesterSlashingReward,
35
- };
36
- }
37
- /**
38
- * TODO: Calculate rewards received by block proposer for including attestations.
39
- */
40
- function computeBlockAttestationRewardPhase0(_block, _preState) {
41
- throw new Error("Unsupported fork! Block attestation reward calculation is not available in phase0");
42
- }
43
- /**
44
- * Calculate rewards received by block proposer for including attestations since Altair.
45
- * Reuses `processAttestationsAltair()`. Has dependency on RewardCache
46
- */
47
- function computeBlockAttestationRewardAltair(config, block, preState) {
48
- const fork = config.getForkSeq(block.slot);
49
- const { attestations } = block.body;
50
- processAttestationsAltair(fork, preState, attestations, false);
51
- return preState.proposerRewards.attestations;
52
- }
53
- function computeSyncAggregateReward(block, preState) {
54
- if (block.body.syncAggregate !== undefined) {
55
- const { syncCommitteeBits } = block.body.syncAggregate;
56
- const { syncProposerReward } = preState.epochCtx;
57
- return syncCommitteeBits.getTrueBitIndexes().length * Math.floor(syncProposerReward); // syncProposerReward should already be integer
58
- }
59
- return 0; // phase0 block does not have syncAggregate
60
- }
61
- /**
62
- * Calculate rewards received by block proposer for including proposer slashings.
63
- * All proposer slashing rewards go to block proposer and none to whistleblower as of Deneb
64
- */
65
- function computeBlockProposerSlashingReward(fork, block, state) {
66
- let proposerSlashingReward = 0;
67
- for (const proposerSlashing of block.body.proposerSlashings) {
68
- const offendingProposerIndex = proposerSlashing.signedHeader1.message.proposerIndex;
69
- const offendingProposerBalance = state.validators.getReadonly(offendingProposerIndex).effectiveBalance;
70
- const whistleblowerRewardQuotient = isForkPostElectra(fork)
71
- ? WHISTLEBLOWER_REWARD_QUOTIENT_ELECTRA
72
- : WHISTLEBLOWER_REWARD_QUOTIENT;
73
- proposerSlashingReward += Math.floor(offendingProposerBalance / whistleblowerRewardQuotient);
74
- }
75
- return proposerSlashingReward;
76
- }
77
- /**
78
- * Calculate rewards received by block proposer for including attester slashings.
79
- * All attester slashing rewards go to block proposer and none to whistleblower as of Deneb
80
- */
81
- function computeBlockAttesterSlashingReward(fork, block, preState) {
82
- let attesterSlashingReward = 0;
83
- for (const attesterSlashing of block.body.attesterSlashings) {
84
- for (const offendingAttesterIndex of getAttesterSlashableIndices(attesterSlashing)) {
85
- const offendingAttesterBalance = preState.validators.getReadonly(offendingAttesterIndex).effectiveBalance;
86
- const whistleblowerRewardQuotient = isForkPostElectra(fork)
87
- ? WHISTLEBLOWER_REWARD_QUOTIENT_ELECTRA
88
- : WHISTLEBLOWER_REWARD_QUOTIENT;
89
- attesterSlashingReward += Math.floor(offendingAttesterBalance / whistleblowerRewardQuotient);
90
- }
91
- }
92
- return attesterSlashingReward;
93
- }
94
- //# sourceMappingURL=blockRewards.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"blockRewards.js","sourceRoot":"","sources":["../../../src/chain/rewards/blockRewards.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,QAAQ,EACR,6BAA6B,EAC7B,qCAAqC,EACrC,iBAAiB,GAClB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAIL,2BAA2B,EAC3B,yBAAyB,GAC1B,MAAM,4BAA4B,CAAC;A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C,sBAAsB,CAAC,CAAC,gBAAgB,CAAC;QACvG,MAAM,2BAA2B,GAAG,iBAAiB,CAAC,IAAI,CAAC;YACzD,CAAC,CAAC,qCAAqC;YACvC,CAAC,CAAC,6BAA6B,CAAC;QAElC,sBAAsB,IAAI,IAAI,CAAC,KAAK,CAAC,wBAAwB,GAAG,2BAA2B,CAAC,CAAC;IAC/F,CAAC;IAED,OAAO,sBAAsB,CAAC;AAChC,CAAC;AAED;;;GAGG;AACH,SAAS,kCAAkC,CACzC,IAAc,EACd,KAAkB,EAClB,QAAmC;IAEnC,IAAI,sBAAsB,GAAG,CAAC,CAAC;IAE/B,KAAK,MAAM,gBAAgB,IAAI,KAAK,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC;QAC5D,KAAK,MAAM,sBAAsB,IAAI,2BAA2B,CAAC,gBAAgB,CAAC,EAAE,CAAC;YACnF,MAAM,wBAAwB,GAAG,QAAQ,CAAC,UAAU,CAAC,WAAW,CAAC,sBAAsB,CAAC,CAAC,gBAAgB,CAAC;YAC1G,MAAM,2BAA2B,GAAG,iBAAiB,CAAC,IAAI,CAAC;gBACzD,CAAC,CAAC,qCAAqC;gBACvC,CAAC,CAAC,6BAA6B,CAAC;YAElC,sBAAsB,IAAI,IAAI,CAAC,KAAK,CAAC,wBAAwB,GAAG,2BAA2B,CAAC,CAAC;QAC/F,CAAC;IACH,CAAC;IAED,OAAO,sBAAsB,CAAC;AAChC,CAAC"}
@@ -1,7 +0,0 @@
1
- import { routes } from "@lodestar/api";
2
- import { BeaconConfig } from "@lodestar/config";
3
- import { CachedBeaconStateAllForks, Index2PubkeyCache } from "@lodestar/state-transition";
4
- import { BeaconBlock, ValidatorIndex } from "@lodestar/types";
5
- export type SyncCommitteeRewards = routes.beacon.SyncCommitteeRewards;
6
- export declare function computeSyncCommitteeRewards(config: BeaconConfig, index2pubkey: Index2PubkeyCache, block: BeaconBlock, preState: CachedBeaconStateAllForks, validatorIds?: (ValidatorIndex | string)[]): Promise<SyncCommitteeRewards>;
7
- //# sourceMappingURL=syncCommitteeRewards.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"syncCommitteeRewards.d.ts","sourceRoot":"","sources":["../../../src/chain/rewards/syncCommitteeRewards.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,eAAe,CAAC;AACrC,OAAO,EAAC,YAAY,EAAC,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EAAC,yBAAyB,EAA2B,iBAAiB,EAAC,MAAM,4BAA4B,CAAC;AACjH,OAAO,EAAC,WAAW,EAAE,cAAc,EAAS,MAAM,iBAAiB,CAAC;AAEpE,MAAM,MAAM,oBAAoB,GAAG,MAAM,CAAC,MAAM,CAAC,oBAAoB,CAAC;AAGtE,wBAAsB,2BAA2B,CAC/C,MAAM,EAAE,YAAY,EACpB,YAAY,EAAE,iBAAiB,EAC/B,KAAK,EAAE,WAAW,EAClB,QAAQ,EAAE,yBAAyB,EACnC,YAAY,GAAE,CAAC,cAAc,GAAG,MAAM,CAAC,EAAO,GAC7C,OAAO,CAAC,oBAAoB,CAAC,CA4C/B"}
@@ -1,36 +0,0 @@
1
- import { ForkName, SYNC_COMMITTEE_SIZE } from "@lodestar/params";
2
- export async function computeSyncCommitteeRewards(config, index2pubkey, block, preState, validatorIds = []) {
3
- const fork = config.getForkName(block.slot);
4
- if (fork === ForkName.phase0) {
5
- throw Error("Cannot get sync rewards as phase0 block does not have sync committee");
6
- }
7
- const altairBlock = block;
8
- const preStateAltair = preState;
9
- // Bound syncCommitteeValidatorIndices in case it goes beyond SYNC_COMMITTEE_SIZE just to be safe
10
- const syncCommitteeValidatorIndices = preStateAltair.epochCtx.currentSyncCommitteeIndexed.validatorIndices.slice(0, SYNC_COMMITTEE_SIZE);
11
- const { syncParticipantReward } = preStateAltair.epochCtx;
12
- const { syncCommitteeBits } = altairBlock.body.syncAggregate;
13
- // Use balance of each committee as starting point such that we cap the penalty to avoid balance dropping below 0
14
- const balances = new Map();
15
- for (const i of syncCommitteeValidatorIndices) {
16
- balances.set(i, { val: preStateAltair.balances.get(i) });
17
- }
18
- for (const i of syncCommitteeValidatorIndices) {
19
- const balanceRecord = balances.get(i);
20
- if (syncCommitteeBits.get(i)) {
21
- // Positive rewards for participants
22
- balanceRecord.val += syncParticipantReward;
23
- }
24
- else {
25
- // Negative rewards for non participants
26
- balanceRecord.val = Math.max(0, balanceRecord.val - syncParticipantReward);
27
- }
28
- }
29
- const rewards = Array.from(balances, ([validatorIndex, v]) => ({ validatorIndex, reward: v.val }));
30
- if (validatorIds.length) {
31
- const filtersSet = new Set(validatorIds);
32
- return rewards.filter((reward) => filtersSet.has(reward.validatorIndex) || filtersSet.has(index2pubkey[reward.validatorIndex].toHex()));
33
- }
34
- return rewards;
35
- }
36
- //# sourceMappingURL=syncCommitteeRewards.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"syncCommitteeRewards.js","sourceRoot":"","sources":["../../../src/chain/rewards/syncCommitteeRewards.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,QAAQ,EAAE,mBAAmB,EAAC,MAAM,kBAAkB,CAAC;AAO/D,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAC/C,MAAoB,EACpB,YAA+B,EAC/B,KAAkB,EAClB,QAAmC,EACnC,eAA4C,EAAE;IAE9C,MAAM,IAAI,GAAG,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC5C,IAAI,IAAI,KAAK,QAAQ,CAAC,MAAM,EAAE,CAAC;QAC7B,MAAM,KAAK,CAAC,sEAAsE,CAAC,CAAC;IACtF,CAAC;IAED,MAAM,WAAW,GAAG,KAA2B,CAAC;IAChD,MAAM,cAAc,GAAG,QAAmC,CAAC;IAE3D,iGAAiG;IACjG,MAAM,6BAA6B,GAAG,cAAc,CAAC,QAAQ,CAAC,2BAA2B,CAAC,gBAAgB,CAAC,KAAK,CAC9G,CAAC,EACD,mBAAmB,CACpB,CAAC;IACF,MAAM,EAA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