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

wasmvm add feature #1128

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Next Next commit
add feature in wasmvm
  • Loading branch information
lucas7788 committed Nov 18, 2019
commit affb1234b84dc731d3ad9e67b406877097ed6f7f
10 changes: 10 additions & 0 deletions common/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion smartcontract/service/wasmvm/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
13 changes: 13 additions & 0 deletions smartcontract/service/wasmvm/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion smartcontract/service/wasmvm/wasm_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down