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

blockchain: implement EIP-2935 #121

Merged
merged 11 commits into from
Nov 7, 2024
2 changes: 1 addition & 1 deletion consensus/clique/clique.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ func (c *Clique) Prepare(chain consensus.ChainReader, header *types.Header) erro

func (c *Clique) InitSnapshot() {}

func (c *Clique) Initialize(chain consensus.ChainContext, header *types.Header, state *state.StateDB) {
func (c *Clique) Initialize(chain consensus.ChainReader, header *types.Header, state *state.StateDB) {
}

// Finalize implements consensus.Engine and returns the final block.
Expand Down
8 changes: 1 addition & 7 deletions consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ type Engine interface {
Prepare(chain ChainReader, header *types.Header) error

// Initialize runs any pre-transaction state modifications (e.g., EIP-2539)
Initialize(chain ChainContext, header *types.Header, state *state.StateDB)
Initialize(chain ChainReader, header *types.Header, state *state.StateDB)

// Finalize runs any post-transaction state modifications (e.g. block rewards)
// and assembles the final block.
Expand Down Expand Up @@ -188,9 +188,3 @@ type ConsensusInfo struct {
Committers []common.Address
Round byte
}

type ChainContext interface {
Config() *params.ChainConfig
Engine() Engine
GetHeader(hash common.Hash, number uint64) *types.Header
}
2 changes: 1 addition & 1 deletion consensus/gxhash/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ func (gxhash *Gxhash) Prepare(chain consensus.ChainReader, header *types.Header)
return nil
}

func (gxhash *Gxhash) Initialize(chain consensus.ChainContext, header *types.Header, state *state.StateDB) {
func (gxhash *Gxhash) Initialize(chain consensus.ChainReader, header *types.Header, state *state.StateDB) {
}

// Finalize implements consensus.Engine, accumulating the block rewards,
Expand Down
2 changes: 1 addition & 1 deletion consensus/istanbul/backend/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ func (sb *backend) Prepare(chain consensus.ChainReader, header *types.Header) er
return nil
}

func (sb *backend) Initialize(chain consensus.ChainContext, header *types.Header, state *state.StateDB) {
func (sb *backend) Initialize(chain consensus.ChainReader, header *types.Header, state *state.StateDB) {
// [EIP-2935] stores the parent block hash in the history storage contract
if chain.Config().IsPragueForkEnabled(header.Number) {
context := blockchain.NewEVMBlockContext(header, chain, nil)
Expand Down
2 changes: 1 addition & 1 deletion consensus/mocks/engine_mock.go

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

35 changes: 3 additions & 32 deletions node/cn/tracers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,34 +429,12 @@ func (api *CommonAPI) traceChain(start, end *types.Block, config *TraceConfig, n
logged = time.Now()
logger.Info("Tracing chain segment", "start", start.NumberU64(), "end", end.NumberU64(), "current", number, "transactions", traced, "elapsed", time.Since(begin))
}
// Retrieve the parent block and target block for tracing.
block, err := api.blockByNumber(localctx, rpc.BlockNumber(number))
if err != nil {
failed = err
break
}
next, err := api.blockByNumber(localctx, rpc.BlockNumber(number+1))
if err != nil {
failed = err
break
}
// Prepare the statedb for tracing. Don't use the live database for
// tracing to avoid persisting state junks into the database. Switch
// over to `preferDisk` mode only if the memory usage exceeds the
// limit, the trie database will be reconstructed from scratch only
// if the relevant state is available in disk.
var preferDisk bool
if statedb != nil {
s1, s2, s3 := statedb.Database().TrieDB().Size()
preferDisk = s1+s2+s3 > defaultTracechainMemLimit
blukat29 marked this conversation as resolved.
Show resolved Hide resolved
}
statedb, release, err = api.backend.StateAtBlock(localctx, block, reexec, statedb, false, preferDisk)
if err != nil {
failed = err
break
}
// Insert parent hash in history contract.
api.backend.Engine().Initialize(newChainContext(localctx, api.backend), next.Header(), statedb)
_, _, _, statedb, release, err = api.backend.StateAtTransaction(localctx, next, 0, reexec)

// Clean out any pending derefs. Note this step must be done after
// constructing tracing state, because the tracing state of block
Expand Down Expand Up @@ -630,17 +608,12 @@ func (api *CommonAPI) traceBlock(ctx context.Context, block *types.Block, config
if block.NumberU64() == 0 {
return nil, errors.New("genesis is not traceable")
}
// Create the parent state database
parent, err := api.blockByNumberAndHash(ctx, rpc.BlockNumber(block.NumberU64()-1), block.ParentHash())
if err != nil {
return nil, err
}
reexec := defaultTraceReexec
if config != nil && config.Reexec != nil {
reexec = *config.Reexec
}

statedb, release, err := api.backend.StateAtBlock(ctx, parent, reexec, nil, true, false)
_, _, _, statedb, release, err := api.backend.StateAtTransaction(ctx, block, 0, reexec)
if err != nil {
return nil, err
}
Expand All @@ -658,7 +631,6 @@ func (api *CommonAPI) traceBlock(ctx context.Context, block *types.Block, config
header = block.Header()
blockCtx = blockchain.NewEVMBlockContext(header, newChainContext(ctx, api.backend), nil)
)
api.backend.Engine().Initialize(newChainContext(ctx, api.backend), header, statedb)

threads := runtime.NumCPU()
if threads > len(txs) {
Expand Down Expand Up @@ -743,7 +715,7 @@ func (api *CommonAPI) standardTraceBlockToFile(ctx context.Context, block *types
if config != nil && config.Reexec != nil {
reexec = *config.Reexec
}
statedb, release, err := api.backend.StateAtBlock(ctx, parent, reexec, nil, true, false)
_, _, _, statedb, release, err := api.backend.StateAtTransaction(ctx, parent, 0, reexec)
blukat29 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return nil, err
}
Expand All @@ -764,7 +736,6 @@ func (api *CommonAPI) standardTraceBlockToFile(ctx context.Context, block *types

header := block.Header()
blockCtx := blockchain.NewEVMBlockContext(header, newChainContext(ctx, api.backend), nil)
api.backend.Engine().Initialize(newChainContext(ctx, api.backend), header, statedb)

// Execute transaction, either tracing all or just the requested one
var (
Expand Down
2 changes: 1 addition & 1 deletion reward/supply_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ func (s *supplyTestEngine) Prepare(chain consensus.ChainReader, header *types.He
return nil
}

func (s *supplyTestEngine) Initialize(chain consensus.ChainContext, header *types.Header, state *state.StateDB) {
func (s *supplyTestEngine) Initialize(chain consensus.ChainReader, header *types.Header, state *state.StateDB) {
}

// Simplfied version of istanbul Finalize for testing native token distribution.
Expand Down
Loading