erigon-pulse/core/genesis_write.go

731 lines
24 KiB
Go
Raw Permalink Normal View History

2015-07-07 00:54:22 +00:00
// Copyright 2014 The go-ethereum Authors
// This file is part of the go-ethereum library.
2015-07-07 00:54:22 +00:00
//
// The go-ethereum library is free software: you can redistribute it and/or modify
2015-07-07 00:54:22 +00: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.
//
// The go-ethereum library is distributed in the hope that it will be useful,
2015-07-07 00:54:22 +00:00
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2015-07-07 00:54:22 +00:00
// 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/>.
2015-07-07 00:54:22 +00:00
2014-12-04 09:28:02 +00:00
package core
2014-02-14 22:56:09 +00:00
import (
"context"
"crypto/ecdsa"
"embed"
"encoding/binary"
"encoding/json"
2015-02-20 17:05:46 +00:00
"fmt"
"math/big"
"sync"
"github.com/c2h5oh/datasize"
"github.com/holiman/uint256"
"github.com/ledgerwatch/log/v3"
"golang.org/x/exp/slices"
"github.com/ledgerwatch/erigon-lib/chain"
"github.com/ledgerwatch/erigon-lib/chain/networkname"
libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/common/hexutil"
2021-07-29 11:53:13 +00:00
"github.com/ledgerwatch/erigon-lib/kv"
2023-06-09 06:46:58 +00:00
"github.com/ledgerwatch/erigon-lib/kv/kvcfg"
2021-07-29 11:53:13 +00:00
"github.com/ledgerwatch/erigon-lib/kv/mdbx"
2023-01-25 09:29:41 +00:00
"github.com/ledgerwatch/erigon-lib/kv/rawdbv3"
"github.com/ledgerwatch/erigon/common"
"github.com/ledgerwatch/erigon/consensus/ethash"
"github.com/ledgerwatch/erigon/consensus/merge"
"github.com/ledgerwatch/erigon/core/rawdb"
"github.com/ledgerwatch/erigon/core/state"
"github.com/ledgerwatch/erigon/core/types"
"github.com/ledgerwatch/erigon/crypto"
2023-03-31 02:19:56 +00:00
"github.com/ledgerwatch/erigon/eth/ethconfig"
"github.com/ledgerwatch/erigon/params"
"github.com/ledgerwatch/erigon/turbo/trie"
2014-02-14 22:56:09 +00:00
)
// CommitGenesisBlock writes or updates the genesis block in db.
// The block that will be used is:
//
2022-08-10 12:04:13 +00:00
// genesis == nil genesis != nil
// +------------------------------------------
// db has no genesis | main-net | genesis
2022-08-10 12:04:13 +00:00
// db has genesis | from DB | genesis (if compatible)
//
// 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.
func CommitGenesisBlock(db kv.RwDB, genesis *types.Genesis, tmpDir string, logger log.Logger) (*chain.Config, *types.Block, error) {
return CommitGenesisBlockWithOverride(db, genesis, nil, tmpDir, logger)
}
func CommitGenesisBlockWithOverride(db kv.RwDB, genesis *types.Genesis, overrideCancunTime *big.Int, tmpDir string, logger log.Logger) (*chain.Config, *types.Block, error) {
tx, err := db.BeginRw(context.Background())
if err != nil {
return nil, nil, err
}
defer tx.Rollback()
c, b, err := WriteGenesisBlock(tx, genesis, overrideCancunTime, tmpDir, logger)
if err != nil {
return c, b, err
}
err = tx.Commit()
if err != nil {
return c, b, err
}
return c, b, nil
}
func WriteGenesisBlock(tx kv.RwTx, genesis *types.Genesis, overrideCancunTime *big.Int, tmpDir string, logger log.Logger) (*chain.Config, *types.Block, error) {
var storedBlock *types.Block
if genesis != nil && genesis.Config == nil {
return params.AllProtocolChanges, nil, types.ErrGenesisNoConfig
}
// Just commit the new block if there is no stored genesis block.
storedHash, storedErr := rawdb.ReadCanonicalHash(tx, 0)
if storedErr != nil {
2021-05-23 05:41:42 +00:00
return nil, nil, storedErr
}
applyOverrides := func(config *chain.Config) {
if overrideCancunTime != nil {
config.CancunTime = overrideCancunTime
}
}
if (storedHash == libcommon.Hash{}) {
custom := true
if genesis == nil {
logger.Info("Writing main-net genesis block")
genesis = MainnetGenesisBlock()
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 21:21:51 +00:00
}
applyOverrides(genesis.Config)
block, _, err1 := write(tx, genesis, tmpDir, logger)
if err1 != nil {
2021-05-23 05:41:42 +00:00
return genesis.Config, nil, err1
}
if custom {
logger.Info("Writing custom genesis block", "hash", block.Hash().String())
}
2021-05-23 05:41:42 +00:00
return genesis.Config, block, nil
}
2021-05-23 05:41:42 +00:00
// Assume mainnet chainId first
chainId := params.MainnetChainConfig.ChainID.Uint64()
// Check whether the genesis block is already written.
if genesis != nil {
block, _, err1 := GenesisToBlock(genesis, tmpDir, logger)
if err1 != nil {
2021-05-23 05:41:42 +00:00
return genesis.Config, nil, err1
}
// Use the incoming chainID for building chain config.
// Allows for mainnet genesis w/ pulsechain config.
chainId = genesis.Config.ChainID.Uint64()
hash := block.Hash()
if hash != storedHash {
return genesis.Config, block, &types.GenesisMismatchError{Stored: storedHash, New: hash}
}
}
number := rawdb.ReadHeaderNumber(tx, storedHash)
if number != nil {
var err error
storedBlock, _, err = rawdb.ReadBlockWithSenders(tx, storedHash, *number)
if err != nil {
return genesis.Config, nil, err
}
2021-05-23 05:41:42 +00:00
}
storedCfg, storedErr := rawdb.ReadChainConfig(tx, storedHash)
if storedErr == nil && storedCfg != nil {
// Use the existing chainID for building chain config.
// Allows for mainnet genesis w/ pulsechain config.
chainId = storedCfg.ChainID.Uint64()
}
// Get the existing chain configuration.
newCfg := genesis.ConfigOrDefault(storedHash, chainId)
applyOverrides(newCfg)
if err := newCfg.CheckConfigForkOrder(); err != nil {
return newCfg, nil, err
}
if storedErr != nil && newCfg.Bor == nil {
return newCfg, nil, storedErr
}
if storedCfg == nil {
logger.Warn("Found genesis block without chain config")
err1 := rawdb.WriteChainConfig(tx, storedHash, newCfg)
if err1 != nil {
return newCfg, nil, err1
}
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 21:21:51 +00:00
}
// Special case: don't change the existing config of a private chain if no new
// config is supplied. This is useful, for example, to preserve DB config created by erigon init.
// In that case, only apply the overrides.
if genesis == nil && params.ChainConfigByGenesisHash(storedHash) == nil {
newCfg = storedCfg
applyOverrides(newCfg)
}
// Check config compatibility and write the config. Compatibility errors
// are returned to the caller unless we're already at block zero.
height := rawdb.ReadHeaderNumber(tx, rawdb.ReadHeadHeaderHash(tx))
if height != nil {
compatibilityErr := storedCfg.CheckCompatible(newCfg, *height)
if compatibilityErr != nil && *height != 0 && compatibilityErr.RewindTo != 0 {
return newCfg, storedBlock, compatibilityErr
More updates to downloader, new p2psentry protocol (#1559) * Initial commit * Add sentry gRPC interface * p2psentry directory * Update README.md * Update README.md * Update README.md * Add go package * Correct syntax * add external downloader interface (#2) * Add txpool (#3) * Add private API (#4) * Invert control.proto, add PeerMinBlock, Separare incoming Tx message into a separate stream (#5) Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local> * Separate upload messages into its own stream (#6) Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local> * Only send changed accounts to listeners (#7) * Txpool interface doc (#9) * More additions * More additions * Fix locking * Intermediate * Fix separation of phases * Intermediate * Fix test * More transformations * New simplified way of downloading headers * Fix hard-coded header sync * Fixed syncing near the tip of the chain * Add architecture diagram source and picture (#10) * More fixes * rename tip to link * Use preverified hashes instead of preverified headers * Fix preverified hashes generation * more parametrisation * Continue parametrisation * Fix grpc data limit, interruption of headers stage * Add ropsten preverified hashes * Typed hashes (#11) * Typed hashes * Fix PeerId * 64-bit tx nonce * Disable penalties * Add goerli settings, bootstrap nodes * Try to fix goerly sync * Remove interfaces * Add proper golang packages, max_block into p2p sentry Status * Prepare for proto overhaul * Squashed 'interfaces/' content from commit ce36053c2 git-subtree-dir: interfaces git-subtree-split: ce36053c24db2f56e48ac752808de60afa1dfb4b * Change EtherReply to address * Adaptations to new types * Switch to new types * Fixes * Fix formatting * Fix lint * Lint fixes, reverse order in types * Fix lint * Fix lint * Fix lint * Fix test * Not supporting eth/66 yet * Fix shutdown * Fix lint * Fix lint * Fix lint * return stopped check Co-authored-by: Artem Vorotnikov <artem@vorotnikov.me> Co-authored-by: b00ris <b00ris@mail.ru> Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local> Co-authored-by: lightclient <14004106+lightclient@users.noreply.github.com> Co-authored-by: canepat <16927169+canepat@users.noreply.github.com>
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 21:21:51 +00:00
}
if err := rawdb.WriteChainConfig(tx, storedHash, newCfg); err != nil {
return newCfg, nil, err
}
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 21:21:51 +00:00
func WriteGenesisState(g *types.Genesis, tx kv.RwTx, tmpDir string, logger log.Logger) (*types.Block, *state.IntraBlockState, error) {
block, statedb, err := GenesisToBlock(g, tmpDir, logger)
if err != nil {
return nil, nil, err
}
2023-06-11 04:49:53 +00:00
histV3, err := kvcfg.HistoryV3.Enabled(tx)
if err != nil {
panic(err)
}
2023-03-31 02:19:56 +00:00
var stateWriter state.StateWriter
if ethconfig.EnableHistoryV4InTest {
panic("implement me")
//tx.(*temporal.Tx).Agg().SetTxNum(0)
//stateWriter = state.NewWriterV4(tx.(kv.TemporalTx))
//defer tx.(*temporal.Tx).Agg().StartUnbufferedWrites().FinishWrites()
} else {
for addr, account := range g.Alloc {
if len(account.Code) > 0 || len(account.Storage) > 0 {
// Special case for weird tests - inaccessible storage
var b [8]byte
binary.BigEndian.PutUint64(b[:], state.FirstContractIncarnation)
if err := tx.Put(kv.IncarnationMap, addr[:], b[:]); err != nil {
return nil, nil, err
}
}
}
2023-03-31 02:19:56 +00:00
stateWriter = state.NewPlainStateWriter(tx, tx, 0)
}
if block.Number().Sign() != 0 {
return nil, statedb, fmt.Errorf("can't commit genesis block with number > 0")
}
2023-03-31 02:19:56 +00:00
if err := statedb.CommitBlock(&chain.Rules{}, stateWriter); err != nil {
2021-10-04 15:16:52 +00:00
return nil, statedb, fmt.Errorf("cannot write state: %w", err)
}
2023-06-11 04:49:53 +00:00
if !histV3 {
if csw, ok := stateWriter.(state.WriterWithChangeSets); ok {
if err := csw.WriteChangeSets(); err != nil {
return nil, statedb, fmt.Errorf("cannot write change sets: %w", err)
}
if err := csw.WriteHistory(); err != nil {
return nil, statedb, fmt.Errorf("cannot write history: %w", err)
}
2023-03-31 02:19:56 +00:00
}
}
return block, statedb, nil
}
func MustCommitGenesis(g *types.Genesis, db kv.RwDB, tmpDir string, logger log.Logger) *types.Block {
tx, err := db.BeginRw(context.Background())
if err != nil {
panic(err)
}
defer tx.Rollback()
block, _, err := write(tx, g, tmpDir, logger)
if err != nil {
panic(err)
}
err = tx.Commit()
if err != nil {
panic(err)
}
return block
}
// Write writes the block and state of a genesis specification to the database.
// The block is committed as the canonical head block.
func write(tx kv.RwTx, g *types.Genesis, tmpDir string, logger log.Logger) (*types.Block, *state.IntraBlockState, error) {
block, statedb, err2 := WriteGenesisState(g, tx, tmpDir, logger)
if err2 != nil {
return block, statedb, err2
}
config := g.Config
if config == nil {
config = params.AllProtocolChanges
}
if err := config.CheckConfigForkOrder(); err != nil {
return nil, nil, err
}
if err := rawdb.WriteBlock(tx, block); err != nil {
return nil, nil, err
}
if err := rawdb.WriteTd(tx, block.Hash(), block.NumberU64(), g.Difficulty); err != nil {
return nil, nil, err
}
2023-01-22 12:39:33 +00:00
if err := rawdbv3.TxNums.WriteForGenesis(tx, 1); err != nil {
return nil, nil, err
}
if err := rawdb.WriteReceipts(tx, block.NumberU64(), nil); err != nil {
return nil, nil, err
}
if err := rawdb.WriteCanonicalHash(tx, block.Hash(), block.NumberU64()); err != nil {
return nil, nil, err
}
rawdb.WriteHeadBlockHash(tx, block.Hash())
if err := rawdb.WriteHeadHeaderHash(tx, block.Hash()); err != nil {
return nil, nil, err
}
if err := rawdb.WriteChainConfig(tx, block.Hash(), config); err != nil {
2020-10-24 17:05:12 +00:00
return nil, nil, err
}
// We support ethash/merge for issuance (for now)
if g.Config.Consensus != chain.EtHashConsensus {
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(merge.ProofOfStakeDifficulty) != 0 {
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
}
return block, statedb, rawdb.WriteTotalBurnt(tx, 0, libcommon.Big0)
}
// GenesisBlockForTesting creates and writes a block in which addr has the given wei balance.
func GenesisBlockForTesting(db kv.RwDB, addr libcommon.Address, balance *big.Int, tmpDir string, logger log.Logger) *types.Block {
g := types.Genesis{Alloc: types.GenesisAlloc{addr: {Balance: balance}}, Config: params.TestChainConfig}
block := MustCommitGenesis(&g, db, tmpDir, logger)
return block
2015-10-05 11:01:34 +00:00
}
type GenAccount struct {
Addr libcommon.Address
Balance *big.Int
}
func GenesisWithAccounts(db kv.RwDB, accs []GenAccount, tmpDir string, logger log.Logger) *types.Block {
g := types.Genesis{Config: params.TestChainConfig}
allocs := make(map[libcommon.Address]types.GenesisAccount)
for _, acc := range accs {
allocs[acc.Addr] = types.GenesisAccount{Balance: acc.Balance}
}
g.Alloc = allocs
block := MustCommitGenesis(&g, db, tmpDir, logger)
return block
}
// MainnetGenesisBlock returns the Ethereum main net genesis block.
func MainnetGenesisBlock() *types.Genesis {
return &types.Genesis{
Config: params.MainnetChainConfig,
Nonce: 66,
ExtraData: hexutil.MustDecode("0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa"),
GasLimit: 5000,
Difficulty: big.NewInt(17179869184),
Alloc: readPrealloc("allocs/mainnet.json"),
}
}
2023-08-26 10:31:29 +00:00
// HoleskyGenesisBlock returns the Holesky main net genesis block.
func HoleskyGenesisBlock() *types.Genesis {
return &types.Genesis{
Config: params.HoleskyChainConfig,
Nonce: 4660,
GasLimit: 25000000,
Difficulty: big.NewInt(1),
2023-09-18 22:36:13 +00:00
Timestamp: 1695902100,
2023-08-26 10:31:29 +00:00
Alloc: readPrealloc("allocs/holesky.json"),
}
}
// SepoliaGenesisBlock returns the Sepolia network genesis block.
func SepoliaGenesisBlock() *types.Genesis {
return &types.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"),
}
}
// GoerliGenesisBlock returns the Görli network genesis block.
func GoerliGenesisBlock() *types.Genesis {
return &types.Genesis{
Config: params.GoerliChainConfig,
Timestamp: 1548854791,
ExtraData: hexutil.MustDecode("0x22466c6578692069732061207468696e6722202d204166726900000000000000e0a2bd4258d2768837baa26a28fe71dc079f84c70000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
GasLimit: 10485760,
Difficulty: big.NewInt(1),
Alloc: readPrealloc("allocs/goerli.json"),
}
}
// MumbaiGenesisBlock returns the Amoy network genesis block.
func MumbaiGenesisBlock() *types.Genesis {
return &types.Genesis{
Merging Turbo bor into devel (#3372) * implemented bor consensus * add bor flags to default * change bucket into snapshot to clique * enable stateSync * bypass reciept checks * fix receipt calculation and bor logs * fix: contract call wrt bor * Update mumbai config * Add: bor-mainnet flag and config * Add bor consensus to integration * use header coinbase in block context * london fork mumbai changes * fix genesis error * Jaipur fork for mumbai * add sysCall to verifyHeader * added bor related rpc method implementation * added bor specific rpc extensions * fixes in snapshot implementation, major refactor for bor rpc * modify consensus specific db path for bor * fix: remove parallel compute for get root hash rpc method * Added bor-receipt flow * Use turbo-bor-lib and bor tables * Use bor table in RPC snapshot * Update README.md * Update README.md * Update README.md * Update README.md * update rpc readme * link rpc docs in readme * Update Readme * Update Readme * move erigon namespace rpc methods to eth * rm: erigon namespace * rm: erigon namespace, update list of available rpc methods, add example * fix: binary name in rpc readme * fix: max db size * Add london to bor-mainnet * updated node.go * add system req to readme * golang version fix readme * added networknames in correct place * nil * ran gofmt * erigon * fixed fake.go * dont need turbor-lib * old readme * fixing readme * half * other half * changed return * fixing return * fixed return * fixed flags * gofmt * merge with devel * latest erigon-lib * fixed context.coinbase * took out syscall * fixed params in hash * bor type now is consensus.Engine * parlia is consensus.Engine * missing arg and repeated importation * repeated importation * fixed eth_receipts.go * deleted duplicate issuance * part of consensus.Engine type * added eth_api issuance * networkname * added erigon_system file * fork struct taken out * added erigon block * getLogByHash for erigonImpl * gofmt * fixed lint * ops * gofmt * gofmt * added APIImple functions * fixed clique test * took out print * fixed state added balance * fixed README * fixed rpcDaemon README * fixed integration README * updated blockchain.go * lint * added bor back into blockchain.go * took out comment * lint * updated daemon * updated wtb * removed duplicate * removed VerifyHeaders * prevent use of wrong Transfer * fixed state_processor.go * fixed state_transition.go * fixed headers * returning err * error handling in bor read tx look up * put for txLookUp * dealing with error * lint * traces * more traces * fixed receipt in execution * getTrasanction receipt for bor or others * nil * lint * ops * deleted syscall * took out else * Merge branch 'devel * tests syscalls * changed borReceipt to receipt * reset header algos * arguments fix * took out prefixes * lint * erigon-named * borReceiptKey = blocknumber * reverts e3b60c2e159d03efcb855f7ab3da5a098dd60c33. * correct hashing tx * dont need it here * lint * added txlookup for bor * change to uint256 * outputs for isBor * wrapper * added isBor and isParlia * isBor * fixed BorTransfer * not readBody * correct prefix * added blockNum * added readStorageBody * readStorageBody * lint * got rid of unnecessary bor_receipt func * onlny if bor * use clone * append * writeToSlice * added isBor flag * fixed writeToSlice * normal sorting * lint * Reset erigon-snapshots * Move bor prefix into if Co-authored-by: Krishna Upadhyaya <krishnau1604@gmail.com> Co-authored-by: Manav Darji <manavdarji.india@gmail.com> Co-authored-by: Uttam Singh <uttamkhanduja@yahoo.in> Co-authored-by: Giulio Rebuffo <giulio.rebuffo@gmail.com> Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
2022-02-07 21:30:46 +00:00
Config: params.MumbaiChainConfig,
Nonce: 0,
Timestamp: 1558348305,
GasLimit: 10000000,
Difficulty: big.NewInt(1),
Mixhash: libcommon.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"),
Coinbase: libcommon.HexToAddress("0x0000000000000000000000000000000000000000"),
Merging Turbo bor into devel (#3372) * implemented bor consensus * add bor flags to default * change bucket into snapshot to clique * enable stateSync * bypass reciept checks * fix receipt calculation and bor logs * fix: contract call wrt bor * Update mumbai config * Add: bor-mainnet flag and config * Add bor consensus to integration * use header coinbase in block context * london fork mumbai changes * fix genesis error * Jaipur fork for mumbai * add sysCall to verifyHeader * added bor related rpc method implementation * added bor specific rpc extensions * fixes in snapshot implementation, major refactor for bor rpc * modify consensus specific db path for bor * fix: remove parallel compute for get root hash rpc method * Added bor-receipt flow * Use turbo-bor-lib and bor tables * Use bor table in RPC snapshot * Update README.md * Update README.md * Update README.md * Update README.md * update rpc readme * link rpc docs in readme * Update Readme * Update Readme * move erigon namespace rpc methods to eth * rm: erigon namespace * rm: erigon namespace, update list of available rpc methods, add example * fix: binary name in rpc readme * fix: max db size * Add london to bor-mainnet * updated node.go * add system req to readme * golang version fix readme * added networknames in correct place * nil * ran gofmt * erigon * fixed fake.go * dont need turbor-lib * old readme * fixing readme * half * other half * changed return * fixing return * fixed return * fixed flags * gofmt * merge with devel * latest erigon-lib * fixed context.coinbase * took out syscall * fixed params in hash * bor type now is consensus.Engine * parlia is consensus.Engine * missing arg and repeated importation * repeated importation * fixed eth_receipts.go * deleted duplicate issuance * part of consensus.Engine type * added eth_api issuance * networkname * added erigon_system file * fork struct taken out * added erigon block * getLogByHash for erigonImpl * gofmt * fixed lint * ops * gofmt * gofmt * added APIImple functions * fixed clique test * took out print * fixed state added balance * fixed README * fixed rpcDaemon README * fixed integration README * updated blockchain.go * lint * added bor back into blockchain.go * took out comment * lint * updated daemon * updated wtb * removed duplicate * removed VerifyHeaders * prevent use of wrong Transfer * fixed state_processor.go * fixed state_transition.go * fixed headers * returning err * error handling in bor read tx look up * put for txLookUp * dealing with error * lint * traces * more traces * fixed receipt in execution * getTrasanction receipt for bor or others * nil * lint * ops * deleted syscall * took out else * Merge branch 'devel * tests syscalls * changed borReceipt to receipt * reset header algos * arguments fix * took out prefixes * lint * erigon-named * borReceiptKey = blocknumber * reverts e3b60c2e159d03efcb855f7ab3da5a098dd60c33. * correct hashing tx * dont need it here * lint * added txlookup for bor * change to uint256 * outputs for isBor * wrapper * added isBor and isParlia * isBor * fixed BorTransfer * not readBody * correct prefix * added blockNum * added readStorageBody * readStorageBody * lint * got rid of unnecessary bor_receipt func * onlny if bor * use clone * append * writeToSlice * added isBor flag * fixed writeToSlice * normal sorting * lint * Reset erigon-snapshots * Move bor prefix into if Co-authored-by: Krishna Upadhyaya <krishnau1604@gmail.com> Co-authored-by: Manav Darji <manavdarji.india@gmail.com> Co-authored-by: Uttam Singh <uttamkhanduja@yahoo.in> Co-authored-by: Giulio Rebuffo <giulio.rebuffo@gmail.com> Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
2022-02-07 21:30:46 +00:00
Alloc: readPrealloc("allocs/mumbai.json"),
}
}
// AmoyGenesisBlock returns the Amoy network genesis block.
func AmoyGenesisBlock() *types.Genesis {
return &types.Genesis{
Config: params.AmoyChainConfig,
Nonce: 0,
Timestamp: 1700225065,
GasLimit: 10000000,
Difficulty: big.NewInt(1),
Mixhash: libcommon.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"),
Coinbase: libcommon.HexToAddress("0x0000000000000000000000000000000000000000"),
Alloc: readPrealloc("allocs/amoy.json"),
}
}
// BorMainnetGenesisBlock returns the Bor Mainnet network genesis block.
func BorMainnetGenesisBlock() *types.Genesis {
return &types.Genesis{
Merging Turbo bor into devel (#3372) * implemented bor consensus * add bor flags to default * change bucket into snapshot to clique * enable stateSync * bypass reciept checks * fix receipt calculation and bor logs * fix: contract call wrt bor * Update mumbai config * Add: bor-mainnet flag and config * Add bor consensus to integration * use header coinbase in block context * london fork mumbai changes * fix genesis error * Jaipur fork for mumbai * add sysCall to verifyHeader * added bor related rpc method implementation * added bor specific rpc extensions * fixes in snapshot implementation, major refactor for bor rpc * modify consensus specific db path for bor * fix: remove parallel compute for get root hash rpc method * Added bor-receipt flow * Use turbo-bor-lib and bor tables * Use bor table in RPC snapshot * Update README.md * Update README.md * Update README.md * Update README.md * update rpc readme * link rpc docs in readme * Update Readme * Update Readme * move erigon namespace rpc methods to eth * rm: erigon namespace * rm: erigon namespace, update list of available rpc methods, add example * fix: binary name in rpc readme * fix: max db size * Add london to bor-mainnet * updated node.go * add system req to readme * golang version fix readme * added networknames in correct place * nil * ran gofmt * erigon * fixed fake.go * dont need turbor-lib * old readme * fixing readme * half * other half * changed return * fixing return * fixed return * fixed flags * gofmt * merge with devel * latest erigon-lib * fixed context.coinbase * took out syscall * fixed params in hash * bor type now is consensus.Engine * parlia is consensus.Engine * missing arg and repeated importation * repeated importation * fixed eth_receipts.go * deleted duplicate issuance * part of consensus.Engine type * added eth_api issuance * networkname * added erigon_system file * fork struct taken out * added erigon block * getLogByHash for erigonImpl * gofmt * fixed lint * ops * gofmt * gofmt * added APIImple functions * fixed clique test * took out print * fixed state added balance * fixed README * fixed rpcDaemon README * fixed integration README * updated blockchain.go * lint * added bor back into blockchain.go * took out comment * lint * updated daemon * updated wtb * removed duplicate * removed VerifyHeaders * prevent use of wrong Transfer * fixed state_processor.go * fixed state_transition.go * fixed headers * returning err * error handling in bor read tx look up * put for txLookUp * dealing with error * lint * traces * more traces * fixed receipt in execution * getTrasanction receipt for bor or others * nil * lint * ops * deleted syscall * took out else * Merge branch 'devel * tests syscalls * changed borReceipt to receipt * reset header algos * arguments fix * took out prefixes * lint * erigon-named * borReceiptKey = blocknumber * reverts e3b60c2e159d03efcb855f7ab3da5a098dd60c33. * correct hashing tx * dont need it here * lint * added txlookup for bor * change to uint256 * outputs for isBor * wrapper * added isBor and isParlia * isBor * fixed BorTransfer * not readBody * correct prefix * added blockNum * added readStorageBody * readStorageBody * lint * got rid of unnecessary bor_receipt func * onlny if bor * use clone * append * writeToSlice * added isBor flag * fixed writeToSlice * normal sorting * lint * Reset erigon-snapshots * Move bor prefix into if Co-authored-by: Krishna Upadhyaya <krishnau1604@gmail.com> Co-authored-by: Manav Darji <manavdarji.india@gmail.com> Co-authored-by: Uttam Singh <uttamkhanduja@yahoo.in> Co-authored-by: Giulio Rebuffo <giulio.rebuffo@gmail.com> Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
2022-02-07 21:30:46 +00:00
Config: params.BorMainnetChainConfig,
Nonce: 0,
Timestamp: 1590824836,
GasLimit: 10000000,
Difficulty: big.NewInt(1),
Mixhash: libcommon.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"),
Coinbase: libcommon.HexToAddress("0x0000000000000000000000000000000000000000"),
Merging Turbo bor into devel (#3372) * implemented bor consensus * add bor flags to default * change bucket into snapshot to clique * enable stateSync * bypass reciept checks * fix receipt calculation and bor logs * fix: contract call wrt bor * Update mumbai config * Add: bor-mainnet flag and config * Add bor consensus to integration * use header coinbase in block context * london fork mumbai changes * fix genesis error * Jaipur fork for mumbai * add sysCall to verifyHeader * added bor related rpc method implementation * added bor specific rpc extensions * fixes in snapshot implementation, major refactor for bor rpc * modify consensus specific db path for bor * fix: remove parallel compute for get root hash rpc method * Added bor-receipt flow * Use turbo-bor-lib and bor tables * Use bor table in RPC snapshot * Update README.md * Update README.md * Update README.md * Update README.md * update rpc readme * link rpc docs in readme * Update Readme * Update Readme * move erigon namespace rpc methods to eth * rm: erigon namespace * rm: erigon namespace, update list of available rpc methods, add example * fix: binary name in rpc readme * fix: max db size * Add london to bor-mainnet * updated node.go * add system req to readme * golang version fix readme * added networknames in correct place * nil * ran gofmt * erigon * fixed fake.go * dont need turbor-lib * old readme * fixing readme * half * other half * changed return * fixing return * fixed return * fixed flags * gofmt * merge with devel * latest erigon-lib * fixed context.coinbase * took out syscall * fixed params in hash * bor type now is consensus.Engine * parlia is consensus.Engine * missing arg and repeated importation * repeated importation * fixed eth_receipts.go * deleted duplicate issuance * part of consensus.Engine type * added eth_api issuance * networkname * added erigon_system file * fork struct taken out * added erigon block * getLogByHash for erigonImpl * gofmt * fixed lint * ops * gofmt * gofmt * added APIImple functions * fixed clique test * took out print * fixed state added balance * fixed README * fixed rpcDaemon README * fixed integration README * updated blockchain.go * lint * added bor back into blockchain.go * took out comment * lint * updated daemon * updated wtb * removed duplicate * removed VerifyHeaders * prevent use of wrong Transfer * fixed state_processor.go * fixed state_transition.go * fixed headers * returning err * error handling in bor read tx look up * put for txLookUp * dealing with error * lint * traces * more traces * fixed receipt in execution * getTrasanction receipt for bor or others * nil * lint * ops * deleted syscall * took out else * Merge branch 'devel * tests syscalls * changed borReceipt to receipt * reset header algos * arguments fix * took out prefixes * lint * erigon-named * borReceiptKey = blocknumber * reverts e3b60c2e159d03efcb855f7ab3da5a098dd60c33. * correct hashing tx * dont need it here * lint * added txlookup for bor * change to uint256 * outputs for isBor * wrapper * added isBor and isParlia * isBor * fixed BorTransfer * not readBody * correct prefix * added blockNum * added readStorageBody * readStorageBody * lint * got rid of unnecessary bor_receipt func * onlny if bor * use clone * append * writeToSlice * added isBor flag * fixed writeToSlice * normal sorting * lint * Reset erigon-snapshots * Move bor prefix into if Co-authored-by: Krishna Upadhyaya <krishnau1604@gmail.com> Co-authored-by: Manav Darji <manavdarji.india@gmail.com> Co-authored-by: Uttam Singh <uttamkhanduja@yahoo.in> Co-authored-by: Giulio Rebuffo <giulio.rebuffo@gmail.com> Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local>
2022-02-07 21:30:46 +00:00
Alloc: readPrealloc("allocs/bor_mainnet.json"),
}
}
func BorDevnetGenesisBlock() *types.Genesis {
return &types.Genesis{
Config: params.BorDevnetChainConfig,
Nonce: 0,
Timestamp: 1558348305,
GasLimit: 10000000,
Difficulty: big.NewInt(1),
Mixhash: libcommon.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"),
Coinbase: libcommon.HexToAddress("0x0000000000000000000000000000000000000000"),
Alloc: readPrealloc("allocs/bor_devnet.json"),
}
}
func GnosisGenesisBlock() *types.Genesis {
return &types.Genesis{
Config: params.GnosisChainConfig,
Timestamp: 0,
AuRaSeal: common.FromHex("0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
GasLimit: 0x989680,
Difficulty: big.NewInt(0x20000),
Alloc: readPrealloc("allocs/gnosis.json"),
}
}
func ChiadoGenesisBlock() *types.Genesis {
return &types.Genesis{
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 11:54:18 +00:00
Config: params.ChiadoChainConfig,
Timestamp: 0,
AuRaSeal: common.FromHex("0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
GasLimit: 0x989680,
Difficulty: big.NewInt(0x20000),
Alloc: readPrealloc("allocs/chiado.json"),
}
}
func PulsechainGenesisBlock() *types.Genesis {
return &types.Genesis{
Config: params.PulsechainChainConfig,
Nonce: 66,
ExtraData: hexutil.MustDecode("0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa"),
GasLimit: 5000,
Difficulty: big.NewInt(17179869184),
Alloc: readPrealloc("allocs/mainnet.json"),
}
}
2023-04-13 19:57:33 +00:00
func PulsechainTestnetV4GenesisBlock() *types.Genesis {
return &types.Genesis{
2023-04-13 19:57:33 +00:00
Config: params.PulsechainTestnetV4ChainConfig,
Nonce: 66,
ExtraData: hexutil.MustDecode("0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa"),
GasLimit: 5000,
Difficulty: big.NewInt(17179869184),
Alloc: readPrealloc("allocs/mainnet.json"),
}
}
2023-02-26 19:52:40 +00:00
func PulsechainDevnetGenesisBlock() *types.Genesis {
return &types.Genesis{
Config: params.PulsechainDevnetChainConfig,
ExtraData: hexutil.MustDecode("0x0000000000000000000000000000000000000000000000000000000000000000123463a4B065722E99115D6c222f267d9cABb5240000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
GasLimit: 30000000,
Difficulty: big.NewInt(131072),
Alloc: readPrealloc("allocs/pulsechain-devnet.json"),
}
}
2021-09-08 04:00:06 +00:00
// Pre-calculated version of:
2022-08-10 12:04:13 +00:00
//
// DevnetSignPrivateKey = crypto.HexToECDSA(sha256.Sum256([]byte("erigon devnet key")))
// DevnetEtherbase=crypto.PubkeyToAddress(DevnetSignPrivateKey.PublicKey)
2021-09-08 04:00:06 +00:00
var DevnetSignPrivateKey, _ = crypto.HexToECDSA("26e86e45f6fc45ec6e2ecd128cec80fa1d1505e5507dcd2ae58c3130a7a97b48")
var DevnetEtherbase = libcommon.HexToAddress("67b1d87101671b127f5f8714789c7192f7ad340e")
2021-09-07 09:12:49 +00:00
// DevnetSignKey is defined like this to allow the devnet process to pre-allocate keys
// for nodes and then pass the address via --miner.etherbase - the function will be called
// to retieve the mining key
var DevnetSignKey = func(address libcommon.Address) *ecdsa.PrivateKey {
return DevnetSignPrivateKey
}
2019-12-10 10:50:16 +00:00
// DeveloperGenesisBlock returns the 'geth --dev' genesis block.
func DeveloperGenesisBlock(period uint64, faucet libcommon.Address) *types.Genesis {
// 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
return &types.Genesis{
Config: &config,
ExtraData: append(append(make([]byte, 32), faucet[:]...), make([]byte, crypto.SignatureLength)...),
GasLimit: 11500000,
Difficulty: big.NewInt(1),
Alloc: readPrealloc("allocs/dev.json"),
2016-11-20 21:32:31 +00:00
}
}
// ToBlock creates the genesis block and writes state of a genesis specification
// to the given database (or discards it if nil).
func GenesisToBlock(g *types.Genesis, tmpDir string, logger log.Logger) (*types.Block, *state.IntraBlockState, error) {
_ = g.Alloc //nil-check
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,
BlobGasUsed: g.BlobGasUsed,
ExcessBlobGas: g.ExcessBlobGas,
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)
}
}
var withdrawals []*types.Withdrawal
if g.Config != nil && g.Config.IsShanghai(g.Number, g.Timestamp) {
withdrawals = []*types.Withdrawal{}
}
if g.Config != nil && g.Config.IsCancun(g.Timestamp) {
if g.BlobGasUsed != nil {
head.BlobGasUsed = g.BlobGasUsed
} else {
head.BlobGasUsed = new(uint64)
}
if g.ExcessBlobGas != nil {
head.ExcessBlobGas = g.ExcessBlobGas
} else {
head.ExcessBlobGas = new(uint64)
}
if g.ParentBeaconBlockRoot != nil {
head.ParentBeaconBlockRoot = g.ParentBeaconBlockRoot
} else {
head.ParentBeaconBlockRoot = &libcommon.Hash{}
}
}
var root libcommon.Hash
var statedb *state.IntraBlockState
wg := sync.WaitGroup{}
wg.Add(1)
2023-05-15 04:07:13 +00:00
var err error
go func() { // we may run inside write tx, can't open 2nd write tx in same goroutine
// TODO(yperbasis): use memdb.MemoryMutation instead
defer wg.Done()
genesisTmpDB := mdbx.NewMDBX(logger).InMem(tmpDir).MapSize(2 * datasize.GB).GrowthStep(1 * datasize.MB).MustOpen()
2023-05-15 04:07:13 +00:00
defer genesisTmpDB.Close()
var tx kv.RwTx
if tx, err = genesisTmpDB.BeginRw(context.Background()); err != nil {
return
}
defer tx.Rollback()
2023-05-15 04:07:13 +00:00
r, w := state.NewDbStateReader(tx), state.NewDbStateWriter(tx, 0)
statedb = state.New(r)
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 {
statedb.CreateAccount(libcommon.Address{}, false)
}
keys := sortedAllocKeys(g.Alloc)
for _, key := range keys {
addr := libcommon.BytesToAddress([]byte(key))
account := g.Alloc[addr]
balance, overflow := uint256.FromBig(account.Balance)
if overflow {
panic("overflow at genesis allocs")
}
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)
}
if len(account.Constructor) > 0 {
if _, err = SysCreate(addr, account.Constructor, *g.Config, statedb, head); err != nil {
return
}
}
if len(account.Code) > 0 || len(account.Storage) > 0 || len(account.Constructor) > 0 {
statedb.SetIncarnation(addr, state.FirstContractIncarnation)
}
}
if err = statedb.FinalizeTx(&chain.Rules{}, w); err != nil {
return
}
if root, err = trie.CalcRoot("genesis", tx); err != nil {
return
}
}()
wg.Wait()
if err != nil {
return nil, nil, err
}
head.Root = root
return types.NewBlock(head, nil, nil, nil, withdrawals), statedb, nil
}
func sortedAllocKeys(m types.GenesisAlloc) []string {
keys := make([]string, len(m))
i := 0
for k := range m {
keys[i] = string(k.Bytes())
i++
}
slices.Sort(keys)
return keys
}
//go:embed allocs
var allocs embed.FS
func readPrealloc(filename string) types.GenesisAlloc {
f, err := allocs.Open(filename)
if err != nil {
panic(fmt.Sprintf("Could not open genesis preallocation for %s: %v", filename, err))
}
defer f.Close()
decoder := json.NewDecoder(f)
ga := make(types.GenesisAlloc)
err = decoder.Decode(&ga)
if err != nil {
panic(fmt.Sprintf("Could not parse genesis preallocation for %s: %v", filename, err))
}
return ga
}
func GenesisBlockByChainName(chain string) *types.Genesis {
switch chain {
case networkname.MainnetChainName:
return MainnetGenesisBlock()
2023-08-26 10:31:29 +00:00
case networkname.HoleskyChainName:
return HoleskyGenesisBlock()
case networkname.SepoliaChainName:
return SepoliaGenesisBlock()
case networkname.GoerliChainName:
return GoerliGenesisBlock()
case networkname.MumbaiChainName:
return MumbaiGenesisBlock()
case networkname.AmoyChainName:
return AmoyGenesisBlock()
case networkname.BorMainnetChainName:
return BorMainnetGenesisBlock()
case networkname.BorDevnetChainName:
return BorDevnetGenesisBlock()
case networkname.GnosisChainName:
return GnosisGenesisBlock()
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 11:54:18 +00:00
case networkname.ChiadoChainName:
return ChiadoGenesisBlock()
case networkname.PulsechainChainName:
return PulsechainGenesisBlock()
2023-04-13 19:57:33 +00:00
case networkname.PulsechainTestnetV4ChainName:
return PulsechainTestnetV4GenesisBlock()
2023-02-26 19:52:40 +00:00
case networkname.PulsechainDevnetChainName:
return PulsechainDevnetGenesisBlock()
default:
return nil
}
}