From f80daf42bd5a3774fa8cabf4cef2b2aedf39d629 Mon Sep 17 00:00:00 2001 From: navie Date: Mon, 22 Jan 2024 23:02:15 +0800 Subject: [PATCH] Rename proposerRewards to blockRewards. Fix import --- packages/api/src/beacon/index.ts | 1 + packages/api/src/beacon/routes/beacon/index.ts | 2 +- packages/api/src/beacon/routes/beacon/rewards.ts | 16 ++++++++-------- packages/api/src/beacon/routes/index.ts | 2 ++ packages/api/test/unit/beacon/testData/beacon.ts | 2 +- .../src/api/impl/beacon/rewards/index.ts | 2 +- packages/beacon-node/src/chain/chain.ts | 3 ++- packages/beacon-node/src/chain/interface.ts | 2 +- .../src/chain/rewards/blockRewards.ts | 12 ++---------- 9 files changed, 19 insertions(+), 23 deletions(-) diff --git a/packages/api/src/beacon/index.ts b/packages/api/src/beacon/index.ts index d07f6f4bed53..147e6ff86df2 100644 --- a/packages/api/src/beacon/index.ts +++ b/packages/api/src/beacon/index.ts @@ -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; diff --git a/packages/api/src/beacon/routes/beacon/index.ts b/packages/api/src/beacon/routes/beacon/index.ts index 28937ab2b6c7..92fcc2093188 100644 --- a/packages/api/src/beacon/routes/beacon/index.ts +++ b/packages/api/src/beacon/routes/beacon/index.ts @@ -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, diff --git a/packages/api/src/beacon/routes/beacon/rewards.ts b/packages/api/src/beacon/routes/beacon/rewards.ts index e7455c00bd37..c4bd821a6bee 100644 --- a/packages/api/src/beacon/routes/beacon/rewards.ts +++ b/packages/api/src/beacon/routes/beacon/rewards.ts @@ -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; @@ -37,11 +37,11 @@ export type Api = { * @param blockId Block identifier. * Can be one of: "head" (canonical head in node's view), "genesis", "finalized", \, \. */ - getProposerRewards( + getBlockRewards( blockId: BlockId ): Promise< ApiClientResponse< - {[HttpStatusCode.OK]: {data: ProposerRewardsResponse; executionOptimistic: ExecutionOptimistic}}, + {[HttpStatusCode.OK]: {data: BlockRewards; executionOptimistic: ExecutionOptimistic}}, HttpStatusCode.BAD_REQUEST | HttpStatusCode.NOT_FOUND > >; @@ -51,17 +51,17 @@ export type Api = { * Define javascript values for each route */ export const routesData: RoutesData = { - 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 { return { - getProposerRewards: { + getBlockRewards: { writeReq: (block_id) => ({params: {block_id: String(block_id)}}), parseReq: ({params}) => [params.block_id], schema: {params: {block_id: Schema.StringRequired}}, @@ -70,7 +70,7 @@ export function getReqSerializers(): ReqSerializers { } export function getReturnTypes(): ReturnTypes { - const ProposerRewardsResponse = new ContainerType( + const BlockRewardsResponse = new ContainerType( { proposerIndex: ssz.ValidatorIndex, total: ssz.UintNum64, @@ -83,6 +83,6 @@ export function getReturnTypes(): ReturnTypes { ); return { - getProposerRewards: ContainerDataExecutionOptimistic(ProposerRewardsResponse), + getBlockRewards: ContainerDataExecutionOptimistic(BlockRewardsResponse), }; } diff --git a/packages/api/src/beacon/routes/index.ts b/packages/api/src/beacon/routes/index.ts index 81eb0cd3276c..651ae5ce3f2e 100644 --- a/packages/api/src/beacon/routes/index.ts +++ b/packages/api/src/beacon/routes/index.ts @@ -30,6 +30,8 @@ export type Api = { validator: ValidatorApi; }; +export type {BlockRewards} from "./beacon/index.js"; + // Reasoning of the API definitions // ================================ // diff --git a/packages/api/test/unit/beacon/testData/beacon.ts b/packages/api/test/unit/beacon/testData/beacon.ts index cd62bcbdf705..6def8181b2fa 100644 --- a/packages/api/test/unit/beacon/testData/beacon.ts +++ b/packages/api/test/unit/beacon/testData/beacon.ts @@ -170,7 +170,7 @@ export const testData: GenericServerTestCases = { // reward - getProposerRewards: { + getBlockRewards: { args: ["head"], res: { executionOptimistic: true, diff --git a/packages/beacon-node/src/api/impl/beacon/rewards/index.ts b/packages/beacon-node/src/api/impl/beacon/rewards/index.ts index a19be8b5efbd..03a182359d90 100644 --- a/packages/beacon-node/src/api/impl/beacon/rewards/index.ts +++ b/packages/beacon-node/src/api/impl/beacon/rewards/index.ts @@ -4,7 +4,7 @@ import {resolveBlockId} from "../blocks/utils.js"; export function getBeaconRewardsApi({chain}: Pick): ServerApi { return { - async getProposerRewards(blockId) { + async getBlockRewards(blockId) { const {block, executionOptimistic} = await resolveBlockId(chain, blockId); const data = await chain.getBlockRewards(block.message); return {data, executionOptimistic}; diff --git a/packages/beacon-node/src/chain/chain.ts b/packages/beacon-node/src/chain/chain.ts index 016e5b5cb836..54de388da19d 100644 --- a/packages/beacon-node/src/chain/chain.ts +++ b/packages/beacon-node/src/chain/chain.ts @@ -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"; @@ -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"; diff --git a/packages/beacon-node/src/chain/interface.ts b/packages/beacon-node/src/chain/interface.ts index 99c1b7ea0c4a..0df79b4e284a 100644 --- a/packages/beacon-node/src/chain/interface.ts +++ b/packages/beacon-node/src/chain/interface.ts @@ -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"; @@ -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}; diff --git a/packages/beacon-node/src/chain/rewards/blockRewards.ts b/packages/beacon-node/src/chain/rewards/blockRewards.ts index 4820b2223631..32a9463fdaba 100644 --- a/packages/beacon-node/src/chain/rewards/blockRewards.ts +++ b/packages/beacon-node/src/chain/rewards/blockRewards.ts @@ -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