Skip to content

Commit

Permalink
disable optimization at creation for issue fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sunny2022da committed Mar 13, 2024
1 parent a3530dc commit ae33548
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
8 changes: 6 additions & 2 deletions core/opcodeCompiler/compiler/opcodeProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,23 @@ func LoadOptimizedCode(address common.Address) OptCode {
}

func GenOrLoadOptimizedCode(address common.Address, code []byte) {
if !enabled {
return
}
task := optimizeTask{generate, address, code}
taskChannel <- task
}

func FlushCodeCache(address common.Address) {
if !enabled {
return
}
task := optimizeTask{flush, address, nil}
taskChannel <- task
}

func RewriteOptimizedCodeForDB(address common.Address, code []byte, hash common.Hash) {
if enabled {
// p.GenOrRewriteOptimizedCode(address, code, hash)
//
GenOrLoadOptimizedCode(address, code)
}
}
Expand Down
14 changes: 12 additions & 2 deletions core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,16 +508,26 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
// The contract is a scoped environment for this execution context only.
contract := NewContract(caller, AccountRef(address), value, gas)
contract.SetCodeOptionalHash(&address, codeAndHash)
// We don't optimize creation code as it run only once.
contract.optimized = false

if evm.Config.Debug {
if evm.depth == 0 {
evm.Config.Tracer.CaptureStart(evm, caller.Address(), address, true, codeAndHash.code, gas, value)
} else {
evm.Config.Tracer.CaptureEnter(typ, caller.Address(), address, codeAndHash.code, gas, value)
}
}
// We don't optimize creation code as it run only once and may cause code cache issue.
contract.optimized = false
if evm.Config.EnableOpcodeOptimizations {
compiler.DisableOptimization()
}
ret, err := evm.interpreter.Run(contract, nil, false)

// After creation, retrieve to optimization
if evm.Config.EnableOpcodeOptimizations {
compiler.EnableOptimization()
}

// Check whether the max code size has been exceeded, assign err if the case.
if err == nil && evm.chainRules.IsEIP158 && len(ret) > params.MaxCodeSize {
err = ErrMaxCodeSizeExceeded
Expand Down

0 comments on commit ae33548

Please sign in to comment.