Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle 0x prefix from execution client commit #7273

Open
wants to merge 2 commits into
base: unstable
Choose a base branch
from
Open
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: 4 additions & 2 deletions packages/beacon-node/src/util/graffiti.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ export function getDefaultGraffiti(
}

if (executionClientVersion != null) {
const {code: executionCode, commit: executionCommit} = executionClientVersion;
let {code: executionCode, commit: executionCommit} = executionClientVersion;

executionCommit = executionCommit.startsWith("0x") ? executionCommit.slice(2, 6) : executionCommit.slice(0, 4);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is there are 0x prefix in the first place? I think our deserialization is not correct, we also don't serialize it correctly according to #7217

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we also don't serialize it correctly according to #7217

Yea will address it in a separate PR

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DATA type must be prepended by 0x as per https://github.com/ethereum/execution-apis/blob/main/src/engine/common.md#encoding

but isn't that the encoding in transit, e.g. see parentHash for example, it's bytes internally but will be hex encoded in transit

parentHash: bytesToData(data.parentHash),

see data conversion functions

export function bytesToData(bytes: Uint8Array): DATA {
return toHex(bytes);
}
/**
* DATA as defined in ethereum execution layer JSON RPC https://eth.wiki/json-rpc/API
*/
export function dataToBytes(hex: DATA, fixedLength: number | null): Uint8Array {
try {
const bytes = fromHex(hex);
if (fixedLength != null && bytes.length !== fixedLength) {
throw Error(`Wrong data length ${bytes.length} expected ${fixedLength}`);
}
return bytes;
} catch (e) {
(e as Error).message = `Invalid hex string: ${(e as Error).message}`;
throw e;
}
}


// Follow the 2-byte commit format in https://github.com/ethereum/execution-apis/pull/517#issuecomment-1918512560
return `${executionCode}${executionCommit.slice(0, 4)}${consensusClientVersion.code}${consensusClientVersion.commit.slice(0, 4)}`;
return `${executionCode}${executionCommit}${consensusClientVersion.code}${consensusClientVersion.commit.slice(0, 4)}`;
}

// No EL client info available. We still want to include CL info albeit not spec compliant
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/test/unit/util/graffiti.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe("Graffiti helper", () => {
});

describe("getDefaultGraffiti", () => {
const executionClientVersion = {code: ClientCode.BU, name: "Besu", version: "24.1.1", commit: "9b0e38fa"};
const executionClientVersion = {code: ClientCode.BU, name: "Besu", version: "24.1.1", commit: "0x9b0e38fa"};
const consensusClientVersion = {
code: ClientCode.LS,
name: "Lodestar",
Expand Down
Loading