Skip to content

Commit

Permalink
Rename proposerRewards to blockRewards. Fix import
Browse files Browse the repository at this point in the history
  • Loading branch information
ensi321 committed Jan 23, 2024
1 parent 45734fa commit f80daf4
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 23 deletions.
1 change: 1 addition & 0 deletions packages/api/src/beacon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {Api} from "./routes/index.js";
export * as routes from "./routes/index.js";
export {getClient} from "./client/index.js";
export type {Api};
export type {BlockRewards} from "./routes/index.js";

// Declare namespaces for CLI options
export type ApiNamespace = keyof Api;
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/beacon/routes/beacon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export * as rewards from "./rewards.js";
export {BroadcastValidation} from "./block.js";
export type {BlockId, BlockHeaderResponse} from "./block.js";
export type {AttestationFilters} from "./pool.js";
export type {ProposerRewardsResponse as ProposerRewards} from "./rewards.js";
export type {BlockRewards} from "./rewards.js";
// TODO: Review if re-exporting all these types is necessary
export type {
StateId,
Expand Down
16 changes: 8 additions & 8 deletions packages/api/src/beacon/routes/beacon/rewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {BlockId} from "./block.js";
*/
export type ExecutionOptimistic = boolean;

export type ProposerRewardsResponse = {
export type BlockRewards = {
proposerIndex: ValidatorIndex;
total: number;
attestations: number;
Expand All @@ -37,11 +37,11 @@ export type Api = {
* @param blockId Block identifier.
* Can be one of: "head" (canonical head in node's view), "genesis", "finalized", \<slot\>, \<hex encoded blockRoot with 0x prefix\>.
*/
getProposerRewards(
getBlockRewards(
blockId: BlockId
): Promise<
ApiClientResponse<
{[HttpStatusCode.OK]: {data: ProposerRewardsResponse; executionOptimistic: ExecutionOptimistic}},
{[HttpStatusCode.OK]: {data: BlockRewards; executionOptimistic: ExecutionOptimistic}},
HttpStatusCode.BAD_REQUEST | HttpStatusCode.NOT_FOUND
>
>;
Expand All @@ -51,17 +51,17 @@ export type Api = {
* Define javascript values for each route
*/
export const routesData: RoutesData<Api> = {
getProposerRewards: {url: "/eth/v1/beacon/rewards/blocks/{block_id}", method: "GET"},
getBlockRewards: {url: "/eth/v1/beacon/rewards/blocks/{block_id}", method: "GET"},
};

export type ReqTypes = {
/* eslint-disable @typescript-eslint/naming-convention */
getProposerRewards: {params: {block_id: string}};
getBlockRewards: {params: {block_id: string}};
};

export function getReqSerializers(): ReqSerializers<Api, ReqTypes> {
return {
getProposerRewards: {
getBlockRewards: {
writeReq: (block_id) => ({params: {block_id: String(block_id)}}),
parseReq: ({params}) => [params.block_id],
schema: {params: {block_id: Schema.StringRequired}},
Expand All @@ -70,7 +70,7 @@ export function getReqSerializers(): ReqSerializers<Api, ReqTypes> {
}

export function getReturnTypes(): ReturnTypes<Api> {
const ProposerRewardsResponse = new ContainerType(
const BlockRewardsResponse = new ContainerType(
{
proposerIndex: ssz.ValidatorIndex,
total: ssz.UintNum64,
Expand All @@ -83,6 +83,6 @@ export function getReturnTypes(): ReturnTypes<Api> {
);

return {
getProposerRewards: ContainerDataExecutionOptimistic(ProposerRewardsResponse),
getBlockRewards: ContainerDataExecutionOptimistic(BlockRewardsResponse),
};
}
2 changes: 2 additions & 0 deletions packages/api/src/beacon/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export type Api = {
validator: ValidatorApi;
};

export type {BlockRewards} from "./beacon/index.js";

// Reasoning of the API definitions
// ================================
//
Expand Down
2 changes: 1 addition & 1 deletion packages/api/test/unit/beacon/testData/beacon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export const testData: GenericServerTestCases<Api> = {

// reward

getProposerRewards: {
getBlockRewards: {
args: ["head"],
res: {
executionOptimistic: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/src/api/impl/beacon/rewards/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {resolveBlockId} from "../blocks/utils.js";

export function getBeaconRewardsApi({chain}: Pick<ApiModules, "chain">): ServerApi<routes.beacon.rewards.Api> {
return {
async getProposerRewards(blockId) {
async getBlockRewards(blockId) {
const {block, executionOptimistic} = await resolveBlockId(chain, blockId);
const data = await chain.getBlockRewards(block.message);
return {data, executionOptimistic};
Expand Down
3 changes: 2 additions & 1 deletion packages/beacon-node/src/chain/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {ProcessShutdownCallback} from "@lodestar/validator";
import {Logger, gweiToWei, isErrorAborted, pruneSetToMax, sleep, toHex} from "@lodestar/utils";
import {ForkSeq, SLOTS_PER_EPOCH} from "@lodestar/params";

import {type BlockRewards} from "@lodestar/api";
import {GENESIS_EPOCH, ZERO_HASH} from "../constants/index.js";
import {IBeaconDb} from "../db/index.js";
import {Metrics} from "../metrics/index.js";
Expand Down Expand Up @@ -76,7 +77,7 @@ import {BlockAttributes, produceBlockBody, produceCommonBlockBody} from "./produ
import {computeNewStateRoot} from "./produceBlock/computeNewStateRoot.js";
import {BlockInput} from "./blocks/types.js";
import {SeenAttestationDatas} from "./seenCache/seenAttestationData.js";
import {BlockRewards, computeBlockRewards} from "./rewards/blockRewards.js";
import {computeBlockRewards} from "./rewards/blockRewards.js";
import {ShufflingCache} from "./shufflingCache.js";
import {StateContextCache} from "./stateCache/stateContextCache.js";
import {SeenGossipBlockInput} from "./seenCache/index.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/src/chain/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {BeaconConfig} from "@lodestar/config";
import {Logger} from "@lodestar/utils";

import {IForkChoice, ProtoBlock} from "@lodestar/fork-choice";
import {type BlockRewards} from "@lodestar/api";
import {IEth1ForBlockProduction} from "../eth1/index.js";
import {IExecutionEngine, IExecutionBuilder} from "../execution/index.js";
import {Metrics} from "../metrics/metrics.js";
Expand Down Expand Up @@ -52,7 +53,6 @@ import {AssembledBlockType, BlockAttributes, BlockType} from "./produceBlock/pro
import {SeenAttestationDatas} from "./seenCache/seenAttestationData.js";
import {SeenGossipBlockInput} from "./seenCache/index.js";
import {ShufflingCache} from "./shufflingCache.js";
import {BlockRewards} from "./rewards/blockRewards.js";

export {BlockType, type AssembledBlockType};
export {type ProposerPreparationData};
Expand Down
12 changes: 2 additions & 10 deletions packages/beacon-node/src/chain/rewards/blockRewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,12 @@ import {
getAttesterSlashableIndices,
processAttestationsAltair,
} from "@lodestar/state-transition";
import {ValidatorIndex, allForks, altair, phase0} from "@lodestar/types";
import {allForks, altair, phase0} from "@lodestar/types";
import {ForkName, WHISTLEBLOWER_REWARD_QUOTIENT} from "@lodestar/params";
import {type BlockRewards} from "@lodestar/api";

type SubRewardValue = number; // All reward values should be integer

export type BlockRewards = {
proposerIndex: ValidatorIndex;
total: SubRewardValue;
attestations: SubRewardValue;
syncAggregate: SubRewardValue;
proposerSlashings: SubRewardValue;
attesterSlashings: SubRewardValue;
};

/**
* Calculate total proposer block rewards given block and the beacon state of the same slot before the block is applied (preState)
* postState can be passed in to read reward cache if available
Expand Down

0 comments on commit f80daf4

Please sign in to comment.