From affb1234b84dc731d3ad9e67b406877097ed6f7f Mon Sep 17 00:00:00 2001 From: Lucas Date: Mon, 18 Nov 2019 16:39:24 +0800 Subject: [PATCH 1/2] add feature in wasmvm --- common/config/config.go | 10 ++++++++++ smartcontract/service/wasmvm/contract.go | 4 +++- smartcontract/service/wasmvm/runtime.go | 13 +++++++++++++ smartcontract/service/wasmvm/wasm_service.go | 4 +++- 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/common/config/config.go b/common/config/config.go index 47a9b81deb..e46d38d945 100644 --- a/common/config/config.go +++ b/common/config/config.go @@ -129,6 +129,16 @@ func GetOpcodeUpdateCheckHeight(id uint32) uint32 { return OPCODE_HASKEY_ENABLE_HEIGHT[id] } +var CONTRACT_DESTROY_ENABLE_HEIGHT = map[uint32]uint32{ + NETWORK_ID_MAIN_NET: constants.OPCODE_HEIGHT_UPDATE_FIRST_MAINNET, //Network main + NETWORK_ID_POLARIS_NET: constants.OPCODE_HEIGHT_UPDATE_FIRST_POLARIS, //Network polaris + NETWORK_ID_SOLO_NET: 0, //Network solo +} + +func GetContractDestroyCheckHeight(id uint32) uint32 { + return CONTRACT_DESTROY_ENABLE_HEIGHT[id] +} + func GetNetworkName(id uint32) string { name, ok := NETWORK_NAME[id] if ok { diff --git a/smartcontract/service/wasmvm/contract.go b/smartcontract/service/wasmvm/contract.go index 51bc73461e..9036023421 100644 --- a/smartcontract/service/wasmvm/contract.go +++ b/smartcontract/service/wasmvm/contract.go @@ -210,7 +210,9 @@ func ContractDestroy(proc *exec.Process) { if err := iter.Error(); err != nil { panic(err) } - self.Service.CacheDB.DeleteContract(contractAddress) + 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 e56da7938c..a102babaab 100644 --- a/smartcontract/service/wasmvm/runtime.go +++ b/smartcontract/service/wasmvm/runtime.go @@ -26,6 +26,7 @@ import ( "github.com/go-interpreter/wagon/exec" "github.com/go-interpreter/wagon/wasm" "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 ab02a08a48..b3ea2bbaca 100644 --- a/smartcontract/service/wasmvm/wasm_service.go +++ b/smartcontract/service/wasmvm/wasm_service.go @@ -103,7 +103,9 @@ func (this *WasmVmService) Invoke() (interface{}, error) { return nil, errors.NewErr("not a wasm contract") } this.ContextRef.PushContext(&context.Context{ContractAddress: contract.Address, Code: wasmCode}) - host := &Runtime{Service: this, Input: contract.Args} + + feature := NewVmFeatureFlag(this.Height) + host := &Runtime{Service: this, Input: contract.Args, Feature: feature} var compiled *exec.CompiledModule if CodeCache != nil { From 6e7f75a3f1d47d0af00374f8f96a6117413714ad Mon Sep 17 00:00:00 2001 From: Lucas Date: Mon, 18 Nov 2019 16:42:45 +0800 Subject: [PATCH 2/2] add contract_destroy height --- common/config/config.go | 6 +++--- common/constants/constants.go | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/common/config/config.go b/common/config/config.go index e46d38d945..fe93f56de7 100644 --- a/common/config/config.go +++ b/common/config/config.go @@ -130,9 +130,9 @@ func GetOpcodeUpdateCheckHeight(id uint32) uint32 { } var CONTRACT_DESTROY_ENABLE_HEIGHT = map[uint32]uint32{ - NETWORK_ID_MAIN_NET: constants.OPCODE_HEIGHT_UPDATE_FIRST_MAINNET, //Network main - NETWORK_ID_POLARIS_NET: constants.OPCODE_HEIGHT_UPDATE_FIRST_POLARIS, //Network polaris - NETWORK_ID_SOLO_NET: 0, //Network solo + 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 { diff --git a/common/constants/constants.go b/common/constants/constants.go index dd00cd16f0..e58205111d 100644 --- a/common/constants/constants.go +++ b/common/constants/constants.go @@ -86,3 +86,8 @@ const STATE_HASH_HEIGHT_POLARIS = 850000 // neovm opcode update check height const OPCODE_HEIGHT_UPDATE_FIRST_MAINNET = 6300000 const OPCODE_HEIGHT_UPDATE_FIRST_POLARIS = 2100000 + +const ( + CONTRACT_DESTROY_MAINNET = 6300000 + CONTRACT_DESTROY_POLARIS = 6300000 +)