Skip to content

Commit

Permalink
update wagon to use new gas counter algorithm (#1139)
Browse files Browse the repository at this point in the history
  • Loading branch information
laizy authored and Honglei-Cong committed Dec 30, 2019
1 parent 614a634 commit 28aaeb1
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ import:
repo: https://github.com/golang/net.git
- package: github.com/go-interpreter/wagon
repo: https://github.com/ontio/wagon.git
version: ef8d35ecd300631b16c7f65e7a7fddd9c06eb336
version: db6073fb277612b196eac4f10fa8ca787b292f96
ignore:
- golang.org/x/sys/unix
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ require (
)

replace (
github.com/go-interpreter/wagon => github.com/ontio/wagon v0.3.1-0.20191012103353-ef8d35ecd300
github.com/go-interpreter/wagon => github.com/ontio/wagon v0.3.1-0.20191223040208-db6073fb2776
golang.org/x/crypto => github.com/golang/crypto v0.0.0-20191029031824-8986dd9e96cf
golang.org/x/net => github.com/golang/net v0.0.0-20191028085509-fe3aa8a45271
golang.org/x/sys => github.com/golang/sys v0.0.0-20190412213103-97732733099d
Expand Down
2 changes: 1 addition & 1 deletion smartcontract/service/wasmvm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
package wasmvm

var (
TIME_STAMP_GAS uint64 = 1
TIMESTAMP_GAS uint64 = 1
BLOCK_HEGHT_GAS uint64 = 1
SELF_ADDRESS_GAS uint64 = 1
CALLER_ADDRESS_GAS uint64 = 1
Expand Down
8 changes: 4 additions & 4 deletions smartcontract/service/wasmvm/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ type Runtime struct {
CallOutPut []byte
}

func TimeStamp(proc *exec.Process) uint64 {
func Timestamp(proc *exec.Process) uint64 {
self := proc.HostData().(*Runtime)
self.checkGas(TIME_STAMP_GAS)
self.checkGas(TIMESTAMP_GAS)
return uint64(self.Service.Time)
}

Expand Down Expand Up @@ -442,7 +442,7 @@ func NewHostModule() *wasm.Module {
m.FunctionIndexSpace = []wasm.Function{
{ //0
Sig: &m.Types.Entries[0],
Host: reflect.ValueOf(TimeStamp),
Host: reflect.ValueOf(Timestamp),
Body: &wasm.FunctionBody{}, // create a dummy wasm body (the actual value will be taken from Host.)
},
{ //1
Expand Down Expand Up @@ -711,7 +711,7 @@ func (self *Runtime) getContractType(addr common.Address) (ContractType, error)
}

func (self *Runtime) checkGas(gaslimit uint64) {
gas := self.Service.vm.AvaliableGas
gas := self.Service.vm.ExecMetrics
if *gas.GasLimit >= gaslimit {
*gas.GasLimit -= gaslimit
} else {
Expand Down
2 changes: 1 addition & 1 deletion smartcontract/service/wasmvm/wasm_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (this *WasmVmService) Invoke() (interface{}, error) {

vm.HostData = host

vm.AvaliableGas = &exec.Gas{GasLimit: this.GasLimit, LocalGasCounter: 0, GasPrice: this.GasPrice, GasFactor: this.GasFactor, ExecStep: this.ExecStep}
vm.ExecMetrics = &exec.Gas{GasLimit: this.GasLimit, LocalGasCounter: 0, GasPrice: this.GasPrice, GasFactor: this.GasFactor, ExecStep: this.ExecStep}
vm.CallStackDepth = uint32(WASM_CALLSTACK_LIMIT)
vm.RecoverPanic = true

Expand Down
2 changes: 1 addition & 1 deletion wasmtest/wasm-test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func ExactTestCase(code []byte) [][]common3.TestCase {
vm.RecoverPanic = true
envGasLimit := uint64(100000000000000)
envExecStep := uint64(100000000000000)
vm.AvaliableGas = &exec.Gas{GasLimit: &envGasLimit, GasPrice: 0, GasFactor: 5, ExecStep: &envExecStep}
vm.ExecMetrics = &exec.Gas{GasLimit: &envGasLimit, GasPrice: 0, GasFactor: 5, ExecStep: &envExecStep}
vm.CallStackDepth = 1024

entry := compiled.RawModule.Export.Entries["invoke"]
Expand Down

0 comments on commit 28aaeb1

Please sign in to comment.