|
|
@@ -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 {
|