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

Path base Implementing #534

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
f83cfea
core,trie,eth,cmd: rework preimage store (#533)
huyngopt1994 Aug 19, 2024
a230f8d
trie, les, tests, core: implement trie tracer: Trie tracer is an aux…
huyngopt1994 Aug 30, 2024
7fdc964
all: introduce trie owner notion (#24750) (#553)
Francesco4203 Sep 4, 2024
5551e70
core, trie: rework trie commiter (#560)
huyngopt1994 Sep 6, 2024
300f75a
all: rework genesis api (#567)
Francesco4203 Sep 10, 2024
5467a36
core, eth: port snap sync changes (#564)
Francesco4203 Sep 11, 2024
59cbb40
core/rawdb: the ancient store implementing is now exported in package…
huyngopt1994 Sep 13, 2024
0deff47
Change ancient chain segments from root ancient to sub folders (#572)
huyngopt1994 Sep 13, 2024
ca1f046
all: move genesis init to blockchain (#570)
Francesco4203 Sep 16, 2024
a16a5d0
Make db inspector for extending multiple ancient stores (#574)
huyngopt1994 Sep 18, 2024
ca6e07f
rawdb,ethdb,eth: implement freezer tail deletion and use atomic refer…
huyngopt1994 Sep 19, 2024
5e601cf
core,eth,tests,trie: abstract node scheme, and contruct database (#578)
huyngopt1994 Sep 25, 2024
0425ed6
cmd, core, eth, trie: track deleted nodes (#576)
Francesco4203 Sep 25, 2024
85a2478
all: prep for path-based trie storage (#582)
Francesco4203 Sep 26, 2024
ea86791
trie: implement NodeBlob api for trie iterator (#584)
Francesco4203 Sep 26, 2024
0698ab0
trie: refactor tracer (#581)
Francesco4203 Sep 26, 2024
6c75343
eth/protocols/snap: fix batch writer when resuming an aborted sync (#…
huyngopt1994 Sep 27, 2024
c01ed5d
trie: rework trie database (#585)
Francesco4203 Sep 30, 2024
98d4d75
trie: add trie db wrapper; refactor trienode (#588)
Francesco4203 Oct 1, 2024
bbeb4e8
trie, core: track state changes in statedb (#589)
Francesco4203 Oct 3, 2024
a51c7b3
all: remove trie cache journal (#595)
huyngopt1994 Oct 4, 2024
e54d241
core, trie: Expose block number to statedb (#593)
Francesco4203 Oct 4, 2024
3cc69e7
final implementing path base (#591)
huyngopt1994 Oct 10, 2024
1160193
trie: remove nodes method and add diskdb method for consistency with …
Francesco4203 Oct 11, 2024
2dc7abe
all: reworkNodeResolver for working with multiple state schemes with …
huyngopt1994 Oct 15, 2024
b78c647
trie: fix issue insert wrong path in stack trie and remove the offset…
huyngopt1994 Oct 17, 2024
9a82eae
all: enable pbss (#600)
Francesco4203 Oct 18, 2024
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
1 change: 1 addition & 0 deletions .github/workflows/test-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
pull_request:
branches:
- master
- path-base-implementing

concurrency:
group: ${{ github.head_ref || github.run_id }}
Expand Down
5 changes: 3 additions & 2 deletions accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/trie"
)

// This nil assignment ensures at compile time that SimulatedBackend implements bind.ContractBackend.
Expand Down Expand Up @@ -77,8 +78,8 @@ type SimulatedBackend struct {
// A simulated backend always uses chainID 1337.
func NewSimulatedBackendWithDatabase(database ethdb.Database, alloc core.GenesisAlloc, gasLimit uint64) *SimulatedBackend {
genesis := core.Genesis{Config: params.AllEthashProtocolChanges, GasLimit: gasLimit, Alloc: alloc}
genesis.MustCommit(database)
blockchain, _ := core.NewBlockChain(database, nil, genesis.Config, ethash.NewFaker(), vm.Config{}, nil, nil)
genesis.MustCommit(database, trie.NewDatabase(database, trie.HashDefaults))
blockchain, _ := core.NewBlockChain(database, nil, &genesis, nil, ethash.NewFaker(), vm.Config{}, nil, nil)

backend := &SimulatedBackend{
database: database,
Expand Down
2 changes: 1 addition & 1 deletion cmd/devp2p/internal/ethtest/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func loadChain(chainfile string, genesis string) (*Chain, error) {
if err != nil {
return nil, err
}
gblock := gen.ToBlock(nil)
gblock := gen.ToBlock()

blocks, err := blocksFromFile(chainfile, gblock)
if err != nil {
Expand Down
2 changes: 0 additions & 2 deletions cmd/devp2p/internal/ethtest/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ func setupGeth(stack *node.Node) error {
Genesis: &chain.genesis,
NetworkId: chain.genesis.Config.ChainID.Uint64(), // 19763
DatabaseCache: 10,
TrieCleanCache: 10,
TrieCleanCacheJournal: "",
TrieCleanCacheRejournal: 60 * time.Minute,
TrieDirtyCache: 16,
TrieTimeout: 60 * time.Minute,
Expand Down
12 changes: 9 additions & 3 deletions cmd/evm/internal/t8ntool/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
statedb.AddBalance(pre.Env.Coinbase, minerReward)
}
// Commit block
root, err := statedb.Commit(chainConfig.IsEIP158(vmContext.BlockNumber))
root, err := statedb.Commit(vmContext.BlockNumber.Uint64(), chainConfig.IsEIP158(vmContext.BlockNumber))
if err != nil {
fmt.Fprintf(os.Stderr, "Could not commit state: %v", err)
return nil, nil, NewError(ErrorEVM, fmt.Errorf("could not commit state: %v", err))
Expand All @@ -258,11 +258,17 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
Difficulty: (*math.HexOrDecimal256)(vmContext.Difficulty),
GasUsed: (math.HexOrDecimal64)(gasUsed),
}
// Re-create statedb instance with new root upon the updated database
// for accessing latest states.
statedb, err = state.New(root, statedb.Database(), nil)
if err != nil {
return nil, nil, NewError(ErrorEVM, fmt.Errorf("could not reopen state: %v", err))
}
return statedb, execRs, nil
}

func MakePreState(db ethdb.Database, accounts core.GenesisAlloc) *state.StateDB {
sdb := state.NewDatabase(db)
sdb := state.NewDatabaseWithConfig(db, &trie.Config{Preimages: true})
statedb, _ := state.New(common.Hash{}, sdb, nil)
for addr, a := range accounts {
statedb.SetCode(addr, a.Code)
Expand All @@ -273,7 +279,7 @@ func MakePreState(db ethdb.Database, accounts core.GenesisAlloc) *state.StateDB
}
}
// Commit and re-open to start with a clean state.
root, _ := statedb.Commit(false)
root, _ := statedb.Commit(0, false)
statedb, _ = state.New(root, sdb, nil)
return statedb
}
Expand Down
27 changes: 21 additions & 6 deletions cmd/evm/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/ethereum/go-ethereum/eth/tracers/logger"
"github.com/ethereum/go-ethereum/internal/flags"
"io/ioutil"
"math/big"
"os"
Expand All @@ -30,12 +28,18 @@ import (
"testing"
"time"

"github.com/ethereum/go-ethereum/eth/tracers/logger"
"github.com/ethereum/go-ethereum/internal/flags"
"github.com/ethereum/go-ethereum/trie"
"github.com/ethereum/go-ethereum/trie/triedb/hashdb"

"github.com/ethereum/go-ethereum/cmd/evm/internal/compiler"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/core/vm/runtime"
"github.com/ethereum/go-ethereum/log"
Expand Down Expand Up @@ -138,11 +142,22 @@ func runCmd(ctx *cli.Context) error {
gen := readGenesis(ctx.String(GenesisFlag.Name))
genesisConfig = gen
db := rawdb.NewMemoryDatabase()
genesis := gen.ToBlock(db)
statedb, _ = state.New(genesis.Root(), state.NewDatabase(db), nil)
triedb := trie.NewDatabase(db, &trie.Config{
HashDB: hashdb.Defaults,
})
defer triedb.Close()
genesis := gen.MustCommit(db, triedb)
sdb := state.NewDatabaseWithNodeDB(db, triedb)
statedb, _ = state.New(genesis.Root(), sdb, nil)
chainConfig = gen.Config
} else {
statedb, _ = state.New(common.Hash{}, state.NewDatabase(rawdb.NewMemoryDatabase()), nil)
db := rawdb.NewMemoryDatabase()
triedb := trie.NewDatabase(db, &trie.Config{
HashDB: hashdb.Defaults,
})
defer triedb.Close()
sdb := state.NewDatabaseWithNodeDB(db, triedb)
statedb, _ = state.New(types.EmptyRootHash, sdb, nil)
genesisConfig = new(core.Genesis)
}
if ctx.String(SenderFlag.Name) != "" {
Expand Down Expand Up @@ -269,7 +284,7 @@ func runCmd(ctx *cli.Context) error {
output, leftOverGas, stats, err := timedExec(bench, execFunc)

if ctx.Bool(DumpFlag.Name) {
statedb.Commit(true)
statedb.Commit(0, true)
statedb.IntermediateRoot(true)
fmt.Println(string(statedb.Dump(nil)))
}
Expand Down
30 changes: 17 additions & 13 deletions cmd/evm/staterunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/ethereum/go-ethereum/eth/tracers/logger"
"io/ioutil"
"os"

"github.com/ethereum/go-ethereum/eth/tracers/logger"

"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/state/snapshot"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/tests"
Expand Down Expand Up @@ -96,21 +99,22 @@ func stateTestCmd(ctx *cli.Context) error {
results := make([]StatetestResult, 0, len(tests))
for key, test := range tests {
for _, st := range test.Subtests() {
dump := ctx.Bool(DumpFlag.Name)
// Run the test and aggregate the result
result := &StatetestResult{Name: key, Fork: st.Fork, Pass: true}
_, s, err := test.Run(st, cfg, false)
// print state root for evmlab tracing
if ctx.Bool(MachineFlag.Name) && s != nil {
fmt.Fprintf(os.Stderr, "{\"stateRoot\": \"%x\"}\n", s.IntermediateRoot(false))
}
if err != nil {
// Test failed, mark as so and dump any state to aid debugging
result.Pass, result.Error = false, err.Error()
if ctx.Bool(DumpFlag.Name) && s != nil {
dump := s.RawDump(nil)
result.State = &dump
test.Run(st, cfg, false, rawdb.HashScheme, func(err error, snaps *snapshot.Tree, state *state.StateDB) {
if err != nil {
// Test failed, mark as so and dump any state to aid debugging
result.Pass, result.Error = false, err.Error()
if dump {
dump := state.RawDump(nil)
result.State = &dump
}
}
}
if ctx.Bool(MachineFlag.Name) && state != nil {
fmt.Fprintf(os.Stderr, "{\"stateRoot\": \"%x\"}\n", state.IntermediateRoot(false))
}
})

results = append(results, *result)

Expand Down
2 changes: 1 addition & 1 deletion cmd/faucet/faucet.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func newFaucet(genesis *core.Genesis, port int, enodes []*enode.Node, network ui
cfg.SyncMode = downloader.LightSync
cfg.NetworkId = network
cfg.Genesis = genesis
utils.SetDNSDiscoveryDefaults(&cfg, genesis.ToBlock(nil).Hash())
utils.SetDNSDiscoveryDefaults(&cfg, genesis.ToBlock().Hash())

lesBackend, err := les.New(stack, &cfg)
if err != nil {
Expand Down
18 changes: 15 additions & 3 deletions cmd/ronin/chaincmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ var (
utils.DataDirFlag,
utils.DBEngineFlag,
utils.ForceOverrideChainConfigFlag,
utils.CachePreimagesFlag,
utils.StateSchemeFlag,
},
Category: "BLOCKCHAIN COMMANDS",
Description: `
Expand Down Expand Up @@ -105,6 +107,9 @@ The dumpgenesis command dumps the genesis block configuration in JSON format to
utils.MetricsInfluxDBBucketFlag,
utils.MetricsInfluxDBOrganizationFlag,
utils.TxLookupLimitFlag,
utils.TransactionHistoryFlag,
utils.StateSchemeFlag,
utils.StateHistoryFlag,
},
Category: "BLOCKCHAIN COMMANDS",
Description: `
Expand All @@ -124,6 +129,7 @@ processing will proceed even if an individual RLP-file import failure occurs.`,
utils.DBEngineFlag,
utils.CacheFlag,
utils.SyncModeFlag,
utils.StateSchemeFlag,
},
Category: "BLOCKCHAIN COMMANDS",
Description: `
Expand Down Expand Up @@ -224,11 +230,14 @@ func initGenesis(ctx *cli.Context) error {
if err != nil {
utils.Fatalf("Failed to open database: %v", err)
}
_, hash, err := core.SetupGenesisBlock(chaindb, genesis, overrideChainConfig)
// Create triedb firstly

triedb := utils.MakeTrieDatabase(ctx, chaindb, ctx.Bool(utils.CachePreimagesFlag.Name), false)
defer chaindb.Close()
_, hash, err := core.SetupGenesisBlock(chaindb, triedb, genesis, overrideChainConfig)
if err != nil {
utils.Fatalf("Failed to write genesis block: %v", err)
}
chaindb.Close()
log.Info("Successfully wrote genesis state", "database", name, "hash", hash)
}
return nil
Expand Down Expand Up @@ -466,7 +475,10 @@ func dump(ctx *cli.Context) error {
if err != nil {
return err
}
state, err := state.New(root, state.NewDatabase(db), nil)
triedb := utils.MakeTrieDatabase(ctx, db, true, false) // always enable preimage lookup
defer triedb.Close()
state, err := state.New(root, state.NewDatabaseWithNodeDB(db, triedb), nil)

if err != nil {
return err
}
Expand Down
4 changes: 4 additions & 0 deletions cmd/ronin/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,10 @@ func deprecated(field string) bool {
return true
case "ethconfig.Config.EWASMInterpreter":
return true
case "ethconfig.Config.TrieCleanCacheJournal":
return true
case "ethconfig.Config.TrieCleanCacheRejournal":
return true
default:
return false
}
Expand Down
Loading
Loading