mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 21:56:43 +00:00
don't store conversion state in genesis db in this PR
Signed-off-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com> Co-authored-by: Gary Rong <garyrong0905@gmail.com>
This commit is contained in:
parent
86183a8373
commit
a483135b2b
6 changed files with 41 additions and 45 deletions
|
|
@ -581,7 +581,6 @@ func GenerateVerkleChain(config *params.ChainConfig, parent *types.Block, engine
|
||||||
|
|
||||||
func GenerateVerkleChainWithGenesis(genesis *Genesis, engine consensus.Engine, n int, gen func(int, *BlockGen)) (common.Hash, ethdb.Database, []*types.Block, []types.Receipts, []*verkle.VerkleProof, []verkle.StateDiff) {
|
func GenerateVerkleChainWithGenesis(genesis *Genesis, engine consensus.Engine, n int, gen func(int, *BlockGen)) (common.Hash, ethdb.Database, []*types.Block, []types.Receipts, []*verkle.VerkleProof, []verkle.StateDiff) {
|
||||||
db := rawdb.NewMemoryDatabase()
|
db := rawdb.NewMemoryDatabase()
|
||||||
saveVerkleTransitionStatusAtVerlkeGenesis(db)
|
|
||||||
cacheConfig := DefaultConfig().WithStateScheme(rawdb.PathScheme)
|
cacheConfig := DefaultConfig().WithStateScheme(rawdb.PathScheme)
|
||||||
cacheConfig.SnapshotLimit = 0
|
cacheConfig.SnapshotLimit = 0
|
||||||
triedb := triedb.NewDatabase(db, cacheConfig.triedbConfig(true))
|
triedb := triedb.NewDatabase(db, cacheConfig.triedbConfig(true))
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/gob"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
@ -146,9 +145,6 @@ func hashAlloc(ga *types.GenesisAlloc, isVerkle bool) (common.Hash, error) {
|
||||||
emptyRoot = types.EmptyVerkleHash
|
emptyRoot = types.EmptyVerkleHash
|
||||||
}
|
}
|
||||||
db := rawdb.NewMemoryDatabase()
|
db := rawdb.NewMemoryDatabase()
|
||||||
if isVerkle {
|
|
||||||
saveVerkleTransitionStatusAtVerlkeGenesis(db)
|
|
||||||
}
|
|
||||||
statedb, err := state.New(emptyRoot, state.NewDatabase(triedb.NewDatabase(db, config), nil))
|
statedb, err := state.New(emptyRoot, state.NewDatabase(triedb.NewDatabase(db, config), nil))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return common.Hash{}, err
|
return common.Hash{}, err
|
||||||
|
|
@ -280,24 +276,6 @@ func (o *ChainOverrides) apply(cfg *params.ChainConfig) error {
|
||||||
return cfg.CheckConfigForkOrder()
|
return cfg.CheckConfigForkOrder()
|
||||||
}
|
}
|
||||||
|
|
||||||
// saveVerkleTransitionStatusAtVerlkeGenesis saves a conversion marker
|
|
||||||
// representing a converted state, which is used in devnets that activate
|
|
||||||
// verkle at genesis.
|
|
||||||
func saveVerkleTransitionStatusAtVerlkeGenesis(db ethdb.Database) {
|
|
||||||
saveVerkleTransitionStatus(db, common.Hash{}, &state.TransitionState{Ended: true})
|
|
||||||
}
|
|
||||||
|
|
||||||
func saveVerkleTransitionStatus(db ethdb.Database, root common.Hash, ts *state.TransitionState) {
|
|
||||||
var buf bytes.Buffer
|
|
||||||
enc := gob.NewEncoder(&buf)
|
|
||||||
err := enc.Encode(ts)
|
|
||||||
if err != nil {
|
|
||||||
log.Error("failed to encode transition state", "err", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
rawdb.WriteVerkleTransitionState(db, root, buf.Bytes())
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetupGenesisBlock writes or updates the genesis block in db.
|
// SetupGenesisBlock writes or updates the genesis block in db.
|
||||||
// The block that will be used is:
|
// The block that will be used is:
|
||||||
//
|
//
|
||||||
|
|
@ -321,11 +299,6 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, triedb *triedb.Database, g
|
||||||
if genesis != nil && genesis.Config == nil {
|
if genesis != nil && genesis.Config == nil {
|
||||||
return nil, common.Hash{}, nil, errGenesisNoConfig
|
return nil, common.Hash{}, nil, errGenesisNoConfig
|
||||||
}
|
}
|
||||||
// In case of verkle-at-genesis, we need to ensure that the conversion
|
|
||||||
// markers are indicating that the conversion has completed.
|
|
||||||
if genesis != nil && genesis.Config.VerkleTime != nil && *genesis.Config.VerkleTime == genesis.Timestamp {
|
|
||||||
saveVerkleTransitionStatusAtVerlkeGenesis(db)
|
|
||||||
}
|
|
||||||
// Commit the genesis if the database is empty
|
// Commit the genesis if the database is empty
|
||||||
ghash := rawdb.ReadCanonicalHash(db, 0)
|
ghash := rawdb.ReadCanonicalHash(db, 0)
|
||||||
if (ghash == common.Hash{}) {
|
if (ghash == common.Hash{}) {
|
||||||
|
|
@ -473,7 +446,7 @@ func (g *Genesis) chainConfigOrDefault(ghash common.Hash, stored *params.ChainCo
|
||||||
// IsVerkle indicates whether the state is already stored in a verkle
|
// IsVerkle indicates whether the state is already stored in a verkle
|
||||||
// tree at genesis time.
|
// tree at genesis time.
|
||||||
func (g *Genesis) IsVerkle() bool {
|
func (g *Genesis) IsVerkle() bool {
|
||||||
return g != nil && g.Config != nil && g.Config.VerkleTime != nil && *g.Config.VerkleTime == g.Timestamp
|
return g.Config.IsVerkleGenesis()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToBlock returns the genesis block according to genesis specification.
|
// ToBlock returns the genesis block according to genesis specification.
|
||||||
|
|
@ -577,9 +550,6 @@ func (g *Genesis) Commit(db ethdb.Database, triedb *triedb.Database) (*types.Blo
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if g.IsVerkle() {
|
|
||||||
saveVerkleTransitionStatus(db, block.Root(), &state.TransitionState{Ended: true})
|
|
||||||
}
|
|
||||||
batch := db.NewBatch()
|
batch := db.NewBatch()
|
||||||
rawdb.WriteGenesisStateSpec(batch, block.Hash(), blob)
|
rawdb.WriteGenesisStateSpec(batch, block.Hash(), blob)
|
||||||
rawdb.WriteBlock(batch, block)
|
rawdb.WriteBlock(batch, block)
|
||||||
|
|
|
||||||
|
|
@ -287,6 +287,7 @@ func TestVerkleGenesisCommit(t *testing.T) {
|
||||||
OsakaTime: &verkleTime,
|
OsakaTime: &verkleTime,
|
||||||
VerkleTime: &verkleTime,
|
VerkleTime: &verkleTime,
|
||||||
TerminalTotalDifficulty: big.NewInt(0),
|
TerminalTotalDifficulty: big.NewInt(0),
|
||||||
|
EnableVerkleAtGenesis: true,
|
||||||
Ethash: nil,
|
Ethash: nil,
|
||||||
Clique: nil,
|
Clique: nil,
|
||||||
BlobScheduleConfig: ¶ms.BlobScheduleConfig{
|
BlobScheduleConfig: ¶ms.BlobScheduleConfig{
|
||||||
|
|
@ -314,7 +315,6 @@ func TestVerkleGenesisCommit(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
db := rawdb.NewMemoryDatabase()
|
db := rawdb.NewMemoryDatabase()
|
||||||
saveVerkleTransitionStatusAtVerlkeGenesis(db)
|
|
||||||
config := *pathdb.Defaults
|
config := *pathdb.Defaults
|
||||||
config.NoAsyncFlush = true
|
config.NoAsyncFlush = true
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -276,6 +276,7 @@ func (db *CachingDB) ReadersWithCacheStats(stateRoot common.Hash) (ReaderWithSta
|
||||||
|
|
||||||
// OpenTrie opens the main account trie at a specific root hash.
|
// OpenTrie opens the main account trie at a specific root hash.
|
||||||
func (db *CachingDB) OpenTrie(root common.Hash) (Trie, error) {
|
func (db *CachingDB) OpenTrie(root common.Hash) (Trie, error) {
|
||||||
|
if db.triedb.IsVerkle() {
|
||||||
ts := db.LoadTransitionState(root)
|
ts := db.LoadTransitionState(root)
|
||||||
if ts.InTransition() {
|
if ts.InTransition() {
|
||||||
panic("transition isn't supported yet")
|
panic("transition isn't supported yet")
|
||||||
|
|
@ -283,6 +284,7 @@ func (db *CachingDB) OpenTrie(root common.Hash) (Trie, error) {
|
||||||
if ts.Transitioned() {
|
if ts.Transitioned() {
|
||||||
return trie.NewVerkleTrie(root, db.triedb, db.pointCache)
|
return trie.NewVerkleTrie(root, db.triedb, db.pointCache)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
tr, err := trie.NewStateTrie(trie.StateTrieID(root), db.triedb)
|
tr, err := trie.NewStateTrie(trie.StateTrieID(root), db.triedb)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -292,11 +294,7 @@ func (db *CachingDB) OpenTrie(root common.Hash) (Trie, error) {
|
||||||
|
|
||||||
// OpenStorageTrie opens the storage trie of an account.
|
// OpenStorageTrie opens the storage trie of an account.
|
||||||
func (db *CachingDB) OpenStorageTrie(stateRoot common.Hash, address common.Address, root common.Hash, self Trie) (Trie, error) {
|
func (db *CachingDB) OpenStorageTrie(stateRoot common.Hash, address common.Address, root common.Hash, self Trie) (Trie, error) {
|
||||||
ts := db.LoadTransitionState(stateRoot)
|
if db.triedb.IsVerkle() {
|
||||||
// In the verkle case, there is only one tree. But the two-tree structure
|
|
||||||
// is hardcoded in the codebase. So we need to return the same trie in this
|
|
||||||
// case.
|
|
||||||
if ts.InTransition() || ts.Transitioned() {
|
|
||||||
return self, nil
|
return self, nil
|
||||||
}
|
}
|
||||||
tr, err := trie.NewStateTrie(trie.StorageTrieID(stateRoot, crypto.Keccak256Hash(address.Bytes()), root), db.triedb)
|
tr, err := trie.NewStateTrie(trie.StorageTrieID(stateRoot, crypto.Keccak256Hash(address.Bytes()), root), db.triedb)
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,7 @@ var (
|
||||||
ShanghaiTime: u64(0),
|
ShanghaiTime: u64(0),
|
||||||
VerkleTime: u64(0),
|
VerkleTime: u64(0),
|
||||||
TerminalTotalDifficulty: common.Big0,
|
TerminalTotalDifficulty: common.Big0,
|
||||||
|
EnableVerkleAtGenesis: true,
|
||||||
BlobScheduleConfig: ¶ms.BlobScheduleConfig{
|
BlobScheduleConfig: ¶ms.BlobScheduleConfig{
|
||||||
Verkle: params.DefaultPragueBlobConfig,
|
Verkle: params.DefaultPragueBlobConfig,
|
||||||
},
|
},
|
||||||
|
|
@ -82,6 +83,7 @@ var (
|
||||||
ShanghaiTime: u64(0),
|
ShanghaiTime: u64(0),
|
||||||
VerkleTime: u64(0),
|
VerkleTime: u64(0),
|
||||||
TerminalTotalDifficulty: common.Big0,
|
TerminalTotalDifficulty: common.Big0,
|
||||||
|
EnableVerkleAtGenesis: true,
|
||||||
BlobScheduleConfig: ¶ms.BlobScheduleConfig{
|
BlobScheduleConfig: ¶ms.BlobScheduleConfig{
|
||||||
Verkle: params.DefaultPragueBlobConfig,
|
Verkle: params.DefaultPragueBlobConfig,
|
||||||
},
|
},
|
||||||
|
|
@ -209,7 +211,7 @@ func TestProcessVerkle(t *testing.T) {
|
||||||
t.Fatalf("block %d imported with error: %v", endnum, err)
|
t.Fatalf("block %d imported with error: %v", endnum, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < 2; i++ {
|
for i := range 2 {
|
||||||
b := blockchain.GetBlockByNumber(uint64(i) + 1)
|
b := blockchain.GetBlockByNumber(uint64(i) + 1)
|
||||||
if b == nil {
|
if b == nil {
|
||||||
t.Fatalf("expected block %d to be present in chain", i+1)
|
t.Fatalf("expected block %d to be present in chain", i+1)
|
||||||
|
|
|
||||||
|
|
@ -423,6 +423,19 @@ type ChainConfig struct {
|
||||||
|
|
||||||
DepositContractAddress common.Address `json:"depositContractAddress,omitempty"`
|
DepositContractAddress common.Address `json:"depositContractAddress,omitempty"`
|
||||||
|
|
||||||
|
// EnableVerkleAtGenesis is a flag that specifies whether the network uses
|
||||||
|
// the Verkle tree starting from the genesis block. If set to true, the
|
||||||
|
// genesis state will be committed using the Verkle tree, eliminating the
|
||||||
|
// need for any Verkle transition later.
|
||||||
|
//
|
||||||
|
// This is a temporary flag only for verkle devnet testing, where verkle is
|
||||||
|
// activated at genesis, and the configured activation date has already passed.
|
||||||
|
//
|
||||||
|
// In production networks (mainnet and public testnets), verkle activation
|
||||||
|
// always occurs after the genesis block, making this flag irrelevant in
|
||||||
|
// those cases.
|
||||||
|
EnableVerkleAtGenesis bool `json:"enableVerkleAtGenesis,omitempty"`
|
||||||
|
|
||||||
// Various consensus engines
|
// Various consensus engines
|
||||||
Ethash *EthashConfig `json:"ethash,omitempty"`
|
Ethash *EthashConfig `json:"ethash,omitempty"`
|
||||||
Clique *CliqueConfig `json:"clique,omitempty"`
|
Clique *CliqueConfig `json:"clique,omitempty"`
|
||||||
|
|
@ -691,6 +704,20 @@ func (c *ChainConfig) IsBPO5(num *big.Int, time uint64) bool {
|
||||||
return c.IsLondon(num) && isTimestampForked(c.BPO5Time, time)
|
return c.IsLondon(num) && isTimestampForked(c.BPO5Time, time)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsVerkleGenesis checks whether the verkle fork is activated at the genesis block.
|
||||||
|
//
|
||||||
|
// Verkle mode is considered enabled if the verkle fork time is configured,
|
||||||
|
// regardless of whether the local time has surpassed the fork activation time.
|
||||||
|
// This is a temporary workaround for verkle devnet testing, where verkle is
|
||||||
|
// activated at genesis, and the configured activation date has already passed.
|
||||||
|
//
|
||||||
|
// In production networks (mainnet and public testnets), verkle activation
|
||||||
|
// always occurs after the genesis block, making this function irrelevant in
|
||||||
|
// those cases.
|
||||||
|
func (c *ChainConfig) IsVerkleGenesis() bool {
|
||||||
|
return c.EnableVerkleAtGenesis
|
||||||
|
}
|
||||||
|
|
||||||
// IsEIP4762 returns whether eip 4762 has been activated at given block.
|
// IsEIP4762 returns whether eip 4762 has been activated at given block.
|
||||||
func (c *ChainConfig) IsEIP4762(num *big.Int, time uint64) bool {
|
func (c *ChainConfig) IsEIP4762(num *big.Int, time uint64) bool {
|
||||||
return c.IsVerkle(num, time)
|
return c.IsVerkle(num, time)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue