Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Break dependency of ethcfg package to core/consensus/etc... move genesis struct to 'types' package #7206

Merged
merged 9 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ type SimulatedBackend struct {

// NewSimulatedBackend creates a new binding backend using a simulated blockchain
// for testing purposes.
func NewSimulatedBackendWithConfig(alloc core.GenesisAlloc, config *chain.Config, gasLimit uint64) *SimulatedBackend {
genesis := core.Genesis{Config: config, GasLimit: gasLimit, Alloc: alloc}
func NewSimulatedBackendWithConfig(alloc types.GenesisAlloc, config *chain.Config, gasLimit uint64) *SimulatedBackend {
genesis := types.Genesis{Config: config, GasLimit: gasLimit, Alloc: alloc}
engine := ethash.NewFaker()
m := stages.MockWithGenesisEngine(nil, &genesis, engine, false)
backend := &SimulatedBackend{
Expand All @@ -109,7 +109,7 @@ func NewSimulatedBackendWithConfig(alloc core.GenesisAlloc, config *chain.Config
}

// A simulated backend always uses chainID 1337.
func NewSimulatedBackend(t *testing.T, alloc core.GenesisAlloc, gasLimit uint64) *SimulatedBackend {
func NewSimulatedBackend(t *testing.T, alloc types.GenesisAlloc, gasLimit uint64) *SimulatedBackend {
b := NewSimulatedBackendWithConfig(alloc, params.TestChainConfig, gasLimit)
t.Cleanup(func() {
b.Close()
Expand All @@ -120,7 +120,7 @@ func NewSimulatedBackend(t *testing.T, alloc core.GenesisAlloc, gasLimit uint64)
return b
}

func NewTestSimulatedBackendWithConfig(t *testing.T, alloc core.GenesisAlloc, config *chain.Config, gasLimit uint64) *SimulatedBackend {
func NewTestSimulatedBackendWithConfig(t *testing.T, alloc types.GenesisAlloc, config *chain.Config, gasLimit uint64) *SimulatedBackend {
b := NewSimulatedBackendWithConfig(alloc, config, gasLimit)
t.Cleanup(func() {
b.Close()
Expand Down
21 changes: 10 additions & 11 deletions accounts/abi/bind/backends/simulated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"github.com/ledgerwatch/erigon/accounts/abi/bind"
"github.com/ledgerwatch/erigon/common"
"github.com/ledgerwatch/erigon/common/u256"
"github.com/ledgerwatch/erigon/core"
"github.com/ledgerwatch/erigon/core/rawdb"
"github.com/ledgerwatch/erigon/core/state"
"github.com/ledgerwatch/erigon/core/types"
Expand All @@ -46,8 +45,8 @@ func TestSimulatedBackend(t *testing.T) {
var gasLimit uint64 = 8000029
key, _ := crypto.GenerateKey() // nolint: gosec
auth, _ := bind.NewKeyedTransactorWithChainID(key, big.NewInt(1337))
genAlloc := make(core.GenesisAlloc)
genAlloc[auth.From] = core.GenesisAccount{Balance: big.NewInt(9223372036854775807)}
genAlloc := make(types.GenesisAlloc)
genAlloc[auth.From] = types.GenesisAccount{Balance: big.NewInt(9223372036854775807)}

sim := NewSimulatedBackend(t, genAlloc, gasLimit)

Expand Down Expand Up @@ -116,7 +115,7 @@ var expectedReturn = []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
func simTestBackend(t *testing.T, testAddr libcommon.Address) *SimulatedBackend {
expectedBal := uint256.NewInt(10000000000)
return NewSimulatedBackend(t,
core.GenesisAlloc{
types.GenesisAlloc{
testAddr: {Balance: expectedBal.ToBig()},
}, 10000000,
)
Expand Down Expand Up @@ -158,7 +157,7 @@ func TestNewSimulatedBackend(t *testing.T) {

func TestSimulatedBackend_AdjustTime(t *testing.T) {
sim := NewSimulatedBackend(t,
core.GenesisAlloc{}, 10000000,
types.GenesisAlloc{}, 10000000,
)

prevTime := sim.pendingBlock.Time()
Expand Down Expand Up @@ -233,7 +232,7 @@ func TestSimulatedBackend_BalanceAt(t *testing.T) {

func TestSimulatedBackend_BlockByHash(t *testing.T) {
sim := NewSimulatedBackend(t,
core.GenesisAlloc{}, 10000000,
types.GenesisAlloc{}, 10000000,
)
bgCtx := context.Background()

Expand All @@ -253,7 +252,7 @@ func TestSimulatedBackend_BlockByHash(t *testing.T) {

func TestSimulatedBackend_BlockByNumber(t *testing.T) {
sim := NewSimulatedBackend(t,
core.GenesisAlloc{}, 10000000,
types.GenesisAlloc{}, 10000000,
)
bgCtx := context.Background()

Expand Down Expand Up @@ -370,7 +369,7 @@ func TestSimulatedBackend_TransactionByHash(t *testing.T) {
testAddr := crypto.PubkeyToAddress(testKey.PublicKey)

sim := NewSimulatedBackend(t,
core.GenesisAlloc{
types.GenesisAlloc{
testAddr: {Balance: big.NewInt(10000000000)},
}, 10000000)
bgCtx := context.Background()
Expand Down Expand Up @@ -433,7 +432,7 @@ func TestSimulatedBackend_EstimateGas(t *testing.T) {
addr := crypto.PubkeyToAddress(key.PublicKey)
opts, _ := bind.NewKeyedTransactorWithChainID(key, big.NewInt(1337))

sim := NewSimulatedBackend(t, core.GenesisAlloc{addr: {Balance: big.NewInt(params.Ether)}}, 10000000)
sim := NewSimulatedBackend(t, types.GenesisAlloc{addr: {Balance: big.NewInt(params.Ether)}}, 10000000)

parsed, _ := abi.JSON(strings.NewReader(contractAbi))
contractAddr, _, _, _ := bind.DeployContract(opts, parsed, common.FromHex(contractBin), sim)
Expand Down Expand Up @@ -537,7 +536,7 @@ func TestSimulatedBackend_EstimateGasWithPrice(t *testing.T) {
key, _ := crypto.GenerateKey()
addr := crypto.PubkeyToAddress(key.PublicKey)

sim := NewSimulatedBackend(t, core.GenesisAlloc{addr: {Balance: big.NewInt(params.Ether*2 + 2e17)}}, 10000000)
sim := NewSimulatedBackend(t, types.GenesisAlloc{addr: {Balance: big.NewInt(params.Ether*2 + 2e17)}}, 10000000)

recipient := libcommon.HexToAddress("deadbeef")
var cases = []struct {
Expand Down Expand Up @@ -875,7 +874,7 @@ func TestSimulatedBackend_TransactionReceipt(t *testing.T) {

func TestSimulatedBackend_SuggestGasPrice(t *testing.T) {
sim := NewSimulatedBackend(t,
core.GenesisAlloc{},
types.GenesisAlloc{},
10000000,
)
bgCtx := context.Background()
Expand Down
6 changes: 2 additions & 4 deletions accounts/abi/bind/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ import (
"time"

libcommon "github.com/ledgerwatch/erigon-lib/common"

"github.com/ledgerwatch/erigon/accounts/abi/bind"
"github.com/ledgerwatch/erigon/accounts/abi/bind/backends"
"github.com/ledgerwatch/erigon/common"
"github.com/ledgerwatch/erigon/common/u256"
"github.com/ledgerwatch/erigon/core"
"github.com/ledgerwatch/erigon/core/types"
"github.com/ledgerwatch/erigon/crypto"
"github.com/ledgerwatch/erigon/params"
Expand Down Expand Up @@ -67,7 +65,7 @@ func TestWaitDeployed(t *testing.T) {

t.Run(name, func(t *testing.T) {
backend := backends.NewSimulatedBackend(t,
core.GenesisAlloc{
types.GenesisAlloc{
crypto.PubkeyToAddress(testKey.PublicKey): {Balance: big.NewInt(10000000000)},
},
10000000,
Expand Down Expand Up @@ -121,7 +119,7 @@ func TestWaitDeployedCornerCases(t *testing.T) {
t.Skip("fix me on win please")
}
backend := backends.NewSimulatedBackend(t,
core.GenesisAlloc{
types.GenesisAlloc{
crypto.PubkeyToAddress(testKey.PublicKey): {Balance: big.NewInt(10000000000)},
},
10000000,
Expand Down
8 changes: 3 additions & 5 deletions cmd/evm/internal/t8ntool/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,16 @@ import (
"github.com/ledgerwatch/erigon-lib/chain"
libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/kv"

"github.com/ledgerwatch/erigon/common"
"github.com/ledgerwatch/erigon/common/math"
"github.com/ledgerwatch/erigon/consensus/ethash"
"github.com/ledgerwatch/erigon/core"
"github.com/ledgerwatch/erigon/core/state"
"github.com/ledgerwatch/erigon/core/types"
)

type Prestate struct {
Env stEnv `json:"env"`
Pre core.GenesisAlloc `json:"pre"`
Env stEnv `json:"env"`
Pre types.GenesisAlloc `json:"pre"`
}

type ommer struct {
Expand Down Expand Up @@ -72,7 +70,7 @@ type stEnvMarshaling struct {
BaseFee *math.HexOrDecimal256
}

func MakePreState(chainRules *chain.Rules, tx kv.RwTx, accounts core.GenesisAlloc) (*state.PlainStateReader, *state.PlainStateWriter) {
func MakePreState(chainRules *chain.Rules, tx kv.RwTx, accounts types.GenesisAlloc) (*state.PlainStateReader, *state.PlainStateWriter) {
var blockNr uint64 = 0
stateReader, stateWriter := state.NewPlainStateReader(tx), state.NewPlainStateWriter(tx, tx, blockNr)
statedb := state.New(stateReader) //ibs
Expand Down
10 changes: 5 additions & 5 deletions cmd/evm/internal/t8ntool/transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ var (
)

type input struct {
Alloc core.GenesisAlloc `json:"alloc,omitempty"`
Env *stEnv `json:"env,omitempty"`
Txs []*txWithKey `json:"txs,omitempty"`
Alloc types.GenesisAlloc `json:"alloc,omitempty"`
Env *stEnv `json:"env,omitempty"`
Txs []*txWithKey `json:"txs,omitempty"`
}

func Main(ctx *cli.Context) error {
Expand Down Expand Up @@ -487,7 +487,7 @@ func signUnsignedTransactions(txs []*txWithKey, signer types.Signer) (types.Tran
return signedTxs, nil
}

type Alloc map[libcommon.Address]core.GenesisAccount
type Alloc map[libcommon.Address]types.GenesisAccount

func (g Alloc) OnRoot(libcommon.Hash) {}

Expand All @@ -500,7 +500,7 @@ func (g Alloc) OnAccount(addr libcommon.Address, dumpAccount state.DumpAccount)
storage[libcommon.HexToHash(k)] = libcommon.HexToHash(v)
}
}
genesisAccount := core.GenesisAccount{
genesisAccount := types.GenesisAccount{
Code: dumpAccount.Code,
Storage: storage,
Balance: balance,
Expand Down
11 changes: 6 additions & 5 deletions cmd/evm/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/ledgerwatch/erigon-lib/common/hexutility"
"github.com/ledgerwatch/erigon-lib/kv/kvcfg"
"github.com/ledgerwatch/erigon-lib/kv/memdb"
"github.com/ledgerwatch/erigon/core/types"
"github.com/ledgerwatch/log/v3"
"github.com/urfave/cli/v2"

Expand All @@ -60,7 +61,7 @@ var runCommand = cli.Command{

// readGenesis will read the given JSON format genesis file and return
// the initialized Genesis structure
func readGenesis(genesisPath string) *core.Genesis {
func readGenesis(genesisPath string) *types.Genesis {
// Make sure we have a valid genesis JSON
//genesisPath := ctx.Args().First()
if len(genesisPath) == 0 {
Expand All @@ -77,7 +78,7 @@ func readGenesis(genesisPath string) *core.Genesis {
}
}(file)

genesis := new(core.Genesis)
genesis := new(types.Genesis)
if err := json.NewDecoder(file).Decode(genesis); err != nil {
utils.Fatalf("invalid genesis file: %v", err)
}
Expand Down Expand Up @@ -137,7 +138,7 @@ func runCmd(ctx *cli.Context) error {
chainConfig *chain.Config
sender = libcommon.BytesToAddress([]byte("sender"))
receiver = libcommon.BytesToAddress([]byte("receiver"))
genesisConfig *core.Genesis
genesisConfig *types.Genesis
)
if ctx.Bool(MachineFlag.Name) {
tracer = logger.NewJSONLogger(logconfig, os.Stdout)
Expand All @@ -150,11 +151,11 @@ func runCmd(ctx *cli.Context) error {
db := memdb.New("")
if ctx.String(GenesisFlag.Name) != "" {
gen := readGenesis(ctx.String(GenesisFlag.Name))
gen.MustCommit(db, "")
core.MustCommitGenesis(gen, db, "")
genesisConfig = gen
chainConfig = gen.Config
} else {
genesisConfig = new(core.Genesis)
genesisConfig = new(types.Genesis)
}
tx, err := db.BeginRw(context.Background())
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/integration/commands/state_domains.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,9 @@ func (b *blockProcessor) PrintStatsLoop(ctx context.Context, interval time.Durat
}
}

func (b *blockProcessor) ApplyGenesis(genesis *core.Genesis) error {
func (b *blockProcessor) ApplyGenesis(genesis *types.Genesis) error {
b.logger.Info("apply genesis", "chain_id", genesis.Config.ChainID)
genBlock, genesisIbs, err := genesis.ToBlock("")
genBlock, genesisIbs, err := core.GenesisToBlock(genesis, "")
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/pics/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,9 @@ func initialState1() error {
address1 = crypto.PubkeyToAddress(key1.PublicKey)
address2 = crypto.PubkeyToAddress(key2.PublicKey)
theAddr = libcommon.Address{1}
gspec = &core.Genesis{
gspec = &types.Genesis{
Config: params.AllProtocolChanges,
Alloc: core.GenesisAlloc{
Alloc: types.GenesisAlloc{
address: {Balance: big.NewInt(9000000000000000000)},
address1: {Balance: big.NewInt(200000000000000000)},
address2: {Balance: big.NewInt(300000000000000000)},
Expand Down
4 changes: 2 additions & 2 deletions cmd/rpcdaemon/commands/erigon_receipts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@ func TestGetBlockReceiptsByBlockHash(t *testing.T) {
// newTestBackend creates a chain with a number of explicitly defined blocks and
// wraps it into a mock backend.
func mockWithGenerator(t *testing.T, blocks int, generator func(int, *core.BlockGen)) *stages.MockSentry {
m := stages.MockWithGenesis(t, &core.Genesis{
m := stages.MockWithGenesis(t, &types.Genesis{
Config: params.TestChainConfig,
Alloc: core.GenesisAlloc{testAddr: {Balance: big.NewInt(1000000)}},
Alloc: types.GenesisAlloc{testAddr: {Balance: big.NewInt(1000000)}},
}, testKey, false)
if blocks > 0 {
chain, _ := core.GenerateChain(m.ChainConfig, m.Genesis, m.Engine, m.DB, blocks, generator, true)
Expand Down
6 changes: 3 additions & 3 deletions cmd/rpcdaemon/commands/eth_callMany_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/ledgerwatch/erigon/accounts/abi/bind/backends"
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/commands/contracts"
"github.com/ledgerwatch/erigon/common/hexutil"
"github.com/ledgerwatch/erigon/core"
"github.com/ledgerwatch/erigon/core/types"
"github.com/ledgerwatch/erigon/crypto"
"github.com/ledgerwatch/erigon/params"
"github.com/ledgerwatch/erigon/rpc"
Expand All @@ -38,9 +38,9 @@ func TestCallMany(t *testing.T) {
address = crypto.PubkeyToAddress(key.PublicKey)
address1 = crypto.PubkeyToAddress(key1.PublicKey)
address2 = crypto.PubkeyToAddress(key2.PublicKey)
gspec = &core.Genesis{
gspec = &types.Genesis{
Config: params.TestChainConfig,
Alloc: core.GenesisAlloc{
Alloc: types.GenesisAlloc{
address: {Balance: big.NewInt(9000000000000000000)},
address1: {Balance: big.NewInt(200000000000000000)},
address2: {Balance: big.NewInt(300000000000000000)},
Expand Down
4 changes: 2 additions & 2 deletions cmd/rpcdaemon/commands/eth_call_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,9 +551,9 @@ func chainWithDeployedContract(t *testing.T) (*stages.MockSentry, libcommon.Addr
bankAddress = crypto.PubkeyToAddress(bankKey.PublicKey)
bankFunds = big.NewInt(1e9)
contract = hexutil.MustDecode("0x608060405234801561001057600080fd5b50610150806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80632e64cec11461003b5780636057361d14610059575b600080fd5b610043610075565b60405161005091906100d9565b60405180910390f35b610073600480360381019061006e919061009d565b61007e565b005b60008054905090565b8060008190555050565b60008135905061009781610103565b92915050565b6000602082840312156100b3576100b26100fe565b5b60006100c184828501610088565b91505092915050565b6100d3816100f4565b82525050565b60006020820190506100ee60008301846100ca565b92915050565b6000819050919050565b600080fd5b61010c816100f4565b811461011757600080fd5b5056fea26469706673582212209a159a4f3847890f10bfb87871a61eba91c5dbf5ee3cf6398207e292eee22a1664736f6c63430008070033")
gspec = &core.Genesis{
gspec = &types.Genesis{
Config: params.TestChainConfig,
Alloc: core.GenesisAlloc{bankAddress: {Balance: bankFunds}},
Alloc: types.GenesisAlloc{bankAddress: {Balance: bankFunds}},
}
)
m := stages.MockWithGenesis(t, gspec, bankKey, false)
Expand Down
5 changes: 2 additions & 3 deletions cmd/rpcdaemon/commands/eth_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/holiman/uint256"
libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/kv/kvcache"

"github.com/ledgerwatch/erigon/rpc/rpccfg"

"github.com/ledgerwatch/erigon/core"
Expand Down Expand Up @@ -65,9 +64,9 @@ func createGasPriceTestKV(t *testing.T, chainSize int) *stages.MockSentry {
var (
key, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
addr = crypto.PubkeyToAddress(key.PublicKey)
gspec = &core.Genesis{
gspec = &types.Genesis{
Config: params.TestChainConfig,
Alloc: core.GenesisAlloc{addr: {Balance: big.NewInt(math.MaxInt64)}},
Alloc: types.GenesisAlloc{addr: {Balance: big.NewInt(math.MaxInt64)}},
}
signer = types.LatestSigner(gspec.Config)
)
Expand Down
12 changes: 6 additions & 6 deletions cmd/rpcdaemon/rpcdaemontest/test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ func CreateTestSentry(t *testing.T) (*stages.MockSentry, *core.ChainPack, []*cor
)

var (
gspec = &core.Genesis{
gspec = &types.Genesis{
Config: params.TestChainConfig,
Alloc: core.GenesisAlloc{
Alloc: types.GenesisAlloc{
address: {Balance: big.NewInt(9000000000000000000)},
address1: {Balance: big.NewInt(200000000000000000)},
address2: {Balance: big.NewInt(300000000000000000)},
Expand Down Expand Up @@ -333,9 +333,9 @@ func CreateTestSentryForTraces(t *testing.T) *stages.MockSentry {
key, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
address = crypto.PubkeyToAddress(key.PublicKey)
funds = big.NewInt(1000000000)
gspec = &core.Genesis{
gspec = &types.Genesis{
Config: params.TestChainConfig,
Alloc: core.GenesisAlloc{
Alloc: types.GenesisAlloc{
address: {Balance: funds},
// The address 0x00ff
a0: {
Expand Down Expand Up @@ -490,9 +490,9 @@ func CreateTestSentryForTracesCollision(t *testing.T) *stages.MockSentry {
aa := crypto.CreateAddress2(bb, [32]byte{}, initHash[:])
t.Logf("Destination address: %x\n", aa)

gspec := &core.Genesis{
gspec := &types.Genesis{
Config: params.TestChainConfig,
Alloc: core.GenesisAlloc{
Alloc: types.GenesisAlloc{
address: {Balance: funds},
// The address 0xAAAAA selfdestructs if called
aa: {
Expand Down
Loading