@lodestar/beacon-node 1.39.0-dev.493cc12d2f → 1.39.0-dev.7ac2136122
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/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/chain.d.ts +8 -9
- package/lib/chain/chain.d.ts.map +1 -1
- package/lib/chain/chain.js +17 -33
- package/lib/chain/chain.js.map +1 -1
- package/lib/chain/interface.d.ts +4 -7
- package/lib/chain/interface.d.ts.map +1 -1
- package/lib/chain/interface.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/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/block.js +1 -1
- package/lib/chain/validation/block.js.map +1 -1
- package/lib/chain/validation/proposerSlashing.js +1 -1
- 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/network/peers/discover.d.ts.map +1 -1
- package/lib/network/peers/discover.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 +3 -1
- package/lib/node/nodejs.js.map +1 -1
- package/lib/sync/backfill/verify.d.ts.map +1 -1
- package/lib/sync/backfill/verify.js +1 -1
- package/lib/sync/backfill/verify.js.map +1 -1
- package/package.json +28 -20
- package/src/chain/blocks/verifyBlocksSignatures.ts +11 -3
- package/src/chain/chain.ts +27 -38
- package/src/chain/interface.ts +4 -6
- package/src/chain/validation/aggregateAndProof.ts +12 -0
- package/src/chain/validation/attesterSlashing.ts +6 -1
- package/src/chain/validation/block.ts +1 -1
- package/src/chain/validation/proposerSlashing.ts +6 -1
- package/src/chain/validation/voluntaryExit.ts +1 -1
- package/src/network/peers/discover.ts +3 -3
- package/src/node/nodejs.ts +9 -2
- package/src/sync/backfill/verify.ts +1 -2
- 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
package/src/chain/interface.ts
CHANGED
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
altair,
|
|
24
24
|
capella,
|
|
25
25
|
phase0,
|
|
26
|
+
rewards,
|
|
26
27
|
} from "@lodestar/types";
|
|
27
28
|
import {Logger} from "@lodestar/utils";
|
|
28
29
|
import {IExecutionBuilder, IExecutionEngine} from "../execution/index.js";
|
|
@@ -48,9 +49,6 @@ import {IChainOptions} from "./options.js";
|
|
|
48
49
|
import {AssembledBlockType, BlockAttributes, BlockType, ProduceResult} from "./produceBlock/produceBlockBody.js";
|
|
49
50
|
import {IStateRegenerator, RegenCaller} from "./regen/index.js";
|
|
50
51
|
import {ReprocessController} from "./reprocess.js";
|
|
51
|
-
import {AttestationsRewards} from "./rewards/attestationsRewards.js";
|
|
52
|
-
import {BlockRewards} from "./rewards/blockRewards.js";
|
|
53
|
-
import {SyncCommitteeRewards} from "./rewards/syncCommitteeRewards.js";
|
|
54
52
|
import {
|
|
55
53
|
SeenAggregators,
|
|
56
54
|
SeenAttesters,
|
|
@@ -255,15 +253,15 @@ export interface IBeaconChain {
|
|
|
255
253
|
regenCanAcceptWork(): boolean;
|
|
256
254
|
blsThreadPoolCanAcceptWork(): boolean;
|
|
257
255
|
|
|
258
|
-
getBlockRewards(blockRef: BeaconBlock | BlindedBeaconBlock): Promise<BlockRewards>;
|
|
256
|
+
getBlockRewards(blockRef: BeaconBlock | BlindedBeaconBlock): Promise<rewards.BlockRewards>;
|
|
259
257
|
getAttestationsRewards(
|
|
260
258
|
epoch: Epoch,
|
|
261
259
|
validatorIds?: (ValidatorIndex | string)[]
|
|
262
|
-
): Promise<{rewards: AttestationsRewards; executionOptimistic: boolean; finalized: boolean}>;
|
|
260
|
+
): Promise<{rewards: rewards.AttestationsRewards; executionOptimistic: boolean; finalized: boolean}>;
|
|
263
261
|
getSyncCommitteeRewards(
|
|
264
262
|
blockRef: BeaconBlock | BlindedBeaconBlock,
|
|
265
263
|
validatorIds?: (ValidatorIndex | string)[]
|
|
266
|
-
): Promise<SyncCommitteeRewards>;
|
|
264
|
+
): Promise<rewards.SyncCommitteeRewards>;
|
|
267
265
|
}
|
|
268
266
|
|
|
269
267
|
export type SSZObjectType =
|
|
@@ -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,
|
|
@@ -51,7 +51,12 @@ export async function validateAttesterSlashing(
|
|
|
51
51
|
});
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
const signatureSets = getAttesterSlashingSignatureSets(
|
|
54
|
+
const signatureSets = getAttesterSlashingSignatureSets(
|
|
55
|
+
chain.config,
|
|
56
|
+
chain.index2pubkey,
|
|
57
|
+
state.slot,
|
|
58
|
+
attesterSlashing
|
|
59
|
+
);
|
|
55
60
|
if (!(await chain.bls.verifySignatureSets(signatureSets, {batchable: true, priority: prioritizeBls}))) {
|
|
56
61
|
throw new AttesterSlashingError(GossipAction.REJECT, {
|
|
57
62
|
code: AttesterSlashingErrorCode.INVALID,
|
|
@@ -154,7 +154,7 @@ export async function validateGossipBlock(
|
|
|
154
154
|
|
|
155
155
|
// [REJECT] The proposer signature, signed_beacon_block.signature, is valid with respect to the proposer_index pubkey.
|
|
156
156
|
if (!chain.seenBlockInputCache.isVerifiedProposerSignature(blockSlot, blockRoot, signedBlock.signature)) {
|
|
157
|
-
const signatureSet = getBlockProposerSignatureSet(chain.config, chain.index2pubkey,
|
|
157
|
+
const signatureSet = getBlockProposerSignatureSet(chain.config, chain.index2pubkey, signedBlock);
|
|
158
158
|
// Don't batch so verification is not delayed
|
|
159
159
|
if (!(await chain.bls.verifySignatureSets([signatureSet], {verifyOnMainThread: true}))) {
|
|
160
160
|
throw new BlockGossipError(GossipAction.REJECT, {
|
|
@@ -44,7 +44,12 @@ async function validateProposerSlashing(
|
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
const signatureSets = getProposerSlashingSignatureSets(
|
|
47
|
+
const signatureSets = getProposerSlashingSignatureSets(
|
|
48
|
+
chain.config,
|
|
49
|
+
chain.index2pubkey,
|
|
50
|
+
state.slot,
|
|
51
|
+
proposerSlashing
|
|
52
|
+
);
|
|
48
53
|
if (!(await chain.bls.verifySignatureSets(signatureSets, {batchable: true, priority: prioritizeBls}))) {
|
|
49
54
|
throw new ProposerSlashingError(GossipAction.REJECT, {
|
|
50
55
|
code: ProposerSlashingErrorCode.INVALID,
|
|
@@ -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,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
|
}
|
package/src/node/nodejs.ts
CHANGED
|
@@ -2,10 +2,11 @@ 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 {CachedBeaconStateAllForks, Index2PubkeyCache} from "@lodestar/state-transition";
|
|
9
10
|
import {phase0} from "@lodestar/types";
|
|
10
11
|
import {sleep} from "@lodestar/utils";
|
|
11
12
|
import {ProcessShutdownCallback} from "@lodestar/validator";
|
|
@@ -45,13 +46,15 @@ export type BeaconNodeModules = {
|
|
|
45
46
|
export type BeaconNodeInitModules = {
|
|
46
47
|
opts: IBeaconNodeOptions;
|
|
47
48
|
config: BeaconConfig;
|
|
49
|
+
pubkey2index: PubkeyIndexMap;
|
|
50
|
+
index2pubkey: Index2PubkeyCache;
|
|
48
51
|
db: IBeaconDb;
|
|
49
52
|
logger: LoggerNode;
|
|
50
53
|
processShutdownCallback: ProcessShutdownCallback;
|
|
51
54
|
privateKey: PrivateKey;
|
|
52
55
|
dataDir: string;
|
|
53
56
|
peerStoreDir?: string;
|
|
54
|
-
anchorState:
|
|
57
|
+
anchorState: CachedBeaconStateAllForks;
|
|
55
58
|
isAnchorStateFinalized: boolean;
|
|
56
59
|
wsCheckpoint?: phase0.Checkpoint;
|
|
57
60
|
metricsRegistries?: Registry[];
|
|
@@ -146,6 +149,8 @@ export class BeaconNode {
|
|
|
146
149
|
static async init<T extends BeaconNode = BeaconNode>({
|
|
147
150
|
opts,
|
|
148
151
|
config,
|
|
152
|
+
pubkey2index,
|
|
153
|
+
index2pubkey,
|
|
149
154
|
db,
|
|
150
155
|
logger,
|
|
151
156
|
processShutdownCallback,
|
|
@@ -220,6 +225,8 @@ export class BeaconNode {
|
|
|
220
225
|
privateKey,
|
|
221
226
|
config,
|
|
222
227
|
clock,
|
|
228
|
+
pubkey2index,
|
|
229
|
+
index2pubkey,
|
|
223
230
|
dataDir,
|
|
224
231
|
db,
|
|
225
232
|
dbName: opts.db.name,
|
|
@@ -55,8 +55,7 @@ export async function verifyBlockProposerSignature(
|
|
|
55
55
|
if (blocks.length === 1 && blocks[0].message.slot === GENESIS_SLOT) return;
|
|
56
56
|
const signatures = blocks.reduce((sigs: ISignatureSet[], block) => {
|
|
57
57
|
// genesis block doesn't have valid signature
|
|
58
|
-
if (block.message.slot !== GENESIS_SLOT)
|
|
59
|
-
sigs.push(getBlockProposerSignatureSet(config, index2pubkey, state, block));
|
|
58
|
+
if (block.message.slot !== GENESIS_SLOT) sigs.push(getBlockProposerSignatureSet(config, index2pubkey, block));
|
|
60
59
|
return sigs;
|
|
61
60
|
}, []);
|
|
62
61
|
|
|
@@ -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;AAEp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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;AAMpC;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,MAAoB,EACpB,KAAkB,EAClB,QAAmC,EACnC,SAAqC;IAErC,MAAM,IAAI,GAAG,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC5C,MAAM,EAAC,YAAY,EAAE,wBAAwB,GAAG,CAAC,EAAE,aAAa,EAAE,yBAAyB,GAAG,CAAC,EAAC,GAC9F,SAAS,EAAE,eAAe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kC,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,Q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