Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 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
5 changes: 4 additions & 1 deletion beacon/engine/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var (
PayloadV1 PayloadVersion = 0x1
PayloadV2 PayloadVersion = 0x2
PayloadV3 PayloadVersion = 0x3
PayloadV4 PayloadVersion = 0x4
)

//go:generate go run github.com/fjl/gencodec -type PayloadAttributes -field-override payloadAttributesMarshaling -out gen_blockparams.go
Expand Down Expand Up @@ -274,6 +275,8 @@ func ExecutableDataToBlockNoHash(data ExecutableData, versionedHashes []common.H
requestsHash = &h
}

body := types.Body{Transactions: txs, Uncles: nil, Withdrawals: data.Withdrawals}

header := &types.Header{
ParentHash: data.ParentHash,
UncleHash: types.EmptyUncleHash,
Expand All @@ -297,7 +300,7 @@ func ExecutableDataToBlockNoHash(data ExecutableData, versionedHashes []common.H
RequestsHash: requestsHash,
}
return types.NewBlockWithHeader(header).
WithBody(types.Body{Transactions: txs, Uncles: nil, Withdrawals: data.Withdrawals}).
WithBody(body).
WithWitness(data.ExecutionWitness),
nil
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/evm/blockrunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func runBlockTest(ctx *cli.Context, fname string) ([]testResult, error) {
continue
}
result := &testResult{Name: name, Pass: true}
if err := tests[name].Run(false, rawdb.HashScheme, ctx.Bool(WitnessCrossCheckFlag.Name), tracer, func(res error, chain *core.BlockChain) {
if err := tests[name].Run(false, rawdb.HashScheme, ctx.Bool(WitnessCrossCheckFlag.Name), false, tracer, func(res error, chain *core.BlockChain) {
if ctx.Bool(DumpFlag.Name) {
if s, _ := chain.State(); s != nil {
result.State = dump(s)
Expand Down
2 changes: 1 addition & 1 deletion cmd/evm/internal/t8ntool/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ func MakePreState(db ethdb.Database, accounts types.GenesisAlloc) *state.StateDB
sdb := state.NewDatabase(tdb, nil)
statedb, _ := state.New(types.EmptyRootHash, sdb)
for addr, a := range accounts {
statedb.SetCode(addr, a.Code)
statedb.SetCode(addr, a.Code, tracing.CodeChangeGenesis)
statedb.SetNonce(addr, a.Nonce, tracing.NonceChangeGenesis)
statedb.SetBalance(addr, uint256.MustFromBig(a.Balance), tracing.BalanceIncreaseGenesisBalance)
for k, v := range a.Storage {
Expand Down
2 changes: 1 addition & 1 deletion cmd/evm/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ func runCmd(ctx *cli.Context) error {
}
} else {
if len(code) > 0 {
prestate.SetCode(receiver, code)
prestate.SetCode(receiver, code, tracing.CodeChangeUnspecified)
}
execFunc = func() ([]byte, uint64, error) {
// don't mutate the state!
Expand Down
2 changes: 1 addition & 1 deletion cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ var (
utils.MinerRecommitIntervalFlag,
utils.MinerNewPayloadTimeoutFlag, // deprecated
utils.MinerDelayLeftoverFlag,
utils.EnableBALFlag,
// utils.MinerNewPayloadTimeout,
utils.NATFlag,
utils.NoDiscoverFlag,
Expand Down Expand Up @@ -191,6 +190,7 @@ var (
utils.IncrSnapshotKeptBlocksFlag,
utils.UseRemoteIncrSnapshotFlag,
utils.RemoteIncrSnapshotURLFlag,
utils.ExperimentalBALFlag,
// utils.BeaconApiFlag,
// utils.BeaconApiHeaderFlag,
// utils.BeaconThresholdFlag,
Expand Down
23 changes: 11 additions & 12 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,6 @@ var (
Usage: "Chapel network: pre-configured Proof-of-Stake-Authority BSC test network",
Category: flags.EthCategory,
}
EnableBALFlag = &cli.BoolFlag{
Name: "enablebal",
Usage: "Enable block access list feature, validator will generate BAL for each block",
Category: flags.EthCategory,
}
// Dev mode
DeveloperFlag = &cli.BoolFlag{
Name: "dev",
Expand Down Expand Up @@ -1325,6 +1320,14 @@ Please note that --` + MetricsHTTPFlag.Name + ` must be set to start the server.
Value: "",
Category: flags.StateCategory,
}

// Block Access List flags

ExperimentalBALFlag = &cli.BoolFlag{
Name: "experimentalbal",
Usage: "Enable block-access-list building when importing post-Cancun blocks, and validation that access lists contained in post-Cancun blocks correctly correspond to the state changes in those blocks. This is used for development purposes only. Do not enable it otherwise.",
Category: flags.MiscCategory,
}
)

var (
Expand Down Expand Up @@ -1799,9 +1802,6 @@ func SetNodeConfig(ctx *cli.Context, cfg *node.Config) {
if ctx.IsSet(DisableSnapProtocolFlag.Name) {
cfg.DisableSnapProtocol = ctx.Bool(DisableSnapProtocolFlag.Name)
}
if ctx.IsSet(EnableBALFlag.Name) {
cfg.EnableBAL = ctx.Bool(EnableBALFlag.Name)
}
if ctx.IsSet(RangeLimitFlag.Name) {
cfg.RangeLimit = ctx.Bool(RangeLimitFlag.Name)
}
Expand Down Expand Up @@ -2101,9 +2101,6 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
if ctx.IsSet(CacheNoPrefetchFlag.Name) {
cfg.NoPrefetch = ctx.Bool(CacheNoPrefetchFlag.Name)
}
if ctx.IsSet(EnableBALFlag.Name) {
cfg.EnableBAL = ctx.Bool(EnableBALFlag.Name)
}
// Read the value from the flag no matter if it's set or not.
cfg.Preimages = ctx.Bool(CachePreimagesFlag.Name)
if cfg.NoPruning && !cfg.Preimages {
Expand Down Expand Up @@ -2377,6 +2374,8 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
}
}

cfg.ExperimentalBAL = ctx.Bool(ExperimentalBALFlag.Name)

// Download and merge incremental snapshot config
if ctx.IsSet(UseRemoteIncrSnapshotFlag.Name) {
cfg.UseRemoteIncrSnapshot = true
Expand Down Expand Up @@ -2798,7 +2797,6 @@ func MakeChain(ctx *cli.Context, stack *node.Node, readonly bool) (*core.BlockCh
options := &core.BlockChainConfig{
TrieCleanLimit: ethconfig.Defaults.TrieCleanCache,
NoPrefetch: ctx.Bool(CacheNoPrefetchFlag.Name),
EnableBAL: ctx.Bool(EnableBALFlag.Name),
TrieDirtyLimit: ethconfig.Defaults.TrieDirtyCache,
ArchiveMode: ctx.String(GCModeFlag.Name) == "archive",
TrieTimeLimit: ethconfig.Defaults.TrieTimeout,
Expand Down Expand Up @@ -2853,6 +2851,7 @@ func MakeChain(ctx *cli.Context, stack *node.Node, readonly bool) (*core.BlockCh
}
options.VmConfig = vmcfg

options.EnableBAL = ctx.Bool(ExperimentalBALFlag.Name)
chain, err := core.NewBlockChain(chainDb, gspec, engine, options)
if err != nil {
Fatalf("Can't create BlockChain: %v", err)
Expand Down
31 changes: 17 additions & 14 deletions consensus/beacon/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ import (
"math/big"
"time"

state2 "github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/vm"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/consensus/misc/eip1559"
"github.com/ethereum/go-ethereum/consensus/misc/eip4844"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/tracing"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/trie"
"github.com/holiman/uint256"
Expand Down Expand Up @@ -405,10 +406,9 @@ func (beacon *Beacon) Finalize(chain consensus.ChainHeaderReader, header *types.

// FinalizeAndAssemble implements consensus.Engine, setting the final state and
// assembling the block.
func (beacon *Beacon) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, body *types.Body, receipts []*types.Receipt, tracer *tracing.Hooks) (*types.Block, []*types.Receipt, error) {
// FinalizeAndAssemble is different with Prepare, it can be used in both block generation.
func (beacon *Beacon) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *types.Header, state *state2.StateDB, body *types.Body, receipts []*types.Receipt, tracer *tracing.Hooks, onFinalization func()) (*types.Block, []*types.Receipt, error) {
if !beacon.IsPoSHeader(header) {
return beacon.ethone.FinalizeAndAssemble(chain, header, state, body, receipts, tracer)
return beacon.ethone.FinalizeAndAssemble(chain, header, state, body, receipts, tracer, onFinalization)
}
shanghai := chain.Config().IsShanghai(header.Number, header.Time)
if shanghai {
Expand All @@ -427,6 +427,10 @@ func (beacon *Beacon) FinalizeAndAssemble(chain consensus.ChainHeaderReader, hea
// Assign the final state root to header.
header.Root = state.IntermediateRoot(true)

if onFinalization != nil {
onFinalization()
}

// Assemble the final block.
block := types.NewBlock(header, body, receipts, trie.NewStackTrie(nil))

Expand Down Expand Up @@ -491,15 +495,6 @@ func (beacon *Beacon) SealHash(header *types.Header) common.Hash {
return beacon.ethone.SealHash(header)
}

func (beacon *Beacon) SignBAL(blockAccessList *types.BlockAccessListEncode) error {
return nil
}

// VerifyBAL verifies the BAL of the block
func (beacon *Beacon) VerifyBAL(block *types.Block, bal *types.BlockAccessListEncode) error {
return nil
}

// CalcDifficulty is the difficulty adjustment algorithm. It returns
// the difficulty that a new block should have when created at time
// given the parent block's time and difficulty.
Expand Down Expand Up @@ -551,3 +546,11 @@ func IsTTDReached(chain consensus.ChainHeaderReader, parentHash common.Hash, par
}
return td.Cmp(chain.Config().TerminalTotalDifficulty) >= 0, nil
}

func (beacon *Beacon) SignBAL(blockAccessList *types.BlockAccessListEncode) error {
return nil
}

func (beacon *Beacon) VerifyBAL(block *types.Block, blockAccessList *types.BlockAccessListEncode) error {
return nil
}
9 changes: 6 additions & 3 deletions consensus/clique/clique.go
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ func (c *Clique) Finalize(chain consensus.ChainHeaderReader, header *types.Heade

// FinalizeAndAssemble implements consensus.Engine, ensuring no uncles are set,
// nor block rewards given, and returns the final block.
func (c *Clique) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, body *types.Body, receipts []*types.Receipt, tracer *tracing.Hooks) (*types.Block, []*types.Receipt, error) {
func (c *Clique) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, body *types.Body, receipts []*types.Receipt, tracer *tracing.Hooks, onFinalize func()) (*types.Block, []*types.Receipt, error) {
if len(body.Withdrawals) > 0 {
return nil, nil, errors.New("clique does not support withdrawals")
}
Expand All @@ -609,6 +609,9 @@ func (c *Clique) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *
// Assign the final state root to header.
header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number))

if onFinalize != nil {
onFinalize()
}
// Assemble and return the final block for sealing.
return types.NewBlock(header, &types.Body{Transactions: body.Transactions}, receipts, trie.NewStackTrie(nil)), receipts, nil
}
Expand Down Expand Up @@ -788,10 +791,10 @@ func encodeSigHeader(w io.Writer, header *types.Header) {
}
}

func (c *Clique) SignBAL(bal *types.BlockAccessListEncode) error {
func (c *Clique) SignBAL(blockAccessList *types.BlockAccessListEncode) error {
return nil
}

func (c *Clique) VerifyBAL(block *types.Block, bal *types.BlockAccessListEncode) error {
func (c *Clique) VerifyBAL(block *types.Block, blockAccessList *types.BlockAccessListEncode) error {
return nil
}
15 changes: 8 additions & 7 deletions consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ import (
"math/big"
"time"

state2 "github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/vm"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/tracing"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/params"
)

Expand Down Expand Up @@ -124,7 +125,7 @@ type Engine 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(chain ChainHeaderReader, header *types.Header, state *state.StateDB, body *types.Body, receipts []*types.Receipt, tracer *tracing.Hooks) (*types.Block, []*types.Receipt, error)
FinalizeAndAssemble(chain ChainHeaderReader, header *types.Header, state *state2.StateDB, body *types.Body, receipts []*types.Receipt, tracer *tracing.Hooks, onFinalization func()) (*types.Block, []*types.Receipt, error)

// Seal generates a new sealing request for the given input block and pushes
// the result into the given channel.
Expand All @@ -136,16 +137,16 @@ type Engine interface {
// SealHash returns the hash of a block prior to it being sealed.
SealHash(header *types.Header) common.Hash

// CalcDifficulty is the difficulty adjustment algorithm. It returns the difficulty
// that a new block should have.
CalcDifficulty(chain ChainHeaderReader, time uint64, parent *types.Header) *big.Int

// SignBAL signs the BAL of the block
SignBAL(blockAccessList *types.BlockAccessListEncode) error

// VerifyBAL verifies the BAL of the block
VerifyBAL(block *types.Block, bal *types.BlockAccessListEncode) error

// CalcDifficulty is the difficulty adjustment algorithm. It returns the difficulty
// that a new block should have.
CalcDifficulty(chain ChainHeaderReader, time uint64, parent *types.Header) *big.Int

// Delay returns the max duration the miner can commit txs
Delay(chain ChainReader, header *types.Header, leftOver *time.Duration) *time.Duration

Expand Down
14 changes: 13 additions & 1 deletion consensus/ethash/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ func (ethash *Ethash) Finalize(chain consensus.ChainHeaderReader, header *types.

// FinalizeAndAssemble implements consensus.Engine, accumulating the block and
// uncle rewards, setting the final state and assembling the block.
func (ethash *Ethash) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, body *types.Body, receipts []*types.Receipt, tracer *tracing.Hooks) (*types.Block, []*types.Receipt, error) {
func (ethash *Ethash) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, body *types.Body, receipts []*types.Receipt, tracer *tracing.Hooks, onFinalize func()) (*types.Block, []*types.Receipt, error) {
if len(body.Withdrawals) > 0 {
return nil, nil, errors.New("ethash does not support withdrawals")
}
Expand All @@ -533,6 +533,10 @@ func (ethash *Ethash) FinalizeAndAssemble(chain consensus.ChainHeaderReader, hea
// Assign the final state root to header.
header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number))

if onFinalize != nil {
onFinalize()
}

// Header seems complete, assemble into a block and return
return types.NewBlock(header, &types.Body{Transactions: body.Transactions, Uncles: body.Uncles}, receipts, trie.NewStackTrie(nil)), receipts, nil
}
Expand Down Expand Up @@ -609,3 +613,11 @@ func accumulateRewards(config *params.ChainConfig, stateDB vm.StateDB, header *t
}
stateDB.AddBalance(header.Coinbase, reward, tracing.BalanceIncreaseRewardMineBlock)
}

func (ethash *Ethash) SignBAL(blockAccessList *types.BlockAccessListEncode) error {
return nil
}

func (ethash *Ethash) VerifyBAL(block *types.Block, blockAccessList *types.BlockAccessListEncode) error {
return nil
}
8 changes: 0 additions & 8 deletions consensus/ethash/ethash.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,3 @@ func (ethash *Ethash) Close() error {
func (ethash *Ethash) Seal(chain consensus.ChainHeaderReader, block *types.Block, results chan<- *types.Block, stop <-chan struct{}) error {
panic("ethash (pow) sealing not supported any more")
}

func (ethash *Ethash) SignBAL(bal *types.BlockAccessListEncode) error {
return nil
}

func (ethash *Ethash) VerifyBAL(block *types.Block, bal *types.BlockAccessListEncode) error {
return nil
}
Loading