Skip to content

Commit

Permalink
consensus/clique: prevent 0 len extradata from panicing (ethereum#23538)
Browse files Browse the repository at this point in the history
Closes ethereum#23522

Co-authored-by: Martin Holst Swende <martin@swende.se>
  • Loading branch information
2 people authored and zzyalbert committed Nov 26, 2021
1 parent cfef274 commit 739aca4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 4 additions & 1 deletion core/genesis.go
Expand Up @@ -306,7 +306,7 @@ func (g *Genesis) ToBlock(db ethdb.Database) *types.Block {
func (g *Genesis) Commit(db ethdb.Database) (*types.Block, error) {
block := g.ToBlock(db)
if block.Number().Sign() != 0 {
return nil, fmt.Errorf("can't commit genesis block with number > 0")
return nil, errors.New("can't commit genesis block with number > 0")
}
config := g.Config
if config == nil {
Expand All @@ -315,6 +315,9 @@ func (g *Genesis) Commit(db ethdb.Database) (*types.Block, error) {
if err := config.CheckConfigForkOrder(); err != nil {
return nil, err
}
if config.Clique != nil && len(block.Extra()) == 0 {
return nil, errors.New("can't start clique chain without signers")
}
rawdb.WriteTd(db, block.Hash(), block.NumberU64(), g.Difficulty)
rawdb.WriteBlock(db, block)
rawdb.WriteReceipts(db, block.Hash(), block.NumberU64(), nil)
Expand Down
6 changes: 4 additions & 2 deletions miner/worker_test.go
Expand Up @@ -74,8 +74,10 @@ var (
func init() {
testTxPoolConfig = core.DefaultTxPoolConfig
testTxPoolConfig.Journal = ""
ethashChainConfig = params.TestChainConfig
cliqueChainConfig = params.TestChainConfig
ethashChainConfig = new(params.ChainConfig)
*ethashChainConfig = *params.TestChainConfig
cliqueChainConfig = new(params.ChainConfig)
*cliqueChainConfig = *params.TestChainConfig
cliqueChainConfig.Clique = &params.CliqueConfig{
Period: 10,
Epoch: 30000,
Expand Down

0 comments on commit 739aca4

Please sign in to comment.