From 75b2452838fad67e4fdbbef60eaa39576c6ffb9b Mon Sep 17 00:00:00 2001 From: NC Date: Fri, 12 Jan 2024 12:16:17 +0800 Subject: [PATCH] This is the Wei --- packages/api/src/beacon/routes/validator.ts | 5 ++--- packages/api/src/utils/types.ts | 2 +- .../api/test/unit/beacon/testData/validator.ts | 6 +++--- .../src/api/impl/validator/index.ts | 6 +++--- packages/beacon-node/src/chain/chain.ts | 11 +++++------ packages/beacon-node/src/chain/interface.ts | 18 +++--------------- .../api/impl/validator/produceBlockV2.test.ts | 2 +- .../state-transition/src/cache/rewardCache.ts | 1 + packages/validator/src/services/block.ts | 4 ++-- 9 files changed, 21 insertions(+), 34 deletions(-) diff --git a/packages/api/src/beacon/routes/validator.ts b/packages/api/src/beacon/routes/validator.ts index 0746797cbf0e..09fbd9de3162 100644 --- a/packages/api/src/beacon/routes/validator.ts +++ b/packages/api/src/beacon/routes/validator.ts @@ -19,7 +19,6 @@ import { StringType, SubcommitteeIndex, Wei, - Gwei, ProducedBlockSource, } from "@lodestar/types"; import {ApiClientResponse} from "../../interfaces.js"; @@ -59,11 +58,11 @@ export type ExtraProduceBlockOps = { blindedLocal?: boolean; }; -export type ProduceBlockOrContentsRes = {executionPayloadValue: Wei; consensusBlockValue: Gwei} & ( +export type ProduceBlockOrContentsRes = {executionPayloadValue: Wei; consensusBlockValue: Wei} & ( | {data: allForks.BeaconBlock; version: ForkPreBlobs} | {data: allForks.BlockContents; version: ForkBlobs} ); -export type ProduceBlindedBlockRes = {executionPayloadValue: Wei; consensusBlockValue: Gwei} & { +export type ProduceBlindedBlockRes = {executionPayloadValue: Wei; consensusBlockValue: Wei} & { data: allForks.BlindedBeaconBlock; version: ForkExecution; }; diff --git a/packages/api/src/utils/types.ts b/packages/api/src/utils/types.ts index b01649a0ef38..e218a71e3033 100644 --- a/packages/api/src/utils/types.ts +++ b/packages/api/src/utils/types.ts @@ -179,7 +179,7 @@ export function WithExecutionOptimistic( } /** - * SSZ factory helper to wrap an existing type with `{executionPayloadValue: Wei, consensusBlockValue: GWei}` + * SSZ factory helper to wrap an existing type with `{executionPayloadValue: Wei, consensusBlockValue: Wei}` */ export function WithBlockValues( type: TypeJson diff --git a/packages/api/test/unit/beacon/testData/validator.ts b/packages/api/test/unit/beacon/testData/validator.ts index 2688f2080eba..0769fbc47d9b 100644 --- a/packages/api/test/unit/beacon/testData/validator.ts +++ b/packages/api/test/unit/beacon/testData/validator.ts @@ -78,7 +78,7 @@ export const testData: GenericServerTestCases = { data: ssz.altair.BeaconBlock.defaultValue(), version: ForkName.altair, executionPayloadValue: ssz.Wei.defaultValue(), - consensusBlockValue: ssz.Gwei.defaultValue(), + consensusBlockValue: ssz.Wei.defaultValue(), }, }, produceBlockV3: { @@ -99,7 +99,7 @@ export const testData: GenericServerTestCases = { data: ssz.altair.BeaconBlock.defaultValue(), version: ForkName.altair, executionPayloadValue: ssz.Wei.defaultValue(), - consensusBlockValue: ssz.Gwei.defaultValue(), + consensusBlockValue: ssz.Wei.defaultValue(), executionPayloadBlinded: false, executionPayloadSource: ProducedBlockSource.engine, }, @@ -122,7 +122,7 @@ export const testData: GenericServerTestCases = { data: ssz.bellatrix.BlindedBeaconBlock.defaultValue(), version: ForkName.bellatrix, executionPayloadValue: ssz.Wei.defaultValue(), - consensusBlockValue: ssz.Gwei.defaultValue(), + consensusBlockValue: ssz.Wei.defaultValue(), }, }, produceAttestationData: { diff --git a/packages/beacon-node/src/api/impl/validator/index.ts b/packages/beacon-node/src/api/impl/validator/index.ts index 839c1df7c463..ff785fc7b8bf 100644 --- a/packages/beacon-node/src/api/impl/validator/index.ts +++ b/packages/beacon-node/src/api/impl/validator/index.ts @@ -35,7 +35,7 @@ import { phase0, } from "@lodestar/types"; import {ExecutionStatus} from "@lodestar/fork-choice"; -import {toHex, racePromisesWithCutoff, RaceEvent, gweiToWei} from "@lodestar/utils"; +import {toHex, racePromisesWithCutoff, RaceEvent} from "@lodestar/utils"; import {AttestationError, AttestationErrorCode, GossipAction, SyncCommitteeError} from "../../../chain/errors/index.js"; import {validateApiAggregateAndProof} from "../../../chain/validation/index.js"; import {ZERO_HASH} from "../../../constants/index.js"; @@ -552,8 +552,8 @@ export function getValidatorApi({ const consensusBlockValueBuilder = blindedBlock?.consensusBlockValue ?? BigInt(0); const consensusBlockValueEngine = fullBlock?.consensusBlockValue ?? BigInt(0); - const blockValueBuilder = builderPayloadValue + gweiToWei(consensusBlockValueBuilder); // Total block value is in wei - const blockValueEngine = enginePayloadValue + gweiToWei(consensusBlockValueEngine); // Total block value is in wei + const blockValueBuilder = builderPayloadValue + consensusBlockValueBuilder; // Total block value is in wei + const blockValueEngine = enginePayloadValue + consensusBlockValueEngine; // Total block value is in wei let executionPayloadSource: ProducedBlockSource | null = null; const shouldOverrideBuilder = fullBlock?.shouldOverrideBuilder ?? false; diff --git a/packages/beacon-node/src/chain/chain.ts b/packages/beacon-node/src/chain/chain.ts index ac2f97128c16..4f96afe232ff 100644 --- a/packages/beacon-node/src/chain/chain.ts +++ b/packages/beacon-node/src/chain/chain.ts @@ -27,11 +27,10 @@ import { Wei, bellatrix, isBlindedBeaconBlock, - Gwei, } from "@lodestar/types"; import {CheckpointWithHex, ExecutionStatus, IForkChoice, ProtoBlock} from "@lodestar/fork-choice"; import {ProcessShutdownCallback} from "@lodestar/validator"; -import {Logger, isErrorAborted, pruneSetToMax, sleep, toHex} from "@lodestar/utils"; +import {Logger, gweiToWei, isErrorAborted, pruneSetToMax, sleep, toHex} from "@lodestar/utils"; import {ForkSeq, SLOTS_PER_EPOCH} from "@lodestar/params"; import {GENESIS_EPOCH, ZERO_HASH} from "../constants/index.js"; @@ -473,7 +472,7 @@ export class BeaconChain implements IBeaconChain { produceBlock(blockAttributes: BlockAttributes): Promise<{ block: allForks.BeaconBlock; executionPayloadValue: Wei; - consensusBlockValue: Gwei; + consensusBlockValue: Wei; shouldOverrideBuilder?: boolean; }> { return this.produceBlockWrapper(BlockType.Full, blockAttributes); @@ -482,7 +481,7 @@ export class BeaconChain implements IBeaconChain { produceBlindedBlock(blockAttributes: BlockAttributes): Promise<{ block: allForks.BlindedBeaconBlock; executionPayloadValue: Wei; - consensusBlockValue: Gwei; + consensusBlockValue: Wei; }> { return this.produceBlockWrapper(BlockType.Blinded, blockAttributes); } @@ -493,7 +492,7 @@ export class BeaconChain implements IBeaconChain { ): Promise<{ block: AssembledBlockType; executionPayloadValue: Wei; - consensusBlockValue: Gwei; + consensusBlockValue: Wei; shouldOverrideBuilder?: boolean; }> { const head = this.forkChoice.getHead(); @@ -572,7 +571,7 @@ export class BeaconChain implements IBeaconChain { this.metrics?.blockProductionCaches.producedContentsCache.set(this.producedContentsCache.size); } - return {block, executionPayloadValue, consensusBlockValue: proposerReward, shouldOverrideBuilder}; + return {block, executionPayloadValue, consensusBlockValue: gweiToWei(proposerReward), shouldOverrideBuilder}; } /** diff --git a/packages/beacon-node/src/chain/interface.ts b/packages/beacon-node/src/chain/interface.ts index a2f7fba34093..da364c9ea447 100644 --- a/packages/beacon-node/src/chain/interface.ts +++ b/packages/beacon-node/src/chain/interface.ts @@ -1,17 +1,5 @@ import {CompositeTypeAny, TreeView, Type} from "@chainsafe/ssz"; -import { - allForks, - UintNum64, - Root, - phase0, - Slot, - RootHex, - Epoch, - ValidatorIndex, - deneb, - Wei, - Gwei, -} from "@lodestar/types"; +import {allForks, UintNum64, Root, phase0, Slot, RootHex, Epoch, ValidatorIndex, deneb, Wei} from "@lodestar/types"; import { BeaconStateAllForks, CachedBeaconStateAllForks, @@ -157,13 +145,13 @@ export interface IBeaconChain { produceBlock(blockAttributes: BlockAttributes): Promise<{ block: allForks.BeaconBlock; executionPayloadValue: Wei; - consensusBlockValue: Gwei; + consensusBlockValue: Wei; shouldOverrideBuilder?: boolean; }>; produceBlindedBlock(blockAttributes: BlockAttributes): Promise<{ block: allForks.BlindedBeaconBlock; executionPayloadValue: Wei; - consensusBlockValue: Gwei; + consensusBlockValue: Wei; }>; /** Process a block until complete */ diff --git a/packages/beacon-node/test/unit/api/impl/validator/produceBlockV2.test.ts b/packages/beacon-node/test/unit/api/impl/validator/produceBlockV2.test.ts index 9ca426672efe..56913e241e3b 100644 --- a/packages/beacon-node/test/unit/api/impl/validator/produceBlockV2.test.ts +++ b/packages/beacon-node/test/unit/api/impl/validator/produceBlockV2.test.ts @@ -72,7 +72,7 @@ describe("api/validator - produceBlockV2", function () { const fullBlock = ssz.bellatrix.BeaconBlock.defaultValue(); const executionPayloadValue = ssz.Wei.defaultValue(); - const consensusBlockValue = ssz.Gwei.defaultValue(); + const consensusBlockValue = ssz.Wei.defaultValue(); const currentSlot = 100000; vi.spyOn(server.chainStub.clock, "currentSlot", "get").mockReturnValue(currentSlot); diff --git a/packages/state-transition/src/cache/rewardCache.ts b/packages/state-transition/src/cache/rewardCache.ts index 669060d143cd..c404f26a3c96 100644 --- a/packages/state-transition/src/cache/rewardCache.ts +++ b/packages/state-transition/src/cache/rewardCache.ts @@ -2,6 +2,7 @@ * A simple data structure to store rewards payable to block proposer in the memory. * Rewards are updated throughout the state transition * Should only hold info for one state transition + * All values are in Gwei */ export type RewardCache = { attestations: number; diff --git a/packages/validator/src/services/block.ts b/packages/validator/src/services/block.ts index c11af904b34d..80b641d269ba 100644 --- a/packages/validator/src/services/block.ts +++ b/packages/validator/src/services/block.ts @@ -11,7 +11,7 @@ import { } from "@lodestar/types"; import {ChainForkConfig} from "@lodestar/config"; import {ForkPreBlobs, ForkBlobs, ForkSeq, ForkExecution} from "@lodestar/params"; -import {ETH_TO_GWEI, ETH_TO_WEI, extendError, gweiToWei, prettyBytes} from "@lodestar/utils"; +import {ETH_TO_WEI, extendError, gweiToWei, prettyBytes} from "@lodestar/utils"; import {Api, ApiError, routes} from "@lodestar/api"; import {IClock, LoggerVc} from "../util/index.js"; import {PubkeyHex} from "../types.js"; @@ -220,7 +220,7 @@ export class BlockProposingService { executionPayloadBlinded: response.executionPayloadBlinded, // winston logger doesn't like bigint executionPayloadValue: `${formatBigDecimal(response.executionPayloadValue, ETH_TO_WEI, MAX_DECIMAL_FACTOR)} ETH`, - consensusBlockValue: `${formatBigDecimal(response.consensusBlockValue, ETH_TO_GWEI, MAX_DECIMAL_FACTOR)} ETH`, + consensusBlockValue: `${formatBigDecimal(response.consensusBlockValue, ETH_TO_WEI, MAX_DECIMAL_FACTOR)} ETH`, totalBlockValue: `${formatBigDecimal( response.executionPayloadValue + gweiToWei(response.consensusBlockValue), ETH_TO_WEI,