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 Dec 24, 2019
1 parent 48d9aed commit 89ecfb3
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 26 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
7 changes: 1 addition & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ module github.com/ontio/ontology
go 1.12

require (
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e // indirect
github.com/JohnCGriffin/overflow v0.0.0-20170615021017-4d914c927216
github.com/Workiva/go-datastructures v1.0.50 // indirect
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e // indirect
github.com/emirpasic/gods v1.12.0 // indirect
github.com/ethereum/go-ethereum v1.9.6
github.com/go-interpreter/wagon v0.6.0
Expand All @@ -18,23 +16,20 @@ require (
github.com/howeyc/gopass v0.0.0-20190910152052-7cb4b85ec19c
github.com/itchyny/base58-go v0.0.5
github.com/mattn/go-isatty v0.0.10 // indirect
github.com/ontio/go-bip32 v0.0.0-20190520025953-d3cea6894a2b // indirect
github.com/ontio/ontology-crypto v1.0.5
github.com/ontio/ontology-eventbus v0.9.1
github.com/ontio/ontology-go-sdk v1.0.9
github.com/orcaman/concurrent-map v0.0.0-20190826125027-8c72a8bb44f6 // indirect
github.com/pborman/uuid v1.2.0
github.com/stretchr/testify v1.3.0
github.com/syndtr/goleveldb v1.0.0
github.com/tyler-smith/go-bip39 v1.0.2 // indirect
github.com/urfave/cli v1.22.1
github.com/valyala/bytebufferpool v1.0.0
golang.org/x/crypto v0.0.0-20191029031824-8986dd9e96cf
golang.org/x/net v0.0.0-20191028085509-fe3aa8a45271
)

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
14 changes: 2 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e h1:ahyvB3q25YnZWly5Gq1ekg6jcmWaGj/vG/MhF4aisoc=
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:kGUqhHd//musdITWjFvNTHn90WG9bMLBEPQZ17Cmlpw=
github.com/JohnCGriffin/overflow v0.0.0-20170615021017-4d914c927216 h1:2ZboyJ8vl75fGesnG9NpMTD2DyQI3FzMXy4x752rGF0=
github.com/JohnCGriffin/overflow v0.0.0-20170615021017-4d914c927216/go.mod h1:X0CRv0ky0k6m906ixxpzmDRLvX58TFUKS2eePweuyxk=
github.com/Workiva/go-datastructures v1.0.50 h1:slDmfW6KCHcC7U+LP3DDBbm4fqTwZGn1beOFPfGaLvo=
github.com/Workiva/go-datastructures v1.0.50/go.mod h1:Z+F2Rca0qCsVYDS8z7bAGm8f3UkzuWYS/oBZz5a7VVA=
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e h1:0XBUw73chJ1VYSsfvcPvVT7auykAJce9FpRr10L6Qhw=
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:P13beTBKr5Q18lJe1rIoLUqjM+CB1zYrRg44ZqGuQSA=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
Expand Down Expand Up @@ -57,16 +53,12 @@ github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU=
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/ontio/go-bip32 v0.0.0-20190520025953-d3cea6894a2b h1:UQDN12BzdWhXQL0t2QcRixHqAIG+JKNvQ20DhrIODtU=
github.com/ontio/go-bip32 v0.0.0-20190520025953-d3cea6894a2b/go.mod h1:J0eVc7BEMmVVXbGv9PHoxjRSEwOwLr0qfzPk8Rdl5iw=
github.com/ontio/ontology-crypto v1.0.5 h1:VYIEL9yF1d8vWxgLedqoQXKdyw2oY46NliGCQn1IKDM=
github.com/ontio/ontology-crypto v1.0.5/go.mod h1:ebrQJ4/VS2F6pwHGktHDYtY/7Y2ca/ogfnlYABrQI2c=
github.com/ontio/ontology-eventbus v0.9.1 h1:nt3AXWx3gOyqtLiU4EwI92Yc4ik/pWHu9xRK15uHSOs=
github.com/ontio/ontology-eventbus v0.9.1/go.mod h1:hCQIlbdPckcfykMeVUdWrqHZ8d30TBdmLfXCVWGkYhM=
github.com/ontio/ontology-go-sdk v1.0.9 h1:9JyUeD7JUt15tSxl4tE3wJNfCogVA0XrjJkm6CIHAa8=
github.com/ontio/ontology-go-sdk v1.0.9/go.mod h1:HeRiwU9NBfsnPNAuB2EAKj8roZTv+HTumtFSik8IcV0=
github.com/ontio/wagon v0.3.1-0.20191012103353-ef8d35ecd300 h1:E+8mJjO4xOPGlbSoJiElZ6yYks/KdPe4j9gXYUMpbdA=
github.com/ontio/wagon v0.3.1-0.20191012103353-ef8d35ecd300/go.mod h1:zHOMvbitcZek8oshsMO5VpyBjWjV9X8cn8WTZwdebpM=
github.com/ontio/wagon v0.3.1-0.20191223040208-db6073fb2776 h1:cfHznrh9WsSH7F253Lr6TkYa38p/3Cgk0PJS7238cRQ=
github.com/ontio/wagon v0.3.1-0.20191223040208-db6073fb2776/go.mod h1:zHOMvbitcZek8oshsMO5VpyBjWjV9X8cn8WTZwdebpM=
github.com/orcaman/concurrent-map v0.0.0-20190826125027-8c72a8bb44f6 h1:lNCW6THrCKBiJBpz8kbVGjC7MgdCGKwuvBgc7LoD6sw=
github.com/orcaman/concurrent-map v0.0.0-20190826125027-8c72a8bb44f6/go.mod h1:Lu3tH6HLW3feq74c2GC+jIMS/K2CFcDWnWD9XkenwhI=
github.com/pborman/uuid v1.2.0 h1:J7Q5mO4ysT1dv8hyrUGHb9+ooztCXu1D8MY8DZYsu3g=
Expand All @@ -82,8 +74,6 @@ github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE=
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
github.com/tyler-smith/go-bip39 v1.0.2 h1:+t3w+KwLXO6154GNJY+qUtIxLTmFjfUmpguQT1OlOT8=
github.com/tyler-smith/go-bip39 v1.0.2/go.mod h1:sJ5fKU0s6JVwZjjcUEX2zFOnvq0ASQ2K9Zr6cf67kNs=
github.com/urfave/cli v1.22.1 h1:+mkCCcOFKPnCmVYVcURKps1Xe+3zP90gSYGNfRkjoIY=
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
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 @@ -18,7 +18,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 @@ -56,9 +56,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 @@ -440,7 +440,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 @@ -709,7 +709,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 @@ -128,7 +128,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 @@ -142,7 +142,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 89ecfb3

Please sign in to comment.