Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions packages/api/src/beacon/routes/beacon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@ export {block, pool, state, rewards};

export type {BlockHeaderResponse, BlockId} from "./block.js";
export {BroadcastValidation} from "./block.js";
export type {
AttestationsRewards,
BlockRewards,
IdealAttestationsReward,
SyncCommitteeRewards,
TotalAttestationsReward,
} from "./rewards.js";
// TODO: Review if re-exporting all these types is necessary
export type {
EpochCommitteeResponse,
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/beacon/routes/beacon/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {ValueOf} from "@chainsafe/ssz";
import {ChainForkConfig} from "@lodestar/config";
import {ForkPostElectra, ForkPreElectra, isForkPostElectra} from "@lodestar/params";
import {
ArrayOf,
AttesterSlashing,
CommitteeIndex,
SingleAttestation,
Expand All @@ -12,7 +13,6 @@ import {
ssz,
} from "@lodestar/types";
import {
ArrayOf,
EmptyArgs,
EmptyMeta,
EmptyMetaCodec,
Expand Down
112 changes: 10 additions & 102 deletions packages/api/src/beacon/routes/beacon/rewards.ts
Original file line number Diff line number Diff line change
@@ -1,112 +1,20 @@
import {ContainerType, ValueOf} from "@chainsafe/ssz";
import {ChainForkConfig} from "@lodestar/config";
import {Epoch, ssz} from "@lodestar/types";
import {ArrayOf, JsonOnlyReq} from "../../../utils/codecs.js";
import {
AttestationsRewards,
AttestationsRewardsType,
BlockRewards,
BlockRewardsType,
Epoch,
SyncCommitteeRewards,
SyncCommitteeRewardsType,
} from "@lodestar/types";
import {JsonOnlyReq} from "../../../utils/codecs.js";
import {Endpoint, RouteDefinitions, Schema} from "../../../utils/index.js";
import {ExecutionOptimisticAndFinalizedCodec, ExecutionOptimisticAndFinalizedMeta} from "../../../utils/metadata.js";
import {fromValidatorIdsStr, toValidatorIdsStr} from "../../../utils/serdes.js";
import {BlockArgs} from "./block.js";
import {ValidatorId} from "./state.js";

const BlockRewardsType = new ContainerType(
{
/** Proposer of the block, the proposer index who receives these rewards */
proposerIndex: ssz.ValidatorIndex,
/** Total block reward, equal to attestations + sync_aggregate + proposer_slashings + attester_slashings */
total: ssz.UintNum64,
/** Block reward component due to included attestations */
attestations: ssz.UintNum64,
/** Block reward component due to included sync_aggregate */
syncAggregate: ssz.UintNum64,
/** Block reward component due to included proposer_slashings */
proposerSlashings: ssz.UintNum64,
/** Block reward component due to included attester_slashings */
attesterSlashings: ssz.UintNum64,
},
{jsonCase: "eth2"}
);

const AttestationsRewardType = new ContainerType(
{
/** Reward for head vote. Could be negative to indicate penalty */
head: ssz.UintNum64,
/** Reward for target vote. Could be negative to indicate penalty */
target: ssz.UintNum64,
/** Reward for source vote. Could be negative to indicate penalty */
source: ssz.UintNum64,
/** Inclusion delay reward (phase0 only) */
inclusionDelay: ssz.UintNum64,
/** Inactivity penalty. Should be a negative number to indicate penalty */
inactivity: ssz.UintNum64,
},
{jsonCase: "eth2"}
);

const IdealAttestationsRewardsType = new ContainerType(
{
...AttestationsRewardType.fields,
effectiveBalance: ssz.UintNum64,
},
{jsonCase: "eth2"}
);

const TotalAttestationsRewardsType = new ContainerType(
{
...AttestationsRewardType.fields,
validatorIndex: ssz.ValidatorIndex,
},
{jsonCase: "eth2"}
);

const AttestationsRewardsType = new ContainerType(
{
idealRewards: ArrayOf(IdealAttestationsRewardsType),
totalRewards: ArrayOf(TotalAttestationsRewardsType),
},
{jsonCase: "eth2"}
);

const SyncCommitteeRewardsType = ArrayOf(
new ContainerType(
{
validatorIndex: ssz.ValidatorIndex,
reward: ssz.UintNum64,
},
{jsonCase: "eth2"}
)
);

/**
* Rewards info for a single block. Every reward value is in Gwei.
*/
export type BlockRewards = ValueOf<typeof BlockRewardsType>;

/**
* Rewards for a single set of (ideal or actual depending on usage) attestations. Reward value is in Gwei
*/
export type AttestationsReward = ValueOf<typeof AttestationsRewardType>;

/**
* Rewards info for ideal attestations ie. Maximum rewards could be earned by making timely head, target and source vote.
* `effectiveBalance` is in Gwei
*/
export type IdealAttestationsReward = ValueOf<typeof IdealAttestationsRewardsType>;

/**
* Rewards info for actual attestations
*/
export type TotalAttestationsReward = ValueOf<typeof TotalAttestationsRewardsType>;

export type AttestationsRewards = ValueOf<typeof AttestationsRewardsType>;

/**
* Rewards info for sync committee participation. Every reward value is in Gwei.
* Note: In the case that block proposer is present in `SyncCommitteeRewards`, the reward value only reflects rewards for
* participating in sync committee. Please refer to `BlockRewards.syncAggregate` for rewards of proposer including sync committee
* outputs into their block
*/
export type SyncCommitteeRewards = ValueOf<typeof SyncCommitteeRewardsType>;

export type Endpoints = {
/**
* Get block rewards
Expand Down
3 changes: 2 additions & 1 deletion packages/api/src/beacon/routes/beacon/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {ContainerType, ValueOf} from "@chainsafe/ssz";
import {ChainForkConfig} from "@lodestar/config";
import {MAX_VALIDATORS_PER_COMMITTEE} from "@lodestar/params";
import {
ArrayOf,
CommitteeIndex,
Epoch,
RootHex,
Expand All @@ -13,7 +14,7 @@ import {
phase0,
ssz,
} from "@lodestar/types";
import {ArrayOf, JsonOnlyReq} from "../../../utils/codecs.js";
import {JsonOnlyReq} from "../../../utils/codecs.js";
import {Endpoint, RequestCodec, RouteDefinitions, Schema} from "../../../utils/index.js";
import {
ExecutionOptimisticAndFinalizedCodec,
Expand Down
3 changes: 1 addition & 2 deletions packages/api/src/beacon/routes/config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {ContainerType, ValueOf} from "@chainsafe/ssz";
import {ChainForkConfig, SpecJson} from "@lodestar/config";
import {ssz} from "@lodestar/types";
import {ArrayOf, ssz} from "@lodestar/types";
import {
ArrayOf,
EmptyArgs,
EmptyMeta,
EmptyMetaCodec,
Expand Down
3 changes: 1 addition & 2 deletions packages/api/src/beacon/routes/debug.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {ContainerType, Type, ValueOf} from "@chainsafe/ssz";
import {ChainForkConfig} from "@lodestar/config";
import {BeaconState, StringType, fulu, ssz} from "@lodestar/types";
import {ArrayOf, BeaconState, StringType, fulu, ssz} from "@lodestar/types";
import {
ArrayOf,
EmptyArgs,
EmptyMeta,
EmptyMetaCodec,
Expand Down
3 changes: 1 addition & 2 deletions packages/api/src/beacon/routes/lodestar.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {ContainerType, Type, ValueOf} from "@chainsafe/ssz";
import {ChainForkConfig} from "@lodestar/config";
import {BeaconState, Epoch, RootHex, Slot, ssz} from "@lodestar/types";
import {ArrayOf, BeaconState, Epoch, RootHex, Slot, ssz} from "@lodestar/types";
import {
ArrayOf,
EmptyArgs,
EmptyMeta,
EmptyRequest,
Expand Down
3 changes: 1 addition & 2 deletions packages/api/src/beacon/routes/node.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {ContainerType, OptionalType, ValueOf} from "@chainsafe/ssz";
import {ChainForkConfig} from "@lodestar/config";
import {StringType, fulu, ssz, stringType} from "@lodestar/types";
import {ArrayOf, StringType, fulu, ssz, stringType} from "@lodestar/types";
import {
ArrayOf,
EmptyArgs,
EmptyMeta,
EmptyMetaCodec,
Expand Down
3 changes: 1 addition & 2 deletions packages/api/src/beacon/routes/proof.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import {CompactMultiProof, ProofType} from "@chainsafe/persistent-merkle-tree";
import {ByteListType, ContainerType} from "@chainsafe/ssz";
import {ChainForkConfig} from "@lodestar/config";
import {ssz} from "@lodestar/types";
import {ArrayOf, ssz} from "@lodestar/types";
import {fromHex, toHex} from "@lodestar/utils";
import {ArrayOf} from "../../utils/codecs.js";
import {Endpoint, RouteDefinitions, Schema} from "../../utils/index.js";
import {VersionCodec, VersionMeta} from "../../utils/metadata.js";

Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/beacon/routes/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
isForkPostElectra,
} from "@lodestar/params";
import {
ArrayOf,
Attestation,
BLSSignature,
BeaconBlock,
Expand All @@ -28,7 +29,6 @@ import {
} from "@lodestar/types";
import {fromHex, toHex, toRootHex} from "@lodestar/utils";
import {
ArrayOf,
EmptyMeta,
EmptyMetaCodec,
EmptyResponseCodec,
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/builder/routes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {ChainForkConfig} from "@lodestar/config";
import {ForkName, VALIDATOR_REGISTRY_LIMIT, isForkPostDeneb} from "@lodestar/params";
import {
ArrayOf,
BLSPubkey,
ExecutionPayload,
ExecutionPayloadAndBlobsBundle,
Expand All @@ -14,7 +15,6 @@ import {
} from "@lodestar/types";
import {fromHex, toPubkeyHex, toRootHex} from "@lodestar/utils";
import {
ArrayOf,
EmptyArgs,
EmptyMeta,
EmptyRequest,
Expand Down
12 changes: 1 addition & 11 deletions packages/api/src/utils/codecs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ArrayType, ListBasicType, ListCompositeType, Type, isBasicType, isCompositeType} from "@chainsafe/ssz";
import {Type} from "@chainsafe/ssz";
import {ForkName} from "@lodestar/params";
import {objectToExpectedCase} from "@lodestar/utils";
import {
Expand Down Expand Up @@ -68,16 +68,6 @@ export const EmptyResponseCodec: ResponseCodec<EmptyResponseEndpoint> = {
isEmpty: true,
};

export function ArrayOf<T>(elementType: Type<T>, limit = Infinity): ArrayType<Type<T>, unknown, unknown> {
if (isCompositeType(elementType)) {
return new ListCompositeType(elementType, limit) as unknown as ArrayType<Type<T>, unknown, unknown>;
}
if (isBasicType(elementType)) {
return new ListBasicType(elementType, limit) as unknown as ArrayType<Type<T>, unknown, unknown>;
}
throw Error(`Unknown type ${elementType.typeName}`);
}

export function WithMeta<T, M extends {version: ForkName}>(getType: (m: M) => Type<T>): ResponseDataCodec<T, M> {
return {
toJson: (data, meta: M) => getType(meta).toJson(data),
Expand Down
9 changes: 6 additions & 3 deletions packages/beacon-node/src/chain/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,29 @@ import {
EpochShuffling,
Index2PubkeyCache,
computeAnchorCheckpoint,
computeAttestationsRewards,
computeBlockRewards,
computeEndSlotAtEpoch,
computeEpochAtSlot,
computeStartSlotAtEpoch,
computeSyncCommitteeRewards,
getEffectiveBalanceIncrementsZeroInactive,
getEffectiveBalancesFromStateBytes,
processSlots,
} from "@lodestar/state-transition";
import {
AttestationsRewards,
BeaconBlock,
BlindedBeaconBlock,
BlindedBeaconBlockBody,
BlockRewards,
Epoch,
Root,
RootHex,
SignedBeaconBlock,
Slot,
Status,
SyncCommitteeRewards,
UintNum64,
ValidatorIndex,
Wei,
Expand Down Expand Up @@ -77,9 +83,6 @@ import {AssembledBlockType, BlockType, ProduceResult} from "./produceBlock/index
import {BlockAttributes, produceBlockBody, produceCommonBlockBody} from "./produceBlock/produceBlockBody.js";
import {QueuedStateRegenerator, RegenCaller} from "./regen/index.js";
import {ReprocessController} from "./reprocess.js";
import {AttestationsRewards, computeAttestationsRewards} from "./rewards/attestationsRewards.js";
import {BlockRewards, computeBlockRewards} from "./rewards/blockRewards.js";
import {SyncCommitteeRewards, computeSyncCommitteeRewards} from "./rewards/syncCommitteeRewards.js";
import {
SeenAggregators,
SeenAttesters,
Expand Down
6 changes: 3 additions & 3 deletions packages/beacon-node/src/chain/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ import {
Index2PubkeyCache,
} from "@lodestar/state-transition";
import {
AttestationsRewards,
BeaconBlock,
BlindedBeaconBlock,
BlockRewards,
Epoch,
Root,
RootHex,
SignedBeaconBlock,
Slot,
Status,
SyncCommitteeRewards,
UintNum64,
ValidatorIndex,
Wei,
Expand Down Expand Up @@ -48,9 +51,6 @@ import {IChainOptions} from "./options.js";
import {AssembledBlockType, BlockAttributes, BlockType, ProduceResult} from "./produceBlock/produceBlockBody.js";
import {IStateRegenerator, RegenCaller} from "./regen/index.js";
import {ReprocessController} from "./reprocess.js";
import {AttestationsRewards} from "./rewards/attestationsRewards.js";
import {BlockRewards} from "./rewards/blockRewards.js";
import {SyncCommitteeRewards} from "./rewards/syncCommitteeRewards.js";
import {
SeenAggregators,
SeenAttesters,
Expand Down
1 change: 1 addition & 0 deletions packages/state-transition/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export {
export * from "./constants/index.js";
export type {EpochTransitionStep} from "./epoch/index.js";
export {type BeaconStateTransitionMetrics, getMetrics} from "./metrics.js";
export * from "./rewards/index.js";
export * from "./signatureSets/index.js";
export * from "./stateTransition.js";
export type {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {PubkeyIndexMap} from "@chainsafe/pubkey-index-map";
import {routes} from "@lodestar/api";
import {BeaconConfig} from "@lodestar/config";
import {
EFFECTIVE_BALANCE_INCREMENT,
Expand All @@ -14,24 +13,19 @@ import {
WEIGHT_DENOMINATOR,
isForkPostElectra,
} from "@lodestar/params";
import {AttestationsRewards, IdealAttestationsReward, TotalAttestationsReward, ValidatorIndex} from "@lodestar/types";
import {fromHex} from "@lodestar/utils";
import {EpochTransitionCache, beforeProcessEpoch} from "../cache/epochTransitionCache.js";
import {CachedBeaconStateAllForks, CachedBeaconStateAltair} from "../types.js";
import {
CachedBeaconStateAllForks,
CachedBeaconStateAltair,
EpochTransitionCache,
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";
import {ValidatorIndex} from "@lodestar/types";
import {fromHex} from "@lodestar/utils";
} from "../util/index.js";

export type AttestationsRewards = routes.beacon.AttestationsRewards;
type IdealAttestationsReward = routes.beacon.IdealAttestationsReward;
type TotalAttestationsReward = routes.beacon.TotalAttestationsReward;
/** Attestations penalty with respect to effective balance in Gwei */
type AttestationsPenalty = {target: number; source: number; effectiveBalance: number};

Expand Down
Loading
Loading