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 f0f076c6c13a..fc5cf953018d 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"; @@ -573,8 +573,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 14fef75c8ad8..f20bc0dbffa2 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"; @@ -498,7 +497,7 @@ export class BeaconChain implements IBeaconChain { produceBlock(blockAttributes: BlockAttributes & {commonBlockBody?: CommonBlockBody}): Promise<{ block: allForks.BeaconBlock; executionPayloadValue: Wei; - consensusBlockValue: Gwei; + consensusBlockValue: Wei; shouldOverrideBuilder?: boolean; }> { return this.produceBlockWrapper(BlockType.Full, blockAttributes); @@ -507,7 +506,7 @@ export class BeaconChain implements IBeaconChain { produceBlindedBlock(blockAttributes: BlockAttributes & {commonBlockBody?: CommonBlockBody}): Promise<{ block: allForks.BlindedBeaconBlock; executionPayloadValue: Wei; - consensusBlockValue: Gwei; + consensusBlockValue: Wei; }> { return this.produceBlockWrapper(BlockType.Blinded, blockAttributes); } @@ -518,7 +517,7 @@ export class BeaconChain implements IBeaconChain { ): Promise<{ block: AssembledBlockType; executionPayloadValue: Wei; - consensusBlockValue: Gwei; + consensusBlockValue: Wei; shouldOverrideBuilder?: boolean; }> { const head = this.forkChoice.getHead(); @@ -598,7 +597,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 0771a01caf08..3939457a8ac3 100644 --- a/packages/beacon-node/src/chain/interface.ts +++ b/packages/beacon-node/src/chain/interface.ts @@ -10,7 +10,6 @@ import { ValidatorIndex, deneb, Wei, - Gwei, capella, altair, } from "@lodestar/types"; @@ -162,13 +161,13 @@ export interface IBeaconChain { produceBlock(blockAttributes: BlockAttributes & {commonBlockBody?: CommonBlockBody}): Promise<{ block: allForks.BeaconBlock; executionPayloadValue: Wei; - consensusBlockValue: Gwei; + consensusBlockValue: Wei; shouldOverrideBuilder?: boolean; }>; produceBlindedBlock(blockAttributes: BlockAttributes & {commonBlockBody?: CommonBlockBody}): 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 dec08bf9967c..72b3dbbae2e7 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"; @@ -221,7 +221,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,