core/types: make blocks immutable

This commit is contained in:
Felix Lange
2015-06-16 12:41:50 +02:00
committed by Jeffrey Wilcke
parent 654564e164
commit 1d42888d30
17 changed files with 457 additions and 587 deletions

View File

@ -73,16 +73,17 @@ func MessageGasValue(msg Message) *big.Int {
return new(big.Int).Mul(msg.Gas(), msg.GasPrice())
}
func IntrinsicGas(msg Message) *big.Int {
// IntrinsicGas computes the 'intrisic gas' for a message
// with the given data.
func IntrinsicGas(data []byte) *big.Int {
igas := new(big.Int).Set(params.TxGas)
for _, byt := range msg.Data() {
for _, byt := range data {
if byt != 0 {
igas.Add(igas, params.TxDataNonZeroGas)
} else {
igas.Add(igas, params.TxDataZeroGas)
}
}
return igas
}
@ -195,7 +196,7 @@ func (self *StateTransition) transitionState() (ret []byte, usedGas *big.Int, er
sender, _ := self.From() // err checked in preCheck
// Pay intrinsic gas
if err = self.UseGas(IntrinsicGas(self.msg)); err != nil {
if err = self.UseGas(IntrinsicGas(self.msg.Data())); err != nil {
return nil, nil, InvalidTxError(err)
}