aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-12-20 09:21:13 +0800
committerobscuren <geffobscura@gmail.com>2014-12-20 09:21:13 +0800
commit1508a23a6fe3cc50f718bfd6c62caae056534c09 (patch)
tree78853077f6b961bf27c5bdf74673c255e96aba1d /core
parentf5b8f3d41b533d51eb81e895ed9b6aa31d7aaaef (diff)
downloadgo-tangerine-1508a23a6fe3cc50f718bfd6c62caae056534c09.tar
go-tangerine-1508a23a6fe3cc50f718bfd6c62caae056534c09.tar.gz
go-tangerine-1508a23a6fe3cc50f718bfd6c62caae056534c09.tar.bz2
go-tangerine-1508a23a6fe3cc50f718bfd6c62caae056534c09.tar.lz
go-tangerine-1508a23a6fe3cc50f718bfd6c62caae056534c09.tar.xz
go-tangerine-1508a23a6fe3cc50f718bfd6c62caae056534c09.tar.zst
go-tangerine-1508a23a6fe3cc50f718bfd6c62caae056534c09.zip
Minor updates on gas and removed/refactored old code.
Diffstat (limited to 'core')
-rw-r--r--core/block_manager.go4
-rw-r--r--core/execution.go15
-rw-r--r--core/state_transition.go21
3 files changed, 19 insertions, 21 deletions
diff --git a/core/block_manager.go b/core/block_manager.go
index 20285f8f0..2567e39c4 100644
--- a/core/block_manager.go
+++ b/core/block_manager.go
@@ -142,6 +142,7 @@ done:
receipt := types.NewReceipt(state.Root(), cumulative)
receipt.SetLogs(state.Logs())
receipt.Bloom = types.CreateBloom(types.Receipts{receipt})
+ chainlogger.Debugln(receipt)
// Notify all subscribers
if !transientProcess {
@@ -214,7 +215,8 @@ func (sm *BlockManager) ProcessWithParent(block, parent *types.Block) (td *big.I
receiptSha := types.DeriveSha(receipts)
if bytes.Compare(receiptSha, block.ReceiptSha) != 0 {
- chainlogger.Debugln(receipts)
+ //chainlogger.Debugf("validating receipt root. received=%x got=%x", block.ReceiptSha, receiptSha)
+ fmt.Printf("%x\n", ethutil.Encode(receipts))
err = fmt.Errorf("validating receipt root. received=%x got=%x", block.ReceiptSha, receiptSha)
return
}
diff --git a/core/execution.go b/core/execution.go
index 44dbd3ace..b7eead0dd 100644
--- a/core/execution.go
+++ b/core/execution.go
@@ -3,6 +3,7 @@ package core
import (
"fmt"
"math/big"
+ "time"
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/vm"
@@ -12,7 +13,6 @@ type Execution struct {
env vm.Environment
address, input []byte
Gas, price, value *big.Int
- object *state.StateObject
SkipTransfer bool
}
@@ -35,8 +35,6 @@ func (self *Execution) exec(code, contextAddr []byte, caller vm.ClosureRef) (ret
env := self.env
evm := vm.New(env, vm.DebugVmTy)
- chainlogger.Debugf("pre state %x\n", env.State().Root())
-
if env.Depth() == vm.MaxCallDepth {
// Consume all gas (by not returning it) and return a depth error
return nil, vm.DepthError{}
@@ -55,13 +53,12 @@ func (self *Execution) exec(code, contextAddr []byte, caller vm.ClosureRef) (ret
}
snapshot := env.State().Copy()
- defer func() {
- env.State().Set(snapshot)
- chainlogger.Debugf("post state %x\n", env.State().Root())
- }()
-
- self.object = to
+ start := time.Now()
ret, err = evm.Run(to, caller, code, self.value, self.Gas, self.price, self.input)
+ if err != nil {
+ env.State().Set(snapshot)
+ }
+ chainlogger.Debugf("vm took %v\n", time.Since(start))
return
}
diff --git a/core/state_transition.go b/core/state_transition.go
index a60f31e3e..7b7026c29 100644
--- a/core/state_transition.go
+++ b/core/state_transition.go
@@ -186,13 +186,13 @@ func (self *StateTransition) TransitionState() (ret []byte, err error) {
vmenv := self.VmEnv()
var ref vm.ClosureRef
if MessageCreatesContract(msg) {
- self.rec = MakeContract(msg, self.state)
-
- ret, err, ref = vmenv.Create(sender, self.rec.Address(), self.msg.Data(), self.gas, self.gasPrice, self.value)
+ contract := MakeContract(msg, self.state)
+ ret, err, ref = vmenv.Create(sender, contract.Address(), self.msg.Data(), self.gas, self.gasPrice, self.value)
if err == nil {
dataGas := big.NewInt(int64(len(ret)))
dataGas.Mul(dataGas, vm.GasCreateByte)
if err = self.UseGas(dataGas); err == nil {
+ //self.state.SetCode(ref.Address(), ret)
ref.SetCode(ret)
}
}
@@ -218,20 +218,19 @@ func MakeContract(msg Message, state *state.StateDB) *state.StateObject {
}
func (self *StateTransition) RefundGas() {
- coinbaseSub := new(big.Int).Set(self.gas)
+ coinbase, sender := self.Coinbase(), self.From()
+ // Return remaining gas
+ remaining := new(big.Int).Mul(self.gas, self.msg.GasPrice())
+ sender.AddAmount(remaining)
+
uhalf := new(big.Int).Div(self.GasUsed(), ethutil.Big2)
for addr, ref := range self.state.Refunds() {
refund := ethutil.BigMin(uhalf, ref)
- coinbaseSub.Add(self.gas, refund)
+ self.gas.Add(self.gas, refund)
self.state.AddBalance([]byte(addr), refund.Mul(refund, self.msg.GasPrice()))
}
- coinbase, sender := self.Coinbase(), self.From()
- coinbase.RefundGas(coinbaseSub, self.msg.GasPrice())
-
- // Return remaining gas
- remaining := new(big.Int).Mul(self.gas, self.msg.GasPrice())
- sender.AddAmount(remaining)
+ coinbase.RefundGas(self.gas, self.msg.GasPrice())
}
func (self *StateTransition) GasUsed() *big.Int {