From 3e637fd03a714d7db67bfa00815caacb9a7f461c Mon Sep 17 00:00:00 2001 From: flywukong <19421226+flywukong@users.noreply.github.com> Date: Tue, 18 Nov 2025 20:34:20 +0800 Subject: [PATCH 1/3] feat: fetch commit id with GetBinaryVersion command --- cmd/jsutils/getchainstatus.js | 42 ++++++++++++++++++++++++++++++++++- eth/backend.go | 11 +++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/cmd/jsutils/getchainstatus.js b/cmd/jsutils/getchainstatus.js index 939b09c183..730ba9da62 100644 --- a/cmd/jsutils/getchainstatus.js +++ b/cmd/jsutils/getchainstatus.js @@ -211,6 +211,12 @@ const validatorMap = new Map([ ['0x32415e630B9B3489639dEE7de21274Ab64016226', ['Kraken' , '0x70Cd30d9216AF7A5654D245e9F5c649b811aB2eB', '0xa80ebd07bd9d717bd538413e8830f673e63dfad496c901de324be5d16b0496aee39352ecfb84fa58d8d8a67746f8ae6c']], ]); +// commitMap maintains the standard commit IDs for official releases +const commitMap = new Map([ + ["v1.6.4", "abcdefgh"], + // Add more official version -> commit mappings as needed +]); + const builderMap = new Map([ // BSC mainnet // blockrazor @@ -320,6 +326,40 @@ async function getBinaryVersion() { let minor = ethers.toNumber(ethers.dataSlice(blockData.extraData, 3, 4)); let patch = ethers.toNumber(ethers.dataSlice(blockData.extraData, 4, 5)); + // Extract commit ID from extraData if version >= 1.6.4 + let commitID = ""; + let versionStr = major + "." + minor + "." + patch; + if (major > 1 || (major === 1 && minor > 6) || (major === 1 && minor === 6 && patch >= 4)) { + try { + // Decode RLP to extract commit ID + // ExtraData structure: [version_uint, commitID_string, "geth", runtime_version, os] + const decoded = ethers.decodeRlp(blockData.extraData); + if (Array.isArray(decoded) && decoded.length > 1) { + // decoded[0] is version (as hex string) + // decoded[1] is commit ID (as hex string) + const commitIDHex = decoded[1]; + if (commitIDHex && commitIDHex !== "0x" && commitIDHex !== "0x00") { + // Convert hex to UTF-8 string + try { + commitID = ethers.toUtf8String(commitIDHex); + } catch (e) { + // If conversion fails, use the hex string directly (removing 0x prefix) + commitID = commitIDHex.substring(2); + } + } + } + } catch (e) { + // If RLP decoding fails, the block might be from an older version + // or the extraData format is different + console.error("Failed to decode extraData:", e.message); + } + + // Format version string with commit ID + if (commitID && commitID.length > 0) { + versionStr = versionStr + "-" + commitID; + } + } + // 2.get minimum txGasPrice based on the last non-zero-gasprice transaction let lastGasPrice = 0; for (let txIndex = blockData.transactions.length - 1; txIndex >= 0; txIndex--) { @@ -332,7 +372,7 @@ async function getBinaryVersion() { break; } var moniker = await getValidatorMoniker(blockData.miner, blockNum); - console.log(blockNum - i * turnLength, blockData.miner, "version =", major + "." + minor + "." + patch, " MinGasPrice = " + lastGasPrice, moniker); + console.log(blockNum - i * turnLength, blockData.miner, "version =", versionStr, " MinGasPrice = " + lastGasPrice, moniker); } } diff --git a/eth/backend.go b/eth/backend.go index a4f6f08586..8f773e135b 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -511,8 +511,19 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) { func makeExtraData(extra []byte) []byte { if len(extra) == 0 { // create default extradata + // For version >= 1.6.4, include commit id (8 characters) + commitID := "" + if gethversion.Major > 1 || (gethversion.Major == 1 && gethversion.Minor > 6) || + (gethversion.Major == 1 && gethversion.Minor == 6 && gethversion.Patch >= 4) { + git, ok := version.VCS() + if ok && len(git.Commit) >= 8 { + commitID = git.Commit[:8] + } + } + extra, _ = rlp.EncodeToBytes([]interface{}{ uint(gethversion.Major<<16 | gethversion.Minor<<8 | gethversion.Patch), + commitID, "geth", runtime.Version(), runtime.GOOS, From 9ef76df6cdb8e79702e18c6421d22e1fd7ed53db Mon Sep 17 00:00:00 2001 From: flywukong <19421226+flywukong@users.noreply.github.com> Date: Thu, 20 Nov 2025 14:16:37 +0800 Subject: [PATCH 2/3] fix: fix length error of extradata --- cmd/jsutils/getchainstatus.js | 81 ++++++++++++++++++----------------- eth/backend.go | 37 +++++++++------- 2 files changed, 63 insertions(+), 55 deletions(-) diff --git a/cmd/jsutils/getchainstatus.js b/cmd/jsutils/getchainstatus.js index 730ba9da62..ee6d050283 100644 --- a/cmd/jsutils/getchainstatus.js +++ b/cmd/jsutils/getchainstatus.js @@ -211,12 +211,6 @@ const validatorMap = new Map([ ['0x32415e630B9B3489639dEE7de21274Ab64016226', ['Kraken' , '0x70Cd30d9216AF7A5654D245e9F5c649b811aB2eB', '0xa80ebd07bd9d717bd538413e8830f673e63dfad496c901de324be5d16b0496aee39352ecfb84fa58d8d8a67746f8ae6c']], ]); -// commitMap maintains the standard commit IDs for official releases -const commitMap = new Map([ - ["v1.6.4", "abcdefgh"], - // Add more official version -> commit mappings as needed -]); - const builderMap = new Map([ // BSC mainnet // blockrazor @@ -321,43 +315,52 @@ async function getBinaryVersion() { let turnLength = program.turnLength; for (let i = 0; i < program.num; i++) { let blockData = await provider.getBlock(blockNum - i * turnLength); - // 1.get Geth client version - let major = ethers.toNumber(ethers.dataSlice(blockData.extraData, 2, 3)); - let minor = ethers.toNumber(ethers.dataSlice(blockData.extraData, 3, 4)); - let patch = ethers.toNumber(ethers.dataSlice(blockData.extraData, 4, 5)); - // Extract commit ID from extraData if version >= 1.6.4 + let major = 0, minor = 0, patch = 0; let commitID = ""; - let versionStr = major + "." + minor + "." + patch; - if (major > 1 || (major === 1 && minor > 6) || (major === 1 && minor === 6 && patch >= 4)) { - try { - // Decode RLP to extract commit ID - // ExtraData structure: [version_uint, commitID_string, "geth", runtime_version, os] - const decoded = ethers.decodeRlp(blockData.extraData); - if (Array.isArray(decoded) && decoded.length > 1) { - // decoded[0] is version (as hex string) - // decoded[1] is commit ID (as hex string) - const commitIDHex = decoded[1]; - if (commitIDHex && commitIDHex !== "0x" && commitIDHex !== "0x00") { - // Convert hex to UTF-8 string - try { - commitID = ethers.toUtf8String(commitIDHex); - } catch (e) { - // If conversion fails, use the hex string directly (removing 0x prefix) - commitID = commitIDHex.substring(2); - } - } - } - } catch (e) { - // If RLP decoding fails, the block might be from an older version - // or the extraData format is different - console.error("Failed to decode extraData:", e.message); - } + + try { + major = ethers.toNumber(ethers.dataSlice(blockData.extraData, 2, 3)); + minor = ethers.toNumber(ethers.dataSlice(blockData.extraData, 3, 4)); + patch = ethers.toNumber(ethers.dataSlice(blockData.extraData, 4, 5)); - // Format version string with commit ID - if (commitID && commitID.length > 0) { - versionStr = versionStr + "-" + commitID; + // Check version: >= 1.6.4 uses new format with commitID + const isNewFormat = major > 1 || (major === 1 && minor > 6) || (major === 1 && minor === 6 && patch >= 4); + + if (isNewFormat) { + const extraVanity = 28; + let vanityBytes = ethers.getBytes(ethers.dataSlice(blockData.extraData, 0, extraVanity)); + + let rlpLength = vanityBytes.length; + if (vanityBytes[0] >= 0xC0 && vanityBytes[0] <= 0xF7) { + rlpLength = (vanityBytes[0] - 0xC0) + 1; + } + + const rlpData = ethers.dataSlice(blockData.extraData, 0, rlpLength); + const decoded = ethers.decodeRlp(rlpData); + + if (Array.isArray(decoded) && decoded.length >= 2) { + const secondElemHex = decoded[1]; + let secondElemStr = ""; + try { + secondElemStr = ethers.toUtf8String(secondElemHex); + } catch (e) { + secondElemStr = secondElemHex; + } + + if (secondElemStr.length > 0 && secondElemStr !== "geth") { + commitID = secondElemStr.startsWith("0x") ? secondElemStr.substring(2) : secondElemStr; + } + } } + } catch (e) { + console.log("Parsing failed:", e.message); + } + + // Format version string + let versionStr = major + "." + minor + "." + patch; + if (commitID && commitID.length > 0) { + versionStr = versionStr + "-" + commitID; } // 2.get minimum txGasPrice based on the last non-zero-gasprice transaction diff --git a/eth/backend.go b/eth/backend.go index 8f773e135b..0a5d25adc5 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -32,7 +32,6 @@ import ( "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/consensus" "github.com/ethereum/go-ethereum/consensus/parlia" "github.com/ethereum/go-ethereum/core" @@ -66,7 +65,6 @@ import ( "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p/dnsdisc" "github.com/ethereum/go-ethereum/p2p/enode" - "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/triedb/pathdb" @@ -510,8 +508,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) { func makeExtraData(extra []byte) []byte { if len(extra) == 0 { - // create default extradata - // For version >= 1.6.4, include commit id (8 characters) + // For version >= 1.6.4, use compact format: [version(uint32), commitID, go_version, os] commitID := "" if gethversion.Major > 1 || (gethversion.Major == 1 && gethversion.Minor > 6) || (gethversion.Major == 1 && gethversion.Minor == 6 && gethversion.Patch >= 4) { @@ -519,19 +516,27 @@ func makeExtraData(extra []byte) []byte { if ok && len(git.Commit) >= 8 { commitID = git.Commit[:8] } - } - extra, _ = rlp.EncodeToBytes([]interface{}{ - uint(gethversion.Major<<16 | gethversion.Minor<<8 | gethversion.Patch), - commitID, - "geth", - runtime.Version(), - runtime.GOOS, - }) - } - if uint64(len(extra)) > params.MaximumExtraDataSize-params.ForkIDSize { - log.Warn("Miner extra data exceed limit", "extra", hexutil.Bytes(extra), "limit", params.MaximumExtraDataSize-params.ForkIDSize) - extra = nil + osName := runtime.GOOS + if len(osName) > 3 { + osName = osName[:3] + } + + versionWord := uint32(gethversion.Major<<16 | gethversion.Minor<<8 | gethversion.Patch) + extra, _ = rlp.EncodeToBytes([]interface{}{ + versionWord, + commitID, + runtime.Version(), + osName, + }) + } else { + extra, _ = rlp.EncodeToBytes([]interface{}{ + uint(gethversion.Major<<16 | gethversion.Minor<<8 | gethversion.Patch), + "geth", + runtime.Version(), + runtime.GOOS, + }) + } } return extra } From ea8fe81193cb024cfacd8cc2578ffc10a6ff5949 Mon Sep 17 00:00:00 2001 From: flywukong <19421226+flywukong@users.noreply.github.com> Date: Fri, 21 Nov 2025 18:44:23 +0800 Subject: [PATCH 3/3] fix: remove version judgement when make extradata --- eth/backend.go | 46 +++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/eth/backend.go b/eth/backend.go index 0a5d25adc5..37312fa5b9 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -28,7 +28,9 @@ import ( "sync" "time" + "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/metrics" + "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/common" @@ -510,33 +512,27 @@ func makeExtraData(extra []byte) []byte { if len(extra) == 0 { // For version >= 1.6.4, use compact format: [version(uint32), commitID, go_version, os] commitID := "" - if gethversion.Major > 1 || (gethversion.Major == 1 && gethversion.Minor > 6) || - (gethversion.Major == 1 && gethversion.Minor == 6 && gethversion.Patch >= 4) { - git, ok := version.VCS() - if ok && len(git.Commit) >= 8 { - commitID = git.Commit[:8] - } - - osName := runtime.GOOS - if len(osName) > 3 { - osName = osName[:3] - } + git, ok := version.VCS() + if ok && len(git.Commit) >= 8 { + commitID = git.Commit[:8] + } - versionWord := uint32(gethversion.Major<<16 | gethversion.Minor<<8 | gethversion.Patch) - extra, _ = rlp.EncodeToBytes([]interface{}{ - versionWord, - commitID, - runtime.Version(), - osName, - }) - } else { - extra, _ = rlp.EncodeToBytes([]interface{}{ - uint(gethversion.Major<<16 | gethversion.Minor<<8 | gethversion.Patch), - "geth", - runtime.Version(), - runtime.GOOS, - }) + osName := runtime.GOOS + if len(osName) > 3 { + osName = osName[:3] } + + versionWord := uint32(gethversion.Major<<16 | gethversion.Minor<<8 | gethversion.Patch) + extra, _ = rlp.EncodeToBytes([]interface{}{ + versionWord, + commitID, + runtime.Version(), + osName, + }) + } + if uint64(len(extra)) > params.MaximumExtraDataSize-params.ForkIDSize { + log.Warn("Miner extra data exceed limit", "extra", hexutil.Bytes(extra), "limit", params.MaximumExtraDataSize-params.ForkIDSize) + extra = nil } return extra }