Skip to content
Open
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
1485d89
feat: pbss implemention
ryanmorphl2 Nov 26, 2024
44392b7
WIP
ryanmorphl2 Nov 26, 2024
cb759c6
WIP
ryanmorphl2 Nov 26, 2024
fade32f
WIP
ryanmorphl2 Nov 27, 2024
4814a62
WIP
ryanmorphl2 Nov 27, 2024
0a527a0
WIP
ryanmorphl2 Dec 4, 2024
01f4ce7
WIP
ryanmorphl2 Dec 4, 2024
811ebab
WIP
ryanmorphl2 Dec 6, 2024
bcf0b6c
WIP
ryanmorphl2 Dec 6, 2024
6c25201
compact key of storage trie node
ryanmorphl2 Dec 12, 2024
62f89aa
rawdb is not found err
ryanmorphl2 Dec 17, 2024
5bf5bcb
remove unused
ryanmorphl2 Dec 17, 2024
bafb670
Copy nodes opt
ryanmorphl2 Dec 17, 2024
7a2557b
WIP
ryanmorphl2 Dec 17, 2024
5be65e2
WIP
ryanmorphl2 Dec 17, 2024
84eaac3
copy nodes opt
ryanmorphl2 Dec 18, 2024
0beacac
WIP
ryanmorphl2 Dec 18, 2024
feb48bb
buffer: get node opt
ryanmorphl2 Dec 18, 2024
a0ed014
rename trie
ryanmorphl2 Dec 19, 2024
bba1e75
rm unused
ryanmorphl2 Dec 19, 2024
d92fee3
WIP
ryanmorphl2 Dec 19, 2024
b1210db
upgrade path zktrie
ryanmorphl2 Dec 19, 2024
c72970d
path trie proof
ryanmorphl2 Dec 19, 2024
b37cd5f
add flag --state.scheme
ryanmorphl2 Dec 19, 2024
ce557df
WIP
ryanmorphl2 Dec 19, 2024
ccd7590
WIP
ryanmorphl2 Dec 19, 2024
207825a
WIP
ryanmorphl2 Dec 19, 2024
bb12ec6
WIP
ryanmorphl2 Dec 19, 2024
6e33fa4
WIP
ryanmorphl2 Dec 20, 2024
570a566
merge main
ryanmorphl2 Dec 24, 2024
b4f0316
upgrage new trie
ryanmorphl2 Dec 26, 2024
9109d84
merge main
ryanmorphl2 Jan 2, 2025
d554540
statedb: copy with originRoot
ryanmorphl2 Jan 17, 2025
49904bf
difflayer: remove unused cache
ryanmorphl2 Jan 17, 2025
9c0f993
trie proof: mark todo
ryanmorphl2 Jan 17, 2025
6d9401f
fix typo
ryanmorphl2 Jan 19, 2025
0f62c7a
offline prune only in hash schema
ryanmorphl2 Feb 10, 2025
dea4aa8
merge main
ryanmorphl2 Feb 10, 2025
d8f08de
preimages commit
ryanmorphl2 Feb 10, 2025
6d086c5
update zktrie version
ryanmorphl2 Feb 11, 2025
eb305cb
return state not available
ryanmorphl2 Mar 4, 2025
e844e22
fix comment
ryanmorphl2 Mar 12, 2025
804cb32
flush with time interval
ryanmorphl2 Mar 14, 2025
1e734d8
flush intercal default time
ryanmorphl2 Mar 18, 2025
284315c
decrease flush intercal default time
ryanmorphl2 Mar 18, 2025
c78b876
set flush intercal default time
ryanmorphl2 Mar 25, 2025
8b62f63
add comment
ryanmorphl2 Mar 27, 2025
409206c
check scheme before using db
ryanmorphl2 Apr 1, 2025
f4cd325
fix log, set interval time
ryanmorphl2 Apr 1, 2025
8f1fd9a
fix log
ryanmorphl2 Apr 2, 2025
65ef219
merge main
ryanmorphl2 Apr 15, 2025
3eb34e6
merge main
ryanmorphl2 Apr 15, 2025
eb9937d
modify flush time logic
ryanmorphl2 Apr 22, 2025
034e32a
default use async buffer
ryanmorphl2 Apr 22, 2025
66e494e
flush with timer
ryanmorphl2 Apr 22, 2025
948d2a6
fix commit done
ryanmorphl2 Apr 22, 2025
ebf6d61
fix commit done
ryanmorphl2 Apr 22, 2025
3e97152
review pr
ryanmorphl2 Apr 22, 2025
5dbe405
set max dirtyBufferSize
ryanmorphl2 Apr 23, 2025
e6e8be9
review pr
ryanmorphl2 Apr 24, 2025
d2ec13b
merge from main
ryanmorphl2 Apr 24, 2025
a8a321c
fix: init with genesis path
ryanmorphl2 Apr 25, 2025
2005ed8
Merge remote-tracking branch 'origin/main' into ryan/pbss
Oct 9, 2025
3cef223
Merge remote-tracking branch 'origin/main' into ryan/pbss
Oct 21, 2025
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
41 changes: 41 additions & 0 deletions .github/workflows/docker_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Push Docker Image

on:
push:
tags:
- morph-v*

env:
IMAGE_NAME: go-ethereum

jobs:
# Push image to GitHub Packages.
push:
runs-on: ubuntu-latest
if: github.event_name == 'push'

steps:
- uses: actions/checkout@v4

- name: Build the Docker image
run: docker build . --file Dockerfile -t "${IMAGE_NAME}"

- name: Log into registry
run: echo "${{ secrets.PACKAGE_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin

- name: Push image
run: |
IMAGE_ID=ghcr.io/${{ github.repository }}

# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "morph-v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^morph-v//')
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:latest
docker push $IMAGE_ID:$VERSION
docker push $IMAGE_ID:latest
31 changes: 31 additions & 0 deletions MakefileEc2.mk
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,34 @@ build-bk-prod-morph-prod-mainnet-to-morph-nccc-geth:
aws s3 cp morph-nccc-geth.tar.gz s3://morph-0582-morph-technical-department-mainnet-data/morph-setup/morph-nccc-geth.tar.gz


# build for holesky
build-bk-prod-morph-prod-testnet-to-morph-geth-holesky:
if [ ! -d dist ]; then mkdir -p dist; fi
$(GORUN) build/ci.go install ./cmd/geth
cp build/bin/geth dist/
tar -czvf morph-geth.tar.gz dist
aws s3 cp morph-geth.tar.gz s3://morph-0582-morph-technical-department-testnet-data/testnet/holesky/morph-setup/morph-geth.tar.gz

build-bk-prod-morph-prod-testnet-to-morph-nccc-geth-holesky:
if [ ! -d dist ]; then mkdir -p dist; fi
$(GORUN) build/ci.go install ./cmd/geth
@echo "Done building."
cp build/bin/geth dist/
tar -czvf morph-nccc-geth.tar.gz dist
aws s3 cp morph-nccc-geth.tar.gz s3://morph-0582-morph-technical-department-testnet-data/testnet/holesky/morph-setup/morph-nccc-geth.tar.gz

build-bk-test-morph-test-qanet-to-morph-geth-qanet:
if [ ! -d dist ]; then mkdir -p dist; fi
$(GORUN) build/ci.go install ./cmd/geth
@echo "Done building."
cp build/bin/geth dist/
tar -czvf morph-geth.tar.gz dist
aws s3 cp morph-geth.tar.gz s3://morph-7637-morph-technical-department-qanet-data/morph-setup/morph-geth.tar.gz

build-bk-test-morph-test-qanet-to-morph-nccc-geth-qanet:
if [ ! -d dist ]; then mkdir -p dist; fi
$(GORUN) build/ci.go install ./cmd/geth
@echo "Done building."
cp build/bin/geth dist/
tar -czvf morph-nccc-geth.tar.gz dist
aws s3 cp morph-nccc-geth.tar.gz s3://morph-7637-morph-technical-department-qanet-data/morph-setup/morph-nccc-geth.tar.gz
3 changes: 2 additions & 1 deletion cmd/geth/chaincmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ var (
ArgsUsage: "<genesisPath>",
Flags: []cli.Flag{
utils.DataDirFlag,
utils.StateSchemeFlag,
},
Category: "BLOCKCHAIN COMMANDS",
Description: `
Expand Down Expand Up @@ -190,7 +191,7 @@ This command dumps out the state for a given block (or latest, if none provided)
// the zero'd block (i.e. genesis) or will fail hard if it can't succeed.
func initGenesis(ctx *cli.Context) error {
// Make sure we have a valid genesis JSON
genesisPath := ctx.Args().First()
genesisPath := ctx.GlobalString(utils.DataDirFlag.Name)
if len(genesisPath) == 0 {
utils.Fatalf("Must supply path to genesis JSON file")
}
Expand Down
48 changes: 48 additions & 0 deletions cmd/geth/dbcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Remove blockchain and state databases`,
dbDumpFreezerIndex,
dbImportCmd,
dbExportCmd,
dbHbss2PbssCmd,
},
}
dbInspectCmd = cli.Command{
Expand Down Expand Up @@ -254,6 +255,18 @@ WARNING: This is a low-level operation which may cause database corruption!`,
},
Description: "Exports the specified chain data to an RLP encoded stream, optionally gzip-compressed.",
}
dbHbss2PbssCmd = cli.Command{
Action: hbss2pbss,
Name: "hbss-to-pbss",
ArgsUsage: "<jobnum (optional)>",
Flags: []cli.Flag{
utils.DataDirFlag,
utils.SyncModeFlag,
utils.AncientFlag,
},
Usage: "Convert Hash-Base to Path-Base trie node.",
Description: `This command iterates the entire trie node database and convert the hash-base node to path-base node.`,
}
Comment on lines +268 to +279
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Fix argument handling or update usage text.

The command definition specifies <jobnum (optional)> in ArgsUsage, but the implementation at lines 743-746 rejects any arguments with "Too many arguments given". This inconsistency will confuse users.

Either update the implementation to accept and use the optional jobnum argument:

-	if ctx.NArg() > 0 {
+	if ctx.NArg() > 1 {
 		log.Error("Too many arguments given")
 		return errors.New("too many arguments")
 	}
+	
+	jobnum := 0
+	if ctx.NArg() == 1 {
+		var err error
+		jobnum, err = strconv.Atoi(ctx.Args().Get(0))
+		if err != nil {
+			log.Error("Invalid jobnum argument", "err", err)
+			return err
+		}
+		// TODO: Use jobnum parameter in conversion
+	}

Or remove the unused argument from the command definition:

-		ArgsUsage: "<jobnum (optional)>",
+		ArgsUsage: "",
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
dbHbss2PbssCmd = cli.Command{
Action: hbss2pbss,
Name: "hbss-to-pbss",
ArgsUsage: "<jobnum (optional)>",
Flags: []cli.Flag{
utils.DataDirFlag,
utils.SyncModeFlag,
utils.AncientFlag,
},
Usage: "Convert Hash-Base to Path-Base trie node.",
Description: `This command iterates the entire trie node database and convert the hash-base node to path-base node.`,
}
dbHbss2PbssCmd = cli.Command{
Action: hbss2pbss,
Name: "hbss-to-pbss",
ArgsUsage: "",
Flags: []cli.Flag{
utils.DataDirFlag,
utils.SyncModeFlag,
utils.AncientFlag,
},
Usage: "Convert Hash-Base to Path-Base trie node.",
Description: `This command iterates the entire trie node database and convert the hash-base node to path-base node.`,
}
🤖 Prompt for AI Agents
In cmd/geth/dbcmd.go around lines 268-279 the command's ArgsUsage advertises an
optional "<jobnum (optional)>" argument but the implementation at lines 743-746
rejects any arguments; either make the handler accept a single optional jobnum
or remove the argument from the command definition. To fix, either (A) update
the handler at ~743-746 to allow 0 or 1 args, validate and parse the single arg
as an integer and use it when running hbss2pbss (return an error if more than 1
arg), and update usage/error messages accordingly; or (B) remove the "<jobnum
(optional)>" text from ArgsUsage and any related help text so the command does
not advertise an unused argument.

)

func removeDB(ctx *cli.Context) error {
Expand Down Expand Up @@ -706,3 +719,38 @@ func exportChaindata(ctx *cli.Context) error {
db := utils.MakeChainDatabase(ctx, stack, true)
return utils.ExportChaindata(ctx.Args().Get(1), kind, exporter(db), stop)
}

func hbss2pbss(ctx *cli.Context) error {
stack, config := makeConfigNode(ctx)
defer stack.Close()

chaindb := utils.MakeChainDatabase(ctx, stack, false)
h2p, err := trie.NewHbss2Pbss(chaindb, stack.ResolvePath(""), stack.ResolvePath(config.Eth.TrieCleanCacheJournal))
if err != nil {
return err
}

if ctx.NArg() > 0 {
log.Error("Too many arguments given")
return errors.New("too many arguments")
}

lastStateID := rawdb.ReadPersistentStateID(chaindb)
if lastStateID == 0 {
h2p.Run()
}

Comment on lines +748 to +752
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Add logging for skipped conversion.

The conversion only runs when lastStateID == 0 (lines 749-751), but there's no else branch to inform users why conversion was skipped. This could lead to confusion when the command appears to succeed but doesn't perform the expected conversion.

Add an informative log message:

 	lastStateID := rawdb.ReadPersistentStateID(chaindb)
 	if lastStateID == 0 {
 		h2p.Run()
+	} else {
+		log.Info("Skipping conversion: path-based state already exists", "stateID", lastStateID)
 	}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
lastStateID := rawdb.ReadPersistentStateID(chaindb)
if lastStateID == 0 {
h2p.Run()
}
lastStateID := rawdb.ReadPersistentStateID(chaindb)
if lastStateID == 0 {
h2p.Run()
} else {
log.Info("Skipping conversion: path-based state already exists", "stateID", lastStateID)
}
🤖 Prompt for AI Agents
In cmd/geth/dbcmd.go around lines 748-752, the code only runs h2p.Run() when
lastStateID == 0 and doesn't inform the user when conversion is skipped; add an
else branch that logs an informative message (using the same logging facility
used elsewhere in this file) stating that the conversion was skipped and include
the current lastStateID value so users know why the conversion did not run.

// prune hbss trie node
err = rawdb.PruneHashTrieNodeInDataBase(chaindb)
if err != nil {
log.Error("Prune Hash trie node in database failed", "error", err)
return err
}
err = h2p.Compact()
if err != nil {
log.Error("Compact trie node failed", "error", err)
return err
}

return nil
}
2 changes: 2 additions & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ var (
utils.GpoIgnoreGasPriceFlag,
configFileFlag,
utils.CatalystFlag,
utils.StateSchemeFlag,
utils.PathDBSyncFlag,
}

rpcFlags = []cli.Flag{
Expand Down
3 changes: 3 additions & 0 deletions cmd/geth/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ func pruneZKState(ctx *cli.Context) error {
defer stack.Close()

chaindb := utils.MakeChainDatabase(ctx, stack, false)
if rawdb.ReadStateScheme(chaindb) != rawdb.HashScheme {
log.Crit("Offline pruning is not required for path scheme")
}
zkPruner, err := pruner.NewZKPruner(chaindb, ctx.GlobalUint64(utils.BloomFilterSizeFlag.Name), stack.ResolvePath(""), stack.ResolvePath(config.Eth.TrieCleanCacheJournal))
if err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions cmd/geth/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ var AppHelpFlagGroups = []flags.FlagGroup{
utils.IdentityFlag,
utils.LightKDFFlag,
utils.WhitelistFlag,
utils.StateSchemeFlag,
utils.PathDBSyncFlag,
},
},
{
Expand Down
53 changes: 53 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import (
"github.com/morph-l2/go-ethereum/params"
"github.com/morph-l2/go-ethereum/rollup/tracing"
"github.com/morph-l2/go-ethereum/rpc"
"github.com/morph-l2/go-ethereum/trie"
)

func init() {
Expand Down Expand Up @@ -851,6 +852,16 @@ var (
Name: "rpc.getlogs.maxrange",
Usage: "Limit max fetched block range for `eth_getLogs` method",
}

StateSchemeFlag = &cli.StringFlag{
Name: "state.scheme",
Usage: "Scheme to use for storing zktrie state ('hash' or 'path')",
}

PathDBSyncFlag = cli.BoolFlag{
Name: "pathdb.sync",
Usage: "Sync flush nodes cache to disk in path schema",
}
Comment on lines +873 to +876
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix terminology: "schema" → "scheme".

The usage text says "path schema" but should be "path scheme" for consistency with the state scheme terminology used throughout the codebase (e.g., StateScheme, rawdb.PathScheme, rawdb.HashScheme).

Apply this diff:

 	PathDBSyncFlag = cli.BoolFlag{
 		Name:  "pathdb.sync",
-		Usage: "Sync flush nodes cache to disk in path schema",
+		Usage: "Sync flush nodes cache to disk in path scheme",
 	}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
PathDBSyncFlag = cli.BoolFlag{
Name: "pathdb.sync",
Usage: "Sync flush nodes cache to disk in path schema",
}
PathDBSyncFlag = cli.BoolFlag{
Name: "pathdb.sync",
Usage: "Sync flush nodes cache to disk in path scheme",
}
🤖 Prompt for AI Agents
In cmd/utils/flags.go around lines 873 to 876, the Usage string for
PathDBSyncFlag uses the term "path schema" which is inconsistent with the
codebase; change "schema" to "scheme" so the Usage reads "Sync flush nodes cache
to disk in path scheme" to match terminology like StateScheme/rawdb.PathScheme.

)

// MakeDataDir retrieves the currently requested data directory, terminating
Expand Down Expand Up @@ -1718,6 +1729,19 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
cfg.EthDiscoveryURLs = SplitAndTrim(urls)
}
}
if ctx.GlobalIsSet(PathDBSyncFlag.Name) {
cfg.PathSyncFlush = true
}

scheme, err := ParseCLIAndConfigStateScheme(ctx.String(StateSchemeFlag.Name), cfg.StateScheme)
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Use ctx.GlobalString instead of ctx.String for flag access.

Line 1754 uses ctx.String(StateSchemeFlag.Name) while the rest of the file consistently uses ctx.GlobalString() for reading global flags. This inconsistency could cause the flag value to not be read correctly.

Apply this diff:

-	scheme, err := ParseCLIAndConfigStateScheme(ctx.String(StateSchemeFlag.Name), cfg.StateScheme)
+	scheme, err := ParseCLIAndConfigStateScheme(ctx.GlobalString(StateSchemeFlag.Name), cfg.StateScheme)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
scheme, err := ParseCLIAndConfigStateScheme(ctx.String(StateSchemeFlag.Name), cfg.StateScheme)
scheme, err := ParseCLIAndConfigStateScheme(ctx.GlobalString(StateSchemeFlag.Name), cfg.StateScheme)
🤖 Prompt for AI Agents
In cmd/utils/flags.go around line 1754, replace the local flag access
ctx.String(StateSchemeFlag.Name) with the global flag accessor
ctx.GlobalString(StateSchemeFlag.Name) so the code consistently reads the global
flag value (keeping the same parameter names and error handling); update that
call only to use ctx.GlobalString and ensure any surrounding code that expects
the returned string remains unchanged.

if err != nil {
Fatalf("%v", err)
}
cfg.StateScheme = scheme
if cfg.StateScheme == rawdb.PathScheme {
trie.GenesisStateInPathZkTrie = true
}
Comment on lines +1759 to +1761
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

🧩 Analysis chain

Setting global variable as a side effect may cause issues.

Setting trie.GenesisStateInPathZkTrie = true as a side effect during config setup creates hidden global state mutation. This could cause problems:

  • In tests if SetEthConfig is called multiple times
  • Makes the system harder to reason about
  • Could lead to unexpected behavior if config is reloaded

Consider whether this global should be set elsewhere (e.g., during trie initialization) or if it should be passed as a parameter rather than mutating global state.

Run the following script to check where else this global variable is accessed or modified:


🏁 Script executed:

#!/bin/bash
# Description: Find all references to GenesisStateInPathZkTrie to understand its usage pattern

rg -n "GenesisStateInPathZkTrie" --type go -C 3

Length of output: 1975


Remove redundant global state mutation from config setup.

The assignment at lines 1759-1761 duplicates identical logic already present in eth/backend.go:144-146. Config setup should not mutate global state; this responsibility belongs in backend initialization where it's already handled. Remove this assignment from cmd/utils/flags.go to eliminate the side effect.

🤖 Prompt for AI Agents
In cmd/utils/flags.go around lines 1759 to 1761, remove the redundant global
state mutation setting trie.GenesisStateInPathZkTrie = true when cfg.StateScheme
== rawdb.PathScheme; this duplicates logic already performed in eth/backend.go
(lines ~144-146) and mutates global state during config setup. Edit the file to
delete those lines so the config setup no longer changes global variables,
leaving initialization of GenesisStateInPathZkTrie exclusively in backend
initialization.


// Override any default configs for hard coded networks.
switch {
case ctx.GlobalBool(MainnetFlag.Name):
Expand Down Expand Up @@ -1765,6 +1789,11 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
// disable prefetch
log.Info("Prefetch disabled")
cfg.NoPrefetch = true

// cheked for path zktrie
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix typo: "cheked" → "checked".

The comment contains a typo that appears three times in the file (lines 1807, 1827, and 1847).

Apply this diff at line 1807:

-		// cheked for path zktrie
+		// checked for path zktrie
 		if cfg.StateScheme == rawdb.PathScheme && !cfg.Genesis.Config.Morph.ZktrieEnabled() {

Repeat the same fix at lines 1827 and 1847.

Also applies to: 1827-1827, 1847-1847

🤖 Prompt for AI Agents
In cmd/utils/flags.go at lines 1807, 1827, and 1847, there is a misspelled
comment "cheked for path zktrie" (typo: "cheked"); update each occurrence to
"checked for path zktrie" so all three comments are corrected.

if cfg.StateScheme == rawdb.PathScheme && !cfg.Genesis.Config.Morph.ZktrieEnabled() {
log.Crit("Must cooperate with zktrie enable to use --state.scheme=path")
}
case ctx.GlobalBool(MorphHoleskyFlag.Name):
if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
cfg.NetworkId = 2810
Expand All @@ -1780,6 +1809,11 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
// disable prefetch
log.Info("Prefetch disabled")
cfg.NoPrefetch = true

// cheked for path zktrie
if cfg.StateScheme == rawdb.PathScheme && !cfg.Genesis.Config.Morph.ZktrieEnabled() {
log.Crit("Must cooperate with zktrie enable to use --state.scheme=path")
}
case ctx.GlobalBool(DeveloperFlag.Name):
if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
cfg.NetworkId = 1337
Expand Down Expand Up @@ -2147,3 +2181,22 @@ func MigrateFlags(action func(ctx *cli.Context) error) func(*cli.Context) error
return action(ctx)
}
}

// ParseCLIAndConfigStateScheme parses state scheme in CLI and config.
func ParseCLIAndConfigStateScheme(cliScheme, cfgScheme string) (string, error) {
if cliScheme == "" {
if cfgScheme != "" {
log.Info("Use config state scheme", "config", cfgScheme)
}
return cfgScheme, nil
}

if !rawdb.ValidateStateScheme(cliScheme) {
return "", fmt.Errorf("invalid state scheme in CLI: %s", cliScheme)
}
if cfgScheme == "" || cliScheme == cfgScheme {
log.Info("Use CLI state scheme", "CLI", cliScheme)
return cliScheme, nil
}
return "", fmt.Errorf("incompatible state scheme, CLI: %s, config: %s", cliScheme, cfgScheme)
}
64 changes: 64 additions & 0 deletions common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ func IsHexAddress(s string) bool {
return len(s) == 2*AddressLength && isHex(s)
}

// Cmp compares two addresses.
func (a Address) Cmp(other Address) int {
return bytes.Compare(a[:], other[:])
}

// Bytes gets the string representation of the underlying address.
func (a Address) Bytes() []byte { return a[:] }

Expand Down Expand Up @@ -433,3 +438,62 @@ func (ma *MixedcaseAddress) ValidChecksum() bool {
func (ma *MixedcaseAddress) Original() string {
return ma.original
}

func ReverseBytes(b []byte) []byte {
o := make([]byte, len(b))
for i := range b {
o[len(b)-1-i] = b[i]
}
return o
}

func bitReverseForNibble(b byte) byte {
switch b {
case 0:
return 0
case 1:
return 8
case 2:
return 4
case 3:
return 12
case 4:
return 2
case 5:
return 10
case 6:
return 6
case 7:
return 14
case 8:
return 1
case 9:
return 9
case 10:
return 5
case 11:
return 13
case 12:
return 3
case 13:
return 11
case 14:
return 7
case 15:
return 15
default:
panic("unexpected input")
}
}

func BitReverse(inp []byte) (out []byte) {

l := len(inp)
out = make([]byte, l)

for i, b := range inp {
out[l-i-1] = bitReverseForNibble(b&15)<<4 + bitReverseForNibble(b>>4)
}

return
}
Loading