Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
90db3e3
core/blobpool: implement txpool for blob txs
karalabe Dec 8, 2022
4658fd6
go.mod: get rid of local billy
karalabe Jun 16, 2023
3b5bce2
core/txpool, eth, miner: integrate blobpool, miner lazy tx loading
karalabe Jun 20, 2023
0c7ad39
eth/catalyst: add newPayloadV5 methods
MariusVanDerWijden May 26, 2023
88bb66a
eth/catalyst: fix test
MariusVanDerWijden Jun 19, 2023
d7db8ba
beacon/engine: reject blocks with txs in network form, fix tests
MariusVanDerWijden Jun 19, 2023
6a63f22
core/txpool/legacypool: allow blob txs, todo drop this commit
MariusVanDerWijden Jun 19, 2023
706772e
eth/catalyst: increase log level
MariusVanDerWijden Jun 19, 2023
8fe6bf1
core: fix types, fixed sendRawTx
MariusVanDerWijden Jun 19, 2023
db8c930
internal/ethapi: add dataGasUsed and excessDataGas to header marshalling
MariusVanDerWijden Jun 19, 2023
6feca89
internal/ethapi: marshall rpc transactions correctly
MariusVanDerWijden Jun 19, 2023
fd99388
internal/ethapi: fix
MariusVanDerWijden Jun 19, 2023
0f4c7eb
core/types: remove unnecessary stuff
MariusVanDerWijden Jun 19, 2023
14c2076
eth/protocols/eth: fix blobTx propagation
MariusVanDerWijden Jun 19, 2023
7c8dffe
internal/ethapi: fix blobtx unmarshalling
MariusVanDerWijden Jun 19, 2023
4417adb
internal/ethapi: debug output
MariusVanDerWijden Jun 19, 2023
23d9177
core/txpool/legacypool: allow blob txs, todo drop this commit
MariusVanDerWijden Jun 19, 2023
f62d6c2
internal/ethapi: remove debug output
MariusVanDerWijden Jun 19, 2023
4d57802
core/txpool/legacypool: rebase on top of blobpool
MariusVanDerWijden Jun 20, 2023
25b2d9c
core/txpool: remove errors.Join
MariusVanDerWijden Jun 20, 2023
385ab59
core, eth, miner: do integration with miner, todo clean up
MariusVanDerWijden Jun 20, 2023
3bad905
core/txpool/blobpool: hack get function together
MariusVanDerWijden Jun 20, 2023
614545c
miner: fix payload building
MariusVanDerWijden Jun 20, 2023
bdac4bb
core/txpool/blobpool: hack get function together
MariusVanDerWijden Jun 20, 2023
49d560d
eth/catalyst: make versionedHashes optional
MariusVanDerWijden Jun 20, 2023
8dcb6a3
miner: fix payload building
MariusVanDerWijden Jun 20, 2023
baa5c0a
core, eth, miner: rebase on latest blobpool
MariusVanDerWijden Jun 21, 2023
62fbdf5
miner: fix max blob check
MariusVanDerWijden Jun 21, 2023
87d42bd
core/genesis: add data gas fields
marioevz Jun 5, 2023
4834e31
cmd/evm: add cancun parameters
marioevz Jun 13, 2023
d9533cd
tests: add cancun fork
marioevz Jun 13, 2023
6f6ba27
core/genesis: add dataGasUsed to genesis block
marioevz Jun 13, 2023
c4147b0
tests: fix genesis parse
marioevz Jun 13, 2023
aef3c57
cmd/evm: make data defaults zero
marioevz Jun 13, 2023
374665d
cmd/evm: always use latest signer
marioevz Jun 13, 2023
803108e
core/types: add DataGasUsed, DataGasPrice to tx receipt
marioevz Jun 14, 2023
3714324
core: add blobdata to receipts
marioevz Jun 14, 2023
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 beacon/engine/gen_ed.go

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

6 changes: 6 additions & 0 deletions beacon/engine/gen_epe.go

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

51 changes: 45 additions & 6 deletions beacon/engine/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto/kzg4844"
"github.com/ethereum/go-ethereum/trie"
)

Expand Down Expand Up @@ -61,6 +62,8 @@ type ExecutableData struct {
BlockHash common.Hash `json:"blockHash" gencodec:"required"`
Transactions [][]byte `json:"transactions" gencodec:"required"`
Withdrawals []*types.Withdrawal `json:"withdrawals"`
DataGasUsed *uint64 `json:"dataGasUsed"`
ExcessDataGas *uint64 `json:"excessDataGas"`
}

// JSON type overrides for executableData.
Expand All @@ -73,13 +76,22 @@ type executableDataMarshaling struct {
ExtraData hexutil.Bytes
LogsBloom hexutil.Bytes
Transactions []hexutil.Bytes
DataGasUsed *hexutil.Uint64
ExcessDataGas *hexutil.Uint64
}

//go:generate go run github.com/fjl/gencodec -type ExecutionPayloadEnvelope -field-override executionPayloadEnvelopeMarshaling -out gen_epe.go

type ExecutionPayloadEnvelope struct {
ExecutionPayload *ExecutableData `json:"executionPayload" gencodec:"required"`
BlockValue *big.Int `json:"blockValue" gencodec:"required"`
BlobsBundle *BlobsBundleV1 `json:"blobsBundle"`
}

type BlobsBundleV1 struct {
Commitments []hexutil.Bytes `json:"commitments"`
Proofs []hexutil.Bytes `json:"proofs"`
Blobs []hexutil.Bytes `json:"blobs"`
}

// JSON type overrides for ExecutionPayloadEnvelope.
Expand Down Expand Up @@ -152,14 +164,15 @@ func decodeTransactions(enc [][]byte) ([]*types.Transaction, error) {
// ExecutableDataToBlock constructs a block from executable data.
// It verifies that the following fields:
//
// len(extraData) <= 32
// uncleHash = emptyUncleHash
// difficulty = 0
// len(extraData) <= 32
// uncleHash = emptyUncleHash
// difficulty = 0
// if versionedHashes != nil, versionedHashes match to blob transactions
//
// and that the blockhash of the constructed block matches the parameters. Nil
// Withdrawals value will propagate through the returned block. Empty
// Withdrawals value must be passed via non-nil, length 0 value in params.
func ExecutableDataToBlock(params ExecutableData) (*types.Block, error) {
func ExecutableDataToBlock(params ExecutableData, versionedHashes []common.Hash) (*types.Block, error) {
txs, err := decodeTransactions(params.Transactions)
if err != nil {
return nil, err
Expand All @@ -174,6 +187,18 @@ func ExecutableDataToBlock(params ExecutableData) (*types.Block, error) {
if params.BaseFeePerGas != nil && (params.BaseFeePerGas.Sign() == -1 || params.BaseFeePerGas.BitLen() > 256) {
return nil, fmt.Errorf("invalid baseFeePerGas: %v", params.BaseFeePerGas)
}
var blobHashes []common.Hash
for _, tx := range txs {
blobHashes = append(blobHashes, tx.BlobHashes()...)
}
if len(blobHashes) != len(versionedHashes) {
return nil, fmt.Errorf("invalid number of versionedHashes: %v blobHashes: %v", versionedHashes, blobHashes)
}
for i := 0; i < len(blobHashes); i++ {
if blobHashes[i] != versionedHashes[i] {
return nil, fmt.Errorf("invalid versionedHash at %v: %v blobHashes: %v", i, versionedHashes, blobHashes)
}
}
// Only set withdrawalsRoot if it is non-nil. This allows CLs to use
// ExecutableData before withdrawals are enabled by marshaling
// Withdrawals as the json null value.
Expand All @@ -199,6 +224,8 @@ func ExecutableDataToBlock(params ExecutableData) (*types.Block, error) {
Extra: params.ExtraData,
MixDigest: params.Random,
WithdrawalsHash: withdrawalsRoot,
ExcessDataGas: params.ExcessDataGas,
DataGasUsed: params.DataGasUsed,
}
block := types.NewBlockWithHeader(header).WithBody(txs, nil /* uncles */).WithWithdrawals(params.Withdrawals)
if block.Hash() != params.BlockHash {
Expand All @@ -209,7 +236,7 @@ func ExecutableDataToBlock(params ExecutableData) (*types.Block, error) {

// BlockToExecutableData constructs the ExecutableData structure by filling the
// fields from the given block. It assumes the given block is post-merge block.
func BlockToExecutableData(block *types.Block, fees *big.Int) *ExecutionPayloadEnvelope {
func BlockToExecutableData(block *types.Block, fees *big.Int, blobs []kzg4844.Blob, commitments []kzg4844.Commitment, proofs []kzg4844.Proof) *ExecutionPayloadEnvelope {
data := &ExecutableData{
BlockHash: block.Hash(),
ParentHash: block.ParentHash(),
Expand All @@ -226,8 +253,20 @@ func BlockToExecutableData(block *types.Block, fees *big.Int) *ExecutionPayloadE
Random: block.MixDigest(),
ExtraData: block.Extra(),
Withdrawals: block.Withdrawals(),
DataGasUsed: block.DataGasUsed(),
ExcessDataGas: block.ExcessDataGas(),
}
blobsBundle := BlobsBundleV1{
Commitments: make([]hexutil.Bytes, 0),
Blobs: make([]hexutil.Bytes, 0),
Proofs: make([]hexutil.Bytes, 0),
}
for i := range blobs {
blobsBundle.Blobs = append(blobsBundle.Blobs, hexutil.Bytes(blobs[i][:]))
blobsBundle.Commitments = append(blobsBundle.Commitments, hexutil.Bytes(commitments[i][:]))
blobsBundle.Proofs = append(blobsBundle.Proofs, hexutil.Bytes(proofs[i][:]))
}
return &ExecutionPayloadEnvelope{ExecutionPayload: data, BlockValue: fees}
return &ExecutionPayloadEnvelope{ExecutionPayload: data, BlockValue: fees, BlobsBundle: &blobsBundle}
}

// ExecutionPayloadBodyV1 is used in the response to GetPayloadBodiesByHashV1 and GetPayloadBodiesByRangeV1
Expand Down
20 changes: 13 additions & 7 deletions cmd/evm/internal/t8ntool/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,20 @@ type header struct {
Nonce *types.BlockNonce `json:"nonce"`
BaseFee *big.Int `json:"baseFeePerGas" rlp:"optional"`
WithdrawalsHash *common.Hash `json:"withdrawalsRoot" rlp:"optional"`
DataGasUsed *uint64 `json:"dataGasUsed" rlp:"optional"`
ExcessDataGas *uint64 `json:"excessDataGas" rlp:"optional"`
}

type headerMarshaling struct {
Difficulty *math.HexOrDecimal256
Number *math.HexOrDecimal256
GasLimit math.HexOrDecimal64
GasUsed math.HexOrDecimal64
Time math.HexOrDecimal64
Extra hexutil.Bytes
BaseFee *math.HexOrDecimal256
Difficulty *math.HexOrDecimal256
Number *math.HexOrDecimal256
GasLimit math.HexOrDecimal64
GasUsed math.HexOrDecimal64
Time math.HexOrDecimal64
Extra hexutil.Bytes
BaseFee *math.HexOrDecimal256
DataGasUsed *math.HexOrDecimal64
ExcessDataGas *math.HexOrDecimal64
}

type bbInput struct {
Expand Down Expand Up @@ -129,6 +133,8 @@ func (i *bbInput) ToBlock() *types.Block {
MixDigest: i.Header.MixDigest,
BaseFee: i.Header.BaseFee,
WithdrawalsHash: i.Header.WithdrawalsHash,
DataGasUsed: i.Header.DataGasUsed,
ExcessDataGas: i.Header.ExcessDataGas,
}

// Fill optional values.
Expand Down
125 changes: 87 additions & 38 deletions cmd/evm/internal/t8ntool/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ type ExecutionResult struct {
Rejected []*rejectedTx `json:"rejected,omitempty"`
Difficulty *math.HexOrDecimal256 `json:"currentDifficulty" gencodec:"required"`
GasUsed math.HexOrDecimal64 `json:"gasUsed"`
DataGasUsed *math.HexOrDecimal64 `json:"dataGasUsed,omitempty"`
BaseFee *math.HexOrDecimal256 `json:"currentBaseFee,omitempty"`
WithdrawalsRoot *common.Hash `json:"withdrawalsRoot,omitempty"`
ExcessDataGas *math.HexOrDecimal64 `json:"currentExcessDataGas,omitempty"`
}

type ommer struct {
Expand All @@ -67,37 +69,43 @@ type ommer struct {

//go:generate go run github.com/fjl/gencodec -type stEnv -field-override stEnvMarshaling -out gen_stenv.go
type stEnv struct {
Coinbase common.Address `json:"currentCoinbase" gencodec:"required"`
Difficulty *big.Int `json:"currentDifficulty"`
Random *big.Int `json:"currentRandom"`
ParentDifficulty *big.Int `json:"parentDifficulty"`
ParentBaseFee *big.Int `json:"parentBaseFee,omitempty"`
ParentGasUsed uint64 `json:"parentGasUsed,omitempty"`
ParentGasLimit uint64 `json:"parentGasLimit,omitempty"`
GasLimit uint64 `json:"currentGasLimit" gencodec:"required"`
Number uint64 `json:"currentNumber" gencodec:"required"`
Timestamp uint64 `json:"currentTimestamp" gencodec:"required"`
ParentTimestamp uint64 `json:"parentTimestamp,omitempty"`
BlockHashes map[math.HexOrDecimal64]common.Hash `json:"blockHashes,omitempty"`
Ommers []ommer `json:"ommers,omitempty"`
Withdrawals []*types.Withdrawal `json:"withdrawals,omitempty"`
BaseFee *big.Int `json:"currentBaseFee,omitempty"`
ParentUncleHash common.Hash `json:"parentUncleHash"`
Coinbase common.Address `json:"currentCoinbase" gencodec:"required"`
Difficulty *big.Int `json:"currentDifficulty"`
Random *big.Int `json:"currentRandom"`
ParentDifficulty *big.Int `json:"parentDifficulty"`
ParentBaseFee *big.Int `json:"parentBaseFee,omitempty"`
ParentGasUsed uint64 `json:"parentGasUsed,omitempty"`
ParentGasLimit uint64 `json:"parentGasLimit,omitempty"`
ParentDataGasUsed *uint64 `json:"parentDataGasUsed,omitempty"`
ParentExcessDataGas *uint64 `json:"parentExcessDataGas,omitempty"`
GasLimit uint64 `json:"currentGasLimit" gencodec:"required"`
Number uint64 `json:"currentNumber" gencodec:"required"`
Timestamp uint64 `json:"currentTimestamp" gencodec:"required"`
ParentTimestamp uint64 `json:"parentTimestamp,omitempty"`
BlockHashes map[math.HexOrDecimal64]common.Hash `json:"blockHashes,omitempty"`
Ommers []ommer `json:"ommers,omitempty"`
Withdrawals []*types.Withdrawal `json:"withdrawals,omitempty"`
BaseFee *big.Int `json:"currentBaseFee,omitempty"`
ParentUncleHash common.Hash `json:"parentUncleHash"`
ExcessDataGas *uint64 `json:"currentExcessDataGas,omitempty"`
}

type stEnvMarshaling struct {
Coinbase common.UnprefixedAddress
Difficulty *math.HexOrDecimal256
Random *math.HexOrDecimal256
ParentDifficulty *math.HexOrDecimal256
ParentBaseFee *math.HexOrDecimal256
ParentGasUsed math.HexOrDecimal64
ParentGasLimit math.HexOrDecimal64
GasLimit math.HexOrDecimal64
Number math.HexOrDecimal64
Timestamp math.HexOrDecimal64
ParentTimestamp math.HexOrDecimal64
BaseFee *math.HexOrDecimal256
Coinbase common.UnprefixedAddress
Difficulty *math.HexOrDecimal256
Random *math.HexOrDecimal256
ParentDifficulty *math.HexOrDecimal256
ParentBaseFee *math.HexOrDecimal256
ParentDataGasUsed *math.HexOrDecimal64
ParentGasUsed math.HexOrDecimal64
ParentGasLimit math.HexOrDecimal64
ParentExcessDataGas *math.HexOrDecimal64
GasLimit math.HexOrDecimal64
Number math.HexOrDecimal64
Timestamp math.HexOrDecimal64
ParentTimestamp math.HexOrDecimal64
BaseFee *math.HexOrDecimal256
ExcessDataGas *math.HexOrDecimal64
}

type rejectedTx struct {
Expand Down Expand Up @@ -154,6 +162,25 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
rnd := common.BigToHash(pre.Env.Random)
vmContext.Random = &rnd
}
// If excess data gas is defined, add it to vmContext
if chainConfig.IsCancun(new(big.Int).SetUint64(pre.Env.Number), pre.Env.Timestamp) {
if pre.Env.ExcessDataGas != nil {
vmContext.ExcessDataGas = pre.Env.ExcessDataGas
} else {
var (
parentDataGasUsed = uint64(0)
parentExcessDataGas = uint64(0)
)
if pre.Env.ParentDataGasUsed != nil {
parentDataGasUsed = *pre.Env.ParentDataGasUsed
}
if pre.Env.ParentExcessDataGas != nil {
parentExcessDataGas = *pre.Env.ParentExcessDataGas
}
edg := misc.CalcExcessDataGas(parentExcessDataGas, parentDataGasUsed)
vmContext.ExcessDataGas = &edg
}
}
// If DAO is supported/enabled, we need to handle it here. In geth 'proper', it's
// done in StateProcessor.Process(block, ...), right before transactions are applied.
if chainConfig.DAOForkSupport &&
Expand All @@ -164,6 +191,16 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,

for i, tx := range txs {
msg, err := core.TransactionToMessage(tx, signer, pre.Env.BaseFee)
if tx.Type() == types.BlobTxType {
if len(tx.BlobHashes()) == 0 {
err = fmt.Errorf("blob transaction with zero blobs")
}
for _, h := range tx.BlobHashes() {
if h[0] != params.BlobTxHashVersion {
err = fmt.Errorf("unversioned blob hash: %v", h)
}
}
}
if err != nil {
log.Warn("rejected tx", "index", i, "hash", tx.Hash(), "error", err)
rejectedTxs = append(rejectedTxs, &rejectedTx{i, err.Error()})
Expand Down Expand Up @@ -273,21 +310,33 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
return nil, nil, NewError(ErrorEVM, fmt.Errorf("could not commit state: %v", err))
}
execRs := &ExecutionResult{
StateRoot: root,
TxRoot: types.DeriveSha(includedTxs, trie.NewStackTrie(nil)),
ReceiptRoot: types.DeriveSha(receipts, trie.NewStackTrie(nil)),
Bloom: types.CreateBloom(receipts),
LogsHash: rlpHash(statedb.Logs()),
Receipts: receipts,
Rejected: rejectedTxs,
Difficulty: (*math.HexOrDecimal256)(vmContext.Difficulty),
GasUsed: (math.HexOrDecimal64)(gasUsed),
BaseFee: (*math.HexOrDecimal256)(vmContext.BaseFee),
StateRoot: root,
TxRoot: types.DeriveSha(includedTxs, trie.NewStackTrie(nil)),
ReceiptRoot: types.DeriveSha(receipts, trie.NewStackTrie(nil)),
Bloom: types.CreateBloom(receipts),
LogsHash: rlpHash(statedb.Logs()),
Receipts: receipts,
Rejected: rejectedTxs,
Difficulty: (*math.HexOrDecimal256)(vmContext.Difficulty),
GasUsed: (math.HexOrDecimal64)(gasUsed),
BaseFee: (*math.HexOrDecimal256)(vmContext.BaseFee),
ExcessDataGas: (*math.HexOrDecimal64)(vmContext.ExcessDataGas),
}
if pre.Env.Withdrawals != nil {
h := types.DeriveSha(types.Withdrawals(pre.Env.Withdrawals), trie.NewStackTrie(nil))
execRs.WithdrawalsRoot = &h
}
if vmContext.ExcessDataGas != nil {
// calculate and set the excess data gas at the end of this block execution
newBlobs := 0
for _, tx := range txs {
if tx.Type() == types.BlobTxType {
newBlobs += len(tx.BlobHashes())
}
}
dataGasUsed := uint64(newBlobs * params.BlobTxDataGasPerBlob)
execRs.DataGasUsed = (*math.HexOrDecimal64)(&dataGasUsed)
}
return statedb, execRs, nil
}

Expand Down
Loading