@lodestar/beacon-node 1.39.0-dev.075956b855 → 1.39.0-dev.0e7901d6a2
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.
- package/README.md +1 -1
- package/lib/api/impl/beacon/state/utils.d.ts +2 -7
- package/lib/api/impl/beacon/state/utils.d.ts.map +1 -1
- package/lib/api/impl/beacon/state/utils.js +0 -12
- package/lib/api/impl/beacon/state/utils.js.map +1 -1
- package/lib/api/impl/lodestar/index.js +1 -1
- package/lib/api/impl/lodestar/index.js.map +1 -1
- package/lib/api/impl/proof/index.d.ts.map +1 -1
- package/lib/api/impl/proof/index.js +1 -2
- package/lib/api/impl/proof/index.js.map +1 -1
- package/lib/api/impl/validator/index.d.ts.map +1 -1
- package/lib/api/impl/validator/index.js +1 -3
- package/lib/api/impl/validator/index.js.map +1 -1
- package/lib/chain/blocks/importBlock.d.ts.map +1 -1
- package/lib/chain/blocks/importBlock.js +12 -3
- package/lib/chain/blocks/importBlock.js.map +1 -1
- package/lib/chain/blocks/verifyBlock.d.ts.map +1 -1
- package/lib/chain/blocks/verifyBlock.js +8 -1
- package/lib/chain/blocks/verifyBlock.js.map +1 -1
- package/lib/chain/blocks/verifyBlocksStateTransitionOnly.d.ts.map +1 -1
- package/lib/chain/blocks/verifyBlocksStateTransitionOnly.js +1 -0
- package/lib/chain/blocks/verifyBlocksStateTransitionOnly.js.map +1 -1
- package/lib/chain/chain.d.ts +7 -9
- package/lib/chain/chain.d.ts.map +1 -1
- package/lib/chain/chain.js +17 -10
- package/lib/chain/chain.js.map +1 -1
- package/lib/chain/interface.d.ts +6 -9
- package/lib/chain/interface.d.ts.map +1 -1
- package/lib/chain/interface.js.map +1 -1
- package/lib/chain/lightClient/proofs.d.ts.map +1 -1
- package/lib/chain/lightClient/proofs.js +0 -2
- package/lib/chain/lightClient/proofs.js.map +1 -1
- package/lib/chain/opPools/aggregatedAttestationPool.d.ts +5 -9
- package/lib/chain/opPools/aggregatedAttestationPool.d.ts.map +1 -1
- package/lib/chain/opPools/aggregatedAttestationPool.js +12 -141
- package/lib/chain/opPools/aggregatedAttestationPool.js.map +1 -1
- package/lib/chain/opPools/opPool.js +5 -8
- package/lib/chain/opPools/opPool.js.map +1 -1
- package/lib/chain/prepareNextSlot.d.ts.map +1 -1
- package/lib/chain/prepareNextSlot.js +4 -7
- package/lib/chain/prepareNextSlot.js.map +1 -1
- package/lib/chain/produceBlock/produceBlockBody.d.ts.map +1 -1
- package/lib/chain/produceBlock/produceBlockBody.js +2 -2
- package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
- package/lib/chain/regen/interface.d.ts +1 -5
- package/lib/chain/regen/interface.d.ts.map +1 -1
- package/lib/chain/regen/queued.d.ts +4 -7
- package/lib/chain/regen/queued.d.ts.map +1 -1
- package/lib/chain/regen/queued.js +15 -25
- package/lib/chain/regen/queued.js.map +1 -1
- package/lib/chain/regen/regen.d.ts +1 -1
- package/lib/chain/regen/regen.d.ts.map +1 -1
- package/lib/chain/regen/regen.js +13 -17
- package/lib/chain/regen/regen.js.map +1 -1
- package/lib/chain/shufflingCache.d.ts +16 -11
- package/lib/chain/shufflingCache.d.ts.map +1 -1
- package/lib/chain/shufflingCache.js +47 -41
- package/lib/chain/shufflingCache.js.map +1 -1
- package/lib/chain/stateCache/blockStateCacheImpl.d.ts +1 -2
- package/lib/chain/stateCache/blockStateCacheImpl.d.ts.map +1 -1
- package/lib/chain/stateCache/blockStateCacheImpl.js +2 -2
- package/lib/chain/stateCache/blockStateCacheImpl.js.map +1 -1
- package/lib/chain/stateCache/fifoBlockStateCache.d.ts +1 -2
- package/lib/chain/stateCache/fifoBlockStateCache.d.ts.map +1 -1
- package/lib/chain/stateCache/fifoBlockStateCache.js +4 -4
- package/lib/chain/stateCache/fifoBlockStateCache.js.map +1 -1
- package/lib/chain/stateCache/inMemoryCheckpointsCache.d.ts +4 -5
- package/lib/chain/stateCache/inMemoryCheckpointsCache.d.ts.map +1 -1
- package/lib/chain/stateCache/inMemoryCheckpointsCache.js +9 -10
- package/lib/chain/stateCache/inMemoryCheckpointsCache.js.map +1 -1
- package/lib/chain/stateCache/persistentCheckpointsCache.d.ts +5 -6
- package/lib/chain/stateCache/persistentCheckpointsCache.d.ts.map +1 -1
- package/lib/chain/stateCache/persistentCheckpointsCache.js +17 -17
- package/lib/chain/stateCache/persistentCheckpointsCache.js.map +1 -1
- package/lib/chain/stateCache/types.d.ts +5 -6
- package/lib/chain/stateCache/types.d.ts.map +1 -1
- package/lib/chain/stateCache/types.js.map +1 -1
- package/lib/chain/validation/attestation.d.ts.map +1 -1
- package/lib/chain/validation/attestation.js +2 -2
- package/lib/chain/validation/attestation.js.map +1 -1
- package/lib/chain/validation/attesterSlashing.d.ts.map +1 -1
- package/lib/chain/validation/attesterSlashing.js +1 -1
- package/lib/chain/validation/attesterSlashing.js.map +1 -1
- package/lib/chain/validation/blobSidecar.d.ts.map +1 -1
- package/lib/chain/validation/blobSidecar.js +2 -3
- package/lib/chain/validation/blobSidecar.js.map +1 -1
- package/lib/chain/validation/block.d.ts.map +1 -1
- package/lib/chain/validation/block.js +2 -0
- package/lib/chain/validation/block.js.map +1 -1
- package/lib/chain/validation/blsToExecutionChange.d.ts.map +1 -1
- package/lib/chain/validation/blsToExecutionChange.js +9 -2
- package/lib/chain/validation/blsToExecutionChange.js.map +1 -1
- package/lib/chain/validation/dataColumnSidecar.d.ts.map +1 -1
- package/lib/chain/validation/dataColumnSidecar.js +2 -3
- package/lib/chain/validation/dataColumnSidecar.js.map +1 -1
- package/lib/chain/validation/proposerSlashing.js +2 -1
- package/lib/chain/validation/proposerSlashing.js.map +1 -1
- package/lib/db/repositories/stateArchive.d.ts +1 -1
- package/lib/db/repositories/stateArchive.d.ts.map +1 -1
- package/lib/db/repositories/stateArchive.js +2 -2
- package/lib/db/repositories/stateArchive.js.map +1 -1
- package/lib/execution/engine/mock.d.ts +9 -6
- package/lib/execution/engine/mock.d.ts.map +1 -1
- package/lib/execution/engine/mock.js +34 -7
- package/lib/execution/engine/mock.js.map +1 -1
- package/lib/metrics/metrics/lodestar.d.ts +1 -6
- package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
- package/lib/metrics/metrics/lodestar.js +3 -17
- package/lib/metrics/metrics/lodestar.js.map +1 -1
- package/lib/network/peers/discover.d.ts.map +1 -1
- package/lib/network/peers/discover.js.map +1 -1
- package/lib/network/reqresp/utils/dataColumnResponseValidation.js +1 -1
- package/lib/network/reqresp/utils/dataColumnResponseValidation.js.map +1 -1
- package/lib/node/nodejs.d.ts.map +1 -1
- package/lib/node/nodejs.js +17 -2
- package/lib/node/nodejs.js.map +1 -1
- package/lib/sync/backfill/backfill.d.ts.map +1 -1
- package/lib/sync/backfill/backfill.js +2 -2
- package/lib/sync/backfill/backfill.js.map +1 -1
- package/lib/sync/backfill/verify.d.ts +2 -2
- package/lib/sync/backfill/verify.d.ts.map +1 -1
- package/lib/sync/backfill/verify.js +2 -2
- package/lib/sync/backfill/verify.js.map +1 -1
- package/lib/util/sszBytes.js +1 -1
- package/lib/util/sszBytes.js.map +1 -1
- package/package.json +28 -20
- package/src/api/impl/beacon/state/utils.ts +2 -22
- package/src/api/impl/lodestar/index.ts +1 -1
- package/src/api/impl/proof/index.ts +1 -2
- package/src/api/impl/validator/index.ts +1 -3
- package/src/chain/blocks/importBlock.ts +13 -3
- package/src/chain/blocks/verifyBlock.ts +9 -3
- package/src/chain/blocks/verifyBlocksStateTransitionOnly.ts +1 -0
- package/src/chain/chain.ts +27 -15
- package/src/chain/interface.ts +6 -8
- package/src/chain/lightClient/proofs.ts +0 -2
- package/src/chain/opPools/aggregatedAttestationPool.ts +19 -191
- package/src/chain/opPools/opPool.ts +5 -7
- package/src/chain/prepareNextSlot.ts +2 -6
- package/src/chain/produceBlock/produceBlockBody.ts +7 -2
- package/src/chain/regen/interface.ts +1 -5
- package/src/chain/regen/queued.ts +15 -34
- package/src/chain/regen/regen.ts +12 -18
- package/src/chain/shufflingCache.ts +67 -50
- package/src/chain/stateCache/blockStateCacheImpl.ts +2 -3
- package/src/chain/stateCache/fifoBlockStateCache.ts +4 -5
- package/src/chain/stateCache/inMemoryCheckpointsCache.ts +9 -15
- package/src/chain/stateCache/persistentCheckpointsCache.ts +17 -25
- package/src/chain/stateCache/types.ts +5 -10
- package/src/chain/validation/attestation.ts +3 -3
- package/src/chain/validation/attesterSlashing.ts +8 -1
- package/src/chain/validation/blobSidecar.ts +3 -3
- package/src/chain/validation/block.ts +3 -0
- package/src/chain/validation/blsToExecutionChange.ts +9 -7
- package/src/chain/validation/dataColumnSidecar.ts +3 -3
- package/src/chain/validation/proposerSlashing.ts +2 -1
- package/src/db/repositories/stateArchive.ts +2 -2
- package/src/execution/engine/mock.ts +40 -13
- package/src/metrics/metrics/lodestar.ts +3 -17
- package/src/network/peers/discover.ts +3 -3
- package/src/network/reqresp/utils/dataColumnResponseValidation.ts +1 -1
- package/src/node/nodejs.ts +18 -3
- package/src/sync/backfill/backfill.ts +2 -14
- package/src/sync/backfill/verify.ts +1 -7
- package/src/util/sszBytes.ts +1 -1
- package/lib/chain/rewards/attestationsRewards.d.ts +0 -8
- package/lib/chain/rewards/attestationsRewards.d.ts.map +0 -1
- package/lib/chain/rewards/attestationsRewards.js +0 -112
- package/lib/chain/rewards/attestationsRewards.js.map +0 -1
- package/lib/chain/rewards/blockRewards.d.ts +0 -15
- package/lib/chain/rewards/blockRewards.d.ts.map +0 -1
- package/lib/chain/rewards/blockRewards.js +0 -94
- package/lib/chain/rewards/blockRewards.js.map +0 -1
- package/lib/chain/rewards/syncCommitteeRewards.d.ts +0 -7
- package/lib/chain/rewards/syncCommitteeRewards.d.ts.map +0 -1
- package/lib/chain/rewards/syncCommitteeRewards.js +0 -36
- package/lib/chain/rewards/syncCommitteeRewards.js.map +0 -1
- package/src/chain/rewards/attestationsRewards.ts +0 -206
- package/src/chain/rewards/blockRewards.ts +0 -153
- package/src/chain/rewards/syncCommitteeRewards.ts +0 -60
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {routes} from "@lodestar/api";
|
|
2
2
|
import {CachedBeaconStateAllForks} from "@lodestar/state-transition";
|
|
3
3
|
import {Epoch, RootHex, phase0} from "@lodestar/types";
|
|
4
|
-
import {StateRegenerationOpts} from "../regen/interface.js";
|
|
5
4
|
|
|
6
5
|
export type CheckpointHex = {epoch: Epoch; rootHex: RootHex};
|
|
7
6
|
|
|
@@ -21,7 +20,7 @@ export type CheckpointHex = {epoch: Epoch; rootHex: RootHex};
|
|
|
21
20
|
* The cache key is state root
|
|
22
21
|
*/
|
|
23
22
|
export interface BlockStateCache {
|
|
24
|
-
get(rootHex: RootHex
|
|
23
|
+
get(rootHex: RootHex): CachedBeaconStateAllForks | null;
|
|
25
24
|
add(item: CachedBeaconStateAllForks): void;
|
|
26
25
|
setHeadState(item: CachedBeaconStateAllForks | null): void;
|
|
27
26
|
/**
|
|
@@ -60,16 +59,12 @@ export interface BlockStateCache {
|
|
|
60
59
|
*/
|
|
61
60
|
export interface CheckpointStateCache {
|
|
62
61
|
init?: () => Promise<void>;
|
|
63
|
-
getOrReload(cp: CheckpointHex
|
|
62
|
+
getOrReload(cp: CheckpointHex): Promise<CachedBeaconStateAllForks | null>;
|
|
64
63
|
getStateOrBytes(cp: CheckpointHex): Promise<CachedBeaconStateAllForks | Uint8Array | null>;
|
|
65
|
-
get(cpOrKey: CheckpointHex | string
|
|
64
|
+
get(cpOrKey: CheckpointHex | string): CachedBeaconStateAllForks | null;
|
|
66
65
|
add(cp: phase0.Checkpoint, state: CachedBeaconStateAllForks): void;
|
|
67
|
-
getLatest(rootHex: RootHex, maxEpoch: Epoch
|
|
68
|
-
getOrReloadLatest(
|
|
69
|
-
rootHex: RootHex,
|
|
70
|
-
maxEpoch: Epoch,
|
|
71
|
-
opts?: StateRegenerationOpts
|
|
72
|
-
): Promise<CachedBeaconStateAllForks | null>;
|
|
66
|
+
getLatest(rootHex: RootHex, maxEpoch: Epoch): CachedBeaconStateAllForks | null;
|
|
67
|
+
getOrReloadLatest(rootHex: RootHex, maxEpoch: Epoch): Promise<CachedBeaconStateAllForks | null>;
|
|
73
68
|
updatePreComputedCheckpoint(rootHex: RootHex, epoch: Epoch): number | null;
|
|
74
69
|
prune(finalizedEpoch: Epoch, justifiedEpoch: Epoch): void;
|
|
75
70
|
pruneFinalized(finalizedEpoch: Epoch): void;
|
|
@@ -12,9 +12,9 @@ import {
|
|
|
12
12
|
isForkPostElectra,
|
|
13
13
|
} from "@lodestar/params";
|
|
14
14
|
import {
|
|
15
|
-
EpochCacheError,
|
|
16
|
-
EpochCacheErrorCode,
|
|
17
15
|
EpochShuffling,
|
|
16
|
+
ShufflingError,
|
|
17
|
+
ShufflingErrorCode,
|
|
18
18
|
SingleSignatureSet,
|
|
19
19
|
computeEpochAtSlot,
|
|
20
20
|
computeSigningRoot,
|
|
@@ -224,7 +224,7 @@ export async function validateApiAttestation(
|
|
|
224
224
|
code: AttestationErrorCode.INVALID_SIGNATURE,
|
|
225
225
|
});
|
|
226
226
|
} catch (err) {
|
|
227
|
-
if (err instanceof
|
|
227
|
+
if (err instanceof ShufflingError && err.type.code === ShufflingErrorCode.COMMITTEE_INDEX_OUT_OF_RANGE) {
|
|
228
228
|
throw new AttestationError(GossipAction.IGNORE, {
|
|
229
229
|
code: AttestationErrorCode.BAD_TARGET_EPOCH,
|
|
230
230
|
});
|
|
@@ -43,7 +43,14 @@ export async function validateAttesterSlashing(
|
|
|
43
43
|
// [REJECT] All of the conditions within process_attester_slashing pass validation.
|
|
44
44
|
try {
|
|
45
45
|
// verifySignature = false, verified in batch below
|
|
46
|
-
assertValidAttesterSlashing(
|
|
46
|
+
assertValidAttesterSlashing(
|
|
47
|
+
chain.config,
|
|
48
|
+
chain.index2pubkey,
|
|
49
|
+
state.slot,
|
|
50
|
+
state.validators.length,
|
|
51
|
+
attesterSlashing,
|
|
52
|
+
false
|
|
53
|
+
);
|
|
47
54
|
} catch (e) {
|
|
48
55
|
throw new AttesterSlashingError(GossipAction.REJECT, {
|
|
49
56
|
code: AttesterSlashingErrorCode.INVALID,
|
|
@@ -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
|
|
|
@@ -134,6 +134,9 @@ export async function validateGossipBlock(
|
|
|
134
134
|
throw new BlockGossipError(GossipAction.IGNORE, {code: BlockErrorCode.PARENT_UNKNOWN, parentRoot});
|
|
135
135
|
});
|
|
136
136
|
|
|
137
|
+
// in forky condition, make sure to populate ShufflingCache with regened state
|
|
138
|
+
chain.shufflingCache.processState(blockState);
|
|
139
|
+
|
|
137
140
|
// Extra conditions for merge fork blocks
|
|
138
141
|
// [REJECT] The block's execution payload timestamp is correct with respect to the slot
|
|
139
142
|
// -- i.e. execution_payload.timestamp == compute_timestamp_at_slot(state, block.slot).
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CachedBeaconStateCapella,
|
|
3
|
-
getBlsToExecutionChangeSignatureSet,
|
|
4
|
-
isValidBlsToExecutionChange,
|
|
5
|
-
} from "@lodestar/state-transition";
|
|
1
|
+
import {getBlsToExecutionChangeSignatureSet, isValidBlsToExecutionChange} from "@lodestar/state-transition";
|
|
6
2
|
import {capella} from "@lodestar/types";
|
|
7
3
|
import {BlsToExecutionChangeError, BlsToExecutionChangeErrorCode, GossipAction} from "../errors/index.js";
|
|
8
4
|
import {IBeaconChain} from "../index.js";
|
|
@@ -42,10 +38,16 @@ async function validateBlsToExecutionChange(
|
|
|
42
38
|
// and chanes relevant to `isValidBlsToExecutionChange()` happen only on processBlock(), not processEpoch()
|
|
43
39
|
const state = chain.getHeadState();
|
|
44
40
|
const {config} = chain;
|
|
45
|
-
|
|
41
|
+
const addressChange = blsToExecutionChange.message;
|
|
42
|
+
if (addressChange.validatorIndex >= state.validators.length) {
|
|
43
|
+
throw new BlsToExecutionChangeError(GossipAction.REJECT, {
|
|
44
|
+
code: BlsToExecutionChangeErrorCode.INVALID,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
const validator = state.validators.getReadonly(addressChange.validatorIndex);
|
|
46
48
|
// [REJECT] All of the conditions within process_bls_to_execution_change pass validation.
|
|
47
49
|
// verifySignature = false, verified in batch below
|
|
48
|
-
const {valid} = isValidBlsToExecutionChange(
|
|
50
|
+
const {valid} = isValidBlsToExecutionChange(config, validator, blsToExecutionChange, false);
|
|
49
51
|
if (!valid) {
|
|
50
52
|
throw new BlsToExecutionChangeError(GossipAction.REJECT, {
|
|
51
53
|
code: BlsToExecutionChangeErrorCode.INVALID,
|
|
@@ -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
|
|
|
@@ -35,8 +35,9 @@ async function validateProposerSlashing(
|
|
|
35
35
|
|
|
36
36
|
// [REJECT] All of the conditions within process_proposer_slashing pass validation.
|
|
37
37
|
try {
|
|
38
|
+
const proposer = state.validators.getReadonly(proposerSlashing.signedHeader1.message.proposerIndex);
|
|
38
39
|
// verifySignature = false, verified in batch below
|
|
39
|
-
assertValidProposerSlashing(state, proposerSlashing, false);
|
|
40
|
+
assertValidProposerSlashing(chain.config, chain.index2pubkey, state.slot, proposerSlashing, proposer, false);
|
|
40
41
|
} catch (e) {
|
|
41
42
|
throw new ProposerSlashingError(GossipAction.REJECT, {
|
|
42
43
|
code: ProposerSlashingErrorCode.INVALID,
|
|
@@ -42,10 +42,10 @@ export class StateArchiveRepository extends Repository<Slot, BeaconStateAllForks
|
|
|
42
42
|
|
|
43
43
|
// Index Root -> Slot
|
|
44
44
|
|
|
45
|
-
async
|
|
45
|
+
async getBinaryByRoot(stateRoot: Root): Promise<Uint8Array | null> {
|
|
46
46
|
const slot = await this.getSlotByRoot(stateRoot);
|
|
47
47
|
if (slot !== null && Number.isInteger(slot)) {
|
|
48
|
-
return this.
|
|
48
|
+
return this.getBinary(slot);
|
|
49
49
|
}
|
|
50
50
|
return null;
|
|
51
51
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import crypto from "node:crypto";
|
|
2
|
+
import {ChainConfig} from "@lodestar/config";
|
|
2
3
|
import {
|
|
3
4
|
BLOB_TX_TYPE,
|
|
4
5
|
BYTES_PER_FIELD_ELEMENT,
|
|
@@ -7,7 +8,9 @@ import {
|
|
|
7
8
|
ForkPostBellatrix,
|
|
8
9
|
ForkPostCapella,
|
|
9
10
|
ForkSeq,
|
|
11
|
+
SLOTS_PER_EPOCH,
|
|
10
12
|
} from "@lodestar/params";
|
|
13
|
+
import {computeTimeAtSlot} from "@lodestar/state-transition";
|
|
11
14
|
import {ExecutionPayload, RootHex, bellatrix, deneb, ssz} from "@lodestar/types";
|
|
12
15
|
import {fromHex, toRootHex} from "@lodestar/utils";
|
|
13
16
|
import {ZERO_HASH_HEX} from "../../constants/index.js";
|
|
@@ -34,14 +37,11 @@ const INTEROP_GAS_LIMIT = 30e6;
|
|
|
34
37
|
const PRUNE_PAYLOAD_ID_AFTER_MS = 5000;
|
|
35
38
|
|
|
36
39
|
export type ExecutionEngineMockOpts = {
|
|
37
|
-
genesisBlockHash
|
|
40
|
+
genesisBlockHash?: string;
|
|
38
41
|
eth1BlockHash?: string;
|
|
39
42
|
onlyPredefinedResponses?: boolean;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
electraForkTimestamp?: number;
|
|
43
|
-
fuluForkTimestamp?: number;
|
|
44
|
-
gloasForkTimestamp?: number;
|
|
43
|
+
genesisTime?: number;
|
|
44
|
+
config?: ChainConfig;
|
|
45
45
|
};
|
|
46
46
|
|
|
47
47
|
type ExecutionBlock = {
|
|
@@ -74,17 +74,21 @@ export class ExecutionEngineMockBackend implements JsonRpcBackend {
|
|
|
74
74
|
/** Preparing payloads to be retrieved via engine_getPayloadV1 */
|
|
75
75
|
private readonly preparingPayloads = new Map<number, PreparedPayload>();
|
|
76
76
|
private readonly payloadsForDeletion = new Map<number, number>();
|
|
77
|
-
|
|
78
77
|
private readonly predefinedPayloadStatuses = new Map<RootHex, PayloadStatus>();
|
|
79
78
|
|
|
80
79
|
private payloadId = 0;
|
|
80
|
+
private capellaForkTimestamp: number;
|
|
81
|
+
private denebForkTimestamp: number;
|
|
82
|
+
private electraForkTimestamp: number;
|
|
83
|
+
private fuluForkTimestamp: number;
|
|
84
|
+
private gloasForkTimestamp: number;
|
|
81
85
|
|
|
82
86
|
readonly handlers: {
|
|
83
87
|
[K in keyof EngineApiRpcParamTypes]: (...args: EngineApiRpcParamTypes[K]) => EngineApiRpcReturnTypes[K];
|
|
84
88
|
};
|
|
85
89
|
|
|
86
90
|
constructor(private readonly opts: ExecutionEngineMockOpts) {
|
|
87
|
-
this.validBlocks.set(opts.genesisBlockHash, {
|
|
91
|
+
this.validBlocks.set(opts.genesisBlockHash ?? ZERO_HASH_HEX, {
|
|
88
92
|
parentHash: ZERO_HASH_HEX,
|
|
89
93
|
blockHash: ZERO_HASH_HEX,
|
|
90
94
|
timestamp: 0,
|
|
@@ -100,6 +104,29 @@ export class ExecutionEngineMockBackend implements JsonRpcBackend {
|
|
|
100
104
|
blockNumber: 1,
|
|
101
105
|
});
|
|
102
106
|
|
|
107
|
+
const {config} = opts;
|
|
108
|
+
|
|
109
|
+
this.capellaForkTimestamp =
|
|
110
|
+
opts.genesisTime && config
|
|
111
|
+
? computeTimeAtSlot(config, config.CAPELLA_FORK_EPOCH * SLOTS_PER_EPOCH, opts.genesisTime)
|
|
112
|
+
: Infinity;
|
|
113
|
+
this.denebForkTimestamp =
|
|
114
|
+
opts.genesisTime && config
|
|
115
|
+
? computeTimeAtSlot(config, config.DENEB_FORK_EPOCH * SLOTS_PER_EPOCH, opts.genesisTime)
|
|
116
|
+
: Infinity;
|
|
117
|
+
this.electraForkTimestamp =
|
|
118
|
+
opts.genesisTime && config
|
|
119
|
+
? computeTimeAtSlot(config, config.ELECTRA_FORK_EPOCH * SLOTS_PER_EPOCH, opts.genesisTime)
|
|
120
|
+
: Infinity;
|
|
121
|
+
this.fuluForkTimestamp =
|
|
122
|
+
opts.genesisTime && config
|
|
123
|
+
? computeTimeAtSlot(config, config.FULU_FORK_EPOCH * SLOTS_PER_EPOCH, opts.genesisTime)
|
|
124
|
+
: Infinity;
|
|
125
|
+
this.gloasForkTimestamp =
|
|
126
|
+
opts.genesisTime && config
|
|
127
|
+
? computeTimeAtSlot(config, config.GLOAS_FORK_EPOCH * SLOTS_PER_EPOCH, opts.genesisTime)
|
|
128
|
+
: Infinity;
|
|
129
|
+
|
|
103
130
|
this.handlers = {
|
|
104
131
|
engine_newPayloadV1: this.notifyNewPayload.bind(this),
|
|
105
132
|
engine_newPayloadV2: this.notifyNewPayload.bind(this),
|
|
@@ -448,11 +475,11 @@ export class ExecutionEngineMockBackend implements JsonRpcBackend {
|
|
|
448
475
|
}
|
|
449
476
|
|
|
450
477
|
private timestampToFork(timestamp: number): ForkPostBellatrix {
|
|
451
|
-
if (timestamp >=
|
|
452
|
-
if (timestamp >=
|
|
453
|
-
if (timestamp >=
|
|
454
|
-
if (timestamp >=
|
|
455
|
-
if (timestamp >=
|
|
478
|
+
if (timestamp >= this.gloasForkTimestamp) return ForkName.gloas;
|
|
479
|
+
if (timestamp >= this.fuluForkTimestamp) return ForkName.fulu;
|
|
480
|
+
if (timestamp >= this.electraForkTimestamp) return ForkName.electra;
|
|
481
|
+
if (timestamp >= this.denebForkTimestamp) return ForkName.deneb;
|
|
482
|
+
if (timestamp >= this.capellaForkTimestamp) return ForkName.capella;
|
|
456
483
|
return ForkName.bellatrix;
|
|
457
484
|
}
|
|
458
485
|
}
|
|
@@ -1308,33 +1308,19 @@ export function createLodestarMetrics(
|
|
|
1308
1308
|
name: "lodestar_shuffling_cache_miss_count",
|
|
1309
1309
|
help: "Count of shuffling cache miss",
|
|
1310
1310
|
}),
|
|
1311
|
-
|
|
1312
|
-
name: "
|
|
1313
|
-
help: "Count of shuffling that were
|
|
1314
|
-
}),
|
|
1315
|
-
shufflingPromiseNotResolvedAndThrownAway: register.gauge({
|
|
1316
|
-
name: "lodestar_shuffling_cache_promise_not_resolved_and_thrown_away_count",
|
|
1317
|
-
help: "Count of shuffling cache promises that were discarded and the shuffling was built synchronously",
|
|
1311
|
+
shufflingSetMultipleTimes: register.gauge({
|
|
1312
|
+
name: "lodestar_shuffling_cache_set_multiple_times_count",
|
|
1313
|
+
help: "Count of shuffling that were set multiple times",
|
|
1318
1314
|
}),
|
|
1319
1315
|
shufflingPromiseNotResolved: register.gauge({
|
|
1320
1316
|
name: "lodestar_shuffling_cache_promise_not_resolved_count",
|
|
1321
1317
|
help: "Count of shuffling cache promises that were requested before the promise was resolved",
|
|
1322
1318
|
}),
|
|
1323
|
-
nextShufflingNotOnEpochCache: register.gauge({
|
|
1324
|
-
name: "lodestar_shuffling_cache_next_shuffling_not_on_epoch_cache",
|
|
1325
|
-
help: "The next shuffling was not on the epoch cache before the epoch transition",
|
|
1326
|
-
}),
|
|
1327
1319
|
shufflingPromiseResolutionTime: register.histogram({
|
|
1328
1320
|
name: "lodestar_shuffling_cache_promise_resolution_time_seconds",
|
|
1329
1321
|
help: "Time from promise insertion until promise resolution when shuffling was ready in seconds",
|
|
1330
1322
|
buckets: [0.5, 1, 1.5, 2],
|
|
1331
1323
|
}),
|
|
1332
|
-
shufflingCalculationTime: register.histogram<{source: "build" | "getSync"}>({
|
|
1333
|
-
name: "lodestar_shuffling_cache_shuffling_calculation_time_seconds",
|
|
1334
|
-
help: "Run time of shuffling calculation",
|
|
1335
|
-
buckets: [0.5, 0.75, 1, 1.25, 1.5],
|
|
1336
|
-
labelNames: ["source"],
|
|
1337
|
-
}),
|
|
1338
1324
|
},
|
|
1339
1325
|
|
|
1340
1326
|
seenCache: {
|
|
@@ -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
|
}
|
|
@@ -55,7 +55,7 @@ export async function handleColumnSidecarUnavailability({
|
|
|
55
55
|
const blobsCount = getBlobKzgCommitmentsCountFromSignedBeaconBlockSerialized(chain.config, blockBytes);
|
|
56
56
|
|
|
57
57
|
// There are zero blobs for that column index, so we can safely return without any error
|
|
58
|
-
if (blobsCount
|
|
58
|
+
if (blobsCount === 0) return;
|
|
59
59
|
|
|
60
60
|
// There are blobs for that column index so we should have synced for it
|
|
61
61
|
// We need to inform to peers that we don't have that expected data
|
package/src/node/nodejs.ts
CHANGED
|
@@ -6,9 +6,10 @@ import {PubkeyIndexMap} from "@chainsafe/pubkey-index-map";
|
|
|
6
6
|
import {BeaconApiMethods} from "@lodestar/api/beacon/server";
|
|
7
7
|
import {BeaconConfig} from "@lodestar/config";
|
|
8
8
|
import type {LoggerNode} from "@lodestar/logger/node";
|
|
9
|
-
import {
|
|
9
|
+
import {ZERO_HASH_HEX} from "@lodestar/params";
|
|
10
|
+
import {CachedBeaconStateAllForks, Index2PubkeyCache, isExecutionCachedStateType} from "@lodestar/state-transition";
|
|
10
11
|
import {phase0} from "@lodestar/types";
|
|
11
|
-
import {sleep} from "@lodestar/utils";
|
|
12
|
+
import {sleep, toRootHex} from "@lodestar/utils";
|
|
12
13
|
import {ProcessShutdownCallback} from "@lodestar/validator";
|
|
13
14
|
import {BeaconRestApiServer, getApi} from "../api/index.js";
|
|
14
15
|
import {BeaconChain, IBeaconChain, initBeaconMetrics} from "../chain/index.js";
|
|
@@ -221,6 +222,20 @@ export class BeaconNode {
|
|
|
221
222
|
)
|
|
222
223
|
: null;
|
|
223
224
|
|
|
225
|
+
let executionEngineOpts = opts.executionEngine;
|
|
226
|
+
if (opts.executionEngine.mode === "mock") {
|
|
227
|
+
const eth1BlockHash = isExecutionCachedStateType(anchorState)
|
|
228
|
+
? toRootHex(anchorState.latestExecutionPayloadHeader.blockHash)
|
|
229
|
+
: undefined;
|
|
230
|
+
executionEngineOpts = {
|
|
231
|
+
...opts.executionEngine,
|
|
232
|
+
genesisBlockHash: ZERO_HASH_HEX,
|
|
233
|
+
eth1BlockHash,
|
|
234
|
+
genesisTime: anchorState.genesisTime,
|
|
235
|
+
config,
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
|
|
224
239
|
const chain = new BeaconChain(opts.chain, {
|
|
225
240
|
privateKey,
|
|
226
241
|
config,
|
|
@@ -236,7 +251,7 @@ export class BeaconNode {
|
|
|
236
251
|
validatorMonitor,
|
|
237
252
|
anchorState,
|
|
238
253
|
isAnchorStateFinalized,
|
|
239
|
-
executionEngine: initializeExecutionEngine(
|
|
254
|
+
executionEngine: initializeExecutionEngine(executionEngineOpts, {
|
|
240
255
|
metrics,
|
|
241
256
|
signal,
|
|
242
257
|
logger: logger.child({module: LoggerModule.execution}),
|
|
@@ -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;
|
package/src/util/sszBytes.ts
CHANGED
|
@@ -479,7 +479,7 @@ export function getBlobKzgCommitmentsCountFromSignedBeaconBlockSerialized(
|
|
|
479
479
|
blockBytes: Uint8Array
|
|
480
480
|
): number {
|
|
481
481
|
const slot = getSlotFromSignedBeaconBlockSerialized(blockBytes);
|
|
482
|
-
if (
|
|
482
|
+
if (slot === null) throw new Error("Can not parse the slot from block bytes");
|
|
483
483
|
|
|
484
484
|
if (config.getForkSeq(slot) < ForkSeq.deneb) return 0;
|
|
485
485
|
|
|
@@ -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,EACV,kBAAkB,GACnB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAC,OAAO,EAAC,MAAM,iBA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AAc,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"}
|