Skip to content

Commit

Permalink
Merge branch 'som/flat_requests' into som/pectra4_engine_api
Browse files Browse the repository at this point in the history
  • Loading branch information
somnathb1 committed Oct 18, 2024
2 parents 4c47c59 + 22a297b commit 4969caf
Show file tree
Hide file tree
Showing 66 changed files with 1,152 additions and 1,994 deletions.
406 changes: 290 additions & 116 deletions cl/abstract/mock_services/beacon_state_mutator_mock.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cl/cltypes/beacon_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestBeaconBody(t *testing.T) {
BaseFee: big.NewInt(1),
}, []types.Transaction{types.NewTransaction(1, [20]byte{}, uint256.NewInt(1), 5, uint256.NewInt(2), nil)}, nil, nil, types.Withdrawals{&types.Withdrawal{
Index: 69,
}}, nil /*requests*/)
}})

// Test BeaconBody
body := &BeaconBody{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (b *blockCollector) Flush(ctx context.Context) error {
b.logger.Warn("bad blocks segment received", "err", err)
return err
}
blocksBatch = append(blocksBatch, types.NewBlockFromStorage(executionPayload.BlockHash, header, txs, nil, body.Withdrawals, body.Requests))
blocksBatch = append(blocksBatch, types.NewBlockFromStorage(executionPayload.BlockHash, header, txs, nil, body.Withdrawals))
if len(blocksBatch) >= batchSize {
b.logger.Info("[Caplin] Inserting blocks", "from", blocksBatch[0].NumberU64(), "to", blocksBatch[len(blocksBatch)-1].NumberU64())
if err := b.engine.InsertBlocks(ctx, blocksBatch, true); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cl/phase1/execution_client/execution_client_direct.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (cc *ExecutionClientDirect) NewPayload(ctx context.Context, payload *cltype
return PayloadStatusInvalidated, err
}

if err := cc.chainRW.InsertBlockAndWait(ctx, types.NewBlockFromStorage(payload.BlockHash, header, txs, nil, body.Withdrawals, body.Requests)); err != nil {
if err := cc.chainRW.InsertBlockAndWait(ctx, types.NewBlockFromStorage(payload.BlockHash, header, txs, nil, body.Withdrawals)); err != nil {
return PayloadStatusNone, err
}

Expand Down
3 changes: 1 addition & 2 deletions cmd/evm/internal/t8ntool/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ type stEnv struct {
UncleHash libcommon.Hash `json:"uncleHash,omitempty"`
Withdrawals []*types.Withdrawal `json:"withdrawals,omitempty"`
WithdrawalsHash *libcommon.Hash `json:"withdrawalsRoot,omitempty"`
Requests types.Requests `json:"requests,omitempty"`
RequestsRoot *libcommon.Hash `json:"requestsRoot,omitempty"`
RequestsHash *libcommon.Hash `json:"requestsHash,omitempty"`
}

type stEnvMarshaling struct {
Expand Down
16 changes: 5 additions & 11 deletions cmd/evm/internal/t8ntool/gen_stenv.go

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

8 changes: 2 additions & 6 deletions cmd/evm/internal/t8ntool/transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,6 @@ func Main(ctx *cli.Context) error {
return NewError(ErrorVMConfig, errors.New("shanghai config but missing 'withdrawals' in env section"))
}

if chainConfig.IsPrague(prestate.Env.Timestamp) && prestate.Env.Requests == nil {
return NewError(ErrorVMConfig, errors.New("prague config but missing 'requests' in env section"))
}

isMerged := chainConfig.TerminalTotalDifficulty != nil && chainConfig.TerminalTotalDifficulty.BitLen() == 0
env := prestate.Env
if isMerged {
Expand Down Expand Up @@ -287,7 +283,7 @@ func Main(ctx *cli.Context) error {
ommerN.SetUint64(header.Number.Uint64() - ommer.Delta)
ommerHeaders[i] = &types.Header{Coinbase: ommer.Address, Number: &ommerN}
}
block := types.NewBlock(header, txs, ommerHeaders, nil /* receipts */, prestate.Env.Withdrawals, prestate.Env.Requests)
block := types.NewBlock(header, txs, ommerHeaders, nil /* receipts */, prestate.Env.Withdrawals)

var hashError error
getHash := func(num uint64) libcommon.Hash {
Expand Down Expand Up @@ -617,7 +613,7 @@ func NewHeader(env stEnv) *types.Header {

header.UncleHash = env.UncleHash
header.WithdrawalsHash = env.WithdrawalsHash
header.RequestsRoot = env.RequestsRoot
header.RequestsHash = env.RequestsHash

return &header
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/rpcdaemon/cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,7 @@ func (e *remoteConsensusEngine) Prepare(_ consensus.ChainHeaderReader, _ *types.
panic("remoteConsensusEngine.Prepare not supported")
}

func (e *remoteConsensusEngine) Finalize(_ *chain.Config, _ *types.Header, _ *state.IntraBlockState, _ types.Transactions, _ []*types.Header, _ types.Receipts, _ []*types.Withdrawal, _ consensus.ChainReader, _ consensus.SystemCall, _ log.Logger) (types.Transactions, types.Receipts, types.Requests, error) {
func (e *remoteConsensusEngine) Finalize(_ *chain.Config, _ *types.Header, _ *state.IntraBlockState, _ types.Transactions, _ []*types.Header, _ types.Receipts, _ []*types.Withdrawal, _ consensus.ChainReader, _ consensus.SystemCall, _ log.Logger) (types.Transactions, types.Receipts, types.FlatRequests, error) {
panic("remoteConsensusEngine.Finalize not supported")
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/state/commands/opcode_tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ func runBlock(engine consensus.Engine, ibs *state.IntraBlockState, txnWriter sta
if !vmConfig.ReadOnly {
// Finalize the block, applying any consensus engine specific extras (e.g. block rewards)
tx := block.Transactions()
if _, _, _, err := engine.FinalizeAndAssemble(chainConfig, header, ibs, tx, block.Uncles(), receipts, block.Withdrawals(), block.Requests(), nil, nil, nil, logger); err != nil {
if _, _, _, _, err := engine.FinalizeAndAssemble(chainConfig, header, ibs, tx, block.Uncles(), receipts, block.Withdrawals(), nil, nil, nil, nil, logger); err != nil {
return nil, fmt.Errorf("finalize of block %d failed: %w", block.NumberU64(), err)
}

Expand Down
1 change: 0 additions & 1 deletion cmd/state/exec3/historical_trace_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,6 @@ func CustomTraceMapReduce(fromBlock, toBlock uint64, consumer TraceConsumer, ctx
GetHashFn: getHashFn,
EvmBlockContext: blockContext,
Withdrawals: b.Withdrawals(),
Requests: b.Requests(),

// use history reader instead of state reader to catch up to the tx where we left off
HistoryExecution: true,
Expand Down
4 changes: 2 additions & 2 deletions cmd/state/exec3/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,9 @@ func (rw *Worker) RunTxTaskNoLock(txTask *state.TxTask, isMining bool) {
}

if isMining {
_, txTask.Txs, txTask.BlockReceipts, err = rw.engine.FinalizeAndAssemble(rw.chainConfig, types.CopyHeader(header), ibs, txTask.Txs, txTask.Uncles, txTask.BlockReceipts, txTask.Withdrawals, txTask.Requests, rw.chain, syscall, nil, rw.logger)
_, txTask.Txs, txTask.BlockReceipts, _, err = rw.engine.FinalizeAndAssemble(rw.chainConfig, types.CopyHeader(header), ibs, txTask.Txs, txTask.Uncles, txTask.BlockReceipts, txTask.Withdrawals, nil /*requests */, rw.chain, syscall, nil, rw.logger)
} else {
_, _, _, err = rw.engine.Finalize(rw.chainConfig, types.CopyHeader(header), ibs, txTask.Txs, txTask.Uncles, txTask.BlockReceipts, txTask.Withdrawals, txTask.Requests, rw.chain, syscall, rw.logger)
_, _, _, err = rw.engine.Finalize(rw.chainConfig, types.CopyHeader(header), ibs, txTask.Txs, txTask.Uncles, txTask.BlockReceipts, txTask.Withdrawals, nil /*requests*/, rw.chain, syscall, rw.logger)
}
if err != nil {
txTask.Error = err
Expand Down
10 changes: 5 additions & 5 deletions consensus/aura/aura.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,9 +706,9 @@ func (c *AuRa) applyRewards(header *types.Header, state *state.IntraBlockState,

// word `signal epoch` == word `pending epoch`
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.Requests,
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.Requests, 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,14 +845,14 @@ 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.Requests, chain consensus.ChainReader, syscall consensus.SystemCall, call consensus.Call, logger log.Logger) (*types.Block, types.Transactions, types.Receipts, 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, err
return nil, nil, nil, nil, err
}

// Assemble and return the final block for sealing
return types.NewBlockForAsembling(header, outTxs, uncles, outReceipts, withdrawals, requests), outTxs, outReceipts, nil
return types.NewBlockForAsembling(header, outTxs, uncles, outReceipts, withdrawals), outTxs, outReceipts, nil, nil
}

// Authorize injects a private key into the consensus engine to mint new blocks
Expand Down
10 changes: 5 additions & 5 deletions consensus/clique/clique.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,19 +380,19 @@ func (c *Clique) CalculateRewards(config *chain.Config, header *types.Header, un
// Finalize implements consensus.Engine, ensuring no uncles are set, nor block
// rewards given.
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.Requests,
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.Requests, 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.Requests, chain consensus.ChainReader, syscall consensus.SystemCall, call consensus.Call, logger log.Logger,
) (*types.Block, types.Transactions, types.Receipts, error) {
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) {
// Assemble and return the final block for sealing
return types.NewBlockForAsembling(header, txs, nil, receipts, withdrawals, requests), txs, receipts, nil
return types.NewBlockForAsembling(header, txs, nil, receipts, withdrawals), txs, receipts, nil, nil
}

// Authorize injects a private key into the consensus engine to mint new blocks
Expand Down
2 changes: 1 addition & 1 deletion consensus/clique/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (c *Clique) verifyHeader(chain consensus.ChainHeaderReader, header *types.H
return consensus.ErrUnexpectedWithdrawals
}

if header.RequestsRoot != nil {
if header.RequestsHash != nil {
return consensus.ErrUnexpectedRequests
}

Expand Down
8 changes: 4 additions & 4 deletions consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,17 +168,17 @@ type EngineWriter interface {
// Finalize runs any post-transaction state modifications (e.g. block rewards)
// 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.Requests, chain ChainReader, syscall SystemCall, logger log.Logger,
) (types.Transactions, types.Receipts, types.Requests, error)
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)

// FinalizeAndAssemble runs any post-transaction state modifications (e.g. block
// rewards) and assembles the final block.
//
// Note: The block header and state database might be updated to reflect any
// 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.Requests, chain ChainReader, syscall SystemCall, call Call, logger log.Logger,
) (*types.Block, types.Transactions, types.Receipts, error)
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)

// Seal generates a new sealing request for the given input block and pushes
// the result into the given channel.
Expand Down
14 changes: 7 additions & 7 deletions consensus/ethash/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func VerifyHeaderBasics(chain consensus.ChainHeaderReader, header, parent *types
return consensus.ErrUnexpectedWithdrawals
}

if header.RequestsRoot != nil {
if header.RequestsHash != nil {
return consensus.ErrUnexpectedRequests
}

Expand Down Expand Up @@ -567,9 +567,9 @@ func (ethash *Ethash) Initialize(config *chain.Config, chain consensus.ChainHead
// Finalize implements consensus.Engine, accumulating the block and uncle rewards,
// setting the final state on the header
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.Requests,
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.Requests, 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 @@ -578,17 +578,17 @@ func (ethash *Ethash) Finalize(config *chain.Config, header *types.Header, state
// FinalizeAndAssemble implements consensus.Engine, accumulating the block and
// uncle rewards, setting the final state and assembling the block.
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.Requests,
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, 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)
if err != nil {
return nil, nil, nil, err
return nil, nil, nil, nil, err
}
// Header seems complete, assemble into a block and return
return types.NewBlock(header, outTxs, uncles, outR, withdrawals, requests), outTxs, outR, nil
return types.NewBlock(header, outTxs, uncles, outR, withdrawals), outTxs, outR, nil, nil
}

// SealHash returns the hash of a block prior to it being sealed.
Expand Down
Loading

0 comments on commit 4969caf

Please sign in to comment.