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

BEP-466: Make the block header format compatible with EIP-7685 #2777

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
12 changes: 12 additions & 0 deletions consensus/beacon/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,18 @@ func (beacon *Beacon) VerifyUncles(chain consensus.ChainReader, block *types.Blo
return nil
}

func (beacon *Beacon) VerifyRequests(header *types.Header, Requests [][]byte) error {
if header.RequestsHash != nil {
reqhash := types.CalcRequestsHash(Requests)
if reqhash != *header.RequestsHash {
return fmt.Errorf("invalid requests hash (remote: %x local: %x)", *header.RequestsHash, reqhash)
}
} else if Requests != nil {
return errors.New("block has requests before prague fork")
}
return nil
}

// verifyHeader checks whether a header conforms to the consensus rules of the
// stock Ethereum consensus engine. The difference between the beacon and classic is
// (a) The following fields are expected to be constants:
Expand Down
4 changes: 4 additions & 0 deletions consensus/clique/clique.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,10 @@ func (c *Clique) VerifyUncles(chain consensus.ChainReader, block *types.Block) e
return nil
}

func (c *Clique) VerifyRequests(header *types.Header, Requests [][]byte) error {
return nil
}

// verifySeal checks whether the signature contained in the header satisfies the
// consensus protocol requirements. The method accepts an optional list of parent
// headers that aren't yet part of the local blockchain to generate the snapshots
Expand Down
3 changes: 3 additions & 0 deletions consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ type Engine interface {
// rules of a given engine.
VerifyUncles(chain ChainReader, block *types.Block) error

// VerifyRequests verifies the consistency between Requests and header.RequestsHash.
VerifyRequests(header *types.Header, Requests [][]byte) error

// NextInTurnValidator return the next in-turn validator for header
NextInTurnValidator(chain ChainHeaderReader, header *types.Header) (common.Address, error)

Expand Down
4 changes: 4 additions & 0 deletions consensus/ethash/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ func (ethash *Ethash) VerifyUncles(chain consensus.ChainReader, block *types.Blo
return nil
}

func (ethash *Ethash) VerifyRequests(header *types.Header, Requests [][]byte) error {
return nil
}

// verifyHeader checks whether a header conforms to the consensus rules of the
// stock Ethereum ethash engine.
// See YP section 4.3.4. "Block Header Validity"
Expand Down
13 changes: 8 additions & 5 deletions consensus/parlia/parlia.go
Original file line number Diff line number Diff line change
Expand Up @@ -650,11 +650,10 @@ func (p *Parlia) verifyHeader(chain consensus.ChainHeaderReader, header *types.H
if header.RequestsHash != nil {
return fmt.Errorf("invalid RequestsHash, have %#x, expected nil", header.ParentBeaconRoot)
}
// } else {
// // TODO(Nathan): need a BEP to define this and `Requests` in struct Body
// if !header.EmptyRequestsHash() {
// return errors.New("header has wrong RequestsHash")
// }
} else {
if header.RequestsHash == nil {
return errors.New("header has nil RequestsHash after Prague")
}
}

// All basic checks passed, verify cascading fields
Expand Down Expand Up @@ -858,6 +857,10 @@ func (p *Parlia) VerifyUncles(chain consensus.ChainReader, block *types.Block) e
return nil
}

func (p *Parlia) VerifyRequests(header *types.Header, Requests [][]byte) error {
return nil
}

// VerifySeal implements consensus.Engine, checking whether the signature contained
// in the header satisfies the consensus protocol requirements.
func (p *Parlia) VerifySeal(chain consensus.ChainReader, header *types.Header) error {
Expand Down
10 changes: 1 addition & 9 deletions core/block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,7 @@ func (v *BlockValidator) ValidateState(block *types.Block, statedb *state.StateD
}

// Validate the parsed requests match the expected header value.
if header.RequestsHash != nil {
reqhash := types.CalcRequestsHash(res.Requests)
if reqhash != *header.RequestsHash {
return fmt.Errorf("invalid requests hash (remote: %x local: %x)", *header.RequestsHash, reqhash)
}
} else if res.Requests != nil {
return errors.New("block has requests before prague fork")
}
return nil
return v.bc.engine.VerifyRequests(block.Header(), res.Requests)
})
validateFuns = append(validateFuns, func() error {
// Validate the state root against the received state root and throw
Expand Down
4 changes: 4 additions & 0 deletions core/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4192,6 +4192,10 @@ func (c *mockParlia) VerifyUncles(chain consensus.ChainReader, block *types.Bloc
return nil
}

func (c *mockParlia) VerifyRequests(header *types.Header, Requests [][]byte) error {
return nil
}

func (c *mockParlia) VerifyHeader(chain consensus.ChainHeaderReader, header *types.Header) error {
return nil
}
Expand Down
15 changes: 10 additions & 5 deletions core/chain_makers.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse
}

var requests [][]byte
if config.IsPrague(b.header.Number, b.header.Time) {
if config.IsPrague(b.header.Number, b.header.Time) && config.Parlia == nil {
requests = [][]byte{}
// EIP-6110 deposits
var blockLogs []*types.Log
Expand Down Expand Up @@ -610,11 +610,16 @@ func (cm *chainMaker) makeHeader(parent *types.Block, state *state.StateDB, engi
excessBlobGas := eip4844.CalcExcessBlobGas(parentExcessBlobGas, parentBlobGasUsed)
header.ExcessBlobGas = &excessBlobGas
header.BlobGasUsed = new(uint64)
if cm.config.Parlia != nil {
header.WithdrawalsHash = &types.EmptyWithdrawalsHash
}
if cm.config.Parlia == nil || cm.config.IsBohr(header.Number, header.Time) {
if cm.config.Parlia == nil {
header.ParentBeaconRoot = new(common.Hash)
} else {
header.WithdrawalsHash = &types.EmptyWithdrawalsHash
if cm.config.IsBohr(header.Number, header.Time) {
header.ParentBeaconRoot = new(common.Hash)
}
if cm.config.IsPrague(header.Number, header.Time) {
header.RequestsHash = &types.EmptyRequestsHash
}
}
}
return header
Expand Down
2 changes: 1 addition & 1 deletion core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg

// Read requests if Prague is enabled.
var requests [][]byte
if p.config.IsPrague(block.Number(), block.Time()) {
if p.config.IsPrague(block.Number(), block.Time()) && p.chain.config.Parlia == nil {
var allCommonLogs []*types.Log
for _, receipt := range receipts {
allCommonLogs = append(allCommonLogs, receipt.Logs...)
Expand Down
2 changes: 1 addition & 1 deletion core/types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ func EncodeSigHeader(w io.Writer, header *Header, chainId *big.Int) {
header.MixDigest,
header.Nonce,
}
if header.ParentBeaconRoot != nil && *header.ParentBeaconRoot == (common.Hash{}) {
if header.ParentBeaconRoot != nil {
toEncode = append(toEncode, header.BaseFee,
header.WithdrawalsHash,
header.BlobGasUsed,
Expand Down
4 changes: 4 additions & 0 deletions eth/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ func (c *mockParlia) VerifyUncles(chain consensus.ChainReader, block *types.Bloc
return nil
}

func (c *mockParlia) VerifyRequests(header *types.Header, Requests [][]byte) error {
return nil
}

func (c *mockParlia) VerifyHeader(chain consensus.ChainHeaderReader, header *types.Header) error {
return nil
}
Expand Down
13 changes: 8 additions & 5 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1028,13 +1028,16 @@ func (w *worker) prepareWork(genParams *generateParams, witness bool) (*environm
}
header.BlobGasUsed = new(uint64)
header.ExcessBlobGas = &excessBlobGas
if w.chainConfig.Parlia != nil {
header.WithdrawalsHash = &types.EmptyWithdrawalsHash
}
if w.chainConfig.Parlia == nil {
header.ParentBeaconRoot = genParams.beaconRoot
} else if w.chainConfig.IsBohr(header.Number, header.Time) {
header.ParentBeaconRoot = new(common.Hash)
} else {
header.WithdrawalsHash = &types.EmptyWithdrawalsHash
if w.chainConfig.IsBohr(header.Number, header.Time) {
header.ParentBeaconRoot = new(common.Hash)
}
if w.chainConfig.IsPrague(header.Number, header.Time) {
header.RequestsHash = &types.EmptyRequestsHash
}
}
}
// Could potentially happen if starting to mine in an odd state.
Expand Down
Loading