2017-03-02 07:03:33 -06:00
|
|
|
// Copyright 2017 The go-ethereum Authors
|
|
|
|
// This file is part of the go-ethereum library.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package core
|
|
|
|
|
|
|
|
import (
|
2023-11-14 06:09:40 -06:00
|
|
|
"bytes"
|
2022-11-28 07:31:28 -06:00
|
|
|
"encoding/json"
|
2017-03-02 07:03:33 -06:00
|
|
|
"math/big"
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/davecgh/go-spew/spew"
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2017-04-04 17:16:29 -05:00
|
|
|
"github.com/ethereum/go-ethereum/consensus/ethash"
|
2018-05-07 06:35:06 -05:00
|
|
|
"github.com/ethereum/go-ethereum/core/rawdb"
|
2024-02-16 12:05:33 -06:00
|
|
|
"github.com/ethereum/go-ethereum/core/types"
|
2017-03-02 07:03:33 -06:00
|
|
|
"github.com/ethereum/go-ethereum/core/vm"
|
|
|
|
"github.com/ethereum/go-ethereum/ethdb"
|
|
|
|
"github.com/ethereum/go-ethereum/params"
|
2024-02-13 07:49:53 -06:00
|
|
|
"github.com/ethereum/go-ethereum/triedb"
|
|
|
|
"github.com/ethereum/go-ethereum/triedb/pathdb"
|
2017-03-02 07:03:33 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestSetupGenesis(t *testing.T) {
|
all: activate pbss as experimental feature (#26274)
* all: activate pbss
* core/rawdb: fix compilation error
* cma, core, eth, les, trie: address comments
* cmd, core, eth, trie: polish code
* core, cmd, eth: address comments
* cmd, core, eth, les, light, tests: address comment
* cmd/utils: shorten log message
* trie/triedb/pathdb: limit node buffer size to 1gb
* cmd/utils: fix opening non-existing db
* cmd/utils: rename flag name
* cmd, core: group chain history flags and fix tests
* core, eth, trie: fix memory leak in snapshot generation
* cmd, eth, internal: deprecate flags
* all: enable state tests for pathdb, fixes
* cmd, core: polish code
* trie/triedb/pathdb: limit the node buffer size to 256mb
---------
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2023-08-10 14:21:36 -05:00
|
|
|
testSetupGenesis(t, rawdb.HashScheme)
|
|
|
|
testSetupGenesis(t, rawdb.PathScheme)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testSetupGenesis(t *testing.T, scheme string) {
|
2017-03-02 07:03:33 -06:00
|
|
|
var (
|
|
|
|
customghash = common.HexToHash("0x89c99d90b79719238d2645c7642f2c9295246e80775b38cfd162b696817fbd50")
|
|
|
|
customg = Genesis{
|
|
|
|
Config: ¶ms.ChainConfig{HomesteadBlock: big.NewInt(3)},
|
2024-02-16 12:05:33 -06:00
|
|
|
Alloc: types.GenesisAlloc{
|
2017-03-02 07:03:33 -06:00
|
|
|
{1}: {Balance: big.NewInt(1), Storage: map[common.Hash]common.Hash{{1}: {1}}},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
oldcustomg = customg
|
|
|
|
)
|
|
|
|
oldcustomg.Config = ¶ms.ChainConfig{HomesteadBlock: big.NewInt(2)}
|
all: activate pbss as experimental feature (#26274)
* all: activate pbss
* core/rawdb: fix compilation error
* cma, core, eth, les, trie: address comments
* cmd, core, eth, trie: polish code
* core, cmd, eth: address comments
* cmd, core, eth, les, light, tests: address comment
* cmd/utils: shorten log message
* trie/triedb/pathdb: limit node buffer size to 1gb
* cmd/utils: fix opening non-existing db
* cmd/utils: rename flag name
* cmd, core: group chain history flags and fix tests
* core, eth, trie: fix memory leak in snapshot generation
* cmd, eth, internal: deprecate flags
* all: enable state tests for pathdb, fixes
* cmd, core: polish code
* trie/triedb/pathdb: limit the node buffer size to 256mb
---------
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2023-08-10 14:21:36 -05:00
|
|
|
|
2017-03-02 07:03:33 -06:00
|
|
|
tests := []struct {
|
cmd, core, miner: rework genesis setup (#30907)
This pull request refactors the genesis setup function, the major
changes are highlighted here:
**(a) Triedb is opened in verkle mode if `EnableVerkleAtGenesis` is
configured in chainConfig or the database has been initialized previously with
`EnableVerkleAtGenesis` configured**.
A new config field `EnableVerkleAtGenesis` has been added in the
chainConfig. This field must be configured with True if Geth wants to initialize
the genesis in Verkle mode.
In the verkle devnet-7, the verkle transition is activated at genesis.
Therefore, the verkle rules should be used since the genesis. In production
networks (mainnet and public testnets), verkle activation always occurs after
the genesis block. Therefore, this flag is only made for devnet and should be
deprecated later. Besides, verkle transition at non-genesis block hasn't been
implemented yet, it should be done in the following PRs.
**(b) The genesis initialization condition has been simplified**
There is a special mode supported by the Geth is that: Geth can be
initialized with an existing chain segment, which can fasten the node sync
process by retaining the chain freezer folder.
Originally, if the triedb is regarded as uninitialized and the genesis block can
be found in the chain freezer, the genesis block along with genesis state will be
committed. This condition has been simplified to checking the presence of chain
config in key-value store. The existence of chain config can represent the genesis
has been committed.
2025-01-14 04:49:30 -06:00
|
|
|
name string
|
|
|
|
fn func(ethdb.Database) (*params.ChainConfig, common.Hash, *params.ConfigCompatError, error)
|
|
|
|
wantConfig *params.ChainConfig
|
|
|
|
wantHash common.Hash
|
|
|
|
wantErr error
|
|
|
|
wantCompactErr *params.ConfigCompatError
|
2017-03-02 07:03:33 -06:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "genesis without ChainConfig",
|
cmd, core, miner: rework genesis setup (#30907)
This pull request refactors the genesis setup function, the major
changes are highlighted here:
**(a) Triedb is opened in verkle mode if `EnableVerkleAtGenesis` is
configured in chainConfig or the database has been initialized previously with
`EnableVerkleAtGenesis` configured**.
A new config field `EnableVerkleAtGenesis` has been added in the
chainConfig. This field must be configured with True if Geth wants to initialize
the genesis in Verkle mode.
In the verkle devnet-7, the verkle transition is activated at genesis.
Therefore, the verkle rules should be used since the genesis. In production
networks (mainnet and public testnets), verkle activation always occurs after
the genesis block. Therefore, this flag is only made for devnet and should be
deprecated later. Besides, verkle transition at non-genesis block hasn't been
implemented yet, it should be done in the following PRs.
**(b) The genesis initialization condition has been simplified**
There is a special mode supported by the Geth is that: Geth can be
initialized with an existing chain segment, which can fasten the node sync
process by retaining the chain freezer folder.
Originally, if the triedb is regarded as uninitialized and the genesis block can
be found in the chain freezer, the genesis block along with genesis state will be
committed. This condition has been simplified to checking the presence of chain
config in key-value store. The existence of chain config can represent the genesis
has been committed.
2025-01-14 04:49:30 -06:00
|
|
|
fn: func(db ethdb.Database) (*params.ChainConfig, common.Hash, *params.ConfigCompatError, error) {
|
2024-02-13 07:49:53 -06:00
|
|
|
return SetupGenesisBlock(db, triedb.NewDatabase(db, newDbConfig(scheme)), new(Genesis))
|
2017-03-02 07:03:33 -06:00
|
|
|
},
|
cmd, core, miner: rework genesis setup (#30907)
This pull request refactors the genesis setup function, the major
changes are highlighted here:
**(a) Triedb is opened in verkle mode if `EnableVerkleAtGenesis` is
configured in chainConfig or the database has been initialized previously with
`EnableVerkleAtGenesis` configured**.
A new config field `EnableVerkleAtGenesis` has been added in the
chainConfig. This field must be configured with True if Geth wants to initialize
the genesis in Verkle mode.
In the verkle devnet-7, the verkle transition is activated at genesis.
Therefore, the verkle rules should be used since the genesis. In production
networks (mainnet and public testnets), verkle activation always occurs after
the genesis block. Therefore, this flag is only made for devnet and should be
deprecated later. Besides, verkle transition at non-genesis block hasn't been
implemented yet, it should be done in the following PRs.
**(b) The genesis initialization condition has been simplified**
There is a special mode supported by the Geth is that: Geth can be
initialized with an existing chain segment, which can fasten the node sync
process by retaining the chain freezer folder.
Originally, if the triedb is regarded as uninitialized and the genesis block can
be found in the chain freezer, the genesis block along with genesis state will be
committed. This condition has been simplified to checking the presence of chain
config in key-value store. The existence of chain config can represent the genesis
has been committed.
2025-01-14 04:49:30 -06:00
|
|
|
wantErr: errGenesisNoConfig,
|
2017-03-02 07:03:33 -06:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "no block in DB, genesis == nil",
|
cmd, core, miner: rework genesis setup (#30907)
This pull request refactors the genesis setup function, the major
changes are highlighted here:
**(a) Triedb is opened in verkle mode if `EnableVerkleAtGenesis` is
configured in chainConfig or the database has been initialized previously with
`EnableVerkleAtGenesis` configured**.
A new config field `EnableVerkleAtGenesis` has been added in the
chainConfig. This field must be configured with True if Geth wants to initialize
the genesis in Verkle mode.
In the verkle devnet-7, the verkle transition is activated at genesis.
Therefore, the verkle rules should be used since the genesis. In production
networks (mainnet and public testnets), verkle activation always occurs after
the genesis block. Therefore, this flag is only made for devnet and should be
deprecated later. Besides, verkle transition at non-genesis block hasn't been
implemented yet, it should be done in the following PRs.
**(b) The genesis initialization condition has been simplified**
There is a special mode supported by the Geth is that: Geth can be
initialized with an existing chain segment, which can fasten the node sync
process by retaining the chain freezer folder.
Originally, if the triedb is regarded as uninitialized and the genesis block can
be found in the chain freezer, the genesis block along with genesis state will be
committed. This condition has been simplified to checking the presence of chain
config in key-value store. The existence of chain config can represent the genesis
has been committed.
2025-01-14 04:49:30 -06:00
|
|
|
fn: func(db ethdb.Database) (*params.ChainConfig, common.Hash, *params.ConfigCompatError, error) {
|
2024-02-13 07:49:53 -06:00
|
|
|
return SetupGenesisBlock(db, triedb.NewDatabase(db, newDbConfig(scheme)), nil)
|
2017-03-02 07:03:33 -06:00
|
|
|
},
|
2017-07-04 04:28:58 -05:00
|
|
|
wantHash: params.MainnetGenesisHash,
|
2017-03-02 07:03:33 -06:00
|
|
|
wantConfig: params.MainnetChainConfig,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "mainnet block in DB, genesis == nil",
|
cmd, core, miner: rework genesis setup (#30907)
This pull request refactors the genesis setup function, the major
changes are highlighted here:
**(a) Triedb is opened in verkle mode if `EnableVerkleAtGenesis` is
configured in chainConfig or the database has been initialized previously with
`EnableVerkleAtGenesis` configured**.
A new config field `EnableVerkleAtGenesis` has been added in the
chainConfig. This field must be configured with True if Geth wants to initialize
the genesis in Verkle mode.
In the verkle devnet-7, the verkle transition is activated at genesis.
Therefore, the verkle rules should be used since the genesis. In production
networks (mainnet and public testnets), verkle activation always occurs after
the genesis block. Therefore, this flag is only made for devnet and should be
deprecated later. Besides, verkle transition at non-genesis block hasn't been
implemented yet, it should be done in the following PRs.
**(b) The genesis initialization condition has been simplified**
There is a special mode supported by the Geth is that: Geth can be
initialized with an existing chain segment, which can fasten the node sync
process by retaining the chain freezer folder.
Originally, if the triedb is regarded as uninitialized and the genesis block can
be found in the chain freezer, the genesis block along with genesis state will be
committed. This condition has been simplified to checking the presence of chain
config in key-value store. The existence of chain config can represent the genesis
has been committed.
2025-01-14 04:49:30 -06:00
|
|
|
fn: func(db ethdb.Database) (*params.ChainConfig, common.Hash, *params.ConfigCompatError, error) {
|
2024-02-13 07:49:53 -06:00
|
|
|
DefaultGenesisBlock().MustCommit(db, triedb.NewDatabase(db, newDbConfig(scheme)))
|
|
|
|
return SetupGenesisBlock(db, triedb.NewDatabase(db, newDbConfig(scheme)), nil)
|
2017-03-02 07:03:33 -06:00
|
|
|
},
|
2017-07-04 04:28:58 -05:00
|
|
|
wantHash: params.MainnetGenesisHash,
|
2017-03-02 07:03:33 -06:00
|
|
|
wantConfig: params.MainnetChainConfig,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "custom block in DB, genesis == nil",
|
cmd, core, miner: rework genesis setup (#30907)
This pull request refactors the genesis setup function, the major
changes are highlighted here:
**(a) Triedb is opened in verkle mode if `EnableVerkleAtGenesis` is
configured in chainConfig or the database has been initialized previously with
`EnableVerkleAtGenesis` configured**.
A new config field `EnableVerkleAtGenesis` has been added in the
chainConfig. This field must be configured with True if Geth wants to initialize
the genesis in Verkle mode.
In the verkle devnet-7, the verkle transition is activated at genesis.
Therefore, the verkle rules should be used since the genesis. In production
networks (mainnet and public testnets), verkle activation always occurs after
the genesis block. Therefore, this flag is only made for devnet and should be
deprecated later. Besides, verkle transition at non-genesis block hasn't been
implemented yet, it should be done in the following PRs.
**(b) The genesis initialization condition has been simplified**
There is a special mode supported by the Geth is that: Geth can be
initialized with an existing chain segment, which can fasten the node sync
process by retaining the chain freezer folder.
Originally, if the triedb is regarded as uninitialized and the genesis block can
be found in the chain freezer, the genesis block along with genesis state will be
committed. This condition has been simplified to checking the presence of chain
config in key-value store. The existence of chain config can represent the genesis
has been committed.
2025-01-14 04:49:30 -06:00
|
|
|
fn: func(db ethdb.Database) (*params.ChainConfig, common.Hash, *params.ConfigCompatError, error) {
|
2024-02-13 07:49:53 -06:00
|
|
|
tdb := triedb.NewDatabase(db, newDbConfig(scheme))
|
all: activate pbss as experimental feature (#26274)
* all: activate pbss
* core/rawdb: fix compilation error
* cma, core, eth, les, trie: address comments
* cmd, core, eth, trie: polish code
* core, cmd, eth: address comments
* cmd, core, eth, les, light, tests: address comment
* cmd/utils: shorten log message
* trie/triedb/pathdb: limit node buffer size to 1gb
* cmd/utils: fix opening non-existing db
* cmd/utils: rename flag name
* cmd, core: group chain history flags and fix tests
* core, eth, trie: fix memory leak in snapshot generation
* cmd, eth, internal: deprecate flags
* all: enable state tests for pathdb, fixes
* cmd, core: polish code
* trie/triedb/pathdb: limit the node buffer size to 256mb
---------
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2023-08-10 14:21:36 -05:00
|
|
|
customg.Commit(db, tdb)
|
|
|
|
return SetupGenesisBlock(db, tdb, nil)
|
2017-03-02 07:03:33 -06:00
|
|
|
},
|
|
|
|
wantHash: customghash,
|
|
|
|
wantConfig: customg.Config,
|
|
|
|
},
|
|
|
|
{
|
2024-08-20 08:59:48 -05:00
|
|
|
name: "custom block in DB, genesis == sepolia",
|
cmd, core, miner: rework genesis setup (#30907)
This pull request refactors the genesis setup function, the major
changes are highlighted here:
**(a) Triedb is opened in verkle mode if `EnableVerkleAtGenesis` is
configured in chainConfig or the database has been initialized previously with
`EnableVerkleAtGenesis` configured**.
A new config field `EnableVerkleAtGenesis` has been added in the
chainConfig. This field must be configured with True if Geth wants to initialize
the genesis in Verkle mode.
In the verkle devnet-7, the verkle transition is activated at genesis.
Therefore, the verkle rules should be used since the genesis. In production
networks (mainnet and public testnets), verkle activation always occurs after
the genesis block. Therefore, this flag is only made for devnet and should be
deprecated later. Besides, verkle transition at non-genesis block hasn't been
implemented yet, it should be done in the following PRs.
**(b) The genesis initialization condition has been simplified**
There is a special mode supported by the Geth is that: Geth can be
initialized with an existing chain segment, which can fasten the node sync
process by retaining the chain freezer folder.
Originally, if the triedb is regarded as uninitialized and the genesis block can
be found in the chain freezer, the genesis block along with genesis state will be
committed. This condition has been simplified to checking the presence of chain
config in key-value store. The existence of chain config can represent the genesis
has been committed.
2025-01-14 04:49:30 -06:00
|
|
|
fn: func(db ethdb.Database) (*params.ChainConfig, common.Hash, *params.ConfigCompatError, error) {
|
2024-02-13 07:49:53 -06:00
|
|
|
tdb := triedb.NewDatabase(db, newDbConfig(scheme))
|
all: activate pbss as experimental feature (#26274)
* all: activate pbss
* core/rawdb: fix compilation error
* cma, core, eth, les, trie: address comments
* cmd, core, eth, trie: polish code
* core, cmd, eth: address comments
* cmd, core, eth, les, light, tests: address comment
* cmd/utils: shorten log message
* trie/triedb/pathdb: limit node buffer size to 1gb
* cmd/utils: fix opening non-existing db
* cmd/utils: rename flag name
* cmd, core: group chain history flags and fix tests
* core, eth, trie: fix memory leak in snapshot generation
* cmd, eth, internal: deprecate flags
* all: enable state tests for pathdb, fixes
* cmd, core: polish code
* trie/triedb/pathdb: limit the node buffer size to 256mb
---------
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2023-08-10 14:21:36 -05:00
|
|
|
customg.Commit(db, tdb)
|
2024-08-20 08:59:48 -05:00
|
|
|
return SetupGenesisBlock(db, tdb, DefaultSepoliaGenesisBlock())
|
2017-03-02 07:03:33 -06:00
|
|
|
},
|
cmd, core, miner: rework genesis setup (#30907)
This pull request refactors the genesis setup function, the major
changes are highlighted here:
**(a) Triedb is opened in verkle mode if `EnableVerkleAtGenesis` is
configured in chainConfig or the database has been initialized previously with
`EnableVerkleAtGenesis` configured**.
A new config field `EnableVerkleAtGenesis` has been added in the
chainConfig. This field must be configured with True if Geth wants to initialize
the genesis in Verkle mode.
In the verkle devnet-7, the verkle transition is activated at genesis.
Therefore, the verkle rules should be used since the genesis. In production
networks (mainnet and public testnets), verkle activation always occurs after
the genesis block. Therefore, this flag is only made for devnet and should be
deprecated later. Besides, verkle transition at non-genesis block hasn't been
implemented yet, it should be done in the following PRs.
**(b) The genesis initialization condition has been simplified**
There is a special mode supported by the Geth is that: Geth can be
initialized with an existing chain segment, which can fasten the node sync
process by retaining the chain freezer folder.
Originally, if the triedb is regarded as uninitialized and the genesis block can
be found in the chain freezer, the genesis block along with genesis state will be
committed. This condition has been simplified to checking the presence of chain
config in key-value store. The existence of chain config can represent the genesis
has been committed.
2025-01-14 04:49:30 -06:00
|
|
|
wantErr: &GenesisMismatchError{Stored: customghash, New: params.SepoliaGenesisHash},
|
2017-03-02 07:03:33 -06:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "compatible config in DB",
|
cmd, core, miner: rework genesis setup (#30907)
This pull request refactors the genesis setup function, the major
changes are highlighted here:
**(a) Triedb is opened in verkle mode if `EnableVerkleAtGenesis` is
configured in chainConfig or the database has been initialized previously with
`EnableVerkleAtGenesis` configured**.
A new config field `EnableVerkleAtGenesis` has been added in the
chainConfig. This field must be configured with True if Geth wants to initialize
the genesis in Verkle mode.
In the verkle devnet-7, the verkle transition is activated at genesis.
Therefore, the verkle rules should be used since the genesis. In production
networks (mainnet and public testnets), verkle activation always occurs after
the genesis block. Therefore, this flag is only made for devnet and should be
deprecated later. Besides, verkle transition at non-genesis block hasn't been
implemented yet, it should be done in the following PRs.
**(b) The genesis initialization condition has been simplified**
There is a special mode supported by the Geth is that: Geth can be
initialized with an existing chain segment, which can fasten the node sync
process by retaining the chain freezer folder.
Originally, if the triedb is regarded as uninitialized and the genesis block can
be found in the chain freezer, the genesis block along with genesis state will be
committed. This condition has been simplified to checking the presence of chain
config in key-value store. The existence of chain config can represent the genesis
has been committed.
2025-01-14 04:49:30 -06:00
|
|
|
fn: func(db ethdb.Database) (*params.ChainConfig, common.Hash, *params.ConfigCompatError, error) {
|
2024-02-13 07:49:53 -06:00
|
|
|
tdb := triedb.NewDatabase(db, newDbConfig(scheme))
|
all: activate pbss as experimental feature (#26274)
* all: activate pbss
* core/rawdb: fix compilation error
* cma, core, eth, les, trie: address comments
* cmd, core, eth, trie: polish code
* core, cmd, eth: address comments
* cmd, core, eth, les, light, tests: address comment
* cmd/utils: shorten log message
* trie/triedb/pathdb: limit node buffer size to 1gb
* cmd/utils: fix opening non-existing db
* cmd/utils: rename flag name
* cmd, core: group chain history flags and fix tests
* core, eth, trie: fix memory leak in snapshot generation
* cmd, eth, internal: deprecate flags
* all: enable state tests for pathdb, fixes
* cmd, core: polish code
* trie/triedb/pathdb: limit the node buffer size to 256mb
---------
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2023-08-10 14:21:36 -05:00
|
|
|
oldcustomg.Commit(db, tdb)
|
|
|
|
return SetupGenesisBlock(db, tdb, &customg)
|
2017-03-02 07:03:33 -06:00
|
|
|
},
|
|
|
|
wantHash: customghash,
|
|
|
|
wantConfig: customg.Config,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "incompatible config in DB",
|
cmd, core, miner: rework genesis setup (#30907)
This pull request refactors the genesis setup function, the major
changes are highlighted here:
**(a) Triedb is opened in verkle mode if `EnableVerkleAtGenesis` is
configured in chainConfig or the database has been initialized previously with
`EnableVerkleAtGenesis` configured**.
A new config field `EnableVerkleAtGenesis` has been added in the
chainConfig. This field must be configured with True if Geth wants to initialize
the genesis in Verkle mode.
In the verkle devnet-7, the verkle transition is activated at genesis.
Therefore, the verkle rules should be used since the genesis. In production
networks (mainnet and public testnets), verkle activation always occurs after
the genesis block. Therefore, this flag is only made for devnet and should be
deprecated later. Besides, verkle transition at non-genesis block hasn't been
implemented yet, it should be done in the following PRs.
**(b) The genesis initialization condition has been simplified**
There is a special mode supported by the Geth is that: Geth can be
initialized with an existing chain segment, which can fasten the node sync
process by retaining the chain freezer folder.
Originally, if the triedb is regarded as uninitialized and the genesis block can
be found in the chain freezer, the genesis block along with genesis state will be
committed. This condition has been simplified to checking the presence of chain
config in key-value store. The existence of chain config can represent the genesis
has been committed.
2025-01-14 04:49:30 -06:00
|
|
|
fn: func(db ethdb.Database) (*params.ChainConfig, common.Hash, *params.ConfigCompatError, error) {
|
2017-03-02 07:03:33 -06:00
|
|
|
// Commit the 'old' genesis block with Homestead transition at #2.
|
|
|
|
// Advance to block #4, past the homestead transition block of customg.
|
2024-02-13 07:49:53 -06:00
|
|
|
tdb := triedb.NewDatabase(db, newDbConfig(scheme))
|
all: activate pbss as experimental feature (#26274)
* all: activate pbss
* core/rawdb: fix compilation error
* cma, core, eth, les, trie: address comments
* cmd, core, eth, trie: polish code
* core, cmd, eth: address comments
* cmd, core, eth, les, light, tests: address comment
* cmd/utils: shorten log message
* trie/triedb/pathdb: limit node buffer size to 1gb
* cmd/utils: fix opening non-existing db
* cmd/utils: rename flag name
* cmd, core: group chain history flags and fix tests
* core, eth, trie: fix memory leak in snapshot generation
* cmd, eth, internal: deprecate flags
* all: enable state tests for pathdb, fixes
* cmd, core: polish code
* trie/triedb/pathdb: limit the node buffer size to 256mb
---------
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2023-08-10 14:21:36 -05:00
|
|
|
oldcustomg.Commit(db, tdb)
|
2018-02-23 06:02:33 -06:00
|
|
|
|
2024-09-04 08:03:06 -05:00
|
|
|
bc, _ := NewBlockChain(db, DefaultCacheConfigWithScheme(scheme), &oldcustomg, nil, ethash.NewFullFaker(), vm.Config{}, nil)
|
2017-08-07 07:47:25 -05:00
|
|
|
defer bc.Stop()
|
2018-02-23 06:02:33 -06:00
|
|
|
|
all: activate pbss as experimental feature (#26274)
* all: activate pbss
* core/rawdb: fix compilation error
* cma, core, eth, les, trie: address comments
* cmd, core, eth, trie: polish code
* core, cmd, eth: address comments
* cmd, core, eth, les, light, tests: address comment
* cmd/utils: shorten log message
* trie/triedb/pathdb: limit node buffer size to 1gb
* cmd/utils: fix opening non-existing db
* cmd/utils: rename flag name
* cmd, core: group chain history flags and fix tests
* core, eth, trie: fix memory leak in snapshot generation
* cmd, eth, internal: deprecate flags
* all: enable state tests for pathdb, fixes
* cmd, core: polish code
* trie/triedb/pathdb: limit the node buffer size to 256mb
---------
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2023-08-10 14:21:36 -05:00
|
|
|
_, blocks, _ := GenerateChainWithGenesis(&oldcustomg, ethash.NewFaker(), 4, nil)
|
2018-02-23 06:02:33 -06:00
|
|
|
bc.InsertChain(blocks)
|
2022-11-28 07:31:28 -06:00
|
|
|
|
2017-03-02 07:03:33 -06:00
|
|
|
// This should return a compatibility error.
|
all: activate pbss as experimental feature (#26274)
* all: activate pbss
* core/rawdb: fix compilation error
* cma, core, eth, les, trie: address comments
* cmd, core, eth, trie: polish code
* core, cmd, eth: address comments
* cmd, core, eth, les, light, tests: address comment
* cmd/utils: shorten log message
* trie/triedb/pathdb: limit node buffer size to 1gb
* cmd/utils: fix opening non-existing db
* cmd/utils: rename flag name
* cmd, core: group chain history flags and fix tests
* core, eth, trie: fix memory leak in snapshot generation
* cmd, eth, internal: deprecate flags
* all: enable state tests for pathdb, fixes
* cmd, core: polish code
* trie/triedb/pathdb: limit the node buffer size to 256mb
---------
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2023-08-10 14:21:36 -05:00
|
|
|
return SetupGenesisBlock(db, tdb, &customg)
|
2017-03-02 07:03:33 -06:00
|
|
|
},
|
|
|
|
wantHash: customghash,
|
|
|
|
wantConfig: customg.Config,
|
cmd, core, miner: rework genesis setup (#30907)
This pull request refactors the genesis setup function, the major
changes are highlighted here:
**(a) Triedb is opened in verkle mode if `EnableVerkleAtGenesis` is
configured in chainConfig or the database has been initialized previously with
`EnableVerkleAtGenesis` configured**.
A new config field `EnableVerkleAtGenesis` has been added in the
chainConfig. This field must be configured with True if Geth wants to initialize
the genesis in Verkle mode.
In the verkle devnet-7, the verkle transition is activated at genesis.
Therefore, the verkle rules should be used since the genesis. In production
networks (mainnet and public testnets), verkle activation always occurs after
the genesis block. Therefore, this flag is only made for devnet and should be
deprecated later. Besides, verkle transition at non-genesis block hasn't been
implemented yet, it should be done in the following PRs.
**(b) The genesis initialization condition has been simplified**
There is a special mode supported by the Geth is that: Geth can be
initialized with an existing chain segment, which can fasten the node sync
process by retaining the chain freezer folder.
Originally, if the triedb is regarded as uninitialized and the genesis block can
be found in the chain freezer, the genesis block along with genesis state will be
committed. This condition has been simplified to checking the presence of chain
config in key-value store. The existence of chain config can represent the genesis
has been committed.
2025-01-14 04:49:30 -06:00
|
|
|
wantCompactErr: ¶ms.ConfigCompatError{
|
2022-12-15 01:40:33 -06:00
|
|
|
What: "Homestead fork block",
|
|
|
|
StoredBlock: big.NewInt(2),
|
|
|
|
NewBlock: big.NewInt(3),
|
|
|
|
RewindToBlock: 1,
|
2017-03-02 07:03:33 -06:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
2018-09-24 07:57:49 -05:00
|
|
|
db := rawdb.NewMemoryDatabase()
|
cmd, core, miner: rework genesis setup (#30907)
This pull request refactors the genesis setup function, the major
changes are highlighted here:
**(a) Triedb is opened in verkle mode if `EnableVerkleAtGenesis` is
configured in chainConfig or the database has been initialized previously with
`EnableVerkleAtGenesis` configured**.
A new config field `EnableVerkleAtGenesis` has been added in the
chainConfig. This field must be configured with True if Geth wants to initialize
the genesis in Verkle mode.
In the verkle devnet-7, the verkle transition is activated at genesis.
Therefore, the verkle rules should be used since the genesis. In production
networks (mainnet and public testnets), verkle activation always occurs after
the genesis block. Therefore, this flag is only made for devnet and should be
deprecated later. Besides, verkle transition at non-genesis block hasn't been
implemented yet, it should be done in the following PRs.
**(b) The genesis initialization condition has been simplified**
There is a special mode supported by the Geth is that: Geth can be
initialized with an existing chain segment, which can fasten the node sync
process by retaining the chain freezer folder.
Originally, if the triedb is regarded as uninitialized and the genesis block can
be found in the chain freezer, the genesis block along with genesis state will be
committed. This condition has been simplified to checking the presence of chain
config in key-value store. The existence of chain config can represent the genesis
has been committed.
2025-01-14 04:49:30 -06:00
|
|
|
config, hash, compatErr, err := test.fn(db)
|
2017-03-02 07:03:33 -06:00
|
|
|
// Check the return values.
|
|
|
|
if !reflect.DeepEqual(err, test.wantErr) {
|
|
|
|
spew := spew.ConfigState{DisablePointerAddresses: true, DisableCapacities: true}
|
|
|
|
t.Errorf("%s: returned error %#v, want %#v", test.name, spew.NewFormatter(err), spew.NewFormatter(test.wantErr))
|
|
|
|
}
|
cmd, core, miner: rework genesis setup (#30907)
This pull request refactors the genesis setup function, the major
changes are highlighted here:
**(a) Triedb is opened in verkle mode if `EnableVerkleAtGenesis` is
configured in chainConfig or the database has been initialized previously with
`EnableVerkleAtGenesis` configured**.
A new config field `EnableVerkleAtGenesis` has been added in the
chainConfig. This field must be configured with True if Geth wants to initialize
the genesis in Verkle mode.
In the verkle devnet-7, the verkle transition is activated at genesis.
Therefore, the verkle rules should be used since the genesis. In production
networks (mainnet and public testnets), verkle activation always occurs after
the genesis block. Therefore, this flag is only made for devnet and should be
deprecated later. Besides, verkle transition at non-genesis block hasn't been
implemented yet, it should be done in the following PRs.
**(b) The genesis initialization condition has been simplified**
There is a special mode supported by the Geth is that: Geth can be
initialized with an existing chain segment, which can fasten the node sync
process by retaining the chain freezer folder.
Originally, if the triedb is regarded as uninitialized and the genesis block can
be found in the chain freezer, the genesis block along with genesis state will be
committed. This condition has been simplified to checking the presence of chain
config in key-value store. The existence of chain config can represent the genesis
has been committed.
2025-01-14 04:49:30 -06:00
|
|
|
if !reflect.DeepEqual(compatErr, test.wantCompactErr) {
|
|
|
|
spew := spew.ConfigState{DisablePointerAddresses: true, DisableCapacities: true}
|
|
|
|
t.Errorf("%s: returned error %#v, want %#v", test.name, spew.NewFormatter(compatErr), spew.NewFormatter(test.wantCompactErr))
|
|
|
|
}
|
2017-03-02 07:03:33 -06:00
|
|
|
if !reflect.DeepEqual(config, test.wantConfig) {
|
|
|
|
t.Errorf("%s:\nreturned %v\nwant %v", test.name, config, test.wantConfig)
|
|
|
|
}
|
|
|
|
if hash != test.wantHash {
|
|
|
|
t.Errorf("%s: returned hash %s, want %s", test.name, hash.Hex(), test.wantHash.Hex())
|
|
|
|
} else if err == nil {
|
|
|
|
// Check database content.
|
2018-05-07 06:35:06 -05:00
|
|
|
stored := rawdb.ReadBlock(db, test.wantHash, 0)
|
2017-03-02 07:03:33 -06:00
|
|
|
if stored.Hash() != test.wantHash {
|
|
|
|
t.Errorf("%s: block in DB has hash %s, want %s", test.name, stored.Hash(), test.wantHash)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-04-15 17:32:16 -05:00
|
|
|
|
2021-11-08 05:06:01 -06:00
|
|
|
// TestGenesisHashes checks the congruity of default genesis data to
|
|
|
|
// corresponding hardcoded genesis hash values.
|
2021-04-15 17:32:16 -05:00
|
|
|
func TestGenesisHashes(t *testing.T) {
|
2021-11-08 05:06:01 -06:00
|
|
|
for i, c := range []struct {
|
2021-04-15 17:32:16 -05:00
|
|
|
genesis *Genesis
|
2021-11-08 05:06:01 -06:00
|
|
|
want common.Hash
|
2021-04-15 17:32:16 -05:00
|
|
|
}{
|
2021-11-08 05:06:01 -06:00
|
|
|
{DefaultGenesisBlock(), params.MainnetGenesisHash},
|
|
|
|
{DefaultSepoliaGenesisBlock(), params.SepoliaGenesisHash},
|
|
|
|
} {
|
|
|
|
// Test via MustCommit
|
all: activate pbss as experimental feature (#26274)
* all: activate pbss
* core/rawdb: fix compilation error
* cma, core, eth, les, trie: address comments
* cmd, core, eth, trie: polish code
* core, cmd, eth: address comments
* cmd, core, eth, les, light, tests: address comment
* cmd/utils: shorten log message
* trie/triedb/pathdb: limit node buffer size to 1gb
* cmd/utils: fix opening non-existing db
* cmd/utils: rename flag name
* cmd, core: group chain history flags and fix tests
* core, eth, trie: fix memory leak in snapshot generation
* cmd, eth, internal: deprecate flags
* all: enable state tests for pathdb, fixes
* cmd, core: polish code
* trie/triedb/pathdb: limit the node buffer size to 256mb
---------
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2023-08-10 14:21:36 -05:00
|
|
|
db := rawdb.NewMemoryDatabase()
|
2024-02-13 07:49:53 -06:00
|
|
|
if have := c.genesis.MustCommit(db, triedb.NewDatabase(db, triedb.HashDefaults)).Hash(); have != c.want {
|
2021-11-08 05:06:01 -06:00
|
|
|
t.Errorf("case: %d a), want: %s, got: %s", i, c.want.Hex(), have.Hex())
|
|
|
|
}
|
|
|
|
// Test via ToBlock
|
2022-08-09 04:44:39 -05:00
|
|
|
if have := c.genesis.ToBlock().Hash(); have != c.want {
|
2021-11-08 05:06:01 -06:00
|
|
|
t.Errorf("case: %d a), want: %s, got: %s", i, c.want.Hex(), have.Hex())
|
2021-04-15 17:32:16 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-10-26 01:44:43 -05:00
|
|
|
|
|
|
|
func TestGenesis_Commit(t *testing.T) {
|
|
|
|
genesis := &Genesis{
|
|
|
|
BaseFee: big.NewInt(params.InitialBaseFee),
|
|
|
|
Config: params.TestChainConfig,
|
|
|
|
// difficulty is nil
|
|
|
|
}
|
|
|
|
|
|
|
|
db := rawdb.NewMemoryDatabase()
|
2024-02-13 07:49:53 -06:00
|
|
|
genesisBlock := genesis.MustCommit(db, triedb.NewDatabase(db, triedb.HashDefaults))
|
2022-11-28 07:31:28 -06:00
|
|
|
|
2021-10-26 01:44:43 -05:00
|
|
|
if genesis.Difficulty != nil {
|
|
|
|
t.Fatalf("assumption wrong")
|
|
|
|
}
|
|
|
|
|
|
|
|
// This value should have been set as default in the ToBlock method.
|
|
|
|
if genesisBlock.Difficulty().Cmp(params.GenesisDifficulty) != 0 {
|
|
|
|
t.Errorf("assumption wrong: want: %d, got: %v", params.GenesisDifficulty, genesisBlock.Difficulty())
|
|
|
|
}
|
|
|
|
|
|
|
|
// Expect the stored total difficulty to be the difficulty of the genesis block.
|
|
|
|
stored := rawdb.ReadTd(db, genesisBlock.Hash(), genesisBlock.NumberU64())
|
|
|
|
|
|
|
|
if stored.Cmp(genesisBlock.Difficulty()) != 0 {
|
|
|
|
t.Errorf("inequal difficulty; stored: %v, genesisBlock: %v", stored, genesisBlock.Difficulty())
|
|
|
|
}
|
|
|
|
}
|
2022-03-22 04:53:22 -05:00
|
|
|
|
|
|
|
func TestReadWriteGenesisAlloc(t *testing.T) {
|
|
|
|
var (
|
|
|
|
db = rawdb.NewMemoryDatabase()
|
2024-02-16 12:05:33 -06:00
|
|
|
alloc = &types.GenesisAlloc{
|
2022-03-22 04:53:22 -05:00
|
|
|
{1}: {Balance: big.NewInt(1), Storage: map[common.Hash]common.Hash{{1}: {1}}},
|
|
|
|
{2}: {Balance: big.NewInt(2), Storage: map[common.Hash]common.Hash{{2}: {2}}},
|
|
|
|
}
|
2024-02-16 12:05:33 -06:00
|
|
|
hash, _ = hashAlloc(alloc, false)
|
2022-03-22 04:53:22 -05:00
|
|
|
)
|
2022-11-28 07:31:28 -06:00
|
|
|
blob, _ := json.Marshal(alloc)
|
|
|
|
rawdb.WriteGenesisStateSpec(db, hash, blob)
|
2022-03-22 04:53:22 -05:00
|
|
|
|
2024-02-16 12:05:33 -06:00
|
|
|
var reload types.GenesisAlloc
|
2022-08-09 04:44:39 -05:00
|
|
|
err := reload.UnmarshalJSON(rawdb.ReadGenesisStateSpec(db, hash))
|
2022-03-22 04:53:22 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to load genesis state %v", err)
|
|
|
|
}
|
|
|
|
if len(reload) != len(*alloc) {
|
|
|
|
t.Fatal("Unexpected genesis allocation")
|
|
|
|
}
|
|
|
|
for addr, account := range reload {
|
|
|
|
want, ok := (*alloc)[addr]
|
|
|
|
if !ok {
|
|
|
|
t.Fatal("Account is not found")
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(want, account) {
|
|
|
|
t.Fatal("Unexpected account")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
all: activate pbss as experimental feature (#26274)
* all: activate pbss
* core/rawdb: fix compilation error
* cma, core, eth, les, trie: address comments
* cmd, core, eth, trie: polish code
* core, cmd, eth: address comments
* cmd, core, eth, les, light, tests: address comment
* cmd/utils: shorten log message
* trie/triedb/pathdb: limit node buffer size to 1gb
* cmd/utils: fix opening non-existing db
* cmd/utils: rename flag name
* cmd, core: group chain history flags and fix tests
* core, eth, trie: fix memory leak in snapshot generation
* cmd, eth, internal: deprecate flags
* all: enable state tests for pathdb, fixes
* cmd, core: polish code
* trie/triedb/pathdb: limit the node buffer size to 256mb
---------
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2023-08-10 14:21:36 -05:00
|
|
|
|
2024-02-13 07:49:53 -06:00
|
|
|
func newDbConfig(scheme string) *triedb.Config {
|
all: activate pbss as experimental feature (#26274)
* all: activate pbss
* core/rawdb: fix compilation error
* cma, core, eth, les, trie: address comments
* cmd, core, eth, trie: polish code
* core, cmd, eth: address comments
* cmd, core, eth, les, light, tests: address comment
* cmd/utils: shorten log message
* trie/triedb/pathdb: limit node buffer size to 1gb
* cmd/utils: fix opening non-existing db
* cmd/utils: rename flag name
* cmd, core: group chain history flags and fix tests
* core, eth, trie: fix memory leak in snapshot generation
* cmd, eth, internal: deprecate flags
* all: enable state tests for pathdb, fixes
* cmd, core: polish code
* trie/triedb/pathdb: limit the node buffer size to 256mb
---------
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2023-08-10 14:21:36 -05:00
|
|
|
if scheme == rawdb.HashScheme {
|
2024-02-13 07:49:53 -06:00
|
|
|
return triedb.HashDefaults
|
all: activate pbss as experimental feature (#26274)
* all: activate pbss
* core/rawdb: fix compilation error
* cma, core, eth, les, trie: address comments
* cmd, core, eth, trie: polish code
* core, cmd, eth: address comments
* cmd, core, eth, les, light, tests: address comment
* cmd/utils: shorten log message
* trie/triedb/pathdb: limit node buffer size to 1gb
* cmd/utils: fix opening non-existing db
* cmd/utils: rename flag name
* cmd, core: group chain history flags and fix tests
* core, eth, trie: fix memory leak in snapshot generation
* cmd, eth, internal: deprecate flags
* all: enable state tests for pathdb, fixes
* cmd, core: polish code
* trie/triedb/pathdb: limit the node buffer size to 256mb
---------
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2023-08-10 14:21:36 -05:00
|
|
|
}
|
2024-02-13 07:49:53 -06:00
|
|
|
return &triedb.Config{PathDB: pathdb.Defaults}
|
all: activate pbss as experimental feature (#26274)
* all: activate pbss
* core/rawdb: fix compilation error
* cma, core, eth, les, trie: address comments
* cmd, core, eth, trie: polish code
* core, cmd, eth: address comments
* cmd, core, eth, les, light, tests: address comment
* cmd/utils: shorten log message
* trie/triedb/pathdb: limit node buffer size to 1gb
* cmd/utils: fix opening non-existing db
* cmd/utils: rename flag name
* cmd, core: group chain history flags and fix tests
* core, eth, trie: fix memory leak in snapshot generation
* cmd, eth, internal: deprecate flags
* all: enable state tests for pathdb, fixes
* cmd, core: polish code
* trie/triedb/pathdb: limit the node buffer size to 256mb
---------
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2023-08-10 14:21:36 -05:00
|
|
|
}
|
2023-11-14 06:09:40 -06:00
|
|
|
|
|
|
|
func TestVerkleGenesisCommit(t *testing.T) {
|
|
|
|
var verkleTime uint64 = 0
|
|
|
|
verkleConfig := ¶ms.ChainConfig{
|
2024-10-23 01:26:18 -05:00
|
|
|
ChainID: big.NewInt(1),
|
|
|
|
HomesteadBlock: big.NewInt(0),
|
|
|
|
DAOForkBlock: nil,
|
|
|
|
DAOForkSupport: false,
|
|
|
|
EIP150Block: big.NewInt(0),
|
|
|
|
EIP155Block: big.NewInt(0),
|
|
|
|
EIP158Block: big.NewInt(0),
|
|
|
|
ByzantiumBlock: big.NewInt(0),
|
|
|
|
ConstantinopleBlock: big.NewInt(0),
|
|
|
|
PetersburgBlock: big.NewInt(0),
|
|
|
|
IstanbulBlock: big.NewInt(0),
|
|
|
|
MuirGlacierBlock: big.NewInt(0),
|
|
|
|
BerlinBlock: big.NewInt(0),
|
|
|
|
LondonBlock: big.NewInt(0),
|
|
|
|
ArrowGlacierBlock: big.NewInt(0),
|
|
|
|
GrayGlacierBlock: big.NewInt(0),
|
|
|
|
MergeNetsplitBlock: nil,
|
|
|
|
ShanghaiTime: &verkleTime,
|
|
|
|
CancunTime: &verkleTime,
|
|
|
|
PragueTime: &verkleTime,
|
|
|
|
VerkleTime: &verkleTime,
|
|
|
|
TerminalTotalDifficulty: big.NewInt(0),
|
cmd, core, miner: rework genesis setup (#30907)
This pull request refactors the genesis setup function, the major
changes are highlighted here:
**(a) Triedb is opened in verkle mode if `EnableVerkleAtGenesis` is
configured in chainConfig or the database has been initialized previously with
`EnableVerkleAtGenesis` configured**.
A new config field `EnableVerkleAtGenesis` has been added in the
chainConfig. This field must be configured with True if Geth wants to initialize
the genesis in Verkle mode.
In the verkle devnet-7, the verkle transition is activated at genesis.
Therefore, the verkle rules should be used since the genesis. In production
networks (mainnet and public testnets), verkle activation always occurs after
the genesis block. Therefore, this flag is only made for devnet and should be
deprecated later. Besides, verkle transition at non-genesis block hasn't been
implemented yet, it should be done in the following PRs.
**(b) The genesis initialization condition has been simplified**
There is a special mode supported by the Geth is that: Geth can be
initialized with an existing chain segment, which can fasten the node sync
process by retaining the chain freezer folder.
Originally, if the triedb is regarded as uninitialized and the genesis block can
be found in the chain freezer, the genesis block along with genesis state will be
committed. This condition has been simplified to checking the presence of chain
config in key-value store. The existence of chain config can represent the genesis
has been committed.
2025-01-14 04:49:30 -06:00
|
|
|
EnableVerkleAtGenesis: true,
|
2024-10-23 01:26:18 -05:00
|
|
|
Ethash: nil,
|
|
|
|
Clique: nil,
|
2023-11-14 06:09:40 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
genesis := &Genesis{
|
|
|
|
BaseFee: big.NewInt(params.InitialBaseFee),
|
|
|
|
Config: verkleConfig,
|
|
|
|
Timestamp: verkleTime,
|
|
|
|
Difficulty: big.NewInt(0),
|
2024-02-16 12:05:33 -06:00
|
|
|
Alloc: types.GenesisAlloc{
|
2023-11-14 06:09:40 -06:00
|
|
|
{1}: {Balance: big.NewInt(1), Storage: map[common.Hash]common.Hash{{1}: {1}}},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2024-12-06 05:14:05 -06:00
|
|
|
expected := common.FromHex("018d20eebb130b5e2b796465fe36aafab650650729a92435aec071bf2386f080")
|
2023-11-14 06:09:40 -06:00
|
|
|
got := genesis.ToBlock().Root().Bytes()
|
|
|
|
if !bytes.Equal(got, expected) {
|
|
|
|
t.Fatalf("invalid genesis state root, expected %x, got %x", expected, got)
|
|
|
|
}
|
|
|
|
|
|
|
|
db := rawdb.NewMemoryDatabase()
|
2024-07-16 08:17:58 -05:00
|
|
|
triedb := triedb.NewDatabase(db, triedb.VerkleDefaults)
|
2023-11-14 06:09:40 -06:00
|
|
|
block := genesis.MustCommit(db, triedb)
|
|
|
|
if !bytes.Equal(block.Root().Bytes(), expected) {
|
2024-06-03 06:17:12 -05:00
|
|
|
t.Fatalf("invalid genesis state root, expected %x, got %x", expected, block.Root())
|
2023-11-14 06:09:40 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test that the trie is verkle
|
|
|
|
if !triedb.IsVerkle() {
|
|
|
|
t.Fatalf("expected trie to be verkle")
|
|
|
|
}
|
2024-07-16 08:17:58 -05:00
|
|
|
vdb := rawdb.NewTable(db, string(rawdb.VerklePrefix))
|
|
|
|
if !rawdb.HasAccountTrieNode(vdb, nil) {
|
2023-11-14 06:09:40 -06:00
|
|
|
t.Fatal("could not find node")
|
|
|
|
}
|
|
|
|
}
|