Skip to content

Commit

Permalink
chore: fix format of printed graffiti from hex to utf-8 (#7306)
Browse files Browse the repository at this point in the history
* chore: fix format of printed graffiti from hex to utf-8

* Use Buffer.from no copy with offset
  • Loading branch information
nflaig authored Dec 19, 2024
1 parent 1f38c8b commit 8c7eaf8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {ZERO_HASH, ZERO_HASH_HEX} from "../../constants/index.js";
import {IEth1ForBlockProduction} from "../../eth1/index.js";
import {numToQuantity} from "../../eth1/provider/utils.js";
import {IExecutionBuilder, IExecutionEngine, PayloadAttributes, PayloadId} from "../../execution/index.js";
import {fromGraffitiBuffer} from "../../util/graffiti.js";
import type {BeaconChain} from "../chain.js";
import {CommonBlockBody} from "../interface.js";
import {validateBlobsAndKzgCommitments} from "./validateBlobsAndKzgCommitments.js";
Expand Down Expand Up @@ -154,7 +155,7 @@ export async function produceBlockBody<T extends BlockType>(
} = blockBody;

Object.assign(logMeta, {
graffiti,
graffiti: fromGraffitiBuffer(graffiti),
attestations: attestations.length,
deposits: deposits.length,
voluntaryExits: voluntaryExits.length,
Expand Down
7 changes: 7 additions & 0 deletions packages/beacon-node/src/util/graffiti.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ export function toGraffitiBuffer(graffiti: string): Buffer {
return Buffer.concat([Buffer.from(graffiti, "utf8"), Buffer.alloc(GRAFFITI_SIZE, 0)], GRAFFITI_SIZE);
}

/**
* Converts a graffiti from 32 bytes buffer back to a UTF-8 string
*/
export function fromGraffitiBuffer(graffiti: Uint8Array): string {
return Buffer.from(graffiti.buffer, graffiti.byteOffset, graffiti.byteLength).toString("utf8");
}

export function getDefaultGraffiti(
consensusClientVersion: ClientVersion,
executionClientVersion: ClientVersion | null | undefined,
Expand Down

0 comments on commit 8c7eaf8

Please sign in to comment.