@lodestar/beacon-node 1.39.0-dev.882891d89c → 1.39.0-dev.90334173dc
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/archiveStore/historicalState/getHistoricalState.d.ts.map +1 -1
- package/lib/chain/archiveStore/historicalState/getHistoricalState.js +5 -3
- package/lib/chain/archiveStore/historicalState/getHistoricalState.js.map +1 -1
- package/lib/chain/archiveStore/utils/archiveBlocks.d.ts.map +1 -1
- package/lib/chain/archiveStore/utils/archiveBlocks.js +19 -14
- package/lib/chain/archiveStore/utils/archiveBlocks.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/verifyBlocksExecutionPayloads.d.ts.map +1 -1
- package/lib/chain/blocks/verifyBlocksExecutionPayloads.js +4 -2
- package/lib/chain/blocks/verifyBlocksExecutionPayloads.js.map +1 -1
- package/lib/chain/blocks/verifyBlocksSignatures.d.ts.map +1 -1
- package/lib/chain/blocks/verifyBlocksSignatures.js +2 -1
- package/lib/chain/blocks/verifyBlocksSignatures.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 +11 -11
- package/lib/chain/chain.d.ts.map +1 -1
- package/lib/chain/chain.js +32 -38
- package/lib/chain/chain.js.map +1 -1
- package/lib/chain/forkChoice/index.d.ts.map +1 -1
- package/lib/chain/forkChoice/index.js +3 -3
- package/lib/chain/forkChoice/index.js.map +1 -1
- package/lib/chain/initState.d.ts +1 -1
- package/lib/chain/initState.d.ts.map +1 -1
- package/lib/chain/initState.js +5 -3
- package/lib/chain/initState.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/aggregateAndProof.js +9 -0
- package/lib/chain/validation/aggregateAndProof.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 +2 -2
- 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 +5 -3
- 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 +3 -2
- package/lib/chain/validation/proposerSlashing.js.map +1 -1
- package/lib/chain/validation/voluntaryExit.js +1 -1
- package/lib/chain/validation/voluntaryExit.js.map +1 -1
- package/lib/db/repositories/checkpointState.d.ts +2 -6
- package/lib/db/repositories/checkpointState.d.ts.map +1 -1
- package/lib/db/repositories/checkpointState.js +3 -15
- package/lib/db/repositories/checkpointState.js.map +1 -1
- package/lib/db/repositories/stateArchive.d.ts +9 -9
- package/lib/db/repositories/stateArchive.d.ts.map +1 -1
- package/lib/db/repositories/stateArchive.js +6 -21
- 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/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.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 +6 -3
- package/lib/node/nodejs.d.ts.map +1 -1
- package/lib/node/nodejs.js +20 -3
- package/lib/node/nodejs.js.map +1 -1
- package/lib/node/notifier.d.ts.map +1 -1
- package/lib/node/notifier.js +9 -6
- package/lib/node/notifier.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 +3 -3
- 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/archiveStore/historicalState/getHistoricalState.ts +5 -3
- package/src/chain/archiveStore/utils/archiveBlocks.ts +21 -14
- package/src/chain/blocks/importBlock.ts +13 -3
- package/src/chain/blocks/verifyBlock.ts +9 -3
- package/src/chain/blocks/verifyBlocksExecutionPayloads.ts +9 -2
- package/src/chain/blocks/verifyBlocksSignatures.ts +11 -3
- package/src/chain/blocks/verifyBlocksStateTransitionOnly.ts +1 -0
- package/src/chain/chain.ts +46 -46
- package/src/chain/forkChoice/index.ts +3 -2
- package/src/chain/initState.ts +5 -3
- 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/aggregateAndProof.ts +12 -0
- package/src/chain/validation/attestation.ts +3 -3
- package/src/chain/validation/attesterSlashing.ts +14 -2
- package/src/chain/validation/blobSidecar.ts +3 -3
- package/src/chain/validation/block.ts +6 -2
- package/src/chain/validation/blsToExecutionChange.ts +9 -7
- package/src/chain/validation/dataColumnSidecar.ts +3 -3
- package/src/chain/validation/proposerSlashing.ts +8 -2
- package/src/chain/validation/voluntaryExit.ts +1 -1
- package/src/db/repositories/checkpointState.ts +3 -19
- package/src/db/repositories/stateArchive.ts +13 -27
- package/src/execution/engine/mock.ts +40 -13
- package/src/index.ts +1 -1
- 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 +26 -4
- package/src/node/notifier.ts +13 -7
- package/src/sync/backfill/backfill.ts +2 -14
- package/src/sync/backfill/verify.ts +2 -9
- 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
|
@@ -59,7 +59,7 @@ async function validateVoluntaryExit(
|
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
const signatureSet = getVoluntaryExitSignatureSet(chain.config, chain.index2pubkey, state, voluntaryExit);
|
|
62
|
+
const signatureSet = getVoluntaryExitSignatureSet(chain.config, chain.index2pubkey, state.slot, voluntaryExit);
|
|
63
63
|
if (!(await chain.bls.verifySignatureSets([signatureSet], {batchable: true, priority: prioritizeBls}))) {
|
|
64
64
|
throw new VoluntaryExitError(GossipAction.REJECT, {
|
|
65
65
|
code: VoluntaryExitErrorCode.INVALID_SIGNATURE,
|
|
@@ -1,31 +1,15 @@
|
|
|
1
1
|
import {ChainForkConfig} from "@lodestar/config";
|
|
2
|
-
import {
|
|
3
|
-
import {BeaconStateAllForks} from "@lodestar/state-transition";
|
|
4
|
-
import {ssz} from "@lodestar/types";
|
|
2
|
+
import {BinaryRepository, Db} from "@lodestar/db";
|
|
5
3
|
import {Bucket, getBucketNameByValue} from "../buckets.js";
|
|
6
4
|
|
|
7
5
|
/**
|
|
8
6
|
* Store temporary checkpoint states.
|
|
9
7
|
* We should only put/get binary data from this repository, consumer will load it into an existing state ViewDU object.
|
|
10
8
|
*/
|
|
11
|
-
export class CheckpointStateRepository extends
|
|
9
|
+
export class CheckpointStateRepository extends BinaryRepository<Uint8Array> {
|
|
12
10
|
constructor(config: ChainForkConfig, db: Db) {
|
|
13
|
-
// Pick some type but won't be used. Casted to any because no type can match `BeaconStateAllForks`
|
|
14
|
-
const type = ssz.phase0.BeaconState;
|
|
15
11
|
const bucket = Bucket.allForks_checkpointState;
|
|
16
12
|
// biome-ignore lint/suspicious/noExplicitAny: The type is complex to specify a proper override
|
|
17
|
-
super(config, db, bucket,
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
getId(): Uint8Array {
|
|
21
|
-
throw Error("CheckpointStateRepository does not work with value");
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
encodeValue(): Uint8Array {
|
|
25
|
-
throw Error("CheckpointStateRepository does not work with value");
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
decodeValue(): BeaconStateAllForks {
|
|
29
|
-
throw Error("CheckpointStateRepository does not work with value");
|
|
13
|
+
super(config, db, bucket, getBucketNameByValue(bucket));
|
|
30
14
|
}
|
|
31
15
|
}
|
|
@@ -1,39 +1,25 @@
|
|
|
1
1
|
import {ChainForkConfig} from "@lodestar/config";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {Epoch, Root, RootHex, Slot, ssz} from "@lodestar/types";
|
|
2
|
+
import {BinaryRepository, Db} from "@lodestar/db";
|
|
3
|
+
import {Root, RootHex, Slot} from "@lodestar/types";
|
|
5
4
|
import {bytesToInt, toHex} from "@lodestar/utils";
|
|
6
|
-
import {getStateTypeFromBytes} from "../../util/multifork.js";
|
|
7
5
|
import {Bucket, getBucketNameByValue} from "../buckets.js";
|
|
8
6
|
import {getRootIndex, getRootIndexKey, storeRootIndex} from "./stateArchiveIndex.js";
|
|
9
7
|
|
|
10
|
-
export
|
|
8
|
+
export type BeaconStateArchive = {
|
|
9
|
+
serialize(): Uint8Array;
|
|
10
|
+
hashTreeRoot(): Root;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export class StateArchiveRepository extends BinaryRepository<Slot> {
|
|
11
14
|
constructor(config: ChainForkConfig, db: Db) {
|
|
12
|
-
// Pick some type but won't be used. Casted to any because no type can match `BeaconStateAllForks`
|
|
13
|
-
// biome-ignore lint/suspicious/noExplicitAny: We need to use `any` type here
|
|
14
|
-
const type = ssz.phase0.BeaconState as any;
|
|
15
15
|
const bucket = Bucket.allForks_stateArchive;
|
|
16
|
-
super(config, db, bucket,
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// Overrides for multi-fork
|
|
20
|
-
|
|
21
|
-
encodeValue(value: BeaconStateAllForks): Uint8Array {
|
|
22
|
-
return value.serialize();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
decodeValue(data: Uint8Array): BeaconStateAllForks {
|
|
26
|
-
return getStateTypeFromBytes(this.config, data).deserializeToViewDU(data);
|
|
16
|
+
super(config, db, bucket, getBucketNameByValue(bucket));
|
|
27
17
|
}
|
|
28
18
|
|
|
29
19
|
// Handle key as slot
|
|
30
20
|
|
|
31
|
-
async put(key: Slot, value:
|
|
32
|
-
await Promise.all([super.
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
getId(state: BeaconStateAllForks): Epoch {
|
|
36
|
-
return state.slot;
|
|
21
|
+
async put(key: Slot, value: BeaconStateArchive): Promise<void> {
|
|
22
|
+
await Promise.all([super.putBinary(key, value.serialize()), storeRootIndex(this.db, key, value.hashTreeRoot())]);
|
|
37
23
|
}
|
|
38
24
|
|
|
39
25
|
decodeKey(data: Uint8Array): number {
|
|
@@ -42,10 +28,10 @@ export class StateArchiveRepository extends Repository<Slot, BeaconStateAllForks
|
|
|
42
28
|
|
|
43
29
|
// Index Root -> Slot
|
|
44
30
|
|
|
45
|
-
async
|
|
31
|
+
async getBinaryByRoot(stateRoot: Root): Promise<Uint8Array | null> {
|
|
46
32
|
const slot = await this.getSlotByRoot(stateRoot);
|
|
47
33
|
if (slot !== null && Number.isInteger(slot)) {
|
|
48
|
-
return this.
|
|
34
|
+
return this.getBinary(slot);
|
|
49
35
|
}
|
|
50
36
|
return null;
|
|
51
37
|
}
|
|
@@ -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
|
}
|
package/src/index.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
export type {RestApiServerMetrics, RestApiServerModules, RestApiServerOpts} from "./api/rest/base.js";
|
|
4
4
|
export {RestApiServer} from "./api/rest/base.js";
|
|
5
|
-
export {checkAndPersistAnchorState
|
|
5
|
+
export {checkAndPersistAnchorState} from "./chain/index.js";
|
|
6
6
|
export {DbCPStateDatastore} from "./chain/stateCache/datastore/db.js";
|
|
7
7
|
export {FileCPStateDatastore} from "./chain/stateCache/datastore/file.js";
|
|
8
8
|
export {BeaconDb, type IBeaconDb} from "./db/index.js";
|
|
@@ -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
|
@@ -2,12 +2,14 @@ import {setMaxListeners} from "node:events";
|
|
|
2
2
|
import {PrivateKey} from "@libp2p/interface";
|
|
3
3
|
import {Registry} from "prom-client";
|
|
4
4
|
import {hasher} from "@chainsafe/persistent-merkle-tree";
|
|
5
|
+
import {PubkeyIndexMap} from "@chainsafe/pubkey-index-map";
|
|
5
6
|
import {BeaconApiMethods} from "@lodestar/api/beacon/server";
|
|
6
7
|
import {BeaconConfig} from "@lodestar/config";
|
|
7
8
|
import type {LoggerNode} from "@lodestar/logger/node";
|
|
8
|
-
import {
|
|
9
|
+
import {ZERO_HASH_HEX} from "@lodestar/params";
|
|
10
|
+
import {CachedBeaconStateAllForks, Index2PubkeyCache, isExecutionCachedStateType} from "@lodestar/state-transition";
|
|
9
11
|
import {phase0} from "@lodestar/types";
|
|
10
|
-
import {sleep} from "@lodestar/utils";
|
|
12
|
+
import {sleep, toRootHex} from "@lodestar/utils";
|
|
11
13
|
import {ProcessShutdownCallback} from "@lodestar/validator";
|
|
12
14
|
import {BeaconRestApiServer, getApi} from "../api/index.js";
|
|
13
15
|
import {BeaconChain, IBeaconChain, initBeaconMetrics} from "../chain/index.js";
|
|
@@ -45,13 +47,15 @@ export type BeaconNodeModules = {
|
|
|
45
47
|
export type BeaconNodeInitModules = {
|
|
46
48
|
opts: IBeaconNodeOptions;
|
|
47
49
|
config: BeaconConfig;
|
|
50
|
+
pubkey2index: PubkeyIndexMap;
|
|
51
|
+
index2pubkey: Index2PubkeyCache;
|
|
48
52
|
db: IBeaconDb;
|
|
49
53
|
logger: LoggerNode;
|
|
50
54
|
processShutdownCallback: ProcessShutdownCallback;
|
|
51
55
|
privateKey: PrivateKey;
|
|
52
56
|
dataDir: string;
|
|
53
57
|
peerStoreDir?: string;
|
|
54
|
-
anchorState:
|
|
58
|
+
anchorState: CachedBeaconStateAllForks;
|
|
55
59
|
isAnchorStateFinalized: boolean;
|
|
56
60
|
wsCheckpoint?: phase0.Checkpoint;
|
|
57
61
|
metricsRegistries?: Registry[];
|
|
@@ -146,6 +150,8 @@ export class BeaconNode {
|
|
|
146
150
|
static async init<T extends BeaconNode = BeaconNode>({
|
|
147
151
|
opts,
|
|
148
152
|
config,
|
|
153
|
+
pubkey2index,
|
|
154
|
+
index2pubkey,
|
|
149
155
|
db,
|
|
150
156
|
logger,
|
|
151
157
|
processShutdownCallback,
|
|
@@ -216,10 +222,26 @@ export class BeaconNode {
|
|
|
216
222
|
)
|
|
217
223
|
: null;
|
|
218
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
|
+
|
|
219
239
|
const chain = new BeaconChain(opts.chain, {
|
|
220
240
|
privateKey,
|
|
221
241
|
config,
|
|
222
242
|
clock,
|
|
243
|
+
pubkey2index,
|
|
244
|
+
index2pubkey,
|
|
223
245
|
dataDir,
|
|
224
246
|
db,
|
|
225
247
|
dbName: opts.db.name,
|
|
@@ -229,7 +251,7 @@ export class BeaconNode {
|
|
|
229
251
|
validatorMonitor,
|
|
230
252
|
anchorState,
|
|
231
253
|
isAnchorStateFinalized,
|
|
232
|
-
executionEngine: initializeExecutionEngine(
|
|
254
|
+
executionEngine: initializeExecutionEngine(executionEngineOpts, {
|
|
233
255
|
metrics,
|
|
234
256
|
signal,
|
|
235
257
|
logger: logger.child({module: LoggerModule.execution}),
|
package/src/node/notifier.ts
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
computeEpochAtSlot,
|
|
7
7
|
computeStartSlotAtEpoch,
|
|
8
8
|
isExecutionCachedStateType,
|
|
9
|
+
isMergeTransitionComplete,
|
|
9
10
|
} from "@lodestar/state-transition";
|
|
10
11
|
import {Epoch} from "@lodestar/types";
|
|
11
12
|
import {ErrorAborted, Logger, prettyBytes, prettyBytesShort, sleep} from "@lodestar/utils";
|
|
@@ -171,13 +172,18 @@ function getHeadExecutionInfo(
|
|
|
171
172
|
|
|
172
173
|
// Add execution status to notifier only if head is on/post bellatrix
|
|
173
174
|
if (isExecutionCachedStateType(headState)) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
175
|
+
if (isMergeTransitionComplete(headState)) {
|
|
176
|
+
const executionPayloadHashInfo =
|
|
177
|
+
headInfo.executionStatus !== ExecutionStatus.PreMerge ? headInfo.executionPayloadBlockHash : "empty";
|
|
178
|
+
const executionPayloadNumberInfo =
|
|
179
|
+
headInfo.executionStatus !== ExecutionStatus.PreMerge ? headInfo.executionPayloadNumber : NaN;
|
|
180
|
+
return [
|
|
181
|
+
`exec-block: ${executionStatusStr}(${executionPayloadNumberInfo} ${prettyBytesShort(
|
|
182
|
+
executionPayloadHashInfo
|
|
183
|
+
)})`,
|
|
184
|
+
];
|
|
185
|
+
}
|
|
186
|
+
return [`exec-block: ${executionStatusStr}`];
|
|
181
187
|
}
|
|
182
188
|
|
|
183
189
|
return [];
|
|
@@ -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,14 +44,12 @@ 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;
|
|
56
50
|
const signatures = blocks.reduce((sigs: ISignatureSet[], block) => {
|
|
57
51
|
// genesis block doesn't have valid signature
|
|
58
|
-
if (block.message.slot !== GENESIS_SLOT)
|
|
59
|
-
sigs.push(getBlockProposerSignatureSet(config, index2pubkey, state, block));
|
|
52
|
+
if (block.message.slot !== GENESIS_SLOT) sigs.push(getBlockProposerSignatureSet(config, index2pubkey, block));
|
|
60
53
|
return sigs;
|
|
61
54
|
}, []);
|
|
62
55
|
|
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,iBAA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Ac,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"}
|