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

Implement EIP-7685 and EIP-6110 #10238

Merged
merged 18 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 14 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
2 changes: 1 addition & 1 deletion cl/cltypes/beacon_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,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 @@ -109,7 +109,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))
blocksBatch = append(blocksBatch, types.NewBlockFromStorage(executionPayload.BlockHash, header, txs, nil, body.Withdrawals, body.Requests))
if len(blocksBatch) >= batchSize {
if err := b.engine.InsertBlocks(ctx, blocksBatch, true); err != nil {
b.logger.Warn("failed to insert blocks", "err", err)
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 @@ -40,7 +40,7 @@ func (cc *ExecutionClientDirect) NewPayload(ctx context.Context, payload *cltype
return true, err
}

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

Expand Down
1 change: 1 addition & 0 deletions cmd/evm/internal/t8ntool/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type stEnv struct {
UncleHash libcommon.Hash `json:"uncleHash,omitempty"`
Withdrawals []*types.Withdrawal `json:"withdrawals,omitempty"`
WithdrawalsHash *libcommon.Hash `json:"withdrawalsRoot,omitempty"`
Requests []*types.Request `json:"requests,omitempty"`
}

type stEnvMarshaling struct {
Expand Down
88 changes: 53 additions & 35 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.

2 changes: 1 addition & 1 deletion cmd/evm/internal/t8ntool/transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,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)
block := types.NewBlock(header, txs, ommerHeaders, nil /* receipts */, prestate.Env.Withdrawals, prestate.Env.Requests)

var hashError error
getHash := func(num uint64) libcommon.Hash {
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 @@ -732,7 +732,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(), nil, nil, nil, logger); err != nil {
if _, _, _, err := engine.FinalizeAndAssemble(chainConfig, header, ibs, tx, block.Uncles(), receipts, block.Withdrawals(), block.Requests(), nil, nil, nil, logger); err != nil {
return nil, fmt.Errorf("finalize of block %d failed: %w", block.NumberU64(), err)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/state/exec3/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func (rw *Worker) RunTxTaskNoLock(txTask *state.TxTask) {
return core.SysCallContract(contract, data, rw.chainConfig, ibs, header, rw.engine, false /* constCall */)
}

_, _, err := rw.engine.Finalize(rw.chainConfig, types.CopyHeader(header), ibs, txTask.Txs, txTask.Uncles, txTask.BlockReceipts, txTask.Withdrawals, rw.chain, syscall, rw.logger)
_, _, 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)
if err != nil {
txTask.Error = err
} else {
Expand Down
2 changes: 1 addition & 1 deletion cmd/state/exec3/state_recon.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func (rw *ReconWorker) runTxTask(txTask *state.TxTask) error {
syscall := func(contract libcommon.Address, data []byte) ([]byte, error) {
return core.SysCallContract(contract, data, rw.chainConfig, ibs, header, rw.engine, false /* constCall */)
}
if _, _, err := rw.engine.Finalize(rw.chainConfig, types.CopyHeader(header), ibs, txTask.Txs, txTask.Uncles, txTask.BlockReceipts, txTask.Withdrawals, rw.chain, syscall, rw.logger); err != nil {
if _, _, 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 != nil {
if _, readError := rw.stateReader.ReadError(); !readError {
return fmt.Errorf("finalize of block %d failed: %w", txTask.BlockNum, err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/state/exec3/trace_worker2.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (rw *TraceWorker2) RunTxTask(txTask *state.TxTask) {
return core.SysCallContract(contract, data, rw.execArgs.ChainConfig, ibs, header, rw.execArgs.Engine, false /* constCall */)
}

_, _, err := rw.execArgs.Engine.Finalize(rw.execArgs.ChainConfig, types.CopyHeader(header), ibs, txTask.Txs, txTask.Uncles, txTask.BlockReceipts, txTask.Withdrawals, rw.chain, syscall, rw.logger)
_, _, err := rw.execArgs.Engine.Finalize(rw.execArgs.ChainConfig, types.CopyHeader(header), ibs, txTask.Txs, txTask.Uncles, txTask.BlockReceipts, txTask.Withdrawals, txTask.Requests, rw.chain, syscall, rw.logger)
if err != nil {
txTask.Error = err
}
Expand Down
8 changes: 4 additions & 4 deletions consensus/aura/aura.go
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ 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,
uncles []*types.Header, receipts types.Receipts, withdrawals []*types.Withdrawal, requests []*types.Request,
chain consensus.ChainReader, syscall consensus.SystemCall, logger log.Logger,
) (types.Transactions, types.Receipts, error) {
if err := c.applyRewards(header, state, syscall); err != nil {
Expand Down Expand Up @@ -842,14 +842,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, chain consensus.ChainReader, syscall consensus.SystemCall, call consensus.Call, logger log.Logger) (*types.Block, types.Transactions, types.Receipts, error) {
outTxs, outReceipts, err := c.Finalize(config, header, state, txs, uncles, receipts, withdrawals, chain, syscall, logger)
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.Request, chain consensus.ChainReader, syscall consensus.SystemCall, call consensus.Call, logger log.Logger) (*types.Block, types.Transactions, types.Receipts, 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
}

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

// Authorize injects a private key into the consensus engine to mint new blocks
Expand Down
12 changes: 6 additions & 6 deletions consensus/clique/clique.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ import (
"context"
"errors"
"fmt"
"github.com/ledgerwatch/erigon-lib/common/hexutil"
"github.com/ledgerwatch/erigon-lib/kv/dbutils"
"io"
"math/big"
"math/rand"
"sync"
"time"

"github.com/ledgerwatch/erigon-lib/common/hexutil"
"github.com/ledgerwatch/erigon-lib/kv/dbutils"

"github.com/goccy/go-json"
lru "github.com/hashicorp/golang-lru/arc/v2"
"github.com/ledgerwatch/erigon/turbo/services"
Expand Down Expand Up @@ -377,7 +378,7 @@ 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,
txs types.Transactions, uncles []*types.Header, r types.Receipts, withdrawals []*types.Withdrawal, requests []*types.Request,
chain consensus.ChainReader, syscall consensus.SystemCall, logger log.Logger,
) (types.Transactions, types.Receipts, error) {
// No block rewards in PoA, so the state remains as is and uncles are dropped
Expand All @@ -388,14 +389,13 @@ func (c *Clique) Finalize(config *chain.Config, header *types.Header, state *sta
// 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,
chain consensus.ChainReader, syscall consensus.SystemCall, call consensus.Call, logger log.Logger,
txs types.Transactions, uncles []*types.Header, receipts types.Receipts, withdrawals []*types.Withdrawal, requests []*types.Request, chain consensus.ChainReader, syscall consensus.SystemCall, call consensus.Call, logger log.Logger,
) (*types.Block, types.Transactions, types.Receipts, error) {
// No block rewards in PoA, so the state remains as is and uncles are dropped
header.UncleHash = types.CalcUncleHash(nil)

// Assemble and return the final block for sealing
return types.NewBlock(header, txs, nil, receipts, withdrawals), txs, receipts, nil
return types.NewBlock(header, txs, nil, receipts, withdrawals, requests), txs, receipts, nil
}

// Authorize injects a private key into the consensus engine to mint new blocks
Expand Down
6 changes: 2 additions & 4 deletions consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ type EngineWriter interface {
// Note: The block header and state database might be updated to reflect any
// consensus rules that happen at finalization (e.g. block rewards).
Finalize(config *chain.Config, header *types.Header, state *state.IntraBlockState,
txs types.Transactions, uncles []*types.Header, receipts types.Receipts, withdrawals []*types.Withdrawal,
chain ChainReader, syscall SystemCall, logger log.Logger,
txs types.Transactions, uncles []*types.Header, receipts types.Receipts, withdrawals []*types.Withdrawal, requests []*types.Request, chain ChainReader, syscall SystemCall, logger log.Logger,
) (types.Transactions, types.Receipts, error)

// FinalizeAndAssemble runs any post-transaction state modifications (e.g. block
Expand All @@ -164,8 +163,7 @@ type EngineWriter interface {
// 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,
chain ChainReader, syscall SystemCall, call Call, logger log.Logger,
txs types.Transactions, uncles []*types.Header, receipts types.Receipts, withdrawals []*types.Withdrawal, requests []*types.Request, chain ChainReader, syscall SystemCall, call Call, logger log.Logger,
) (*types.Block, types.Transactions, types.Receipts, error)

// Seal generates a new sealing request for the given input block and pushes
Expand Down
Loading
Loading