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 41 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
098647e
core,trie,eth,cmd: rework preimage store (#533)
huyngopt1994 Aug 19, 2024
9b7810e
trie, les, tests, core: implement trie tracer: Trie tracer is an aux…
huyngopt1994 Aug 30, 2024
8a8f0e4
all: introduce trie owner notion (#24750) (#553)
Francesco4203 Sep 4, 2024
06ad1b3
core, trie: rework trie commiter (#560)
huyngopt1994 Sep 6, 2024
df5fc51
all: rework genesis api (#567)
Francesco4203 Sep 10, 2024
26b2889
core, eth: port snap sync changes (#564)
Francesco4203 Sep 11, 2024
8644337
core/rawdb: the ancient store implementing is now exported in package…
huyngopt1994 Sep 13, 2024
afc5060
Change ancient chain segments from root ancient to sub folders (#572)
huyngopt1994 Sep 13, 2024
468e247
all: move genesis init to blockchain (#570)
Francesco4203 Sep 16, 2024
d9bf4b0
Make db inspector for extending multiple ancient stores (#574)
huyngopt1994 Sep 18, 2024
6de49a5
rawdb,ethdb,eth: implement freezer tail deletion and use atomic refer…
huyngopt1994 Sep 19, 2024
44d3f93
core,eth,tests,trie: abstract node scheme, and contruct database (#578)
huyngopt1994 Sep 25, 2024
d3f93f9
cmd, core, eth, trie: track deleted nodes (#576)
Francesco4203 Sep 25, 2024
1b936fa
all: prep for path-based trie storage (#582)
Francesco4203 Sep 26, 2024
e844c32
trie: implement NodeBlob api for trie iterator (#584)
Francesco4203 Sep 26, 2024
11e077b
trie: refactor tracer (#581)
Francesco4203 Sep 26, 2024
0ded46b
eth/protocols/snap: fix batch writer when resuming an aborted sync (#…
huyngopt1994 Sep 27, 2024
56eb323
trie: rework trie database (#585)
Francesco4203 Sep 30, 2024
97ccc2e
trie: add trie db wrapper; refactor trienode (#588)
Francesco4203 Oct 1, 2024
1287e48
trie, core: track state changes in statedb (#589)
Francesco4203 Oct 3, 2024
bcfeb7e
all: remove trie cache journal (#595)
huyngopt1994 Oct 4, 2024
8759d46
core, trie: Expose block number to statedb (#593)
Francesco4203 Oct 4, 2024
211f9ae
final implementing path base (#591)
huyngopt1994 Oct 10, 2024
e18619a
trie: remove nodes method and add diskdb method for consistency with …
Francesco4203 Oct 11, 2024
8031359
all: reworkNodeResolver for working with multiple state schemes with …
huyngopt1994 Oct 15, 2024
cf4a752
trie: fix issue insert wrong path in stack trie and remove the offset…
huyngopt1994 Oct 17, 2024
3ea219b
all: enable pbss (#600)
Francesco4203 Oct 18, 2024
a5d7f7b
Fix missing passing scheme when init genesis and avoid referencing sa…
huyngopt1994 Oct 25, 2024
d912955
core, eth/downloader: pbss fix release v1.13.1 (#614)
Francesco4203 Oct 25, 2024
92a5166
rlp, trie: faster trie node encoding (#24126) (#606)
minh-bq Oct 29, 2024
1af8129
core, accounts, eth, trie: pbss fix release v1.13.2 (#615)
Francesco4203 Oct 29, 2024
17113e8
trie/triedb/pathdb, core/rawdb: pbss fix release v1.13.5 (corner-case…
Francesco4203 Oct 29, 2024
6c0bfbf
cmd/ronin/chaincmd: open ancient freezer when init genesis (#620)
Francesco4203 Oct 30, 2024
d1e7874
[docker] remove duplicate param in entrypoint.sh
huyngopt1994 Oct 31, 2024
4700b40
consensus: get Validators from genesis instead of triedb in v1 consor…
huyngopt1994 Nov 1, 2024
6e71b46
cmd,rawdb: avoid extend Tail method in chainfreezer which make db ins…
huyngopt1994 Nov 7, 2024
63c0e37
trie: pbss fix release v1.13.5 continue (#621)
Francesco4203 Nov 8, 2024
fa4a087
core, triedb/pathdb: pbss fix release v1.13.8 (continue) and v1.14.0 …
Francesco4203 Nov 8, 2024
8b1fa06
protocols/snap/sync_test: each peer have a different account trie (#628)
Francesco4203 Nov 9, 2024
935aa9d
core, cmd, trie: pbss fix release v1.13.6 and v1.13.8 (#618)
Francesco4203 Nov 11, 2024
190f2ff
v2/consortium_test: fix for pbss: do not insert inserted blocks (#613)
Francesco4203 Nov 14, 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
20 changes: 11 additions & 9 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 Expand Up @@ -180,7 +181,6 @@ func (b *SimulatedBackend) CodeAt(ctx context.Context, contract common.Address,
if err != nil {
return nil, err
}

return stateDB.GetCode(contract), nil
}

Expand All @@ -193,7 +193,6 @@ func (b *SimulatedBackend) BalanceAt(ctx context.Context, contract common.Addres
if err != nil {
return nil, err
}

return stateDB.GetBalance(contract), nil
}

Expand All @@ -206,7 +205,6 @@ func (b *SimulatedBackend) NonceAt(ctx context.Context, contract common.Address,
if err != nil {
return 0, err
}

return stateDB.GetNonce(contract), nil
}

Expand All @@ -219,7 +217,6 @@ func (b *SimulatedBackend) StorageAt(ctx context.Context, contract common.Addres
if err != nil {
return nil, err
}

val := stateDB.GetState(contract, key)
return val[:], nil
}
Expand Down Expand Up @@ -666,7 +663,10 @@ func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx *types.Transa
}
block.AddTxWithChain(b.blockchain, tx)
}, true)
stateDB, _ := b.blockchain.State()
stateDB, err := b.blockchain.State()
if err != nil {
return err
}

b.pendingBlock = blocks[0]
b.pendingState, _ = state.New(b.pendingBlock.Root(), stateDB.Database(), nil)
Expand Down Expand Up @@ -781,11 +781,13 @@ func (b *SimulatedBackend) AdjustTime(adjustment time.Duration) error {
blocks, _ := core.GenerateChain(b.config, b.blockchain.CurrentBlock(), ethash.NewFaker(), b.database, 1, func(number int, block *core.BlockGen) {
block.OffsetTime(int64(adjustment.Seconds()))
}, true)
stateDB, _ := b.blockchain.State()
stateDB, err := b.blockchain.State()
if err != nil {
return err
}

b.pendingBlock = blocks[0]
b.pendingState, _ = state.New(b.pendingBlock.Root(), stateDB.Database(), nil)

return nil
}

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
3 changes: 1 addition & 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 All @@ -101,6 +99,7 @@ func setupGeth(stack *node.Node) error {
if err != nil {
return err
}
backend.SetSynced()

_, err = backend.BlockChain().InsertChain(chain.blocks[1:], nil)
return err
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
21 changes: 17 additions & 4 deletions cmd/ronin/chaincmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ var (
utils.DataDirFlag,
utils.DBEngineFlag,
utils.ForceOverrideChainConfigFlag,
utils.CachePreimagesFlag,
utils.StateSchemeFlag,
utils.AncientFlag,
},
Category: "BLOCKCHAIN COMMANDS",
Description: `
Expand Down Expand Up @@ -105,6 +108,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 +130,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 @@ -220,15 +227,18 @@ func initGenesis(ctx *cli.Context) error {
defer stack.Close()

for _, name := range []string{"chaindata", "lightchaindata"} {
chaindb, err := stack.OpenDatabase(name, 0, 0, "", false)
chaindb, err := stack.OpenDatabaseWithFreezer(name, 0, 0, ctx.String(utils.AncientFlag.Name), "", false)
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 +476,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