Skip to content
Merged
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
6 changes: 3 additions & 3 deletions packages/beacon-node/src/api/impl/validator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
phase0,
} from "@lodestar/types";
import {ExecutionStatus} from "@lodestar/fork-choice";
import {toHex, racePromisesWithCutoff, RaceEvent} from "@lodestar/utils";
import {toHex, racePromisesWithCutoff, RaceEvent, gweiToWei} 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";
Expand Down Expand Up @@ -541,8 +541,8 @@ export function getValidatorApi({
const consensusBlockValueBuilder = blindedBlock?.consensusBlockValue ?? BigInt(0);
const consensusBlockValueEngine = fullBlock?.consensusBlockValue ?? BigInt(0);

const blockValueBuilder = builderPayloadValue + consensusBlockValueBuilder;
const blockValueEngine = enginePayloadValue + consensusBlockValueEngine;
const blockValueBuilder = builderPayloadValue + gweiToWei(consensusBlockValueBuilder); // Total block value is in wei
const blockValueEngine = enginePayloadValue + gweiToWei(consensusBlockValueEngine); // Total block value is in wei

let selectedSource: ProducedBlockSource | null = null;

Expand Down
12 changes: 12 additions & 0 deletions packages/utils/src/ethConversion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const ETH_TO_GWEI = BigInt(10 ** 9);
export const GWEI_TO_WEI = BigInt(10 ** 9);
export const ETH_TO_WEI = ETH_TO_GWEI * GWEI_TO_WEI;

type EthNumeric = bigint;

/**
* Convert gwei to wei.
*/
export function gweiToWei(gwei: EthNumeric): EthNumeric {
return gwei * GWEI_TO_WEI;
}
1 change: 1 addition & 0 deletions packages/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ export * from "./url.js";
export * from "./verifyMerkleBranch.js";
export * from "./promise.js";
export * from "./waitFor.js";
export * from "./ethConversion.js";
7 changes: 3 additions & 4 deletions packages/validator/src/services/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from "@lodestar/types";
import {ChainForkConfig} from "@lodestar/config";
import {ForkPreBlobs, ForkBlobs, ForkSeq} from "@lodestar/params";
import {extendError, prettyBytes} from "@lodestar/utils";
import {ETH_TO_GWEI, 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";
Expand All @@ -21,7 +21,6 @@ import {formatBigDecimal} from "../util/format.js";
import {ValidatorStore} from "./validatorStore.js";
import {BlockDutiesService, GENESIS_SLOT} from "./blockDuties.js";

const ETH_TO_WEI = BigInt("1000000000000000000");
// display upto 5 decimal places
const MAX_DECIMAL_FACTOR = BigInt("100000");

Expand Down Expand Up @@ -220,9 +219,9 @@ export class BlockProposingService {
source: response.executionPayloadBlinded ? ProducedBlockSource.builder : ProducedBlockSource.engine,
// winston logger doesn't like bigint
executionPayloadValue: `${formatBigDecimal(response.executionPayloadValue, ETH_TO_WEI, MAX_DECIMAL_FACTOR)} ETH`,
consensusBlockValue: `${formatBigDecimal(response.consensusBlockValue, ETH_TO_WEI, MAX_DECIMAL_FACTOR)} ETH`,
consensusBlockValue: `${formatBigDecimal(response.consensusBlockValue, ETH_TO_GWEI, MAX_DECIMAL_FACTOR)} ETH`,
totalBlockValue: `${formatBigDecimal(
response.executionPayloadValue + response.consensusBlockValue,
response.executionPayloadValue + gweiToWei(response.consensusBlockValue),
ETH_TO_WEI,
MAX_DECIMAL_FACTOR
)} ETH`,
Expand Down