Skip to content

Commit

Permalink
set the default value for ParentBeaconRoot to zero hash
Browse files Browse the repository at this point in the history
  • Loading branch information
buddh0 committed Jul 2, 2024
1 parent 68b7d35 commit 9b75dd8
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 8 deletions.
4 changes: 2 additions & 2 deletions consensus/parlia/parlia.go
Original file line number Diff line number Diff line change
Expand Up @@ -620,8 +620,8 @@ func (p *Parlia) verifyHeader(chain consensus.ChainHeaderReader, header *types.H
return fmt.Errorf("invalid parentBeaconRoot, have %#x, expected nil", header.ParentBeaconRoot)
}
} else {
if header.ParentBeaconRoot == nil || *header.ParentBeaconRoot != types.EmptyRootHash {
return fmt.Errorf("invalid parentBeaconRoot, have %#x, expected EmptyRootHash", header.ParentBeaconRoot)
if header.ParentBeaconRoot == nil || *header.ParentBeaconRoot != (common.Hash{}) {
return fmt.Errorf("invalid parentBeaconRoot, have %#x, expected zero Hash", header.ParentBeaconRoot)
}
}

Expand Down
4 changes: 1 addition & 3 deletions core/chain_makers.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,10 +486,8 @@ func (cm *chainMaker) makeHeader(parent *types.Block, state *state.StateDB, engi
if cm.config.Parlia != nil {
header.WithdrawalsHash = &types.EmptyWithdrawalsHash
}
if cm.config.Parlia == nil {
if cm.config.Parlia == nil || cm.config.IsBohr(header.Number, header.Time) {
header.ParentBeaconRoot = new(common.Hash)
} else if cm.config.IsBohr(header.Number, header.Time) {
header.ParentBeaconRoot = &types.EmptyRootHash
}
}
return header
Expand Down
2 changes: 1 addition & 1 deletion core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ func (g *Genesis) ToBlock() *types.Block {
// EIP-4788: The parentBeaconBlockRoot of the genesis block is always
// the zero hash. This is because the genesis block does not have a parent
// by definition.
if conf.Parlia == nil {
if conf.Parlia == nil || conf.IsBohr(num, g.Timestamp) {
head.ParentBeaconRoot = new(common.Hash)
}

Expand Down
2 changes: 1 addition & 1 deletion core/types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ func SealHash(header *Header, chainId *big.Int) (hash common.Hash) {

func EncodeSigHeader(w io.Writer, header *Header, chainId *big.Int) {
var err error
if header.ParentBeaconRoot != nil && *header.ParentBeaconRoot == EmptyRootHash {
if header.ParentBeaconRoot != nil && *header.ParentBeaconRoot == (common.Hash{}) {
err = rlp.Encode(w, []interface{}{
chainId,
header.ParentHash,
Expand Down
2 changes: 1 addition & 1 deletion miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ func (w *worker) prepareWork(genParams *generateParams) (*environment, error) {
if w.chainConfig.Parlia == nil {
header.ParentBeaconRoot = genParams.beaconRoot
} else if w.chainConfig.IsBohr(header.Number, header.Time) {
header.ParentBeaconRoot = &types.EmptyRootHash
header.ParentBeaconRoot = new(common.Hash)
}
}
// Could potentially happen if starting to mine in an odd state.
Expand Down

0 comments on commit 9b75dd8

Please sign in to comment.