all: fix rebasing issues

This commit is contained in:
Marius van der Wijden 2026-04-22 10:17:08 +02:00 committed by MariusVanDerWijden
parent 1a8c2e0918
commit 7e4656581f
12 changed files with 76 additions and 83 deletions

View file

@ -18,10 +18,11 @@ package engine
import ( import (
"fmt" "fmt"
"github.com/ethereum/go-ethereum/core/types/bal"
"math/big" "math/big"
"slices" "slices"
"github.com/ethereum/go-ethereum/core/types/bal"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"

View file

@ -258,7 +258,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
snapshot = statedb.Snapshot() snapshot = statedb.Snapshot()
gp = gaspool.Snapshot() gp = gaspool.Snapshot()
) )
_, receipt, err := core.ApplyTransactionWithEVM(msg, gaspool, statedb, vmContext.BlockNumber, blockHash, pre.Env.Timestamp, tx, evm) _, _, receipt, err := core.ApplyTransactionWithEVM(msg, gaspool, statedb, vmContext.BlockNumber, blockHash, pre.Env.Timestamp, tx, evm)
if err != nil { if err != nil {
statedb.RevertToSnapshot(snapshot) statedb.RevertToSnapshot(snapshot)
log.Info("rejected tx", "index", i, "hash", tx.Hash(), "from", msg.From, "error", err) log.Info("rejected tx", "index", i, "hash", tx.Hash(), "from", msg.From, "error", err)
@ -327,11 +327,11 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
return nil, nil, nil, NewError(ErrorEVM, fmt.Errorf("could not parse requests logs: %v", err)) return nil, nil, nil, NewError(ErrorEVM, fmt.Errorf("could not parse requests logs: %v", err))
} }
// EIP-7002 // EIP-7002
if _, err := core.ProcessWithdrawalQueue(&requests, evm); err != nil { if _, _, err := core.ProcessWithdrawalQueue(&requests, evm); err != nil {
return nil, nil, nil, NewError(ErrorEVM, fmt.Errorf("could not process withdrawal requests: %v", err)) return nil, nil, nil, NewError(ErrorEVM, fmt.Errorf("could not process withdrawal requests: %v", err))
} }
// EIP-7251 // EIP-7251
if _, err := core.ProcessConsolidationQueue(&requests, evm); err != nil { if _, _, err := core.ProcessConsolidationQueue(&requests, evm); err != nil {
return nil, nil, nil, NewError(ErrorEVM, fmt.Errorf("could not process consolidation requests: %v", err)) return nil, nil, nil, NewError(ErrorEVM, fmt.Errorf("could not process consolidation requests: %v", err))
} }
} }

View file

@ -21,13 +21,14 @@ import (
"bytes" "bytes"
"errors" "errors"
"fmt" "fmt"
"github.com/ethereum/go-ethereum/core/types/bal"
"io" "io"
"math/big" "math/big"
"math/rand" "math/rand"
"sync" "sync"
"time" "time"
"github.com/ethereum/go-ethereum/core/types/bal"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/common/lru" "github.com/ethereum/go-ethereum/common/lru"
@ -579,28 +580,6 @@ func (c *Clique) Finalize(chain consensus.ChainHeaderReader, header *types.Heade
return nil, nil return nil, nil
} }
<<<<<<< HEAD
=======
// FinalizeAndAssemble implements consensus.Engine, ensuring no uncles are set,
// nor block rewards given, and returns the final block.
func (c *Clique) FinalizeAndAssemble(ctx context.Context, chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, body *types.Body, receipts []*types.Receipt, createBAL func(*bal.StateAccessList, *bal.StateMutations) *bal.BlockAccessList) (*types.Block, error) {
if createBAL != nil {
panic("BALs not supported")
}
if len(body.Withdrawals) > 0 {
return nil, errors.New("clique does not support withdrawals")
}
// Finalize block
c.Finalize(chain, header, state, body)
// Assign the final state root to header.
header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number))
// Assemble and return the final block for sealing.
return types.NewBlock(header, &types.Body{Transactions: body.Transactions}, receipts, trie.NewStackTrie(nil)), nil
}
>>>>>>> 1d26ca9bc1 (all: implement BAL single-threaded execution and validation)
// Authorize injects a private key into the consensus engine to mint new blocks // Authorize injects a private key into the consensus engine to mint new blocks
// with. // with.
func (c *Clique) Authorize(signer common.Address) { func (c *Clique) Authorize(signer common.Address) {

View file

@ -32,7 +32,6 @@ import (
"github.com/ethereum/go-ethereum/crypto/keccak" "github.com/ethereum/go-ethereum/crypto/keccak"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
"github.com/holiman/uint256"
) )
// Tests block header storage and retrieval operations. // Tests block header storage and retrieval operations.
@ -906,13 +905,17 @@ func makeTestBAL(t *testing.T) (rlp.RawValue, *bal.BlockAccessList) {
t.Helper() t.Helper()
cb := bal.NewConstructionBlockAccessList() cb := bal.NewConstructionBlockAccessList()
addr := common.HexToAddress("0x1111111111111111111111111111111111111111") /*
cb.AccountRead(addr) TODO MariusVanDerWijden fix after rebase
cb.StorageRead(addr, common.BytesToHash([]byte{0x01})) addr := common.HexToAddress("0x1111111111111111111111111111111111111111")
cb.StorageWrite(0, addr, common.BytesToHash([]byte{0x02}), common.BytesToHash([]byte{0xaa}))
cb.BalanceChange(0, addr, uint256.NewInt(100))
cb.NonceChange(addr, 0, 1)
cb.AccountRead(addr)
cb.StorageRead(addr, common.BytesToHash([]byte{0x01}))
cb.StorageWrite(0, addr, common.BytesToHash([]byte{0x02}), common.BytesToHash([]byte{0xaa}))
cb.BalanceChange(0, addr, uint256.NewInt(100))
cb.NonceChange(addr, 0, 1)
*/
var buf bytes.Buffer var buf bytes.Buffer
if err := cb.EncodeRLP(&buf); err != nil { if err := cb.EncodeRLP(&buf); err != nil {
t.Fatalf("failed to encode BAL: %v", err) t.Fatalf("failed to encode BAL: %v", err)

View file

@ -19,11 +19,12 @@ package state
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"github.com/ethereum/go-ethereum/core/types/bal"
"maps" "maps"
"slices" "slices"
"time" "time"
"github.com/ethereum/go-ethereum/core/types/bal"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"

View file

@ -20,7 +20,6 @@ package state
import ( import (
"errors" "errors"
"fmt" "fmt"
"github.com/ethereum/go-ethereum/core/types/bal"
"maps" "maps"
"slices" "slices"
"sort" "sort"
@ -28,6 +27,8 @@ import (
"sync/atomic" "sync/atomic"
"time" "time"
"github.com/ethereum/go-ethereum/core/types/bal"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/stateless" "github.com/ethereum/go-ethereum/core/stateless"
"github.com/ethereum/go-ethereum/core/tracing" "github.com/ethereum/go-ethereum/core/tracing"

View file

@ -18,10 +18,11 @@ package state
import ( import (
"bytes" "bytes"
"github.com/ethereum/go-ethereum/core/types/bal"
"math/big" "math/big"
"sort" "sort"
"github.com/ethereum/go-ethereum/core/types/bal"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/stateless" "github.com/ethereum/go-ethereum/core/stateless"
"github.com/ethereum/go-ethereum/core/tracing" "github.com/ethereum/go-ethereum/core/tracing"

View file

@ -18,9 +18,10 @@ package core
import ( import (
"context" "context"
"github.com/ethereum/go-ethereum/core/types/bal"
"sync/atomic" "sync/atomic"
"github.com/ethereum/go-ethereum/core/types/bal"
"github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/core/vm"

View file

@ -19,9 +19,10 @@ package bal
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"maps"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/holiman/uint256" "github.com/holiman/uint256"
"maps"
) )
// ConstructionAccountAccesses contains post-block account state for mutations as well as // ConstructionAccountAccesses contains post-block account state for mutations as well as

View file

@ -25,6 +25,7 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/internal/testrand" "github.com/ethereum/go-ethereum/internal/testrand"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
"github.com/holiman/uint256" "github.com/holiman/uint256"
) )
@ -37,48 +38,51 @@ func equalBALs(a *BlockAccessList, b *BlockAccessList) bool {
} }
func makeTestConstructionBAL() ConstructionBlockAccessList { func makeTestConstructionBAL() ConstructionBlockAccessList {
return map[common.Address]*ConstructionAccountAccesses{ return ConstructionBlockAccessList{
common.BytesToAddress([]byte{0xff, 0xff}): { list: map[common.Address]*ConstructionAccountAccesses{
StorageWrites: map[common.Hash]map[uint16]common.Hash{ common.BytesToAddress([]byte{0xff, 0xff}): {
common.BytesToHash([]byte{0x01}): { StorageWrites: map[common.Hash]map[uint16]common.Hash{
1: common.BytesToHash([]byte{1, 2, 3, 4}), common.BytesToHash([]byte{0x01}): {
2: common.BytesToHash([]byte{1, 2, 3, 4, 5, 6}), 1: common.BytesToHash([]byte{1, 2, 3, 4}),
2: common.BytesToHash([]byte{1, 2, 3, 4, 5, 6}),
},
common.BytesToHash([]byte{0x10}): {
20: common.BytesToHash([]byte{1, 2, 3, 4}),
},
}, },
common.BytesToHash([]byte{0x10}): { StorageReads: map[common.Hash]struct{}{
20: common.BytesToHash([]byte{1, 2, 3, 4}), common.BytesToHash([]byte{1, 2, 3, 4, 5, 6, 7}): {},
}, },
}, BalanceChanges: map[uint16]*uint256.Int{
StorageReads: map[common.Hash]struct{}{ 1: uint256.NewInt(100),
common.BytesToHash([]byte{1, 2, 3, 4, 5, 6, 7}): {}, 2: uint256.NewInt(500),
},
BalanceChanges: map[uint16]*uint256.Int{
1: uint256.NewInt(100),
2: uint256.NewInt(500),
},
NonceChanges: map[uint16]uint64{
1: 2,
2: 6,
},
CodeChanges: map[uint16][]byte{0: common.Hex2Bytes("deadbeef")},
},
common.BytesToAddress([]byte{0xff, 0xff, 0xff}): {
StorageWrites: map[common.Hash]map[uint16]common.Hash{
common.BytesToHash([]byte{0x01}): {
2: common.BytesToHash([]byte{1, 2, 3, 4, 5, 6}),
3: common.BytesToHash([]byte{1, 2, 3, 4, 5, 6, 7, 8}),
}, },
NonceChanges: map[uint16]uint64{
1: 2,
2: 6,
},
CodeChanges: map[uint16][]byte{0: common.Hex2Bytes("deadbeef")},
}, },
StorageReads: map[common.Hash]struct{}{ common.BytesToAddress([]byte{0xff, 0xff, 0xff}): {
common.BytesToHash([]byte{1, 2, 3, 4, 5, 6, 7, 8}): {}, StorageWrites: map[common.Hash]map[uint16]common.Hash{
}, common.BytesToHash([]byte{0x01}): {
BalanceChanges: map[uint16]*uint256.Int{ 2: common.BytesToHash([]byte{1, 2, 3, 4, 5, 6}),
2: uint256.NewInt(100), 3: common.BytesToHash([]byte{1, 2, 3, 4, 5, 6, 7, 8}),
3: uint256.NewInt(500), },
}, },
NonceChanges: map[uint16]uint64{ StorageReads: map[common.Hash]struct{}{
1: 2, common.BytesToHash([]byte{1, 2, 3, 4, 5, 6, 7, 8}): {},
},
BalanceChanges: map[uint16]*uint256.Int{
2: uint256.NewInt(100),
3: uint256.NewInt(500),
},
NonceChanges: map[uint16]uint64{
1: 2,
},
}, },
}, },
transactionCount: 1,
} }
} }
@ -212,7 +216,7 @@ func TestBlockAccessListCopy(t *testing.T) {
} }
// Make sure the mutations on copy won't affect the origin // Make sure the mutations on copy won't affect the origin
for _, aa := range cpyCpy { for _, aa := range *cpyCpy {
for i := 0; i < len(aa.StorageReads); i++ { for i := 0; i < len(aa.StorageReads); i++ {
aa.StorageReads[i] = &EncodedStorage{new(uint256.Int).SetBytes(testrand.Bytes(32))} aa.StorageReads[i] = &EncodedStorage{new(uint256.Int).SetBytes(testrand.Bytes(32))}
} }
@ -226,7 +230,7 @@ func TestBlockAccessListValidation(t *testing.T) {
// Validate the block access list after RLP decoding // Validate the block access list after RLP decoding
testBALMaxIndex := 20 testBALMaxIndex := 20
enc := makeTestBAL(true) enc := makeTestBAL(true)
if err := enc.Validate(testBALMaxIndex); err != nil { if err := enc.Validate(testBALMaxIndex, params.MaxGasLimit); err != nil {
t.Fatalf("Unexpected validation error: %v", err) t.Fatalf("Unexpected validation error: %v", err)
} }
var buf bytes.Buffer var buf bytes.Buffer
@ -238,14 +242,14 @@ func TestBlockAccessListValidation(t *testing.T) {
if err := dec.DecodeRLP(rlp.NewStream(bytes.NewReader(buf.Bytes()), 0)); err != nil { if err := dec.DecodeRLP(rlp.NewStream(bytes.NewReader(buf.Bytes()), 0)); err != nil {
t.Fatalf("Unexpected RLP-decode error: %v", err) t.Fatalf("Unexpected RLP-decode error: %v", err)
} }
if err := dec.Validate(testBALMaxIndex); err != nil { if err := dec.Validate(testBALMaxIndex, params.MaxGasLimit); err != nil {
t.Fatalf("Unexpected validation error: %v", err) t.Fatalf("Unexpected validation error: %v", err)
} }
// Validate the derived block access list // Validate the derived block access list
cBAL := makeTestConstructionBAL() cBAL := makeTestConstructionBAL()
listB := cBAL.ToEncodingObj() listB := cBAL.ToEncodingObj()
if err := listB.Validate(testBALMaxIndex); err != nil { if err := listB.Validate(testBALMaxIndex, params.MaxGasLimit); err != nil {
t.Fatalf("Unexpected validation error: %v", err) t.Fatalf("Unexpected validation error: %v", err)
} }
} }

View file

@ -37,12 +37,13 @@ func makeTestBAL(minSize int) *bal.BlockAccessList {
n := minSize/33 + 1 // 33 bytes per storage read slot in RLP n := minSize/33 + 1 // 33 bytes per storage read slot in RLP
access := bal.AccountAccess{ access := bal.AccountAccess{
Address: common.HexToAddress("0x01"), Address: common.HexToAddress("0x01"),
StorageReads: make([][32]byte, n), StorageReads: make([]*bal.EncodedStorage, n),
} }
for i := range access.StorageReads { for i := range access.StorageReads {
binary.BigEndian.PutUint64(access.StorageReads[i][24:], uint64(i)) read := access.StorageReads[i].ToHash()
binary.BigEndian.PutUint64(read[24:], uint64(i))
} }
return &bal.BlockAccessList{Accesses: []bal.AccountAccess{access}} return &bal.BlockAccessList{access}
} }
// getChainWithBALs creates a minimal test chain with BALs stored for each block. // getChainWithBALs creates a minimal test chain with BALs stored for each block.

View file

@ -620,7 +620,7 @@ func TestSelfdestructStateTracer(t *testing.T) {
} }
context := core.NewEVMBlockContext(block.Header(), blockchain, nil) context := core.NewEVMBlockContext(block.Header(), blockchain, nil)
evm := vm.NewEVM(context, hookedState, tt.genesis.Config, vm.Config{Tracer: tracer.Hooks()}) evm := vm.NewEVM(context, hookedState, tt.genesis.Config, vm.Config{Tracer: tracer.Hooks()})
_, _, err = core.ApplyTransactionWithEVM(msg, core.NewGasPool(msg.GasLimit), statedb, block.Number(), block.Hash(), block.Time(), tx, evm) _, _, _, err = core.ApplyTransactionWithEVM(msg, core.NewGasPool(msg.GasLimit), statedb, block.Number(), block.Hash(), block.Time(), tx, evm)
if err != nil { if err != nil {
t.Fatalf("failed to execute transaction: %v", err) t.Fatalf("failed to execute transaction: %v", err)
} }