diff options
author | Felix Lange <fjl@twurst.com> | 2015-06-26 20:17:36 +0800 |
---|---|---|
committer | Jeffrey Wilcke <geffobscura@gmail.com> | 2015-06-30 00:51:48 +0800 |
commit | fccc7d71eb1e8e655f9bcd9c6d7856b70bbeda36 (patch) | |
tree | 4c6f3a04cb1e5f8e28e806be66e3287d8dd19e5e /core/state_transition.go | |
parent | d0bb90c69e5572417128fdb8188f53cc45f76002 (diff) | |
download | dexon-fccc7d71eb1e8e655f9bcd9c6d7856b70bbeda36.tar.gz dexon-fccc7d71eb1e8e655f9bcd9c6d7856b70bbeda36.tar.zst dexon-fccc7d71eb1e8e655f9bcd9c6d7856b70bbeda36.zip |
core: remove superfluous big.Int allocations
With blocks now being immutable, use big.Int values from
accessor functions instead of copying their results.
Diffstat (limited to 'core/state_transition.go')
-rw-r--r-- | core/state_transition.go | 38 |
1 files changed, 13 insertions, 25 deletions
diff --git a/core/state_transition.go b/core/state_transition.go index 60bd36d90..e2212dfef 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -13,10 +13,6 @@ import ( "github.com/ethereum/go-ethereum/params" ) -const tryJit = false - -var () - /* * The State transitioning model * @@ -69,10 +65,6 @@ func MessageCreatesContract(msg Message) bool { return msg.To() == nil } -func MessageGasValue(msg Message) *big.Int { - return new(big.Int).Mul(msg.Gas(), msg.GasPrice()) -} - // IntrinsicGas computes the 'intrisic gas' for a message // with the given data. func IntrinsicGas(data []byte) *big.Int { @@ -104,7 +96,7 @@ func NewStateTransition(env vm.Environment, msg Message, coinbase *state.StateOb env: env, msg: msg, gas: new(big.Int), - gasPrice: new(big.Int).Set(msg.GasPrice()), + gasPrice: msg.GasPrice(), initialGas: new(big.Int), value: msg.Value(), data: msg.Data(), @@ -148,26 +140,22 @@ func (self *StateTransition) AddGas(amount *big.Int) { } func (self *StateTransition) BuyGas() error { - var err error + mgas := self.msg.Gas() + mgval := new(big.Int).Mul(mgas, self.gasPrice) sender, err := self.From() if err != nil { return err } - if sender.Balance().Cmp(MessageGasValue(self.msg)) < 0 { - return fmt.Errorf("insufficient ETH for gas (%x). Req %v, has %v", sender.Address().Bytes()[:4], MessageGasValue(self.msg), sender.Balance()) + if sender.Balance().Cmp(mgval) < 0 { + return fmt.Errorf("insufficient ETH for gas (%x). Req %v, has %v", sender.Address().Bytes()[:4], mgval, sender.Balance()) } - - coinbase := self.Coinbase() - err = coinbase.SubGas(self.msg.Gas(), self.msg.GasPrice()) - if err != nil { + if err = self.Coinbase().SubGas(mgas, self.gasPrice); err != nil { return err } - - self.AddGas(self.msg.Gas()) - self.initialGas.Set(self.msg.Gas()) - sender.SubBalance(MessageGasValue(self.msg)) - + self.AddGas(mgas) + self.initialGas.Set(mgas) + sender.SubBalance(mgval) return nil } @@ -245,15 +233,15 @@ func (self *StateTransition) refundGas() { coinbase := self.Coinbase() sender, _ := self.From() // err already checked // Return remaining gas - remaining := new(big.Int).Mul(self.gas, self.msg.GasPrice()) + remaining := new(big.Int).Mul(self.gas, self.gasPrice) sender.AddBalance(remaining) - uhalf := new(big.Int).Div(self.gasUsed(), common.Big2) + uhalf := remaining.Div(self.gasUsed(), common.Big2) refund := common.BigMin(uhalf, self.state.Refunds()) self.gas.Add(self.gas, refund) - self.state.AddBalance(sender.Address(), refund.Mul(refund, self.msg.GasPrice())) + self.state.AddBalance(sender.Address(), refund.Mul(refund, self.gasPrice)) - coinbase.AddGas(self.gas, self.msg.GasPrice()) + coinbase.AddGas(self.gas, self.gasPrice) } func (self *StateTransition) gasUsed() *big.Int { |