Skip to content

Commit

Permalink
eth/catalyst: go generate, fix nitpicks
Browse files Browse the repository at this point in the history
  • Loading branch information
MariusVanDerWijden committed Jan 19, 2023
1 parent 90308c4 commit b49a883
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 53 deletions.
46 changes: 46 additions & 0 deletions core/beacon/gen_epe.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 11 additions & 52 deletions eth/fetcher/block_fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus/beacon"
"github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/rawdb"
Expand All @@ -37,53 +36,24 @@ import (
)

var (
testdb = rawdb.NewMemoryDatabase()
testKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
testAddress = crypto.PubkeyToAddress(testKey.PublicKey)
unknownBlock = types.NewBlock(&types.Header{GasLimit: params.GenesisGasLimit, BaseFee: big.NewInt(params.InitialBaseFee)}, nil, nil, nil, trie.NewStackTrie(nil))
gspec *core.Genesis
genesis *types.Block
)

func init() {
config := &params.ChainConfig{
ChainID: big.NewInt(1),
HomesteadBlock: big.NewInt(0),
DAOForkBlock: nil,
DAOForkSupport: true,
EIP150Block: big.NewInt(0),
EIP155Block: big.NewInt(0),
EIP158Block: big.NewInt(0),
ByzantiumBlock: big.NewInt(0),
ConstantinopleBlock: big.NewInt(0),
PetersburgBlock: big.NewInt(0),
IstanbulBlock: big.NewInt(0),
MuirGlacierBlock: big.NewInt(0),
BerlinBlock: big.NewInt(0),
LondonBlock: big.NewInt(0),
ArrowGlacierBlock: big.NewInt(0),
GrayGlacierBlock: big.NewInt(0),
MergeNetsplitBlock: big.NewInt(0),
ShanghaiTime: big.NewInt(0),
TerminalTotalDifficulty: big.NewInt(0),
TerminalTotalDifficultyPassed: true,
Ethash: new(params.EthashConfig),
}

gspec = &core.Genesis{
Config: config,
testdb = rawdb.NewMemoryDatabase()
testKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
testAddress = crypto.PubkeyToAddress(testKey.PublicKey)
gspec = &core.Genesis{
Config: params.TestChainConfig,
Alloc: core.GenesisAlloc{testAddress: {Balance: big.NewInt(1000000000000000)}},
BaseFee: big.NewInt(params.InitialBaseFee),
}
genesis = gspec.MustCommit(testdb)
}
genesis = gspec.MustCommit(testdb)
unknownBlock = types.NewBlock(&types.Header{GasLimit: params.GenesisGasLimit, BaseFee: big.NewInt(params.InitialBaseFee)}, nil, nil, nil, trie.NewStackTrie(nil))
)

// makeChain creates a chain of n blocks starting at and including parent.
// the returned hash chain is ordered head->parent. In addition, every 3rd block
// contains a transaction and every 5th an uncle to allow testing correct block
// reassembly.
func makeChain(n int, seed byte, parent *types.Block) ([]common.Hash, map[common.Hash]*types.Block) {
blocks, _ := core.GenerateChain(gspec.Config, parent, beacon.New(ethash.NewFaker()), testdb, n, func(i int, block *core.BlockGen) {
blocks, _ := core.GenerateChain(gspec.Config, parent, ethash.NewFaker(), testdb, n, func(i int, block *core.BlockGen) {
block.SetCoinbase(common.Address{seed})

// If the block number is multiple of 3, send a bonus transaction to the miner
Expand All @@ -99,12 +69,6 @@ func makeChain(n int, seed byte, parent *types.Block) ([]common.Hash, map[common
if i > 0 && i%5 == 0 {
block.AddUncle(&types.Header{ParentHash: block.PrevBlock(i - 2).Hash(), Number: big.NewInt(int64(i - 1))})
}
// If the block number is a multiple of 7, add a withdrawal
if i > 0 && i%7 == 0 {
block.AddWithdrawal(&types.Withdrawal{Address: testAddress, Amount: 42})
block.AddWithdrawal(&types.Withdrawal{Address: testAddress, Amount: 43})
block.AddWithdrawal(&types.Withdrawal{Address: testAddress, Amount: 44})
}
})
hashes := make([]common.Hash, n+1)
hashes[len(hashes)-1] = parent.Hash()
Expand Down Expand Up @@ -269,17 +233,13 @@ func (f *fetcherTester) makeBodyFetcher(peer string, blocks map[common.Hash]*typ
// Create a function that returns blocks from the closure
return func(hashes []common.Hash, sink chan *eth.Response) (*eth.Request, error) {
// Gather the block bodies to return
var (
transactions = make([][]*types.Transaction, 0, len(hashes))
uncles = make([][]*types.Header, 0, len(hashes))
withdrawals = make([][]*types.Withdrawal, 0, len(hashes))
)
transactions := make([][]*types.Transaction, 0, len(hashes))
uncles := make([][]*types.Header, 0, len(hashes))

for _, hash := range hashes {
if block, ok := closure[hash]; ok {
transactions = append(transactions, block.Transactions())
uncles = append(uncles, block.Uncles())
withdrawals = append(withdrawals, block.Withdrawals())
}
}
// Return on a new thread
Expand All @@ -288,7 +248,6 @@ func (f *fetcherTester) makeBodyFetcher(peer string, blocks map[common.Hash]*typ
bodies[i] = &eth.BlockBody{
Transactions: txs,
Uncles: uncles[i],
Withdrawals: withdrawals[i],
}
}
req := &eth.Request{
Expand Down
2 changes: 1 addition & 1 deletion params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ func (c *ChainConfig) Description() string {
banner += fmt.Sprintf(" - Arrow Glacier: #%-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/arrow-glacier.md)\n", c.ArrowGlacierBlock)
}
if c.GrayGlacierBlock != nil {
banner += fmt.Sprintf(" - Gray Glacier: %-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/gray-glacier.md)\n", c.GrayGlacierBlock)
banner += fmt.Sprintf(" - Gray Glacier: #%-8v (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/gray-glacier.md)\n", c.GrayGlacierBlock)
}
banner += "\n"

Expand Down

0 comments on commit b49a883

Please sign in to comment.