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 all commits
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
9 changes: 9 additions & 0 deletions common/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions common/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions smartcontract/service/wasmvm/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
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 @@ -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"
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
2 changes: 2 additions & 0 deletions smartcontract/service/wasmvm/wasm_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down