Skip to content

Commit 5817dab

Browse files
committed
Merge branch 'develop' into poc-9
2 parents 84a4f76 + a562430 commit 5817dab

2 files changed

Lines changed: 12 additions & 14 deletions

File tree

‎cmd/ethereum/flags.go‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ func Init() {
133133

134134
flag.StringVar(&BootNodes, "bootnodes", "", "space-separated node URLs for discovery bootstrap")
135135
flag.IntVar(&MaxPeer, "maxpeer", 30, "maximum desired peers")
136-
flag.IntVar(&MinerThreads, "minerthreads", runtime.NumCPU(), "number of miner threads")
137136

138137
flag.Parse()
139138

‎vm/vm_jit.go‎

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type RuntimeData struct {
5050
timestamp int64
5151
code *byte
5252
codeSize uint64
53+
codeHash i256
5354
}
5455

5556
func hash2llvm(h []byte) i256 {
@@ -180,6 +181,7 @@ func (self *JitVm) Run(me, caller ContextRef, code []byte, value, gas, price *bi
180181
self.data.timestamp = self.env.Time()
181182
self.data.code = getDataPtr(code)
182183
self.data.codeSize = uint64(len(code))
184+
self.data.codeHash = hash2llvm(crypto.Sha3(code)) // TODO: Get already computed hash?
183185

184186
jit := C.evmjit_create()
185187
retCode := C.evmjit_run(jit, unsafe.Pointer(&self.data), unsafe.Pointer(self))
@@ -197,12 +199,12 @@ func (self *JitVm) Run(me, caller ContextRef, code []byte, value, gas, price *bi
197199
receiverAddr := llvm2hashRef(bswap(&self.data.address))
198200
receiver := state.GetOrNewStateObject(receiverAddr)
199201
balance := state.GetBalance(me.Address())
200-
receiver.AddAmount(balance)
202+
receiver.AddBalance(balance)
201203
state.Delete(me.Address())
202204
}
203205
}
204-
205-
C.evmjit_destroy(jit);
206+
207+
C.evmjit_destroy(jit)
206208
return
207209
}
208210

@@ -278,7 +280,7 @@ func env_blockhash(_vm unsafe.Pointer, _number unsafe.Pointer, _result unsafe.Po
278280
}
279281

280282
//export env_call
281-
func env_call(_vm unsafe.Pointer, _gas unsafe.Pointer, _receiveAddr unsafe.Pointer, _value unsafe.Pointer, inDataPtr unsafe.Pointer, inDataLen uint64, outDataPtr *byte, outDataLen uint64, _codeAddr unsafe.Pointer) bool {
283+
func env_call(_vm unsafe.Pointer, _gas *int64, _receiveAddr unsafe.Pointer, _value unsafe.Pointer, inDataPtr unsafe.Pointer, inDataLen uint64, outDataPtr *byte, outDataLen uint64, _codeAddr unsafe.Pointer) bool {
282284
vm := (*JitVm)(_vm)
283285

284286
//fmt.Printf("env_call (depth %d)\n", vm.Env().Depth())
@@ -297,16 +299,15 @@ func env_call(_vm unsafe.Pointer, _gas unsafe.Pointer, _receiveAddr unsafe.Point
297299
inData := C.GoBytes(inDataPtr, C.int(inDataLen))
298300
outData := llvm2bytesRef(outDataPtr, outDataLen)
299301
codeAddr := llvm2hash((*i256)(_codeAddr))
300-
llvmGas := (*i256)(_gas)
301-
gas := llvm2big(llvmGas)
302+
gas := big.NewInt(*_gas)
302303
var out []byte
303304
var err error
304305
if bytes.Equal(codeAddr, receiveAddr) {
305306
out, err = vm.env.Call(vm.me, codeAddr, inData, gas, vm.price, value)
306307
} else {
307308
out, err = vm.env.CallCode(vm.me, codeAddr, inData, gas, vm.price, value)
308309
}
309-
*llvmGas = big2llvm(gas)
310+
*_gas = gas.Int64()
310311
if err == nil {
311312
copy(outData, out)
312313
return true
@@ -317,25 +318,23 @@ func env_call(_vm unsafe.Pointer, _gas unsafe.Pointer, _receiveAddr unsafe.Point
317318
}
318319

319320
//export env_create
320-
func env_create(_vm unsafe.Pointer, _gas unsafe.Pointer, _value unsafe.Pointer, initDataPtr unsafe.Pointer, initDataLen uint64, _result unsafe.Pointer) {
321+
func env_create(_vm unsafe.Pointer, _gas *int64, _value unsafe.Pointer, initDataPtr unsafe.Pointer, initDataLen uint64, _result unsafe.Pointer) {
321322
vm := (*JitVm)(_vm)
322323

323324
value := llvm2big((*i256)(_value))
324325
initData := C.GoBytes(initDataPtr, C.int(initDataLen)) // TODO: Unnecessary if low balance
325326
result := (*i256)(_result)
326327
*result = i256{}
327328

328-
llvmGas := (*i256)(_gas)
329-
gas := llvm2big(llvmGas)
330-
329+
gas := big.NewInt(*_gas)
331330
ret, suberr, ref := vm.env.Create(vm.me, nil, initData, gas, vm.price, value)
332331
if suberr == nil {
333332
dataGas := big.NewInt(int64(len(ret))) // TODO: Nto the best design. env.Create can do it, it has the reference to gas counter
334333
dataGas.Mul(dataGas, GasCreateByte)
335334
gas.Sub(gas, dataGas)
336335
*result = hash2llvm(ref.Address())
337336
}
338-
*llvmGas = big2llvm(gas)
337+
*_gas = gas.Int64()
339338
}
340339

341340
//export env_log
@@ -358,7 +357,7 @@ func env_log(_vm unsafe.Pointer, dataPtr unsafe.Pointer, dataLen uint64, _topic1
358357
topics = append(topics, llvm2hash((*i256)(_topic4)))
359358
}
360359

361-
vm.Env().AddLog(state.NewLog(vm.me.Address(), topics, data))
360+
vm.Env().AddLog(state.NewLog(vm.me.Address(), topics, data, vm.env.BlockNumber().Uint64()))
362361
}
363362

364363
//export env_extcode

0 commit comments

Comments
 (0)