Skip to content

Commit 95741b1

Browse files
s1nafjl
andauthored
core: move genesis alloc types to core/types (#29003)
We want to use these types in public user-facing APIs, so they shouldn't be in core. Co-authored-by: Felix Lange <fjl@twurst.com>
1 parent 3c30de2 commit 95741b1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+328
-287
lines changed

accounts/abi/bind/backends/simulated.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"context"
2121

2222
"github.com/ethereum/go-ethereum/common"
23-
"github.com/ethereum/go-ethereum/core"
23+
"github.com/ethereum/go-ethereum/core/types"
2424
"github.com/ethereum/go-ethereum/ethclient/simulated"
2525
)
2626

@@ -43,7 +43,7 @@ func (b *SimulatedBackend) Fork(ctx context.Context, parentHash common.Hash) err
4343
//
4444
// Deprecated: please use simulated.Backend from package
4545
// github.com/ethereum/go-ethereum/ethclient/simulated instead.
46-
func NewSimulatedBackend(alloc core.GenesisAlloc, gasLimit uint64) *SimulatedBackend {
46+
func NewSimulatedBackend(alloc types.GenesisAlloc, gasLimit uint64) *SimulatedBackend {
4747
b := simulated.NewBackend(alloc, simulated.WithBlockGasLimit(gasLimit))
4848
return &SimulatedBackend{
4949
Backend: b,

accounts/abi/bind/bind_test.go

Lines changed: 50 additions & 50 deletions
Large diffs are not rendered by default.

accounts/abi/bind/util_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525

2626
"github.com/ethereum/go-ethereum/accounts/abi/bind"
2727
"github.com/ethereum/go-ethereum/common"
28-
"github.com/ethereum/go-ethereum/core"
2928
"github.com/ethereum/go-ethereum/core/types"
3029
"github.com/ethereum/go-ethereum/crypto"
3130
"github.com/ethereum/go-ethereum/ethclient/simulated"
@@ -57,7 +56,7 @@ func TestWaitDeployed(t *testing.T) {
5756
t.Parallel()
5857
for name, test := range waitDeployedTests {
5958
backend := simulated.NewBackend(
60-
core.GenesisAlloc{
59+
types.GenesisAlloc{
6160
crypto.PubkeyToAddress(testKey.PublicKey): {Balance: big.NewInt(10000000000000000)},
6261
},
6362
)
@@ -102,7 +101,7 @@ func TestWaitDeployed(t *testing.T) {
102101

103102
func TestWaitDeployedCornerCases(t *testing.T) {
104103
backend := simulated.NewBackend(
105-
core.GenesisAlloc{
104+
types.GenesisAlloc{
106105
crypto.PubkeyToAddress(testKey.PublicKey): {Balance: big.NewInt(10000000000000000)},
107106
},
108107
)

cmd/evm/internal/t8ntool/execution.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ import (
4242
)
4343

4444
type Prestate struct {
45-
Env stEnv `json:"env"`
46-
Pre core.GenesisAlloc `json:"pre"`
45+
Env stEnv `json:"env"`
46+
Pre types.GenesisAlloc `json:"pre"`
4747
}
4848

4949
// ExecutionResult contains the execution status after running a state test, any
@@ -355,7 +355,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
355355
return statedb, execRs, body, nil
356356
}
357357

358-
func MakePreState(db ethdb.Database, accounts core.GenesisAlloc) *state.StateDB {
358+
func MakePreState(db ethdb.Database, accounts types.GenesisAlloc) *state.StateDB {
359359
sdb := state.NewDatabaseWithConfig(db, &triedb.Config{Preimages: true})
360360
statedb, _ := state.New(types.EmptyRootHash, sdb, nil)
361361
for addr, a := range accounts {

cmd/evm/internal/t8ntool/transition.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
"github.com/ethereum/go-ethereum/common"
2828
"github.com/ethereum/go-ethereum/common/hexutil"
2929
"github.com/ethereum/go-ethereum/consensus/misc/eip1559"
30-
"github.com/ethereum/go-ethereum/core"
3130
"github.com/ethereum/go-ethereum/core/state"
3231
"github.com/ethereum/go-ethereum/core/types"
3332
"github.com/ethereum/go-ethereum/core/vm"
@@ -74,10 +73,10 @@ var (
7473
)
7574

7675
type input struct {
77-
Alloc core.GenesisAlloc `json:"alloc,omitempty"`
78-
Env *stEnv `json:"env,omitempty"`
79-
Txs []*txWithKey `json:"txs,omitempty"`
80-
TxRlp string `json:"txsRlp,omitempty"`
76+
Alloc types.GenesisAlloc `json:"alloc,omitempty"`
77+
Env *stEnv `json:"env,omitempty"`
78+
Txs []*txWithKey `json:"txs,omitempty"`
79+
TxRlp string `json:"txsRlp,omitempty"`
8180
}
8281

8382
func Transition(ctx *cli.Context) error {
@@ -272,7 +271,7 @@ func applyCancunChecks(env *stEnv, chainConfig *params.ChainConfig) error {
272271
return nil
273272
}
274273

275-
type Alloc map[common.Address]core.GenesisAccount
274+
type Alloc map[common.Address]types.Account
276275

277276
func (g Alloc) OnRoot(common.Hash) {}
278277

@@ -288,7 +287,7 @@ func (g Alloc) OnAccount(addr *common.Address, dumpAccount state.DumpAccount) {
288287
storage[k] = common.HexToHash(v)
289288
}
290289
}
291-
genesisAccount := core.GenesisAccount{
290+
genesisAccount := types.Account{
292291
Code: dumpAccount.Code,
293292
Storage: storage,
294293
Balance: balance,

cmd/utils/history_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func TestHistoryImportAndExport(t *testing.T) {
5050
address = crypto.PubkeyToAddress(key.PublicKey)
5151
genesis = &core.Genesis{
5252
Config: params.TestChainConfig,
53-
Alloc: core.GenesisAlloc{address: {Balance: big.NewInt(1000000000000000000)}},
53+
Alloc: types.GenesisAlloc{address: {Balance: big.NewInt(1000000000000000000)}},
5454
}
5555
signer = types.LatestSigner(genesis.Config)
5656
)

consensus/clique/clique_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func TestReimportMirroredState(t *testing.T) {
4747
genspec := &core.Genesis{
4848
Config: params.AllCliqueProtocolChanges,
4949
ExtraData: make([]byte, extraVanity+common.AddressLength+extraSeal),
50-
Alloc: map[common.Address]core.GenesisAccount{
50+
Alloc: map[common.Address]types.Account{
5151
addr: {Balance: big.NewInt(10000000000000000)},
5252
},
5353
BaseFee: big.NewInt(params.InitialBaseFee),

core/bench_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ func benchInsertChain(b *testing.B, disk bool, gen func(int, *BlockGen)) {
189189
// generator function.
190190
gspec := &Genesis{
191191
Config: params.TestChainConfig,
192-
Alloc: GenesisAlloc{benchRootAddr: {Balance: benchRootFunds}},
192+
Alloc: types.GenesisAlloc{benchRootAddr: {Balance: benchRootFunds}},
193193
}
194194
_, chain, _ := GenerateChainWithGenesis(gspec, ethash.NewFaker(), b.N, gen)
195195

core/block_validator_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func testHeaderVerificationForMerging(t *testing.T, isClique bool) {
106106
gspec = &Genesis{
107107
Config: &config,
108108
ExtraData: make([]byte, 32+common.AddressLength+crypto.SignatureLength),
109-
Alloc: map[common.Address]GenesisAccount{
109+
Alloc: map[common.Address]types.Account{
110110
addr: {Balance: big.NewInt(1)},
111111
},
112112
BaseFee: big.NewInt(params.InitialBaseFee),

core/blockchain.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2455,7 +2455,7 @@ func (bc *BlockChain) SetTrieFlushInterval(interval time.Duration) {
24552455
bc.flushInterval.Store(int64(interval))
24562456
}
24572457

2458-
// GetTrieFlushInterval gets the in-memory tries flush interval
2458+
// GetTrieFlushInterval gets the in-memory tries flushAlloc interval
24592459
func (bc *BlockChain) GetTrieFlushInterval() time.Duration {
24602460
return time.Duration(bc.flushInterval.Load())
24612461
}

core/blockchain_test.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ func testFastVsFullChains(t *testing.T, scheme string) {
839839
funds = big.NewInt(1000000000000000)
840840
gspec = &Genesis{
841841
Config: params.TestChainConfig,
842-
Alloc: GenesisAlloc{address: {Balance: funds}},
842+
Alloc: types.GenesisAlloc{address: {Balance: funds}},
843843
BaseFee: big.NewInt(params.InitialBaseFee),
844844
}
845845
signer = types.LatestSigner(gspec.Config)
@@ -972,7 +972,7 @@ func testLightVsFastVsFullChainHeads(t *testing.T, scheme string) {
972972
funds = big.NewInt(1000000000000000)
973973
gspec = &Genesis{
974974
Config: params.TestChainConfig,
975-
Alloc: GenesisAlloc{address: {Balance: funds}},
975+
Alloc: types.GenesisAlloc{address: {Balance: funds}},
976976
BaseFee: big.NewInt(params.InitialBaseFee),
977977
}
978978
)
@@ -1092,7 +1092,7 @@ func testChainTxReorgs(t *testing.T, scheme string) {
10921092
gspec = &Genesis{
10931093
Config: params.TestChainConfig,
10941094
GasLimit: 3141592,
1095-
Alloc: GenesisAlloc{
1095+
Alloc: types.GenesisAlloc{
10961096
addr1: {Balance: big.NewInt(1000000000000000)},
10971097
addr2: {Balance: big.NewInt(1000000000000000)},
10981098
addr3: {Balance: big.NewInt(1000000000000000)},
@@ -1207,7 +1207,7 @@ func testLogReorgs(t *testing.T, scheme string) {
12071207

12081208
// this code generates a log
12091209
code = common.Hex2Bytes("60606040525b7f24ec1d3ff24c2f6ff210738839dbc339cd45a5294d85c79361016243157aae7b60405180905060405180910390a15b600a8060416000396000f360606040526008565b00")
1210-
gspec = &Genesis{Config: params.TestChainConfig, Alloc: GenesisAlloc{addr1: {Balance: big.NewInt(10000000000000000)}}}
1210+
gspec = &Genesis{Config: params.TestChainConfig, Alloc: types.GenesisAlloc{addr1: {Balance: big.NewInt(10000000000000000)}}}
12111211
signer = types.LatestSigner(gspec.Config)
12121212
)
12131213

@@ -1264,7 +1264,7 @@ func testLogRebirth(t *testing.T, scheme string) {
12641264
var (
12651265
key1, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
12661266
addr1 = crypto.PubkeyToAddress(key1.PublicKey)
1267-
gspec = &Genesis{Config: params.TestChainConfig, Alloc: GenesisAlloc{addr1: {Balance: big.NewInt(10000000000000000)}}}
1267+
gspec = &Genesis{Config: params.TestChainConfig, Alloc: types.GenesisAlloc{addr1: {Balance: big.NewInt(10000000000000000)}}}
12681268
signer = types.LatestSigner(gspec.Config)
12691269
engine = ethash.NewFaker()
12701270
blockchain, _ = NewBlockChain(rawdb.NewMemoryDatabase(), DefaultCacheConfigWithScheme(scheme), gspec, nil, engine, vm.Config{}, nil, nil)
@@ -1346,7 +1346,7 @@ func testSideLogRebirth(t *testing.T, scheme string) {
13461346
var (
13471347
key1, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
13481348
addr1 = crypto.PubkeyToAddress(key1.PublicKey)
1349-
gspec = &Genesis{Config: params.TestChainConfig, Alloc: GenesisAlloc{addr1: {Balance: big.NewInt(10000000000000000)}}}
1349+
gspec = &Genesis{Config: params.TestChainConfig, Alloc: types.GenesisAlloc{addr1: {Balance: big.NewInt(10000000000000000)}}}
13501350
signer = types.LatestSigner(gspec.Config)
13511351
blockchain, _ = NewBlockChain(rawdb.NewMemoryDatabase(), DefaultCacheConfigWithScheme(scheme), gspec, nil, ethash.NewFaker(), vm.Config{}, nil, nil)
13521352
)
@@ -1443,7 +1443,7 @@ func testReorgSideEvent(t *testing.T, scheme string) {
14431443
addr1 = crypto.PubkeyToAddress(key1.PublicKey)
14441444
gspec = &Genesis{
14451445
Config: params.TestChainConfig,
1446-
Alloc: GenesisAlloc{addr1: {Balance: big.NewInt(10000000000000000)}},
1446+
Alloc: types.GenesisAlloc{addr1: {Balance: big.NewInt(10000000000000000)}},
14471447
}
14481448
signer = types.LatestSigner(gspec.Config)
14491449
)
@@ -1586,7 +1586,7 @@ func testEIP155Transition(t *testing.T, scheme string) {
15861586
EIP155Block: big.NewInt(2),
15871587
HomesteadBlock: new(big.Int),
15881588
},
1589-
Alloc: GenesisAlloc{address: {Balance: funds}, deleteAddr: {Balance: new(big.Int)}},
1589+
Alloc: types.GenesisAlloc{address: {Balance: funds}, deleteAddr: {Balance: new(big.Int)}},
15901590
}
15911591
)
15921592
genDb, blocks, _ := GenerateChainWithGenesis(gspec, ethash.NewFaker(), 4, func(i int, block *BlockGen) {
@@ -1701,7 +1701,7 @@ func testEIP161AccountRemoval(t *testing.T, scheme string) {
17011701
EIP150Block: new(big.Int),
17021702
EIP158Block: big.NewInt(2),
17031703
},
1704-
Alloc: GenesisAlloc{address: {Balance: funds}},
1704+
Alloc: types.GenesisAlloc{address: {Balance: funds}},
17051705
}
17061706
)
17071707
_, blocks, _ := GenerateChainWithGenesis(gspec, ethash.NewFaker(), 3, func(i int, block *BlockGen) {
@@ -1932,7 +1932,7 @@ func testBlockchainRecovery(t *testing.T, scheme string) {
19321932
key, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
19331933
address = crypto.PubkeyToAddress(key.PublicKey)
19341934
funds = big.NewInt(1000000000)
1935-
gspec = &Genesis{Config: params.TestChainConfig, Alloc: GenesisAlloc{address: {Balance: funds}}}
1935+
gspec = &Genesis{Config: params.TestChainConfig, Alloc: types.GenesisAlloc{address: {Balance: funds}}}
19361936
)
19371937
height := uint64(1024)
19381938
_, blocks, receipts := GenerateChainWithGenesis(gspec, ethash.NewFaker(), int(height), nil)
@@ -2137,7 +2137,7 @@ func testSideImport(t *testing.T, numCanonBlocksInSidechain, blocksBetweenCommon
21372137

21382138
gspec = &Genesis{
21392139
Config: &chainConfig,
2140-
Alloc: GenesisAlloc{addr: {Balance: big.NewInt(math.MaxInt64)}},
2140+
Alloc: types.GenesisAlloc{addr: {Balance: big.NewInt(math.MaxInt64)}},
21412141
BaseFee: big.NewInt(params.InitialBaseFee),
21422142
}
21432143
signer = types.LatestSigner(gspec.Config)
@@ -2732,7 +2732,7 @@ func benchmarkLargeNumberOfValueToNonexisting(b *testing.B, numTxs, numBlocks in
27322732
bankFunds = big.NewInt(100000000000000000)
27332733
gspec = &Genesis{
27342734
Config: params.TestChainConfig,
2735-
Alloc: GenesisAlloc{
2735+
Alloc: types.GenesisAlloc{
27362736
testBankAddress: {Balance: bankFunds},
27372737
common.HexToAddress("0xc0de"): {
27382738
Code: []byte{0x60, 0x01, 0x50},
@@ -2910,7 +2910,7 @@ func testDeleteCreateRevert(t *testing.T, scheme string) {
29102910
funds = big.NewInt(100000000000000000)
29112911
gspec = &Genesis{
29122912
Config: params.TestChainConfig,
2913-
Alloc: GenesisAlloc{
2913+
Alloc: types.GenesisAlloc{
29142914
address: {Balance: funds},
29152915
// The address 0xAAAAA selfdestructs if called
29162916
aa: {
@@ -3034,7 +3034,7 @@ func testDeleteRecreateSlots(t *testing.T, scheme string) {
30343034

30353035
gspec := &Genesis{
30363036
Config: params.TestChainConfig,
3037-
Alloc: GenesisAlloc{
3037+
Alloc: types.GenesisAlloc{
30383038
address: {Balance: funds},
30393039
// The address 0xAAAAA selfdestructs if called
30403040
aa: {
@@ -3120,7 +3120,7 @@ func testDeleteRecreateAccount(t *testing.T, scheme string) {
31203120

31213121
gspec := &Genesis{
31223122
Config: params.TestChainConfig,
3123-
Alloc: GenesisAlloc{
3123+
Alloc: types.GenesisAlloc{
31243124
address: {Balance: funds},
31253125
// The address 0xAAAAA selfdestructs if called
31263126
aa: {
@@ -3241,7 +3241,7 @@ func testDeleteRecreateSlotsAcrossManyBlocks(t *testing.T, scheme string) {
32413241
t.Logf("Destination address: %x\n", aa)
32423242
gspec := &Genesis{
32433243
Config: params.TestChainConfig,
3244-
Alloc: GenesisAlloc{
3244+
Alloc: types.GenesisAlloc{
32453245
address: {Balance: funds},
32463246
// The address 0xAAAAA selfdestructs if called
32473247
aa: {
@@ -3436,7 +3436,7 @@ func testInitThenFailCreateContract(t *testing.T, scheme string) {
34363436

34373437
gspec := &Genesis{
34383438
Config: params.TestChainConfig,
3439-
Alloc: GenesisAlloc{
3439+
Alloc: types.GenesisAlloc{
34403440
address: {Balance: funds},
34413441
// The address aa has some funds
34423442
aa: {Balance: big.NewInt(100000)},
@@ -3511,7 +3511,7 @@ func testEIP2718Transition(t *testing.T, scheme string) {
35113511
funds = big.NewInt(1000000000000000)
35123512
gspec = &Genesis{
35133513
Config: params.TestChainConfig,
3514-
Alloc: GenesisAlloc{
3514+
Alloc: types.GenesisAlloc{
35153515
address: {Balance: funds},
35163516
// The address 0xAAAA sloads 0x00 and 0x01
35173517
aa: {
@@ -3596,7 +3596,7 @@ func testEIP1559Transition(t *testing.T, scheme string) {
35963596
config = *params.AllEthashProtocolChanges
35973597
gspec = &Genesis{
35983598
Config: &config,
3599-
Alloc: GenesisAlloc{
3599+
Alloc: types.GenesisAlloc{
36003600
addr1: {Balance: funds},
36013601
addr2: {Balance: funds},
36023602
// The address 0xAAAA sloads 0x00 and 0x01
@@ -3737,7 +3737,7 @@ func testSetCanonical(t *testing.T, scheme string) {
37373737
funds = big.NewInt(100000000000000000)
37383738
gspec = &Genesis{
37393739
Config: params.TestChainConfig,
3740-
Alloc: GenesisAlloc{address: {Balance: funds}},
3740+
Alloc: types.GenesisAlloc{address: {Balance: funds}},
37413741
BaseFee: big.NewInt(params.InitialBaseFee),
37423742
}
37433743
signer = types.LatestSigner(gspec.Config)
@@ -3854,7 +3854,7 @@ func testCanonicalHashMarker(t *testing.T, scheme string) {
38543854
var (
38553855
gspec = &Genesis{
38563856
Config: params.TestChainConfig,
3857-
Alloc: GenesisAlloc{},
3857+
Alloc: types.GenesisAlloc{},
38583858
BaseFee: big.NewInt(params.InitialBaseFee),
38593859
}
38603860
engine = ethash.NewFaker()
@@ -3967,7 +3967,7 @@ func testCreateThenDelete(t *testing.T, config *params.ChainConfig) {
39673967
}...)
39683968
gspec := &Genesis{
39693969
Config: config,
3970-
Alloc: GenesisAlloc{
3970+
Alloc: types.GenesisAlloc{
39713971
address: {Balance: funds},
39723972
},
39733973
}
@@ -4053,7 +4053,7 @@ func TestDeleteThenCreate(t *testing.T) {
40534053

40544054
gspec := &Genesis{
40554055
Config: params.TestChainConfig,
4056-
Alloc: GenesisAlloc{
4056+
Alloc: types.GenesisAlloc{
40574057
address: {Balance: funds},
40584058
},
40594059
}
@@ -4165,7 +4165,7 @@ func TestTransientStorageReset(t *testing.T) {
41654165
}...)
41664166
gspec := &Genesis{
41674167
Config: params.TestChainConfig,
4168-
Alloc: GenesisAlloc{
4168+
Alloc: types.GenesisAlloc{
41694169
address: {Balance: funds},
41704170
},
41714171
}
@@ -4233,7 +4233,7 @@ func TestEIP3651(t *testing.T) {
42334233
config = *params.AllEthashProtocolChanges
42344234
gspec = &Genesis{
42354235
Config: &config,
4236-
Alloc: GenesisAlloc{
4236+
Alloc: types.GenesisAlloc{
42374237
addr1: {Balance: funds},
42384238
addr2: {Balance: funds},
42394239
// The address 0xAAAA sloads 0x00 and 0x01

0 commit comments

Comments
 (0)