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

Engine API and type changes for flat requests in Pectra #12337

Merged
merged 20 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Change FlatRequests to slice rather than ptr
  • Loading branch information
somnathb1 committed Oct 18, 2024
commit 22a297ba6694c5bfa921c52cc1df23513a7bcc37
4 changes: 2 additions & 2 deletions consensus/aura/aura.go
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ func (c *AuRa) applyRewards(header *types.Header, state *state.IntraBlockState,
func (c *AuRa) Finalize(config *chain.Config, header *types.Header, state *state.IntraBlockState, txs types.Transactions,
uncles []*types.Header, receipts types.Receipts, withdrawals []*types.Withdrawal, requests types.FlatRequests,
chain consensus.ChainReader, syscall consensus.SystemCall, logger log.Logger,
) (types.Transactions, types.Receipts, *types.FlatRequests, error) {
) (types.Transactions, types.Receipts, types.FlatRequests, error) {
if err := c.applyRewards(header, state, syscall); err != nil {
return nil, nil, nil, err
}
Expand Down Expand Up @@ -845,7 +845,7 @@ func allHeadersUntil(chain consensus.ChainHeaderReader, from *types.Header, to l
//}

// FinalizeAndAssemble implements consensus.Engine
func (c *AuRa) FinalizeAndAssemble(config *chain.Config, header *types.Header, state *state.IntraBlockState, txs types.Transactions, uncles []*types.Header, receipts types.Receipts, withdrawals []*types.Withdrawal, requests types.FlatRequests, chain consensus.ChainReader, syscall consensus.SystemCall, call consensus.Call, logger log.Logger) (*types.Block, types.Transactions, types.Receipts, *types.FlatRequests, error) {
func (c *AuRa) FinalizeAndAssemble(config *chain.Config, header *types.Header, state *state.IntraBlockState, txs types.Transactions, uncles []*types.Header, receipts types.Receipts, withdrawals []*types.Withdrawal, requests types.FlatRequests, chain consensus.ChainReader, syscall consensus.SystemCall, call consensus.Call, logger log.Logger) (*types.Block, types.Transactions, types.Receipts, types.FlatRequests, error) {
outTxs, outReceipts, _, err := c.Finalize(config, header, state, txs, uncles, receipts, withdrawals, requests, chain, syscall, logger)
if err != nil {
return nil, nil, nil, nil, err
Expand Down
4 changes: 2 additions & 2 deletions consensus/clique/clique.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,15 +382,15 @@ func (c *Clique) CalculateRewards(config *chain.Config, header *types.Header, un
func (c *Clique) Finalize(config *chain.Config, header *types.Header, state *state.IntraBlockState,
txs types.Transactions, uncles []*types.Header, r types.Receipts, withdrawals []*types.Withdrawal, requests types.FlatRequests,
chain consensus.ChainReader, syscall consensus.SystemCall, logger log.Logger,
) (types.Transactions, types.Receipts, *types.FlatRequests, error) {
) (types.Transactions, types.Receipts, types.FlatRequests, error) {
return txs, r, nil, nil
}

// FinalizeAndAssemble implements consensus.Engine, ensuring no uncles are set,
// nor block rewards given, and returns the final block.
func (c *Clique) FinalizeAndAssemble(chainConfig *chain.Config, header *types.Header, state *state.IntraBlockState,
txs types.Transactions, uncles []*types.Header, receipts types.Receipts, withdrawals []*types.Withdrawal, requests types.FlatRequests, chain consensus.ChainReader, syscall consensus.SystemCall, call consensus.Call, logger log.Logger,
) (*types.Block, types.Transactions, types.Receipts, *types.FlatRequests, error) {
) (*types.Block, types.Transactions, types.Receipts, types.FlatRequests, error) {
// Assemble and return the final block for sealing
return types.NewBlockForAsembling(header, txs, nil, receipts, withdrawals), txs, receipts, nil, nil
}
Expand Down
4 changes: 2 additions & 2 deletions consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ type EngineWriter interface {
// but does not assemble the block.
Finalize(config *chain.Config, header *types.Header, state *state.IntraBlockState,
txs types.Transactions, uncles []*types.Header, receipts types.Receipts, withdrawals []*types.Withdrawal, requests types.FlatRequests, chain ChainReader, syscall SystemCall, logger log.Logger,
) (types.Transactions, types.Receipts, *types.FlatRequests, error)
) (types.Transactions, types.Receipts, types.FlatRequests, error)

// FinalizeAndAssemble runs any post-transaction state modifications (e.g. block
// rewards) and assembles the final block.
Expand All @@ -178,7 +178,7 @@ type EngineWriter interface {
// consensus rules that happen at finalization (e.g. block rewards).
FinalizeAndAssemble(config *chain.Config, header *types.Header, state *state.IntraBlockState,
txs types.Transactions, uncles []*types.Header, receipts types.Receipts, withdrawals []*types.Withdrawal, requests types.FlatRequests, chain ChainReader, syscall SystemCall, call Call, logger log.Logger,
) (*types.Block, types.Transactions, types.Receipts, *types.FlatRequests, error)
) (*types.Block, types.Transactions, types.Receipts, types.FlatRequests, error)

// Seal generates a new sealing request for the given input block and pushes
// the result into the given channel.
Expand Down
4 changes: 2 additions & 2 deletions consensus/ethash/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ func (ethash *Ethash) Initialize(config *chain.Config, chain consensus.ChainHead
func (ethash *Ethash) Finalize(config *chain.Config, header *types.Header, state *state.IntraBlockState,
txs types.Transactions, uncles []*types.Header, r types.Receipts, withdrawals []*types.Withdrawal, requests types.FlatRequests,
chain consensus.ChainReader, syscall consensus.SystemCall, logger log.Logger,
) (types.Transactions, types.Receipts, *types.FlatRequests, error) {
) (types.Transactions, types.Receipts, types.FlatRequests, error) {
// Accumulate any block and uncle rewards and commit the final state root
accumulateRewards(config, state, header, uncles)
return txs, r, nil, nil
Expand All @@ -580,7 +580,7 @@ func (ethash *Ethash) Finalize(config *chain.Config, header *types.Header, state
func (ethash *Ethash) FinalizeAndAssemble(chainConfig *chain.Config, header *types.Header, state *state.IntraBlockState,
txs types.Transactions, uncles []*types.Header, r types.Receipts, withdrawals []*types.Withdrawal, requests types.FlatRequests,
chain consensus.ChainReader, syscall consensus.SystemCall, call consensus.Call, logger log.Logger,
) (*types.Block, types.Transactions, types.Receipts, *types.FlatRequests, error) {
) (*types.Block, types.Transactions, types.Receipts, types.FlatRequests, error) {

// Finalize block
outTxs, outR, _, err := ethash.Finalize(chainConfig, header, state, txs, uncles, r, withdrawals, requests, chain, syscall, logger)
Expand Down
6 changes: 3 additions & 3 deletions consensus/merge/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (s *Merge) CalculateRewards(config *chain.Config, header *types.Header, unc
func (s *Merge) Finalize(config *chain.Config, header *types.Header, state *state.IntraBlockState,
txs types.Transactions, uncles []*types.Header, receipts types.Receipts, withdrawals []*types.Withdrawal, requestsInBlock types.FlatRequests,
chain consensus.ChainReader, syscall consensus.SystemCall, logger log.Logger,
) (types.Transactions, types.Receipts, *types.FlatRequests, error) {
) (types.Transactions, types.Receipts, types.FlatRequests, error) {
if !misc.IsPoSHeader(header) {
return s.eth1Engine.Finalize(config, header, state, txs, uncles, receipts, withdrawals, requestsInBlock, chain, syscall, logger)
}
Expand Down Expand Up @@ -210,12 +210,12 @@ func (s *Merge) Finalize(config *chain.Config, header *types.Header, state *stat

}

return txs, receipts, &rs, nil
return txs, receipts, rs, nil
}

func (s *Merge) FinalizeAndAssemble(config *chain.Config, header *types.Header, state *state.IntraBlockState,
txs types.Transactions, uncles []*types.Header, receipts types.Receipts, withdrawals []*types.Withdrawal, requests types.FlatRequests, chain consensus.ChainReader, syscall consensus.SystemCall, call consensus.Call, logger log.Logger,
) (*types.Block, types.Transactions, types.Receipts, *types.FlatRequests, error) {
) (*types.Block, types.Transactions, types.Receipts, types.FlatRequests, error) {
if !misc.IsPoSHeader(header) {
return s.eth1Engine.FinalizeAndAssemble(config, header, state, txs, uncles, receipts, withdrawals, requests, chain, syscall, call, logger)
}
Expand Down
2 changes: 1 addition & 1 deletion core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ func FinalizeBlockExecution(
withdrawals []*types.Withdrawal, requests types.FlatRequests, chainReader consensus.ChainReader,
isMining bool,
logger log.Logger,
) (newBlock *types.Block, newTxs types.Transactions, newReceipt types.Receipts, retRequests *types.FlatRequests, err error) {
) (newBlock *types.Block, newTxs types.Transactions, newReceipt types.Receipts, retRequests types.FlatRequests, err error) {
syscall := func(contract libcommon.Address, data []byte) ([]byte, error) {
return SysCallContract(contract, data, cc, ibs, header, engine, false /* constCall */)
}
Expand Down
20 changes: 4 additions & 16 deletions core/types/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package types

import (
"bytes"
"crypto/sha256"

libcommon "github.com/erigontech/erigon-lib/common"
Expand Down Expand Up @@ -46,28 +45,17 @@ func (f *FlatRequest) EncodingSize() int { return 0 }

type FlatRequests []FlatRequest

func (r *FlatRequests) Hash() *libcommon.Hash {
if r == nil || len(*r) < len(KnownRequestTypes) {
func (r FlatRequests) Hash() *libcommon.Hash {
if r == nil || len(r) < len(KnownRequestTypes) {
return nil
}
sha := sha256.New()
for i, t := range KnownRequestTypes {
hi := sha256.Sum256(append([]byte{t}, (*r)[i].RequestData...))
hi := sha256.Sum256(append([]byte{t}, r[i].RequestData...))
sha.Write(hi[:])
}
h := libcommon.BytesToHash(sha.Sum(nil))
return &h
}

func (r *FlatRequests) Hash3() (h libcommon.Hash) {
return sha256.Sum256([]byte{})
}

func (r FlatRequests) Len() int { return len(r) }

// EncodeIndex encodes the i'th request to w. Note that this does not check for errors
// because we assume that *request will only ever contain valid requests that were either
// constructed by decoding or via public API in this package.
func (r FlatRequests) EncodeIndex(i int, w *bytes.Buffer) {
// r[i].EncodeRLP(w)
}
func (r FlatRequests) Len() int { return len(r) }
2 changes: 1 addition & 1 deletion eth/stagedsync/stage_mining_create_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type MiningBlock struct {
Receipts types.Receipts
Withdrawals []*types.Withdrawal
PreparedTxs types.TransactionsStream
Requests *types.FlatRequests
Requests types.FlatRequests
}

type MiningState struct {
Expand Down
4 changes: 2 additions & 2 deletions polygon/bor/bor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ func (c *Bor) CalculateRewards(config *chain.Config, header *types.Header, uncle
func (c *Bor) Finalize(config *chain.Config, header *types.Header, state *state.IntraBlockState,
txs types.Transactions, uncles []*types.Header, r types.Receipts, withdrawals []*types.Withdrawal, requests types.FlatRequests,
chain consensus.ChainReader, syscall consensus.SystemCall, logger log.Logger,
) (types.Transactions, types.Receipts, *types.FlatRequests, error) {
) (types.Transactions, types.Receipts, types.FlatRequests, error) {
headerNumber := header.Number.Uint64()

if withdrawals != nil || header.WithdrawalsHash != nil {
Expand Down Expand Up @@ -1103,7 +1103,7 @@ func (c *Bor) changeContractCodeIfNeeded(headerNumber uint64, state *state.Intra
func (c *Bor) FinalizeAndAssemble(chainConfig *chain.Config, header *types.Header, state *state.IntraBlockState,
txs types.Transactions, uncles []*types.Header, receipts types.Receipts, withdrawals []*types.Withdrawal, requests types.FlatRequests,
chain consensus.ChainReader, syscall consensus.SystemCall, call consensus.Call, logger log.Logger,
) (*types.Block, types.Transactions, types.Receipts, *types.FlatRequests, error) {
) (*types.Block, types.Transactions, types.Receipts, types.FlatRequests, error) {
// stateSyncData := []*types.StateSyncData{}

headerNumber := header.Number.Uint64()
Expand Down
2 changes: 1 addition & 1 deletion polygon/bor/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ func NewFaker() *FakeBor {
func (f *FakeBor) Finalize(config *chain.Config, header *types.Header, state *state.IntraBlockState,
txs types.Transactions, uncles []*types.Header, r types.Receipts, withdrawals []*types.Withdrawal, requests types.FlatRequests,
chain consensus.ChainReader, syscall consensus.SystemCall, logger log.Logger,
) (types.Transactions, types.Receipts, *types.FlatRequests, error) {
) (types.Transactions, types.Receipts, types.FlatRequests, error) {
return f.FakeEthash.Finalize(config, header, state, txs, uncles, r, withdrawals, requests, chain, syscall, logger)
}