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

pbss implemention #161

Open
wants to merge 46 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
46 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
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)
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Changed source of genesis path - possible regression

The change from using ctx.Args().First() to ctx.GlobalString(utils.DataDirFlag.Name) for retrieving the genesis path is significant. This changes the expected input from a direct argument to a global flag value, which might cause confusion or backward compatibility issues.

This change appears to be incorrect. The DataDirFlag typically points to the Ethereum data directory, not the genesis JSON file path. Check whether this change was intentional or if it should continue to use the first argument as the genesis file path:


🏁 Script executed:

#!/bin/bash
# Check if the usage of DataDirFlag instead of the first argument is intentional
# by examining the help text and other uses of DataDirFlag in the codebase

# First, look at the help text of the initCommand
grep -A 10 "ArgsUsage" cmd/geth/chaincmd.go | head -n 5

# Then, check how DataDirFlag is described in flags.go
grep -A 5 "DataDirFlag" cmd/utils/flags.go | grep "Usage"

# Look for similar patterns in other command implementations
grep -A 2 "ctx.Args().First()" cmd/geth/chaincmd.go

Length of output: 872


Action Required: Revert Genesis Path Retrieval to Use Command Argument

The current change uses the data directory flag (ctx.GlobalString(utils.DataDirFlag.Name)) to obtain the genesis file path, which contradicts the command’s documented usage of <genesisPath>. Other parts of the codebase consistently use ctx.Args().First() for file path retrieval, confirming that the intended behavior is to use the first argument.

  • File: cmd/geth/chaincmd.go at line 194
  • Issue: Using DataDirFlag (intended for specifying the data directory) as the source for the genesis JSON file path is misleading and may break backward compatibility.
  • Snippet Recommendation:
    - genesisPath := ctx.GlobalString(utils.DataDirFlag.Name)
    + genesisPath := ctx.Args().First()

Please review whether this change was intentional. If not, revert to using ctx.Args().First() to align with both the command’s usage documentation and similar implementations elsewhere in the code.

📝 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
genesisPath := ctx.GlobalString(utils.DataDirFlag.Name)
genesisPath := ctx.Args().First()

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.`,
}
)

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()
}

// 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",
}
)

// 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)
if err != nil {
Fatalf("%v", err)
}
cfg.StateScheme = scheme
if cfg.StateScheme == rawdb.PathScheme {
trie.GenesisStateInPathZkTrie = true
}

// 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
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