2015-07-07 02:54:22 +02:00
|
|
|
// Copyright 2014 The go-ethereum Authors
|
2015-07-22 18:48:40 +02:00
|
|
|
// This file is part of the go-ethereum library.
|
2015-07-07 02:54:22 +02:00
|
|
|
//
|
2015-07-23 18:35:11 +02:00
|
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
2015-07-07 02:54:22 +02:00
|
|
|
// 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.
|
|
|
|
//
|
2015-07-22 18:48:40 +02:00
|
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
2015-07-07 02:54:22 +02:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-07-22 18:48:40 +02:00
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2015-07-07 02:54:22 +02:00
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
2015-07-22 18:48:40 +02:00
|
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
2015-07-07 02:54:22 +02:00
|
|
|
|
2014-12-04 10:28:02 +01:00
|
|
|
package core
|
2014-02-14 23:56:09 +01:00
|
|
|
|
|
|
|
import (
|
2017-07-11 13:49:14 +02:00
|
|
|
"bytes"
|
2020-05-25 13:12:25 +02:00
|
|
|
"context"
|
2021-04-09 13:00:50 +01:00
|
|
|
"embed"
|
2020-05-26 13:27:21 +01:00
|
|
|
"encoding/binary"
|
2017-07-11 13:49:14 +02:00
|
|
|
"encoding/hex"
|
|
|
|
"encoding/json"
|
2017-03-02 14:03:33 +01:00
|
|
|
"errors"
|
2015-02-20 18:05:46 +01:00
|
|
|
"fmt"
|
2015-06-19 01:57:16 +02:00
|
|
|
"math/big"
|
2021-06-05 22:17:04 +07:00
|
|
|
"sync"
|
2014-08-21 14:47:58 +02:00
|
|
|
|
2022-08-24 17:38:59 +07:00
|
|
|
"github.com/c2h5oh/datasize"
|
2020-05-25 13:12:25 +02:00
|
|
|
"github.com/holiman/uint256"
|
2023-01-13 18:12:18 +00:00
|
|
|
"github.com/ledgerwatch/erigon-lib/chain"
|
|
|
|
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
2021-07-29 18:53:13 +07:00
|
|
|
"github.com/ledgerwatch/erigon-lib/kv"
|
|
|
|
"github.com/ledgerwatch/erigon-lib/kv/mdbx"
|
2023-01-25 16:29:41 +07:00
|
|
|
"github.com/ledgerwatch/erigon-lib/kv/rawdbv3"
|
2021-05-21 01:25:53 +07:00
|
|
|
"github.com/ledgerwatch/erigon/common"
|
|
|
|
"github.com/ledgerwatch/erigon/common/hexutil"
|
|
|
|
"github.com/ledgerwatch/erigon/common/math"
|
2021-12-16 23:08:27 +01:00
|
|
|
"github.com/ledgerwatch/erigon/consensus/ethash"
|
|
|
|
"github.com/ledgerwatch/erigon/consensus/serenity"
|
2021-05-21 01:25:53 +07:00
|
|
|
"github.com/ledgerwatch/erigon/core/rawdb"
|
|
|
|
"github.com/ledgerwatch/erigon/core/state"
|
|
|
|
"github.com/ledgerwatch/erigon/core/types"
|
|
|
|
"github.com/ledgerwatch/erigon/crypto"
|
|
|
|
"github.com/ledgerwatch/erigon/params"
|
2022-03-03 15:57:10 +01:00
|
|
|
"github.com/ledgerwatch/erigon/params/networkname"
|
2021-05-21 01:25:53 +07:00
|
|
|
"github.com/ledgerwatch/erigon/turbo/trie"
|
2023-01-25 16:29:41 +07:00
|
|
|
"github.com/ledgerwatch/log/v3"
|
|
|
|
"golang.org/x/exp/slices"
|
2014-02-14 23:56:09 +01:00
|
|
|
)
|
|
|
|
|
2017-03-02 14:03:33 +01:00
|
|
|
//go:generate gencodec -type Genesis -field-override genesisSpecMarshaling -out gen_genesis.go
|
|
|
|
//go:generate gencodec -type GenesisAccount -field-override genesisAccountMarshaling -out gen_genesis_account.go
|
2015-07-10 14:29:40 +02:00
|
|
|
|
2021-04-09 13:00:50 +01:00
|
|
|
//go:embed allocs
|
|
|
|
var allocs embed.FS
|
|
|
|
|
2020-12-08 09:44:29 +00:00
|
|
|
var ErrGenesisNoConfig = errors.New("genesis has no chain configuration")
|
2014-12-23 13:48:44 +01:00
|
|
|
|
2017-03-02 14:03:33 +01:00
|
|
|
// Genesis specifies the header fields, state of a genesis block. It also defines hard
|
|
|
|
// fork switch-over blocks through the chain configuration.
|
|
|
|
type Genesis struct {
|
2023-01-13 18:12:18 +00:00
|
|
|
Config *chain.Config `json:"config"`
|
|
|
|
Nonce uint64 `json:"nonce"`
|
|
|
|
Timestamp uint64 `json:"timestamp"`
|
|
|
|
ExtraData []byte `json:"extraData"`
|
|
|
|
GasLimit uint64 `json:"gasLimit" gencodec:"required"`
|
|
|
|
Difficulty *big.Int `json:"difficulty" gencodec:"required"`
|
|
|
|
Mixhash libcommon.Hash `json:"mixHash"`
|
|
|
|
Coinbase libcommon.Address `json:"coinbase"`
|
|
|
|
Alloc GenesisAlloc `json:"alloc" gencodec:"required"`
|
|
|
|
AuRaStep uint64 `json:"auRaStep"`
|
|
|
|
AuRaSeal []byte `json:"auRaSeal"`
|
2017-07-11 13:49:14 +02:00
|
|
|
|
|
|
|
// These fields are used for consensus tests. Please don't use them
|
|
|
|
// in actual genesis blocks.
|
2023-01-13 18:12:18 +00:00
|
|
|
Number uint64 `json:"number"`
|
|
|
|
GasUsed uint64 `json:"gasUsed"`
|
|
|
|
ParentHash libcommon.Hash `json:"parentHash"`
|
|
|
|
BaseFee *big.Int `json:"baseFeePerGas"`
|
2017-03-02 14:03:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// GenesisAlloc specifies the initial state that is part of the genesis block.
|
2023-01-13 18:12:18 +00:00
|
|
|
type GenesisAlloc map[libcommon.Address]GenesisAccount
|
2017-03-02 14:03:33 +01:00
|
|
|
|
2021-06-30 16:30:21 +07:00
|
|
|
type AuthorityRoundSeal struct {
|
|
|
|
/// Seal step.
|
|
|
|
Step uint64 `json:"step"`
|
|
|
|
/// Seal signature.
|
2023-01-13 18:12:18 +00:00
|
|
|
Signature libcommon.Hash `json:"signature"`
|
2021-06-30 16:30:21 +07:00
|
|
|
}
|
|
|
|
|
2023-01-24 14:43:52 +07:00
|
|
|
var genesisTmpDB kv.RwDB
|
2023-02-11 20:44:51 +00:00
|
|
|
var genesisDBLock sync.Mutex
|
2023-01-24 14:43:52 +07:00
|
|
|
|
2017-07-11 13:49:14 +02:00
|
|
|
func (ga *GenesisAlloc) UnmarshalJSON(data []byte) error {
|
|
|
|
m := make(map[common.UnprefixedAddress]GenesisAccount)
|
|
|
|
if err := json.Unmarshal(data, &m); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
*ga = make(GenesisAlloc)
|
|
|
|
for addr, a := range m {
|
2023-01-13 18:12:18 +00:00
|
|
|
(*ga)[libcommon.Address(addr)] = a
|
2017-07-11 13:49:14 +02:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-03-02 14:03:33 +01:00
|
|
|
// GenesisAccount is an account in the state of the genesis block.
|
2022-11-21 17:21:59 +01:00
|
|
|
// Either use "constructor" for deployment code or "code" directly for the final code.
|
2017-03-02 14:03:33 +01:00
|
|
|
type GenesisAccount struct {
|
2023-01-13 18:12:18 +00:00
|
|
|
Constructor []byte `json:"constructor,omitempty"` // deployment code
|
|
|
|
Code []byte `json:"code,omitempty"` // final contract code
|
|
|
|
Storage map[libcommon.Hash]libcommon.Hash `json:"storage,omitempty"`
|
|
|
|
Balance *big.Int `json:"balance" gencodec:"required"`
|
|
|
|
Nonce uint64 `json:"nonce,omitempty"`
|
|
|
|
PrivateKey []byte `json:"secretKey,omitempty"` // for tests
|
2017-03-02 14:03:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// field type overrides for gencodec
|
|
|
|
type genesisSpecMarshaling struct {
|
|
|
|
Nonce math.HexOrDecimal64
|
|
|
|
Timestamp math.HexOrDecimal64
|
|
|
|
ExtraData hexutil.Bytes
|
|
|
|
GasLimit math.HexOrDecimal64
|
2017-07-11 13:49:14 +02:00
|
|
|
GasUsed math.HexOrDecimal64
|
2017-07-17 10:33:13 +02:00
|
|
|
Number math.HexOrDecimal64
|
2017-03-02 14:03:33 +01:00
|
|
|
Difficulty *math.HexOrDecimal256
|
2021-07-11 04:05:56 +00:00
|
|
|
BaseFee *math.HexOrDecimal256
|
2017-03-02 14:03:33 +01:00
|
|
|
Alloc map[common.UnprefixedAddress]GenesisAccount
|
|
|
|
}
|
2017-07-11 13:49:14 +02:00
|
|
|
|
2017-03-02 14:03:33 +01:00
|
|
|
type genesisAccountMarshaling struct {
|
2022-11-21 17:21:59 +01:00
|
|
|
Constructor hexutil.Bytes
|
|
|
|
Code hexutil.Bytes
|
|
|
|
Balance *math.HexOrDecimal256
|
|
|
|
Nonce math.HexOrDecimal64
|
|
|
|
Storage map[storageJSON]storageJSON
|
|
|
|
PrivateKey hexutil.Bytes
|
2017-07-11 13:49:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// storageJSON represents a 256 bit byte array, but allows less than 256 bits when
|
|
|
|
// unmarshaling from hex.
|
2023-01-13 18:12:18 +00:00
|
|
|
type storageJSON libcommon.Hash
|
2017-07-11 13:49:14 +02:00
|
|
|
|
|
|
|
func (h *storageJSON) UnmarshalText(text []byte) error {
|
|
|
|
text = bytes.TrimPrefix(text, []byte("0x"))
|
|
|
|
if len(text) > 64 {
|
|
|
|
return fmt.Errorf("too many hex characters in storage key/value %q", text)
|
|
|
|
}
|
|
|
|
offset := len(h) - len(text)/2 // pad on the left
|
|
|
|
if _, err := hex.Decode(h[offset:], text); err != nil {
|
|
|
|
return fmt.Errorf("invalid hex storage key/value %q", text)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h storageJSON) MarshalText() ([]byte, error) {
|
|
|
|
return hexutil.Bytes(h[:]).MarshalText()
|
2017-03-02 14:03:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// GenesisMismatchError is raised when trying to overwrite an existing
|
|
|
|
// genesis block with an incompatible one.
|
|
|
|
type GenesisMismatchError struct {
|
2023-01-13 18:12:18 +00:00
|
|
|
Stored, New libcommon.Hash
|
2017-03-02 14:03:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (e *GenesisMismatchError) Error() string {
|
2022-08-03 02:49:06 +02:00
|
|
|
config := params.ChainConfigByGenesisHash(e.Stored)
|
|
|
|
if config == nil {
|
|
|
|
return fmt.Sprintf("database contains incompatible genesis (have %x, new %x)", e.Stored, e.New)
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("database contains incompatible genesis (try with --chain=%s)", config.ChainName)
|
2017-03-02 14:03:33 +01:00
|
|
|
}
|
|
|
|
|
2021-06-05 22:17:04 +07:00
|
|
|
// CommitGenesisBlock writes or updates the genesis block in db.
|
2017-03-02 14:03:33 +01:00
|
|
|
// The block that will be used is:
|
|
|
|
//
|
2022-08-10 19:04:13 +07:00
|
|
|
// genesis == nil genesis != nil
|
|
|
|
// +------------------------------------------
|
|
|
|
// db has no genesis | main-net default | genesis
|
|
|
|
// db has genesis | from DB | genesis (if compatible)
|
2017-03-02 14:03:33 +01:00
|
|
|
//
|
|
|
|
// The stored chain configuration will be updated if it is compatible (i.e. does not
|
|
|
|
// specify a fork block below the local head block). In case of a conflict, the
|
|
|
|
// error is a *params.ConfigCompatError and the new, unwritten config is returned.
|
|
|
|
//
|
|
|
|
// The returned chain configuration is never nil.
|
2023-02-11 20:44:51 +00:00
|
|
|
func CommitGenesisBlock(db kv.RwDB, genesis *Genesis, tmpDir string) (*chain.Config, *types.Block, error) {
|
|
|
|
return CommitGenesisBlockWithOverride(db, genesis, nil, tmpDir)
|
2022-05-26 21:21:51 +02:00
|
|
|
}
|
|
|
|
|
2023-02-11 20:44:51 +00:00
|
|
|
func CommitGenesisBlockWithOverride(db kv.RwDB, genesis *Genesis, overrideShanghaiTime *big.Int, tmpDir string) (*chain.Config, *types.Block, error) {
|
2021-06-05 22:17:04 +07:00
|
|
|
tx, err := db.BeginRw(context.Background())
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
defer tx.Rollback()
|
2023-02-11 20:44:51 +00:00
|
|
|
c, b, err := WriteGenesisBlock(tx, genesis, overrideShanghaiTime, tmpDir)
|
2021-06-05 22:17:04 +07:00
|
|
|
if err != nil {
|
|
|
|
return c, b, err
|
|
|
|
}
|
|
|
|
err = tx.Commit()
|
|
|
|
if err != nil {
|
|
|
|
return c, b, err
|
|
|
|
}
|
|
|
|
return c, b, nil
|
|
|
|
}
|
|
|
|
|
2023-02-11 20:44:51 +00:00
|
|
|
func MustCommitGenesisBlock(db kv.RwDB, genesis *Genesis, tmpDir string) (*chain.Config, *types.Block) {
|
|
|
|
c, b, err := CommitGenesisBlock(db, genesis, tmpDir)
|
2021-06-05 22:17:04 +07:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return c, b
|
|
|
|
}
|
|
|
|
|
2023-02-11 20:44:51 +00:00
|
|
|
func WriteGenesisBlock(db kv.RwTx, genesis *Genesis, overrideShanghaiTime *big.Int, tmpDir string) (*chain.Config, *types.Block, error) {
|
2017-03-02 14:03:33 +01:00
|
|
|
if genesis != nil && genesis.Config == nil {
|
2022-11-21 17:21:59 +01:00
|
|
|
return params.AllProtocolChanges, nil, ErrGenesisNoConfig
|
2017-02-28 23:18:13 +01:00
|
|
|
}
|
2017-03-02 14:03:33 +01:00
|
|
|
// Just commit the new block if there is no stored genesis block.
|
2022-05-27 10:25:29 +02:00
|
|
|
storedHash, storedErr := rawdb.ReadCanonicalHash(db, 0)
|
2021-03-29 06:58:45 +03:00
|
|
|
if storedErr != nil {
|
2021-05-23 12:41:42 +07:00
|
|
|
return nil, nil, storedErr
|
2020-10-10 13:05:56 +07:00
|
|
|
}
|
2022-07-04 13:19:08 +02:00
|
|
|
|
2023-01-13 18:12:18 +00:00
|
|
|
applyOverrides := func(config *chain.Config) {
|
2022-12-23 17:06:56 +01:00
|
|
|
if overrideShanghaiTime != nil {
|
|
|
|
config.ShanghaiTime = overrideShanghaiTime
|
2022-07-04 13:19:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-13 18:12:18 +00:00
|
|
|
if (storedHash == libcommon.Hash{}) {
|
2021-04-09 17:44:25 +01:00
|
|
|
custom := true
|
2017-03-02 14:03:33 +01:00
|
|
|
if genesis == nil {
|
|
|
|
log.Info("Writing default main-net genesis block")
|
|
|
|
genesis = DefaultGenesisBlock()
|
2021-04-09 17:44:25 +01:00
|
|
|
custom = false
|
common: move big integer math to common/math (#3699)
* common: remove CurrencyToString
Move denomination values to params instead.
* common: delete dead code
* common: move big integer operations to common/math
This commit consolidates all big integer operations into common/math and
adds tests and documentation.
There should be no change in semantics for BigPow, BigMin, BigMax, S256,
U256, Exp and their behaviour is now locked in by tests.
The BigD, BytesToBig and Bytes2Big functions don't provide additional
value, all uses are replaced by new(big.Int).SetBytes().
BigToBytes is now called PaddedBigBytes, its minimum output size
parameter is now specified as the number of bytes instead of bits. The
single use of this function is in the EVM's MSTORE instruction.
Big and String2Big are replaced by ParseBig, which is slightly stricter.
It previously accepted leading zeros for hexadecimal inputs but treated
decimal inputs as octal if a leading zero digit was present.
ParseUint64 is used in places where String2Big was used to decode a
uint64.
The new functions MustParseBig and MustParseUint64 are now used in many
places where parsing errors were previously ignored.
* common: delete unused big integer variables
* accounts/abi: replace uses of BytesToBig with use of encoding/binary
* common: remove BytesToBig
* common: remove Bytes2Big
* common: remove BigTrue
* cmd/utils: add BigFlag and use it for error-checked integer flags
While here, remove environment variable processing for DirectoryFlag
because we don't use it.
* core: add missing error checks in genesis block parser
* common: remove String2Big
* cmd/evm: use utils.BigFlag
* common/math: check for 256 bit overflow in ParseBig
This is supposed to prevent silent overflow/truncation of values in the
genesis block JSON. Without this check, a genesis block that set a
balance larger than 256 bits would lead to weird behaviour in the VM.
* cmd/utils: fixup import
2017-02-26 22:21:51 +01:00
|
|
|
}
|
2022-07-04 13:19:08 +02:00
|
|
|
applyOverrides(genesis.Config)
|
2023-02-11 20:44:51 +00:00
|
|
|
block, _, err1 := genesis.Write(db, tmpDir)
|
2021-03-28 16:27:06 +07:00
|
|
|
if err1 != nil {
|
2021-05-23 12:41:42 +07:00
|
|
|
return genesis.Config, nil, err1
|
2019-07-18 15:26:22 +03:00
|
|
|
}
|
2021-04-09 17:44:25 +01:00
|
|
|
if custom {
|
|
|
|
log.Info("Writing custom genesis block", "hash", block.Hash().String())
|
|
|
|
}
|
2021-05-23 12:41:42 +07:00
|
|
|
return genesis.Config, block, nil
|
core, cmd, vendor: fixes and database inspection tool (#15)
* core, eth: some fixes for freezer
* vendor, core/rawdb, cmd/geth: add db inspector
* core, cmd/utils: check ancient store path forceily
* cmd/geth, common, core/rawdb: a few fixes
* cmd/geth: support windows file rename and fix rename error
* core: support ancient plugin
* core, cmd: streaming file copy
* cmd, consensus, core, tests: keep genesis in leveldb
* core: write txlookup during ancient init
* core: bump database version
2019-05-14 22:07:44 +08:00
|
|
|
}
|
2023-01-03 10:12:10 -08:00
|
|
|
// Assume mainnet chainId first
|
|
|
|
chainId := params.MainnetChainConfig.ChainID.Uint64()
|
|
|
|
// Note: The `genesis` argument will be one of:
|
|
|
|
// - nil: if running without the `init` command and without providing a chain flag (pulsechain, ropsten, etc..)
|
|
|
|
// - defaulted: when a chain flag is provided (pulsechain, ropsten, etc..), genesis will hold the defaults
|
|
|
|
// - custom: if running with the `init` command supplying a custom genesis.json file, genesis will hold the file contents
|
|
|
|
// Check whether the genesis block is already written.
|
2021-05-23 12:41:42 +07:00
|
|
|
|
2017-03-02 14:03:33 +01:00
|
|
|
// Check whether the genesis block is already written.
|
|
|
|
if genesis != nil {
|
2023-02-11 20:44:51 +00:00
|
|
|
block, _, err1 := genesis.ToBlock(tmpDir)
|
2021-03-23 07:25:10 +00:00
|
|
|
if err1 != nil {
|
2021-05-23 12:41:42 +07:00
|
|
|
return genesis.Config, nil, err1
|
2019-05-27 14:51:49 +01:00
|
|
|
}
|
2023-01-03 10:12:10 -08:00
|
|
|
chainId = genesis.Config.ChainID.Uint64()
|
2019-05-27 14:51:49 +01:00
|
|
|
hash := block.Hash()
|
2022-05-27 10:25:29 +02:00
|
|
|
if hash != storedHash {
|
|
|
|
return genesis.Config, block, &GenesisMismatchError{storedHash, hash}
|
2015-07-10 14:29:40 +02:00
|
|
|
}
|
|
|
|
}
|
2022-05-27 10:25:29 +02:00
|
|
|
storedBlock, err := rawdb.ReadBlockByHash(db, storedHash)
|
2021-05-23 12:41:42 +07:00
|
|
|
if err != nil {
|
2021-06-05 22:17:04 +07:00
|
|
|
return genesis.Config, nil, err
|
2021-05-23 12:41:42 +07:00
|
|
|
}
|
2017-03-02 14:03:33 +01:00
|
|
|
// Get the existing chain configuration.
|
2023-01-03 10:12:10 -08:00
|
|
|
newCfg := genesis.configOrDefault(storedHash, chainId)
|
2022-07-04 13:19:08 +02:00
|
|
|
applyOverrides(newCfg)
|
2022-05-27 10:25:29 +02:00
|
|
|
if err := newCfg.CheckConfigForkOrder(); err != nil {
|
|
|
|
return newCfg, nil, err
|
2019-10-16 13:23:14 +02:00
|
|
|
}
|
2022-05-27 10:25:29 +02:00
|
|
|
storedCfg, storedErr := rawdb.ReadChainConfig(db, storedHash)
|
2022-12-07 17:04:14 +05:30
|
|
|
if storedErr != nil && newCfg.Bor == nil {
|
2022-05-27 10:25:29 +02:00
|
|
|
return newCfg, nil, storedErr
|
2020-10-24 13:57:09 +07:00
|
|
|
}
|
2022-05-27 10:25:29 +02:00
|
|
|
if storedCfg == nil {
|
2018-05-07 14:35:06 +03:00
|
|
|
log.Warn("Found genesis block without chain config")
|
2022-05-27 10:25:29 +02:00
|
|
|
err1 := rawdb.WriteChainConfig(db, storedHash, newCfg)
|
2020-10-24 13:57:09 +07:00
|
|
|
if err1 != nil {
|
2022-05-27 10:25:29 +02:00
|
|
|
return newCfg, nil, err1
|
2020-10-24 13:57:09 +07:00
|
|
|
}
|
2022-05-27 10:25:29 +02:00
|
|
|
return newCfg, storedBlock, nil
|
common: move big integer math to common/math (#3699)
* common: remove CurrencyToString
Move denomination values to params instead.
* common: delete dead code
* common: move big integer operations to common/math
This commit consolidates all big integer operations into common/math and
adds tests and documentation.
There should be no change in semantics for BigPow, BigMin, BigMax, S256,
U256, Exp and their behaviour is now locked in by tests.
The BigD, BytesToBig and Bytes2Big functions don't provide additional
value, all uses are replaced by new(big.Int).SetBytes().
BigToBytes is now called PaddedBigBytes, its minimum output size
parameter is now specified as the number of bytes instead of bits. The
single use of this function is in the EVM's MSTORE instruction.
Big and String2Big are replaced by ParseBig, which is slightly stricter.
It previously accepted leading zeros for hexadecimal inputs but treated
decimal inputs as octal if a leading zero digit was present.
ParseUint64 is used in places where String2Big was used to decode a
uint64.
The new functions MustParseBig and MustParseUint64 are now used in many
places where parsing errors were previously ignored.
* common: delete unused big integer variables
* accounts/abi: replace uses of BytesToBig with use of encoding/binary
* common: remove BytesToBig
* common: remove Bytes2Big
* common: remove BigTrue
* cmd/utils: add BigFlag and use it for error-checked integer flags
While here, remove environment variable processing for DirectoryFlag
because we don't use it.
* core: add missing error checks in genesis block parser
* common: remove String2Big
* cmd/evm: use utils.BigFlag
* common/math: check for 256 bit overflow in ParseBig
This is supposed to prevent silent overflow/truncation of values in the
genesis block JSON. Without this check, a genesis block that set a
balance larger than 256 bits would lead to weird behaviour in the VM.
* cmd/utils: fixup import
2017-02-26 22:21:51 +01:00
|
|
|
}
|
2022-06-23 10:41:15 +02:00
|
|
|
// Special case: don't change the existing config of a private chain if no new
|
2022-06-21 10:17:54 +02:00
|
|
|
// config is supplied. This is useful, for example, to preserve DB config created by erigon init.
|
2022-06-23 10:41:15 +02:00
|
|
|
// In that case, only apply the overrides.
|
2023-01-03 10:12:10 -08:00
|
|
|
// Added: support custom config for PrimordialPulse fork with mainnet genesis
|
|
|
|
// and non-standard chain id.
|
|
|
|
if genesis == nil && (storedCfg.PrimordialPulseBlock != nil ||
|
|
|
|
params.ChainConfigByGenesisHash(storedHash) == nil) {
|
2022-06-23 10:41:15 +02:00
|
|
|
newCfg = storedCfg
|
2022-07-04 13:19:08 +02:00
|
|
|
applyOverrides(newCfg)
|
2022-06-21 10:17:54 +02:00
|
|
|
}
|
2017-03-02 14:03:33 +01:00
|
|
|
// Check config compatibility and write the config. Compatibility errors
|
|
|
|
// are returned to the caller unless we're already at block zero.
|
2018-05-07 14:35:06 +03:00
|
|
|
height := rawdb.ReadHeaderNumber(db, rawdb.ReadHeadHeaderHash(db))
|
2022-05-27 10:25:29 +02:00
|
|
|
if height != nil {
|
|
|
|
compatibilityErr := storedCfg.CheckCompatible(newCfg, *height)
|
|
|
|
if compatibilityErr != nil && *height != 0 && compatibilityErr.RewindTo != 0 {
|
|
|
|
return newCfg, storedBlock, compatibilityErr
|
2021-03-19 21:24:49 +00:00
|
|
|
}
|
common: move big integer math to common/math (#3699)
* common: remove CurrencyToString
Move denomination values to params instead.
* common: delete dead code
* common: move big integer operations to common/math
This commit consolidates all big integer operations into common/math and
adds tests and documentation.
There should be no change in semantics for BigPow, BigMin, BigMax, S256,
U256, Exp and their behaviour is now locked in by tests.
The BigD, BytesToBig and Bytes2Big functions don't provide additional
value, all uses are replaced by new(big.Int).SetBytes().
BigToBytes is now called PaddedBigBytes, its minimum output size
parameter is now specified as the number of bytes instead of bits. The
single use of this function is in the EVM's MSTORE instruction.
Big and String2Big are replaced by ParseBig, which is slightly stricter.
It previously accepted leading zeros for hexadecimal inputs but treated
decimal inputs as octal if a leading zero digit was present.
ParseUint64 is used in places where String2Big was used to decode a
uint64.
The new functions MustParseBig and MustParseUint64 are now used in many
places where parsing errors were previously ignored.
* common: delete unused big integer variables
* accounts/abi: replace uses of BytesToBig with use of encoding/binary
* common: remove BytesToBig
* common: remove Bytes2Big
* common: remove BigTrue
* cmd/utils: add BigFlag and use it for error-checked integer flags
While here, remove environment variable processing for DirectoryFlag
because we don't use it.
* core: add missing error checks in genesis block parser
* common: remove String2Big
* cmd/evm: use utils.BigFlag
* common/math: check for 256 bit overflow in ParseBig
This is supposed to prevent silent overflow/truncation of values in the
genesis block JSON. Without this check, a genesis block that set a
balance larger than 256 bits would lead to weird behaviour in the VM.
* cmd/utils: fixup import
2017-02-26 22:21:51 +01:00
|
|
|
}
|
2022-05-27 10:25:29 +02:00
|
|
|
if err := rawdb.WriteChainConfig(db, storedHash, newCfg); err != nil {
|
|
|
|
return newCfg, nil, err
|
2020-10-24 13:57:09 +07:00
|
|
|
}
|
2022-05-27 10:25:29 +02:00
|
|
|
return newCfg, storedBlock, nil
|
2017-03-02 14:03:33 +01:00
|
|
|
}
|
common: move big integer math to common/math (#3699)
* common: remove CurrencyToString
Move denomination values to params instead.
* common: delete dead code
* common: move big integer operations to common/math
This commit consolidates all big integer operations into common/math and
adds tests and documentation.
There should be no change in semantics for BigPow, BigMin, BigMax, S256,
U256, Exp and their behaviour is now locked in by tests.
The BigD, BytesToBig and Bytes2Big functions don't provide additional
value, all uses are replaced by new(big.Int).SetBytes().
BigToBytes is now called PaddedBigBytes, its minimum output size
parameter is now specified as the number of bytes instead of bits. The
single use of this function is in the EVM's MSTORE instruction.
Big and String2Big are replaced by ParseBig, which is slightly stricter.
It previously accepted leading zeros for hexadecimal inputs but treated
decimal inputs as octal if a leading zero digit was present.
ParseUint64 is used in places where String2Big was used to decode a
uint64.
The new functions MustParseBig and MustParseUint64 are now used in many
places where parsing errors were previously ignored.
* common: delete unused big integer variables
* accounts/abi: replace uses of BytesToBig with use of encoding/binary
* common: remove BytesToBig
* common: remove Bytes2Big
* common: remove BigTrue
* cmd/utils: add BigFlag and use it for error-checked integer flags
While here, remove environment variable processing for DirectoryFlag
because we don't use it.
* core: add missing error checks in genesis block parser
* common: remove String2Big
* cmd/evm: use utils.BigFlag
* common/math: check for 256 bit overflow in ParseBig
This is supposed to prevent silent overflow/truncation of values in the
genesis block JSON. Without this check, a genesis block that set a
balance larger than 256 bits would lead to weird behaviour in the VM.
* cmd/utils: fixup import
2017-02-26 22:21:51 +01:00
|
|
|
|
2023-01-03 10:12:10 -08:00
|
|
|
func (g *Genesis) configOrDefault(genesisHash libcommon.Hash, chainId uint64) *chain.Config {
|
|
|
|
pulseChainConfig := params.ChainConfigByChainName(networkname.PulsechainChainName)
|
2023-03-23 16:00:27 -05:00
|
|
|
pulseChainTestnetV3Config := params.ChainConfigByChainName(networkname.PulsechainTestnetV3ChainName)
|
2023-01-03 10:12:10 -08:00
|
|
|
config := &chain.Config{}
|
|
|
|
switch {
|
|
|
|
case g != nil:
|
2017-03-02 14:03:33 +01:00
|
|
|
return g.Config
|
2023-01-03 10:12:10 -08:00
|
|
|
case pulseChainConfig.ChainID.Uint64() == chainId:
|
|
|
|
config = params.ChainConfigByChainName(networkname.PulsechainChainName)
|
|
|
|
break
|
2023-03-23 16:00:27 -05:00
|
|
|
case pulseChainTestnetV3Config.ChainID.Uint64() == chainId:
|
|
|
|
config = params.ChainConfigByChainName(networkname.PulsechainTestnetV3ChainName)
|
2023-01-03 10:12:10 -08:00
|
|
|
break
|
|
|
|
default:
|
|
|
|
config = params.ChainConfigByGenesisHash(genesisHash)
|
2022-02-23 21:24:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if config != nil {
|
|
|
|
return config
|
|
|
|
} else {
|
2022-11-21 17:21:59 +01:00
|
|
|
return params.AllProtocolChanges
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func sortedAllocKeys(m GenesisAlloc) []string {
|
|
|
|
keys := make([]string, len(m))
|
|
|
|
i := 0
|
|
|
|
for k := range m {
|
|
|
|
keys[i] = string(k.Bytes())
|
|
|
|
i++
|
2017-03-02 14:03:33 +01:00
|
|
|
}
|
2022-11-21 17:21:59 +01:00
|
|
|
slices.Sort(keys)
|
|
|
|
return keys
|
2017-03-02 14:03:33 +01:00
|
|
|
}
|
2015-02-20 18:05:46 +01:00
|
|
|
|
2018-02-05 18:40:32 +02:00
|
|
|
// ToBlock creates the genesis block and writes state of a genesis specification
|
|
|
|
// to the given database (or discards it if nil).
|
2023-02-11 20:44:51 +00:00
|
|
|
func (g *Genesis) ToBlock(tmpDir string) (*types.Block, *state.IntraBlockState, error) {
|
2022-09-18 17:41:01 +07:00
|
|
|
_ = g.Alloc //nil-check
|
2022-11-21 17:21:59 +01:00
|
|
|
|
|
|
|
head := &types.Header{
|
|
|
|
Number: new(big.Int).SetUint64(g.Number),
|
|
|
|
Nonce: types.EncodeNonce(g.Nonce),
|
|
|
|
Time: g.Timestamp,
|
|
|
|
ParentHash: g.ParentHash,
|
|
|
|
Extra: g.ExtraData,
|
|
|
|
GasLimit: g.GasLimit,
|
|
|
|
GasUsed: g.GasUsed,
|
|
|
|
Difficulty: g.Difficulty,
|
|
|
|
MixDigest: g.Mixhash,
|
|
|
|
Coinbase: g.Coinbase,
|
|
|
|
BaseFee: g.BaseFee,
|
|
|
|
AuRaStep: g.AuRaStep,
|
|
|
|
AuRaSeal: g.AuRaSeal,
|
|
|
|
}
|
|
|
|
if g.GasLimit == 0 {
|
|
|
|
head.GasLimit = params.GenesisGasLimit
|
|
|
|
}
|
|
|
|
if g.Difficulty == nil {
|
|
|
|
head.Difficulty = params.GenesisDifficulty
|
|
|
|
}
|
|
|
|
if g.Config != nil && (g.Config.IsLondon(0)) {
|
|
|
|
if g.BaseFee != nil {
|
|
|
|
head.BaseFee = g.BaseFee
|
|
|
|
} else {
|
|
|
|
head.BaseFee = new(big.Int).SetUint64(params.InitialBaseFee)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-20 09:09:04 +00:00
|
|
|
var withdrawals []*types.Withdrawal
|
|
|
|
if g.Config != nil && (g.Config.IsShanghai(g.Timestamp)) {
|
|
|
|
withdrawals = []*types.Withdrawal{}
|
|
|
|
}
|
|
|
|
|
2023-01-13 18:12:18 +00:00
|
|
|
var root libcommon.Hash
|
2021-06-05 22:17:04 +07:00
|
|
|
var statedb *state.IntraBlockState
|
|
|
|
wg := sync.WaitGroup{}
|
|
|
|
wg.Add(1)
|
2023-02-11 20:44:51 +00:00
|
|
|
var err error
|
2021-06-05 22:17:04 +07:00
|
|
|
go func() { // we may run inside write tx, can't open 2nd write tx in same goroutine
|
2022-11-21 17:21:59 +01:00
|
|
|
// TODO(yperbasis): use memdb.MemoryMutation instead
|
2021-06-05 22:17:04 +07:00
|
|
|
defer wg.Done()
|
2023-01-24 14:43:52 +07:00
|
|
|
genesisDBLock.Lock()
|
|
|
|
defer genesisDBLock.Unlock()
|
2023-02-11 20:44:51 +00:00
|
|
|
if genesisTmpDB == nil {
|
|
|
|
genesisTmpDB = mdbx.NewMDBX(log.New()).InMem(tmpDir).MapSize(2 * datasize.GB).PageSize(2 * 4096).MustOpen()
|
|
|
|
}
|
|
|
|
var tx kv.RwTx
|
|
|
|
if tx, err = genesisTmpDB.BeginRw(context.Background()); err != nil {
|
|
|
|
return
|
2015-07-25 21:48:53 +02:00
|
|
|
}
|
2021-06-05 22:17:04 +07:00
|
|
|
defer tx.Rollback()
|
2021-07-24 14:14:11 +07:00
|
|
|
r, w := state.NewDbStateReader(tx), state.NewDbStateWriter(tx, 0)
|
2021-06-05 22:17:04 +07:00
|
|
|
statedb = state.New(r)
|
2022-11-21 17:21:59 +01:00
|
|
|
|
|
|
|
hasConstructorAllocation := false
|
|
|
|
for _, account := range g.Alloc {
|
|
|
|
if len(account.Constructor) > 0 {
|
|
|
|
hasConstructorAllocation = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// See https://github.com/NethermindEth/nethermind/blob/master/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/LoadGenesisBlockAuRa.cs
|
|
|
|
if hasConstructorAllocation && g.Config.Aura != nil {
|
2023-01-13 18:12:18 +00:00
|
|
|
statedb.CreateAccount(libcommon.Address{}, false)
|
2022-11-21 17:21:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
keys := sortedAllocKeys(g.Alloc)
|
|
|
|
for _, key := range keys {
|
2023-01-13 18:12:18 +00:00
|
|
|
addr := libcommon.BytesToAddress([]byte(key))
|
2022-11-21 17:21:59 +01:00
|
|
|
account := g.Alloc[addr]
|
|
|
|
|
2021-06-26 01:13:40 +07:00
|
|
|
balance, overflow := uint256.FromBig(account.Balance)
|
|
|
|
if overflow {
|
|
|
|
panic("overflow at genesis allocs")
|
|
|
|
}
|
2021-06-05 22:17:04 +07:00
|
|
|
statedb.AddBalance(addr, balance)
|
|
|
|
statedb.SetCode(addr, account.Code)
|
|
|
|
statedb.SetNonce(addr, account.Nonce)
|
|
|
|
for key, value := range account.Storage {
|
|
|
|
key := key
|
|
|
|
val := uint256.NewInt(0).SetBytes(value.Bytes())
|
|
|
|
statedb.SetState(addr, &key, *val)
|
|
|
|
}
|
2019-12-20 15:25:40 +03:00
|
|
|
|
2022-11-21 17:21:59 +01:00
|
|
|
if len(account.Constructor) > 0 {
|
2023-02-11 20:44:51 +00:00
|
|
|
if _, err = SysCreate(addr, account.Constructor, *g.Config, statedb, head); err != nil {
|
|
|
|
return
|
2022-11-21 17:21:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(account.Code) > 0 || len(account.Storage) > 0 || len(account.Constructor) > 0 {
|
2022-06-15 22:17:16 +02:00
|
|
|
statedb.SetIncarnation(addr, state.FirstContractIncarnation)
|
2021-06-05 22:17:04 +07:00
|
|
|
}
|
2019-12-20 15:25:40 +03:00
|
|
|
}
|
2023-02-11 20:44:51 +00:00
|
|
|
if err = statedb.FinalizeTx(&chain.Rules{}, w); err != nil {
|
|
|
|
return
|
2021-06-05 22:17:04 +07:00
|
|
|
}
|
2023-02-11 20:44:51 +00:00
|
|
|
if root, err = trie.CalcRoot("genesis", tx); err != nil {
|
|
|
|
return
|
2021-06-05 22:17:04 +07:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
wg.Wait()
|
2023-02-11 20:44:51 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
2021-06-05 22:17:04 +07:00
|
|
|
|
2022-11-21 17:21:59 +01:00
|
|
|
head.Root = root
|
2018-02-05 18:40:32 +02:00
|
|
|
|
2022-12-20 09:09:04 +00:00
|
|
|
return types.NewBlock(head, nil, nil, nil, withdrawals), statedb, nil
|
2017-03-02 14:03:33 +01:00
|
|
|
}
|
2015-07-10 14:29:40 +02:00
|
|
|
|
2023-02-11 20:44:51 +00:00
|
|
|
func (g *Genesis) WriteGenesisState(tx kv.RwTx, tmpDir string) (*types.Block, *state.IntraBlockState, error) {
|
|
|
|
block, statedb, err := g.ToBlock(tmpDir)
|
2019-05-27 14:51:49 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
2021-03-28 16:27:06 +07:00
|
|
|
for addr, account := range g.Alloc {
|
2022-06-15 22:17:16 +02:00
|
|
|
if len(account.Code) > 0 || len(account.Storage) > 0 {
|
2021-03-28 16:27:06 +07:00
|
|
|
// Special case for weird tests - inaccessible storage
|
|
|
|
var b [8]byte
|
|
|
|
binary.BigEndian.PutUint64(b[:], state.FirstContractIncarnation)
|
2021-07-28 09:47:38 +07:00
|
|
|
if err := tx.Put(kv.IncarnationMap, addr[:], b[:]); err != nil {
|
2021-03-28 16:27:06 +07:00
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-11 13:49:14 +02:00
|
|
|
if block.Number().Sign() != 0 {
|
2019-05-27 14:51:49 +01:00
|
|
|
return nil, statedb, fmt.Errorf("can't commit genesis block with number > 0")
|
|
|
|
}
|
2020-05-31 09:57:47 +03:00
|
|
|
|
2021-06-04 20:32:48 +07:00
|
|
|
blockWriter := state.NewPlainStateWriter(tx, tx, 0)
|
2020-05-31 09:57:47 +03:00
|
|
|
|
2023-01-13 18:12:18 +00:00
|
|
|
if err := statedb.CommitBlock(&chain.Rules{}, blockWriter); err != nil {
|
2021-10-04 17:16:52 +02:00
|
|
|
return nil, statedb, fmt.Errorf("cannot write state: %w", err)
|
2020-05-31 09:57:47 +03:00
|
|
|
}
|
|
|
|
if err := blockWriter.WriteChangeSets(); err != nil {
|
2021-10-04 17:16:52 +02:00
|
|
|
return nil, statedb, fmt.Errorf("cannot write change sets: %w", err)
|
2020-05-31 09:57:47 +03:00
|
|
|
}
|
Pruning for: exec, log_index, tx_lookup, history stages (#2399)
* Pruning for: exec, log_index, tx_lookup, history stages
* Pruning for: exec, log_index, tx_lookup, history stages
* Pruning for: exec, log_index, tx_lookup, history stages
* Pruning for: exec, log_index, tx_lookup, history stages
* add tvm flag
* save
* db migration for storage mode
add flag --prune=
remove flag --storage-mode=
add flag --experiments=tevm,...
rename integration set_storage_mode to set_prune
* fix
* forward move of stages must skip everything before PruneTo
* keep in db progress of prune method
* keep in db progress of prune method
* simplify logs
* simplify logs
* simplify logs
* fix test
* simplify logs
* simplify logs
* simplify logs
* simplify logs
* remove callTraceSet as dupsort
use etl transform for txlookup prune
remove some logs
* cleanup tests a bit
* print_stages and eth_sync to show prune progress
* fix print_stages
* add readme about --prune.to flag
* more docs
* add --prune.history.older and other flags support
* fix migration on empty db
* better toString
* better toString
2021-07-21 03:03:19 +07:00
|
|
|
if err := blockWriter.WriteHistory(); err != nil {
|
2021-10-04 17:16:52 +02:00
|
|
|
return nil, statedb, fmt.Errorf("cannot write history: %w", err)
|
2020-04-09 18:23:29 +01:00
|
|
|
}
|
2020-05-07 06:59:00 +01:00
|
|
|
return block, statedb, nil
|
|
|
|
}
|
|
|
|
|
2023-02-11 20:44:51 +00:00
|
|
|
func (g *Genesis) MustWrite(tx kv.RwTx, tmpDir string, history bool) (*types.Block, *state.IntraBlockState) {
|
|
|
|
b, s, err := g.Write(tx, tmpDir)
|
2021-06-05 22:17:04 +07:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return b, s
|
|
|
|
}
|
|
|
|
|
2021-07-24 11:28:05 +07:00
|
|
|
// Write writes the block and state of a genesis specification to the database.
|
2020-05-07 06:59:00 +01:00
|
|
|
// The block is committed as the canonical head block.
|
2023-02-11 20:44:51 +00:00
|
|
|
func (g *Genesis) Write(tx kv.RwTx, tmpDir string) (*types.Block, *state.IntraBlockState, error) {
|
|
|
|
block, statedb, err2 := g.WriteGenesisState(tx, tmpDir)
|
2021-03-26 17:05:35 +07:00
|
|
|
if err2 != nil {
|
|
|
|
return block, statedb, err2
|
2020-05-07 06:59:00 +01:00
|
|
|
}
|
|
|
|
config := g.Config
|
|
|
|
if config == nil {
|
2022-11-21 17:21:59 +01:00
|
|
|
config = params.AllProtocolChanges
|
2020-05-07 06:59:00 +01:00
|
|
|
}
|
|
|
|
if err := config.CheckConfigForkOrder(); err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
2021-03-26 17:05:35 +07:00
|
|
|
if err := rawdb.WriteTd(tx, block.Hash(), block.NumberU64(), g.Difficulty); err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
2021-05-19 10:47:28 +07:00
|
|
|
if err := rawdb.WriteBlock(tx, block); err != nil {
|
2021-03-26 17:05:35 +07:00
|
|
|
return nil, nil, err
|
|
|
|
}
|
2023-01-22 19:39:33 +07:00
|
|
|
if err := rawdbv3.TxNums.WriteForGenesis(tx, 1); err != nil {
|
2022-09-18 17:41:01 +07:00
|
|
|
return nil, nil, err
|
|
|
|
}
|
2021-03-26 17:05:35 +07:00
|
|
|
if err := rawdb.WriteReceipts(tx, block.NumberU64(), nil); err != nil {
|
2020-10-24 13:57:09 +07:00
|
|
|
return nil, nil, err
|
|
|
|
}
|
2021-04-20 00:58:05 +03:00
|
|
|
|
2021-03-26 17:05:35 +07:00
|
|
|
if err := rawdb.WriteCanonicalHash(tx, block.Hash(), block.NumberU64()); err != nil {
|
2020-10-24 13:57:09 +07:00
|
|
|
return nil, nil, err
|
|
|
|
}
|
2021-04-20 00:58:05 +03:00
|
|
|
|
2021-03-26 17:05:35 +07:00
|
|
|
rawdb.WriteHeadBlockHash(tx, block.Hash())
|
|
|
|
if err := rawdb.WriteHeadHeaderHash(tx, block.Hash()); err != nil {
|
2020-10-25 15:38:55 +07:00
|
|
|
return nil, nil, err
|
|
|
|
}
|
2021-03-26 17:05:35 +07:00
|
|
|
if err := rawdb.WriteChainConfig(tx, block.Hash(), config); err != nil {
|
2020-10-25 00:05:12 +07:00
|
|
|
return nil, nil, err
|
|
|
|
}
|
2021-12-16 23:08:27 +01:00
|
|
|
// We support ethash/serenity for issuance (for now)
|
2023-01-13 18:12:18 +00:00
|
|
|
if g.Config.Consensus != chain.EtHashConsensus {
|
2021-12-16 23:08:27 +01:00
|
|
|
return block, statedb, nil
|
|
|
|
}
|
|
|
|
// Issuance is the sum of allocs
|
|
|
|
genesisIssuance := big.NewInt(0)
|
|
|
|
for _, account := range g.Alloc {
|
|
|
|
genesisIssuance.Add(genesisIssuance, account.Balance)
|
|
|
|
}
|
|
|
|
|
|
|
|
// BlockReward can be present at genesis
|
|
|
|
if block.Header().Difficulty.Cmp(serenity.SerenityDifficulty) == 0 {
|
|
|
|
// Proof-of-stake is 0.3 ether per block (TODO: revisit)
|
|
|
|
genesisIssuance.Add(genesisIssuance, serenity.RewardSerenity)
|
|
|
|
} else {
|
|
|
|
blockReward, _ := ethash.AccumulateRewards(g.Config, block.Header(), nil)
|
|
|
|
// Set BlockReward
|
|
|
|
genesisIssuance.Add(genesisIssuance, blockReward.ToBig())
|
|
|
|
}
|
|
|
|
if err := rawdb.WriteTotalIssued(tx, 0, genesisIssuance); err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
2023-01-27 11:39:34 +07:00
|
|
|
return block, statedb, rawdb.WriteTotalBurnt(tx, 0, libcommon.Big0)
|
2021-05-19 10:47:28 +07:00
|
|
|
}
|
2021-03-26 17:05:35 +07:00
|
|
|
|
2017-03-02 14:03:33 +01:00
|
|
|
// MustCommit writes the genesis block and state to db, panicking on error.
|
|
|
|
// The block is committed as the canonical head block.
|
2023-02-11 20:44:51 +00:00
|
|
|
func (g *Genesis) MustCommit(db kv.RwDB, tmpDir string) *types.Block {
|
2021-06-05 22:17:04 +07:00
|
|
|
tx, err := db.BeginRw(context.Background())
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
defer tx.Rollback()
|
2023-02-11 20:44:51 +00:00
|
|
|
block, _ := g.MustWrite(tx, tmpDir, true)
|
2021-06-05 22:17:04 +07:00
|
|
|
err = tx.Commit()
|
common: move big integer math to common/math (#3699)
* common: remove CurrencyToString
Move denomination values to params instead.
* common: delete dead code
* common: move big integer operations to common/math
This commit consolidates all big integer operations into common/math and
adds tests and documentation.
There should be no change in semantics for BigPow, BigMin, BigMax, S256,
U256, Exp and their behaviour is now locked in by tests.
The BigD, BytesToBig and Bytes2Big functions don't provide additional
value, all uses are replaced by new(big.Int).SetBytes().
BigToBytes is now called PaddedBigBytes, its minimum output size
parameter is now specified as the number of bytes instead of bits. The
single use of this function is in the EVM's MSTORE instruction.
Big and String2Big are replaced by ParseBig, which is slightly stricter.
It previously accepted leading zeros for hexadecimal inputs but treated
decimal inputs as octal if a leading zero digit was present.
ParseUint64 is used in places where String2Big was used to decode a
uint64.
The new functions MustParseBig and MustParseUint64 are now used in many
places where parsing errors were previously ignored.
* common: delete unused big integer variables
* accounts/abi: replace uses of BytesToBig with use of encoding/binary
* common: remove BytesToBig
* common: remove Bytes2Big
* common: remove BigTrue
* cmd/utils: add BigFlag and use it for error-checked integer flags
While here, remove environment variable processing for DirectoryFlag
because we don't use it.
* core: add missing error checks in genesis block parser
* common: remove String2Big
* cmd/evm: use utils.BigFlag
* common/math: check for 256 bit overflow in ParseBig
This is supposed to prevent silent overflow/truncation of values in the
genesis block JSON. Without this check, a genesis block that set a
balance larger than 256 bits would lead to weird behaviour in the VM.
* cmd/utils: fixup import
2017-02-26 22:21:51 +01:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2015-07-10 14:29:40 +02:00
|
|
|
return block
|
|
|
|
}
|
|
|
|
|
2017-03-02 14:03:33 +01:00
|
|
|
// GenesisBlockForTesting creates and writes a block in which addr has the given wei balance.
|
2023-02-11 20:44:51 +00:00
|
|
|
func GenesisBlockForTesting(db kv.RwDB, addr libcommon.Address, balance *big.Int, tmpDir string) *types.Block {
|
2019-05-27 14:51:49 +01:00
|
|
|
g := Genesis{Alloc: GenesisAlloc{addr: {Balance: balance}}, Config: params.TestChainConfig}
|
2023-02-11 20:44:51 +00:00
|
|
|
block := g.MustCommit(db, tmpDir)
|
2019-05-27 14:51:49 +01:00
|
|
|
return block
|
2015-10-05 13:01:34 +02:00
|
|
|
}
|
|
|
|
|
2020-10-02 16:08:28 +03:00
|
|
|
type GenAccount struct {
|
2023-01-13 18:12:18 +00:00
|
|
|
Addr libcommon.Address
|
2020-10-02 16:08:28 +03:00
|
|
|
Balance *big.Int
|
|
|
|
}
|
|
|
|
|
2023-02-11 20:44:51 +00:00
|
|
|
func GenesisWithAccounts(db kv.RwDB, accs []GenAccount, tmpDir string) *types.Block {
|
2020-10-02 16:08:28 +03:00
|
|
|
g := Genesis{Config: params.TestChainConfig}
|
2023-01-13 18:12:18 +00:00
|
|
|
allocs := make(map[libcommon.Address]GenesisAccount)
|
2020-10-02 16:08:28 +03:00
|
|
|
for _, acc := range accs {
|
|
|
|
allocs[acc.Addr] = GenesisAccount{Balance: acc.Balance}
|
|
|
|
}
|
|
|
|
g.Alloc = allocs
|
2023-02-11 20:44:51 +00:00
|
|
|
block := g.MustCommit(db, tmpDir)
|
2020-10-02 16:08:28 +03:00
|
|
|
return block
|
|
|
|
}
|
|
|
|
|
2017-03-02 14:03:33 +01:00
|
|
|
// DefaultGenesisBlock returns the Ethereum main net genesis block.
|
|
|
|
func DefaultGenesisBlock() *Genesis {
|
|
|
|
return &Genesis{
|
|
|
|
Config: params.MainnetChainConfig,
|
|
|
|
Nonce: 66,
|
|
|
|
ExtraData: hexutil.MustDecode("0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa"),
|
|
|
|
GasLimit: 5000,
|
|
|
|
Difficulty: big.NewInt(17179869184),
|
2021-04-09 13:00:50 +01:00
|
|
|
Alloc: readPrealloc("allocs/mainnet.json"),
|
2017-03-02 14:03:33 +01:00
|
|
|
}
|
2015-11-17 18:33:25 +02:00
|
|
|
}
|
|
|
|
|
2022-03-03 15:57:10 +01:00
|
|
|
// DefaultSepoliaGenesisBlock returns the Sepolia network genesis block.
|
2022-02-10 01:27:36 -06:00
|
|
|
func DefaultSepoliaGenesisBlock() *Genesis {
|
|
|
|
return &Genesis{
|
|
|
|
Config: params.SepoliaChainConfig,
|
|
|
|
Nonce: 0,
|
|
|
|
ExtraData: []byte("Sepolia, Athens, Attica, Greece!"),
|
|
|
|
GasLimit: 30000000,
|
|
|
|
Difficulty: big.NewInt(131072),
|
|
|
|
Timestamp: 1633267481,
|
|
|
|
Alloc: readPrealloc("allocs/sepolia.json"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-04 12:36:20 +03:00
|
|
|
// DefaultRinkebyGenesisBlock returns the Rinkeby network genesis block.
|
|
|
|
func DefaultRinkebyGenesisBlock() *Genesis {
|
|
|
|
return &Genesis{
|
|
|
|
Config: params.RinkebyChainConfig,
|
|
|
|
Timestamp: 1492009146,
|
|
|
|
ExtraData: hexutil.MustDecode("0x52657370656374206d7920617574686f7269746168207e452e436172746d616e42eb768f2244c8811c63729a21a3569731535f067ffc57839b00206d1ad20c69a1981b489f772031b279182d99e65703f0076e4812653aab85fca0f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
|
|
|
|
GasLimit: 4700000,
|
|
|
|
Difficulty: big.NewInt(1),
|
2021-04-09 13:00:50 +01:00
|
|
|
Alloc: readPrealloc("allocs/rinkeby.json"),
|
2017-05-04 12:36:20 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-16 17:58:24 +02:00
|
|
|
// DefaultGoerliGenesisBlock returns the Görli network genesis block.
|
|
|
|
func DefaultGoerliGenesisBlock() *Genesis {
|
|
|
|
return &Genesis{
|
|
|
|
Config: params.GoerliChainConfig,
|
|
|
|
Timestamp: 1548854791,
|
|
|
|
ExtraData: hexutil.MustDecode("0x22466c6578692069732061207468696e6722202d204166726900000000000000e0a2bd4258d2768837baa26a28fe71dc079f84c70000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
|
|
|
|
GasLimit: 10485760,
|
|
|
|
Difficulty: big.NewInt(1),
|
2021-04-09 13:00:50 +01:00
|
|
|
Alloc: readPrealloc("allocs/goerli.json"),
|
2018-11-16 17:58:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-07 18:01:54 +07:00
|
|
|
func DefaultSokolGenesisBlock() *Genesis {
|
|
|
|
/*
|
|
|
|
header rlp: f9020da00000000000000000000000000000000000000000000000000000000000000000a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a0fad4af258fd11939fae0c6c6eec9d340b1caac0b0196fd9a1bc3f489c5bf00b3a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000830200008083663be080808080b8410000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
|
|
*/
|
|
|
|
return &Genesis{
|
2021-06-30 16:30:21 +07:00
|
|
|
Config: params.SokolChainConfig,
|
|
|
|
Timestamp: 0x0,
|
2022-10-21 12:43:44 +02:00
|
|
|
AuRaSeal: common.FromHex("0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
|
2021-06-07 18:01:54 +07:00
|
|
|
GasLimit: 0x663BE0,
|
|
|
|
Difficulty: big.NewInt(0x20000),
|
|
|
|
Alloc: readPrealloc("allocs/sokol.json"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-14 22:06:35 +03:00
|
|
|
func DefaultBSCGenesisBlock() *Genesis {
|
|
|
|
return &Genesis{
|
|
|
|
Config: params.BSCChainConfig,
|
|
|
|
Nonce: 0x00,
|
|
|
|
Timestamp: 0x5e9da7ce,
|
|
|
|
ExtraData: hexutil.MustDecode("0x00000000000000000000000000000000000000000000000000000000000000002a7cdd959bfe8d9487b2a43b33565295a698f7e26488aa4d1955ee33403f8ccb1d4de5fb97c7ade29ef9f4360c606c7ab4db26b016007d3ad0ab86a0ee01c3b1283aa067c58eab4709f85e99d46de5fe685b1ded8013785d6623cc18d214320b6bb6475978f3adfc719c99674c072166708589033e2d9afec2be4ec20253b8642161bc3f444f53679c1f3d472f7be8361c80a4c1e7e9aaf001d0877f1cfde218ce2fd7544e0b2cc94692d4a704debef7bcb61328b8f7166496996a7da21cf1f1b04d9b3e26a3d0772d4c407bbe49438ed859fe965b140dcf1aab71a96bbad7cf34b5fa511d8e963dbba288b1960e75d64430b3230294d12c6ab2aac5c2cd68e80b16b581ea0a6e3c511bbd10f4519ece37dc24887e11b55d7ae2f5b9e386cd1b50a4550696d957cb4900f03a82012708dafc9e1b880fd083b32182b869be8e0922b81f8e175ffde54d797fe11eb03f9e3bf75f1d68bf0b8b6fb4e317a0f9d6f03eaf8ce6675bc60d8c4d90829ce8f72d0163c1d5cf348a862d55063035e7a025f4da968de7e4d7e4004197917f4070f1d6caa02bbebaebb5d7e581e4b66559e635f805ff0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
|
|
|
|
GasLimit: 0x2625a00,
|
|
|
|
Difficulty: big.NewInt(0x1),
|
2023-01-13 18:12:18 +00:00
|
|
|
Mixhash: libcommon.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"),
|
|
|
|
Coinbase: libcommon.HexToAddress("0xffffFFFfFFffffffffffffffFfFFFfffFFFfFFfE"),
|
2022-01-14 22:06:35 +03:00
|
|
|
Alloc: readPrealloc("allocs/bsc.json"),
|
|
|
|
Number: 0x00,
|
|
|
|
GasUsed: 0x00,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func DefaultChapelGenesisBlock() *Genesis {
|
|
|
|
return &Genesis{
|
|
|
|
Config: params.ChapelChainConfig,
|
|
|
|
Nonce: 0x00,
|
|
|
|
Timestamp: 0x5e9da7ce,
|
|
|
|
ExtraData: hexutil.MustDecode("0x00000000000000000000000000000000000000000000000000000000000000001284214b9b9c85549ab3d2b972df0deef66ac2c9b71b214cb885500844365e95cd9942c7276e7fd8a2959d3f95eae5dc7d70144ce1b73b403b7eb6e0980a75ecd1309ea12fa2ed87a8744fbfc9b863d535552c16704d214347f29fa77f77da6d75d7c752f474cf03cceff28abc65c9cbae594f725c80e12d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
|
|
|
|
GasLimit: 0x2625a00,
|
|
|
|
Difficulty: big.NewInt(0x1),
|
2023-01-13 18:12:18 +00:00
|
|
|
Mixhash: libcommon.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"),
|
|
|
|
Coinbase: libcommon.HexToAddress("0xffffFFFfFFffffffffffffffFfFFFfffFFFfFFfE"),
|
2022-01-14 22:06:35 +03:00
|
|
|
Alloc: readPrealloc("allocs/chapel.json"),
|
|
|
|
Number: 0x00,
|
|
|
|
GasUsed: 0x00,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func DefaultRialtoGenesisBlock() *Genesis {
|
|
|
|
return &Genesis{
|
|
|
|
Config: params.RialtoChainConfig,
|
|
|
|
Nonce: 0x00,
|
|
|
|
Timestamp: 0x5e9da7ce,
|
|
|
|
ExtraData: hexutil.MustDecode("0x00000000000000000000000000000000000000000000000000000000000000001284214b9b9c85549ab3d2b972df0deef66ac2c9b71b214cb885500844365e95cd9942c7276e7fd8a2959d3f95eae5dc7d70144ce1b73b403b7eb6e0980a75ecd1309ea12fa2ed87a8744fbfc9b863d535552c16704d214347f29fa77f77da6d75d7c752f474cf03cceff28abc65c9cbae594f725c80e12d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
|
|
|
|
GasLimit: 0x2625a00,
|
|
|
|
Difficulty: big.NewInt(0x1),
|
2023-01-13 18:12:18 +00:00
|
|
|
Mixhash: libcommon.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"),
|
|
|
|
Coinbase: libcommon.HexToAddress("0xffffFFFfFFffffffffffffffFfFFFfffFFFfFFfE"),
|
2022-01-14 22:06:35 +03:00
|
|
|
Alloc: readPrealloc("allocs/bsc.json"),
|
|
|
|
Number: 0x00,
|
|
|
|
GasUsed: 0x00,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-08 00:30:46 +03:00
|
|
|
func DefaultMumbaiGenesisBlock() *Genesis {
|
|
|
|
return &Genesis{
|
|
|
|
Config: params.MumbaiChainConfig,
|
|
|
|
Nonce: 0,
|
|
|
|
Timestamp: 1558348305,
|
|
|
|
GasLimit: 10000000,
|
|
|
|
Difficulty: big.NewInt(1),
|
2023-01-13 18:12:18 +00:00
|
|
|
Mixhash: libcommon.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"),
|
|
|
|
Coinbase: libcommon.HexToAddress("0x0000000000000000000000000000000000000000"),
|
2022-02-08 00:30:46 +03:00
|
|
|
Alloc: readPrealloc("allocs/mumbai.json"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-10 19:04:13 +07:00
|
|
|
// DefaultBorMainnet returns the Bor Mainnet network gensis block.
|
2022-02-08 00:30:46 +03:00
|
|
|
func DefaultBorMainnetGenesisBlock() *Genesis {
|
|
|
|
return &Genesis{
|
|
|
|
Config: params.BorMainnetChainConfig,
|
|
|
|
Nonce: 0,
|
|
|
|
Timestamp: 1590824836,
|
|
|
|
GasLimit: 10000000,
|
|
|
|
Difficulty: big.NewInt(1),
|
2023-01-13 18:12:18 +00:00
|
|
|
Mixhash: libcommon.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"),
|
|
|
|
Coinbase: libcommon.HexToAddress("0x0000000000000000000000000000000000000000"),
|
2022-02-08 00:30:46 +03:00
|
|
|
Alloc: readPrealloc("allocs/bor_mainnet.json"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-10 14:02:04 +05:30
|
|
|
func DefaultBorDevnetGenesisBlock() *Genesis {
|
|
|
|
return &Genesis{
|
|
|
|
Config: params.BorDevnetChainConfig,
|
|
|
|
Nonce: 0,
|
|
|
|
Timestamp: 1558348305,
|
|
|
|
GasLimit: 10000000,
|
|
|
|
Difficulty: big.NewInt(1),
|
2023-01-13 18:12:18 +00:00
|
|
|
Mixhash: libcommon.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"),
|
|
|
|
Coinbase: libcommon.HexToAddress("0x0000000000000000000000000000000000000000"),
|
2022-06-10 14:02:04 +05:30
|
|
|
Alloc: readPrealloc("allocs/bor_devnet.json"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-12 19:21:52 +04:00
|
|
|
func DefaultGnosisGenesisBlock() *Genesis {
|
|
|
|
return &Genesis{
|
|
|
|
Config: params.GnosisChainConfig,
|
2022-10-21 12:43:44 +02:00
|
|
|
Timestamp: 0,
|
|
|
|
AuRaSeal: common.FromHex("0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
|
2022-07-12 19:21:52 +04:00
|
|
|
GasLimit: 0x989680,
|
|
|
|
Difficulty: big.NewInt(0x20000),
|
2022-10-21 12:43:44 +02:00
|
|
|
Alloc: readPrealloc("allocs/gnosis.json"),
|
2022-07-12 19:21:52 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
feat: add chiado config (#6058)
Hey guys, I'm trying to add the Chiado network ([Gnosis'
testnet](https://docs.gnosischain.com/about/networks/chiado)) now that
Gnosis can be synced fully with Erigon, so we can test it on the testnet
as well.
This is mostly inspired from
https://github.com/ledgerwatch/erigon/commit/cd5ef32f379ff51043b7ce1b0c3c471e18b99459.
Probably missing:
- [ ] The right consensus config (currently only a copy of Gnosis)
- [ ] Fixes to the chainspec?
- [ ] Presumably something in `cl/clparams/config.go`
Current state:
```
$ ./build/bin/erigon --chain=chiado --log.console.verbosity=debug
WARN[11-16|11:52:28.188] no log dir set, console logging only
WARN[11-16|11:52:28.193] no log dir set, console logging only
INFO[11-16|11:52:28.193] Build info git_branch=feat/chiado git_tag=v2021.10.03-2291-g17fae73f8 git_commit=17fae73f8af5348ba7c04684f2a2978daf81b67e
INFO[11-16|11:52:28.193] Starting Erigon on devnet=chiado
INFO[11-16|11:52:28.194] Maximum peer count ETH=100 total=100
INFO[11-16|11:52:28.194] starting HTTP APIs APIs=eth,erigon,engine
INFO[11-16|11:52:28.194] torrent verbosity level=WRN
INFO[11-16|11:52:30.300] Set global gas cap cap=50000000
INFO[11-16|11:52:30.302] Opening Database label=chaindata path=/home/filoozom/.local/share/erigon/chiado/chaindata
INFO[11-16|11:52:30.310] Initialised chain configuration config="{ChainID: 10200, Homestead: 0, DAO: <nil>, DAO Support: false, Tangerine Whistle: 0, Spurious Dragon: 0, Byzantium: 0, Constantinople: 0, Petersburg: 0, Istanbul: 0, Muir Glacier: <nil>, Berlin: 0, London: 0, Arrow Glacier: <nil>, Gray Glacier: <nil>, Terminal Total Difficulty: <nil>, Merge Netsplit: <nil>, Shanghai: <nil>, Cancun: <nil>, Engine: aura}" genesis=0xf463abeb7ee27fa62be3ac36a264e8174ee3458da451e6403df47618fd2cf415
WARN[11-16|11:52:30.311] Incorrect snapshot enablement got=true change_to=false
INFO[11-16|11:52:30.311] Effective prune_flags= snapshot_flags= history.v3=false
INFO[11-16|11:52:30.312] Initialising Ethereum protocol network=10200
INFO[11-16|11:52:30.329] Starting private RPC server on=127.0.0.1:9090
INFO[11-16|11:52:30.329] new subscription to logs established
INFO[11-16|11:52:30.329] rpc filters: subscribing to Erigon events
DBUG[11-16|11:52:30.330] Establishing event subscription channel with the RPC daemon ...
INFO[11-16|11:52:30.330] New txs subscriber joined
INFO[11-16|11:52:30.330] new subscription to newHeaders established
INFO[11-16|11:52:30.330] Reading JWT secret path=/home/filoozom/.local/share/erigon/chiado/jwt.hex
INFO[11-16|11:52:30.331] HTTP endpoint opened for Engine API url=localhost:8551 ws=true ws.compression=true
INFO[11-16|11:52:30.332] HTTP endpoint opened url=localhost:8545 ws=false ws.compression=true grpc=false
DBUG[11-16|11:52:30.336] Couldn't add port mapping proto=tcp extport=30304 intport=30304 interface="UPnP or NAT-PMP" err="no UPnP or NAT-PMP router discovered"
DBUG[11-16|11:52:30.336] Couldn't add port mapping proto=udp extport=30304 intport=30304 interface="UPnP or NAT-PMP" err="no UPnP or NAT-PMP router discovered"
DBUG[11-16|11:52:30.336] QuerySeeds read nodes from the node DB count=0
DBUG[11-16|11:52:30.341] [1/16 Snapshots] DONE in=134.7µs
INFO[11-16|11:52:30.341] [txpool] Started
INFO[11-16|11:52:30.341] [2/16 Headers] Waiting for headers... from=0
DBUG[11-16|11:52:30.341] [Downloader] Request skeleton anchors=0 top seen height=0 highestInDb=0
DBUG[11-16|11:52:30.343] Couldn't add port mapping proto=tcp extport=30303 intport=30303 interface="UPnP or NAT-PMP" err="no UPnP or NAT-PMP router discovered"
DBUG[11-16|11:52:30.343] Couldn't add port mapping proto=udp extport=30303 intport=30303 interface="UPnP or NAT-PMP" err="no UPnP or NAT-PMP router discovered"
DBUG[11-16|11:52:30.344] QuerySeeds read nodes from the node DB count=0
DBUG[11-16|11:52:30.346] QuerySeeds read nodes from the node DB count=0
INFO[11-16|11:52:30.347] Started P2P networking version=67 self=enode://47d2e31d90fe140bfd967f147c1d4e8a4834b4c6b895a4bb7082100be60aa5e9a73e98e996da9b0257f02f9ad39b683755abe6ca3e9aefe0170a478a8559dcfb@127.0.0.1:30304 name=erigon/v2.30.0-dev-17fae73f/linux-amd64/go1.18.1
DBUG[11-16|11:52:30.351] QuerySeeds read nodes from the node DB count=0
INFO[11-16|11:52:30.351] Started P2P networking version=66 self=enode://47d2e31d90fe140bfd967f147c1d4e8a4834b4c6b895a4bb7082100be60aa5e9a73e98e996da9b0257f02f9ad39b683755abe6ca3e9aefe0170a478a8559dcfb@127.0.0.1:30303 name=erigon/v2.30.0-dev-17fae73f/linux-amd64/go1.18.1
DBUG[11-16|11:52:31.342] [Downloader] Request skeleton anchors=0 top seen height=0 highestInDb=0
[...]
DBUG[11-16|11:52:32.342] [Downloader] Request skeleton anchors=0 top seen height=0 highestInDb=0
INFO[11-16|11:37:00.062] [p2p] GoodPeers eth66=0 eth67=0
INFO[11-16|11:37:00.077] [txpool] stat block=0 pending=0 baseFee=0 queued=0 alloc=42.7MB sys=79.5MB
INFO[11-16|11:37:00.089] [2/16 Headers] No block headers to write in this log period block number=0
INFO[11-16|11:37:00.089] Req/resp stats req=0 reqMin=0 reqMax=0 skel=0 skelMin=0 skelMax=0 resp=0 respMin=0 respMax=0 dups=0
DBUG[11-16|11:37:00.089] [Downloader] Queue sizes anchors=0 links=0 persisted=1
DBUG[11-16|11:37:00.089] [Downloader] Request skeleton anchors=0 top seen height=0 highestInDb=0
[...]
DBUG[11-16|11:37:06.095] [Downloader] Request skeleton anchors=0 top seen height=0 highestInDb=0
```
I guess it comes down to:
```
--- FAIL: TestDefaultBSCGenesisBlock (0.34s)
genesis_test.go:27:
Error Trace: /home/filoozom/projects/erigon/core/genesis_test.go:27
/home/filoozom/projects/erigon/core/genesis_test.go:30
Error: Not equal:
expected: []byte{0xe8, 0x72, 0x46, 0x2c, 0x6b, 0xd5, 0xf4, 0x2, 0xec, 0x81, 0xde, 0x7c, 0x5b, 0xd2, 0x82, 0x3e, 0x13, 0x7c, 0x66, 0x6b, 0x78, 0xe8, 0x2b, 0x7e, 0xb0, 0xbe, 0x95, 0xaf, 0x5e, 0xce, 0xa1, 0x8d}
actual : []byte{0xad, 0xa4, 0x4f, 0xd8, 0xd2, 0xec, 0xab, 0x8b, 0x8, 0xf2, 0x56, 0xaf, 0x7, 0xad, 0x3e, 0x77, 0x7f, 0x17, 0xfb, 0x43, 0x4f, 0x8f, 0x8e, 0x67, 0x8b, 0x31, 0x2f, 0x57, 0x62, 0x12, 0xba, 0x9a}
Diff:
--- Expected
+++ Actual
@@ -1,4 +1,4 @@
([]uint8) (len=32) {
- 00000000 e8 72 46 2c 6b d5 f4 02 ec 81 de 7c 5b d2 82 3e |.rF,k......|[..>|
- 00000010 13 7c 66 6b 78 e8 2b 7e b0 be 95 af 5e ce a1 8d |.|fkx.+~....^...|
+ 00000000 ad a4 4f d8 d2 ec ab 8b 08 f2 56 af 07 ad 3e 77 |..O.......V...>w|
+ 00000010 7f 17 fb 43 4f 8f 8e 67 8b 31 2f 57 62 12 ba 9a |...CO..g.1/Wb...|
}
Test: TestDefaultBSCGenesisBlock
Messages: chiado
FAIL
FAIL github.com/ledgerwatch/erigon/core 0.823s
```
----------
Turns out that the `code` in Erigon's chainspec is not the same as
`constructor` in Nethermind for example.
Comparison for Sokol:
- Erigon:
https://github.com/ledgerwatch/erigon/blob/devel/core/allocs/sokol.json#L20-L34
- Nethermind:
https://github.com/NethermindEth/nethermind/blob/master/src/Nethermind/Chains/sokol.json#L248-L252
2022-11-18 12:54:18 +01:00
|
|
|
func DefaultChiadoGenesisBlock() *Genesis {
|
|
|
|
return &Genesis{
|
|
|
|
Config: params.ChiadoChainConfig,
|
|
|
|
Timestamp: 0,
|
|
|
|
AuRaSeal: common.FromHex("0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
|
|
|
|
GasLimit: 0x989680,
|
|
|
|
Difficulty: big.NewInt(0x20000),
|
|
|
|
Alloc: readPrealloc("allocs/chiado.json"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-03 10:12:10 -08:00
|
|
|
func DefaultPulsechainGenesisBlock() *Genesis {
|
|
|
|
return &Genesis{
|
|
|
|
Config: params.PulsechainChainConfig,
|
|
|
|
Nonce: 66,
|
|
|
|
ExtraData: hexutil.MustDecode("0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa"),
|
|
|
|
GasLimit: 5000,
|
|
|
|
Difficulty: big.NewInt(17179869184),
|
|
|
|
Alloc: readPrealloc("allocs/mainnet.json"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-23 16:00:27 -05:00
|
|
|
func DefaultPulsechainTestnetV3GenesisBlock() *Genesis {
|
2023-01-03 10:12:10 -08:00
|
|
|
return &Genesis{
|
2023-03-23 16:00:27 -05:00
|
|
|
Config: params.PulsechainTestnetV3ChainConfig,
|
2023-01-03 10:12:10 -08:00
|
|
|
Nonce: 66,
|
|
|
|
ExtraData: hexutil.MustDecode("0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa"),
|
|
|
|
GasLimit: 5000,
|
|
|
|
Difficulty: big.NewInt(17179869184),
|
|
|
|
Alloc: readPrealloc("allocs/mainnet.json"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-26 13:52:40 -06:00
|
|
|
func DefaultPulsechainDevnetGenesisBlock() *Genesis {
|
|
|
|
return &Genesis{
|
|
|
|
Config: params.PulsechainDevnetChainConfig,
|
|
|
|
ExtraData: hexutil.MustDecode("0x0000000000000000000000000000000000000000000000000000000000000000123463a4B065722E99115D6c222f267d9cABb5240000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
|
|
|
|
GasLimit: 30000000,
|
|
|
|
Difficulty: big.NewInt(131072),
|
|
|
|
Alloc: readPrealloc("allocs/pulsechain-devnet.json"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-08 11:00:06 +07:00
|
|
|
// Pre-calculated version of:
|
2022-08-10 19:04:13 +07:00
|
|
|
//
|
|
|
|
// DevnetSignPrivateKey = crypto.HexToECDSA(sha256.Sum256([]byte("erigon devnet key")))
|
|
|
|
// DevnetEtherbase=crypto.PubkeyToAddress(DevnetSignPrivateKey.PublicKey)
|
2021-09-08 11:00:06 +07:00
|
|
|
var DevnetSignPrivateKey, _ = crypto.HexToECDSA("26e86e45f6fc45ec6e2ecd128cec80fa1d1505e5507dcd2ae58c3130a7a97b48")
|
2023-01-13 18:12:18 +00:00
|
|
|
var DevnetEtherbase = libcommon.HexToAddress("67b1d87101671b127f5f8714789c7192f7ad340e")
|
2021-09-07 16:12:49 +07:00
|
|
|
|
2019-12-10 11:50:16 +01:00
|
|
|
// DeveloperGenesisBlock returns the 'geth --dev' genesis block.
|
2023-01-13 18:12:18 +00:00
|
|
|
func DeveloperGenesisBlock(period uint64, faucet libcommon.Address) *Genesis {
|
2017-10-24 13:40:42 +03:00
|
|
|
// Override the default period to the user requested one
|
|
|
|
config := *params.AllCliqueProtocolChanges
|
|
|
|
config.Clique.Period = period
|
|
|
|
|
|
|
|
// Assemble and return the genesis with the precompiles and faucet pre-funded
|
2017-03-02 14:03:33 +01:00
|
|
|
return &Genesis{
|
2017-10-24 13:40:42 +03:00
|
|
|
Config: &config,
|
2019-08-22 15:14:06 +02:00
|
|
|
ExtraData: append(append(make([]byte, 32), faucet[:]...), make([]byte, crypto.SignatureLength)...),
|
2020-07-16 14:08:38 +02:00
|
|
|
GasLimit: 11500000,
|
2017-10-24 13:40:42 +03:00
|
|
|
Difficulty: big.NewInt(1),
|
2022-02-26 11:27:22 +04:00
|
|
|
Alloc: readPrealloc("allocs/dev.json"),
|
2016-11-20 22:32:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-09 13:00:50 +01:00
|
|
|
func readPrealloc(filename string) GenesisAlloc {
|
|
|
|
f, err := allocs.Open(filename)
|
|
|
|
if err != nil {
|
|
|
|
panic(fmt.Sprintf("Could not open genesis preallocation for %s: %v", filename, err))
|
2017-03-02 14:03:33 +01:00
|
|
|
}
|
2021-04-09 13:00:50 +01:00
|
|
|
defer f.Close()
|
|
|
|
decoder := json.NewDecoder(f)
|
|
|
|
ga := make(GenesisAlloc)
|
|
|
|
err = decoder.Decode(&ga)
|
|
|
|
if err != nil {
|
|
|
|
panic(fmt.Sprintf("Could not parse genesis preallocation for %s: %v", filename, err))
|
2017-01-09 12:09:37 +01:00
|
|
|
}
|
2017-03-02 14:03:33 +01:00
|
|
|
return ga
|
2015-11-17 18:33:25 +02:00
|
|
|
}
|
2022-03-03 15:57:10 +01:00
|
|
|
|
|
|
|
func DefaultGenesisBlockByChainName(chain string) *Genesis {
|
|
|
|
switch chain {
|
|
|
|
case networkname.MainnetChainName:
|
|
|
|
return DefaultGenesisBlock()
|
|
|
|
case networkname.SepoliaChainName:
|
|
|
|
return DefaultSepoliaGenesisBlock()
|
|
|
|
case networkname.RinkebyChainName:
|
|
|
|
return DefaultRinkebyGenesisBlock()
|
|
|
|
case networkname.GoerliChainName:
|
|
|
|
return DefaultGoerliGenesisBlock()
|
|
|
|
case networkname.SokolChainName:
|
|
|
|
return DefaultSokolGenesisBlock()
|
|
|
|
case networkname.BSCChainName:
|
|
|
|
return DefaultBSCGenesisBlock()
|
|
|
|
case networkname.ChapelChainName:
|
|
|
|
return DefaultChapelGenesisBlock()
|
|
|
|
case networkname.RialtoChainName:
|
|
|
|
return DefaultRialtoGenesisBlock()
|
|
|
|
case networkname.MumbaiChainName:
|
|
|
|
return DefaultMumbaiGenesisBlock()
|
|
|
|
case networkname.BorMainnetChainName:
|
|
|
|
return DefaultBorMainnetGenesisBlock()
|
2022-06-10 14:02:04 +05:30
|
|
|
case networkname.BorDevnetChainName:
|
|
|
|
return DefaultBorDevnetGenesisBlock()
|
2022-07-12 19:21:52 +04:00
|
|
|
case networkname.GnosisChainName:
|
|
|
|
return DefaultGnosisGenesisBlock()
|
feat: add chiado config (#6058)
Hey guys, I'm trying to add the Chiado network ([Gnosis'
testnet](https://docs.gnosischain.com/about/networks/chiado)) now that
Gnosis can be synced fully with Erigon, so we can test it on the testnet
as well.
This is mostly inspired from
https://github.com/ledgerwatch/erigon/commit/cd5ef32f379ff51043b7ce1b0c3c471e18b99459.
Probably missing:
- [ ] The right consensus config (currently only a copy of Gnosis)
- [ ] Fixes to the chainspec?
- [ ] Presumably something in `cl/clparams/config.go`
Current state:
```
$ ./build/bin/erigon --chain=chiado --log.console.verbosity=debug
WARN[11-16|11:52:28.188] no log dir set, console logging only
WARN[11-16|11:52:28.193] no log dir set, console logging only
INFO[11-16|11:52:28.193] Build info git_branch=feat/chiado git_tag=v2021.10.03-2291-g17fae73f8 git_commit=17fae73f8af5348ba7c04684f2a2978daf81b67e
INFO[11-16|11:52:28.193] Starting Erigon on devnet=chiado
INFO[11-16|11:52:28.194] Maximum peer count ETH=100 total=100
INFO[11-16|11:52:28.194] starting HTTP APIs APIs=eth,erigon,engine
INFO[11-16|11:52:28.194] torrent verbosity level=WRN
INFO[11-16|11:52:30.300] Set global gas cap cap=50000000
INFO[11-16|11:52:30.302] Opening Database label=chaindata path=/home/filoozom/.local/share/erigon/chiado/chaindata
INFO[11-16|11:52:30.310] Initialised chain configuration config="{ChainID: 10200, Homestead: 0, DAO: <nil>, DAO Support: false, Tangerine Whistle: 0, Spurious Dragon: 0, Byzantium: 0, Constantinople: 0, Petersburg: 0, Istanbul: 0, Muir Glacier: <nil>, Berlin: 0, London: 0, Arrow Glacier: <nil>, Gray Glacier: <nil>, Terminal Total Difficulty: <nil>, Merge Netsplit: <nil>, Shanghai: <nil>, Cancun: <nil>, Engine: aura}" genesis=0xf463abeb7ee27fa62be3ac36a264e8174ee3458da451e6403df47618fd2cf415
WARN[11-16|11:52:30.311] Incorrect snapshot enablement got=true change_to=false
INFO[11-16|11:52:30.311] Effective prune_flags= snapshot_flags= history.v3=false
INFO[11-16|11:52:30.312] Initialising Ethereum protocol network=10200
INFO[11-16|11:52:30.329] Starting private RPC server on=127.0.0.1:9090
INFO[11-16|11:52:30.329] new subscription to logs established
INFO[11-16|11:52:30.329] rpc filters: subscribing to Erigon events
DBUG[11-16|11:52:30.330] Establishing event subscription channel with the RPC daemon ...
INFO[11-16|11:52:30.330] New txs subscriber joined
INFO[11-16|11:52:30.330] new subscription to newHeaders established
INFO[11-16|11:52:30.330] Reading JWT secret path=/home/filoozom/.local/share/erigon/chiado/jwt.hex
INFO[11-16|11:52:30.331] HTTP endpoint opened for Engine API url=localhost:8551 ws=true ws.compression=true
INFO[11-16|11:52:30.332] HTTP endpoint opened url=localhost:8545 ws=false ws.compression=true grpc=false
DBUG[11-16|11:52:30.336] Couldn't add port mapping proto=tcp extport=30304 intport=30304 interface="UPnP or NAT-PMP" err="no UPnP or NAT-PMP router discovered"
DBUG[11-16|11:52:30.336] Couldn't add port mapping proto=udp extport=30304 intport=30304 interface="UPnP or NAT-PMP" err="no UPnP or NAT-PMP router discovered"
DBUG[11-16|11:52:30.336] QuerySeeds read nodes from the node DB count=0
DBUG[11-16|11:52:30.341] [1/16 Snapshots] DONE in=134.7µs
INFO[11-16|11:52:30.341] [txpool] Started
INFO[11-16|11:52:30.341] [2/16 Headers] Waiting for headers... from=0
DBUG[11-16|11:52:30.341] [Downloader] Request skeleton anchors=0 top seen height=0 highestInDb=0
DBUG[11-16|11:52:30.343] Couldn't add port mapping proto=tcp extport=30303 intport=30303 interface="UPnP or NAT-PMP" err="no UPnP or NAT-PMP router discovered"
DBUG[11-16|11:52:30.343] Couldn't add port mapping proto=udp extport=30303 intport=30303 interface="UPnP or NAT-PMP" err="no UPnP or NAT-PMP router discovered"
DBUG[11-16|11:52:30.344] QuerySeeds read nodes from the node DB count=0
DBUG[11-16|11:52:30.346] QuerySeeds read nodes from the node DB count=0
INFO[11-16|11:52:30.347] Started P2P networking version=67 self=enode://47d2e31d90fe140bfd967f147c1d4e8a4834b4c6b895a4bb7082100be60aa5e9a73e98e996da9b0257f02f9ad39b683755abe6ca3e9aefe0170a478a8559dcfb@127.0.0.1:30304 name=erigon/v2.30.0-dev-17fae73f/linux-amd64/go1.18.1
DBUG[11-16|11:52:30.351] QuerySeeds read nodes from the node DB count=0
INFO[11-16|11:52:30.351] Started P2P networking version=66 self=enode://47d2e31d90fe140bfd967f147c1d4e8a4834b4c6b895a4bb7082100be60aa5e9a73e98e996da9b0257f02f9ad39b683755abe6ca3e9aefe0170a478a8559dcfb@127.0.0.1:30303 name=erigon/v2.30.0-dev-17fae73f/linux-amd64/go1.18.1
DBUG[11-16|11:52:31.342] [Downloader] Request skeleton anchors=0 top seen height=0 highestInDb=0
[...]
DBUG[11-16|11:52:32.342] [Downloader] Request skeleton anchors=0 top seen height=0 highestInDb=0
INFO[11-16|11:37:00.062] [p2p] GoodPeers eth66=0 eth67=0
INFO[11-16|11:37:00.077] [txpool] stat block=0 pending=0 baseFee=0 queued=0 alloc=42.7MB sys=79.5MB
INFO[11-16|11:37:00.089] [2/16 Headers] No block headers to write in this log period block number=0
INFO[11-16|11:37:00.089] Req/resp stats req=0 reqMin=0 reqMax=0 skel=0 skelMin=0 skelMax=0 resp=0 respMin=0 respMax=0 dups=0
DBUG[11-16|11:37:00.089] [Downloader] Queue sizes anchors=0 links=0 persisted=1
DBUG[11-16|11:37:00.089] [Downloader] Request skeleton anchors=0 top seen height=0 highestInDb=0
[...]
DBUG[11-16|11:37:06.095] [Downloader] Request skeleton anchors=0 top seen height=0 highestInDb=0
```
I guess it comes down to:
```
--- FAIL: TestDefaultBSCGenesisBlock (0.34s)
genesis_test.go:27:
Error Trace: /home/filoozom/projects/erigon/core/genesis_test.go:27
/home/filoozom/projects/erigon/core/genesis_test.go:30
Error: Not equal:
expected: []byte{0xe8, 0x72, 0x46, 0x2c, 0x6b, 0xd5, 0xf4, 0x2, 0xec, 0x81, 0xde, 0x7c, 0x5b, 0xd2, 0x82, 0x3e, 0x13, 0x7c, 0x66, 0x6b, 0x78, 0xe8, 0x2b, 0x7e, 0xb0, 0xbe, 0x95, 0xaf, 0x5e, 0xce, 0xa1, 0x8d}
actual : []byte{0xad, 0xa4, 0x4f, 0xd8, 0xd2, 0xec, 0xab, 0x8b, 0x8, 0xf2, 0x56, 0xaf, 0x7, 0xad, 0x3e, 0x77, 0x7f, 0x17, 0xfb, 0x43, 0x4f, 0x8f, 0x8e, 0x67, 0x8b, 0x31, 0x2f, 0x57, 0x62, 0x12, 0xba, 0x9a}
Diff:
--- Expected
+++ Actual
@@ -1,4 +1,4 @@
([]uint8) (len=32) {
- 00000000 e8 72 46 2c 6b d5 f4 02 ec 81 de 7c 5b d2 82 3e |.rF,k......|[..>|
- 00000010 13 7c 66 6b 78 e8 2b 7e b0 be 95 af 5e ce a1 8d |.|fkx.+~....^...|
+ 00000000 ad a4 4f d8 d2 ec ab 8b 08 f2 56 af 07 ad 3e 77 |..O.......V...>w|
+ 00000010 7f 17 fb 43 4f 8f 8e 67 8b 31 2f 57 62 12 ba 9a |...CO..g.1/Wb...|
}
Test: TestDefaultBSCGenesisBlock
Messages: chiado
FAIL
FAIL github.com/ledgerwatch/erigon/core 0.823s
```
----------
Turns out that the `code` in Erigon's chainspec is not the same as
`constructor` in Nethermind for example.
Comparison for Sokol:
- Erigon:
https://github.com/ledgerwatch/erigon/blob/devel/core/allocs/sokol.json#L20-L34
- Nethermind:
https://github.com/NethermindEth/nethermind/blob/master/src/Nethermind/Chains/sokol.json#L248-L252
2022-11-18 12:54:18 +01:00
|
|
|
case networkname.ChiadoChainName:
|
|
|
|
return DefaultChiadoGenesisBlock()
|
2023-01-03 10:12:10 -08:00
|
|
|
case networkname.PulsechainChainName:
|
|
|
|
return DefaultPulsechainGenesisBlock()
|
2023-02-26 13:52:40 -06:00
|
|
|
case networkname.PulsechainDevnetChainName:
|
|
|
|
return DefaultPulsechainDevnetGenesisBlock()
|
2023-03-23 16:00:27 -05:00
|
|
|
case networkname.PulsechainTestnetV3ChainName:
|
|
|
|
return DefaultPulsechainTestnetV3GenesisBlock()
|
2022-03-03 15:57:10 +01:00
|
|
|
default:
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|