Skip to content

Commit

Permalink
Remove ETH suffix from payload values
Browse files Browse the repository at this point in the history
  • Loading branch information
nflaig committed Oct 29, 2024
1 parent 7073842 commit e82df99
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
14 changes: 11 additions & 3 deletions packages/beacon-node/src/api/impl/validator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,15 @@ import {
getValidatorStatus,
} from "@lodestar/types";
import {ExecutionStatus, DataAvailabilityStatus} from "@lodestar/fork-choice";
import {fromHex, toHex, resolveOrRacePromises, prettyWeiToEth, toRootHex, TimeoutError} from "@lodestar/utils";
import {
fromHex,
toHex,
resolveOrRacePromises,
prettyWeiToEth,
toRootHex,
TimeoutError,
formatWeiToEth,
} from "@lodestar/utils";
import {
AttestationError,
AttestationErrorCode,
Expand Down Expand Up @@ -442,7 +450,7 @@ export function getValidatorApi(

metrics?.blockProductionSuccess.inc({source});
metrics?.blockProductionNumAggregated.observe({source}, block.body.attestations.length);
metrics?.blockProductionExecutionPayloadValue.observe({source}, Number(prettyWeiToEth(executionPayloadValue)));
metrics?.blockProductionExecutionPayloadValue.observe({source}, Number(formatWeiToEth(executionPayloadValue)));
logger.verbose("Produced blinded block", {
slot,
executionPayloadValue,
Expand Down Expand Up @@ -517,7 +525,7 @@ export function getValidatorApi(

metrics?.blockProductionSuccess.inc({source});
metrics?.blockProductionNumAggregated.observe({source}, block.body.attestations.length);
metrics?.blockProductionExecutionPayloadValue.observe({source}, Number(prettyWeiToEth(executionPayloadValue)));
metrics?.blockProductionExecutionPayloadValue.observe({source}, Number(formatWeiToEth(executionPayloadValue)));
logger.verbose("Produced execution block", {
slot,
executionPayloadValue,
Expand Down
15 changes: 9 additions & 6 deletions packages/utils/src/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,16 @@ const MAX_DECIMAL_FACTOR = BigInt("100000");

/**
* Format wei as ETH, with up to 5 decimals
*
* By default, append ' ETH', can be omitted by setting `suffix` to `false`
*/
export function prettyWeiToEth(wei: bigint, suffix = true): string {
let eth = formatBigDecimal(wei, ETH_TO_WEI, MAX_DECIMAL_FACTOR);
if (suffix) eth += " ETH";
return eth;
export function formatWeiToEth(wei: bigint): string {
return formatBigDecimal(wei, ETH_TO_WEI, MAX_DECIMAL_FACTOR);
}

/**
* Format wei as ETH, with up to 5 decimals and append ' ETH'
*/
export function prettyWeiToEth(wei: bigint): string {
return `${formatWeiToEth(wei)} ETH`;
}

/**
Expand Down

0 comments on commit e82df99

Please sign in to comment.