diff --git a/common/config/config.go b/common/config/config.go index 020e9936c7..cd23a082e3 100644 --- a/common/config/config.go +++ b/common/config/config.go @@ -137,6 +137,15 @@ func GetOpcodeUpdateCheckHeight(id uint32) uint32 { return OPCODE_HASKEY_ENABLE_HEIGHT[id] } +var CONTRACT_DESTROY_ENABLE_HEIGHT = map[uint32]uint32{ + NETWORK_ID_MAIN_NET: constants.CONTRACT_DESTROY_MAINNET, //Network main + NETWORK_ID_POLARIS_NET: constants.CONTRACT_DESTROY_POLARIS, //Network polaris + NETWORK_ID_SOLO_NET: 0, //Network solo +} + +func GetContractDestroyCheckHeight(id uint32) uint32 { + return CONTRACT_DESTROY_ENABLE_HEIGHT[id] +} var GAS_ROUND_TUNE_HEIGHT = map[uint32]uint32{ NETWORK_ID_MAIN_NET: constants.GAS_ROUND_TUNE_HEIGHT_MAINNET, //Network main NETWORK_ID_POLARIS_NET: constants.GAS_ROUND_TUNE_HEIGHT_POLARIS, //Network polaris diff --git a/common/constants/constants.go b/common/constants/constants.go index 81c6d8f6b9..d33d861ba4 100644 --- a/common/constants/constants.go +++ b/common/constants/constants.go @@ -87,6 +87,10 @@ const STATE_HASH_HEIGHT_POLARIS = 850000 const OPCODE_HEIGHT_UPDATE_FIRST_MAINNET = 6300000 const OPCODE_HEIGHT_UPDATE_FIRST_POLARIS = 2100000 +const ( + CONTRACT_DESTROY_MAINNET = 6300000 + CONTRACT_DESTROY_POLARIS = 6300000 +) // gas round tune operation height const GAS_ROUND_TUNE_HEIGHT_MAINNET = 8500000 const GAS_ROUND_TUNE_HEIGHT_POLARIS = 10100000 diff --git a/smartcontract/service/wasmvm/contract.go b/smartcontract/service/wasmvm/contract.go index b9aa6403fc..3144d735bf 100644 --- a/smartcontract/service/wasmvm/contract.go +++ b/smartcontract/service/wasmvm/contract.go @@ -230,6 +230,9 @@ func ContractDestroy(proc *exec.Process) { if err != nil { panic(err) } + if !self.Feature.AllowContractDestroyBug { + self.Service.CacheDB.DeleteContract(contractAddress) + } //the contract has been deleted ,quit the contract operation proc.Terminate() } diff --git a/smartcontract/service/wasmvm/runtime.go b/smartcontract/service/wasmvm/runtime.go index 8980b099f7..f776bc6c0d 100644 --- a/smartcontract/service/wasmvm/runtime.go +++ b/smartcontract/service/wasmvm/runtime.go @@ -25,6 +25,7 @@ import ( "reflect" "github.com/ontio/ontology/common" + "github.com/ontio/ontology/common/config" "github.com/ontio/ontology/common/log" "github.com/ontio/ontology/core/payload" "github.com/ontio/ontology/core/types" @@ -54,6 +55,18 @@ type Runtime struct { Input []byte Output []byte CallOutPut []byte + Feature VmFeatureFlag +} + +type VmFeatureFlag struct { + AllowContractDestroyBug bool +} + +func NewVmFeatureFlag(blockHeight uint32) VmFeatureFlag { + var feature VmFeatureFlag + enableHeight := config.GetContractDestroyCheckHeight(config.DefConfig.P2PNode.NetworkId) + feature.AllowContractDestroyBug = blockHeight <= enableHeight + return feature } func Timestamp(proc *exec.Process) uint64 { diff --git a/smartcontract/service/wasmvm/wasm_service.go b/smartcontract/service/wasmvm/wasm_service.go index cad9904698..91b686b14a 100644 --- a/smartcontract/service/wasmvm/wasm_service.go +++ b/smartcontract/service/wasmvm/wasm_service.go @@ -150,6 +150,8 @@ func (this *WasmVmService) Invoke() (interface{}, error) { this.ContextRef.PushContext(&context.Context{ContractAddress: contract.Address, Code: wasmCode}) + feature := NewVmFeatureFlag(this.Height) + host := &Runtime{Service: this, Input: contract.Args, Feature: feature} var output []byte if this.JitMode { output, err = invokeJit(this, contract, wasmCode)