From 6184781b49242b8029522612ad94cd45b508abc1 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 8 Apr 2015 20:47:32 +0200 Subject: Improved transaction pool The transaction pool will now some easily be able to pre determine the validity of a transaction by checking the following: * Account existst * gas limit higher than the instrinsic gas * enough funds to pay upfront costs * nonce check --- core/state_transition.go | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'core/state_transition.go') diff --git a/core/state_transition.go b/core/state_transition.go index e67abb951..d95cbd35a 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -74,6 +74,19 @@ func MessageGasValue(msg Message) *big.Int { return new(big.Int).Mul(msg.Gas(), msg.GasPrice()) } +func IntrinsicGas(msg Message) *big.Int { + igas := new(big.Int).Set(params.TxGas) + for _, byt := range msg.Data() { + if byt != 0 { + igas.Add(igas, params.TxDataNonZeroGas) + } else { + igas.Add(igas, params.TxDataZeroGas) + } + } + + return igas +} + func ApplyMessage(env vm.Environment, msg Message, coinbase *state.StateObject) ([]byte, *big.Int, error) { return NewStateTransition(env, msg, coinbase).transitionState() } @@ -177,22 +190,8 @@ func (self *StateTransition) transitionState() (ret []byte, usedGas *big.Int, er sender = self.From() ) - // Transaction gas - if err = self.UseGas(params.TxGas); err != nil { - return nil, nil, InvalidTxError(err) - } - - // Pay data gas - dgas := new(big.Int) - for _, byt := range self.data { - if byt != 0 { - dgas.Add(dgas, params.TxDataNonZeroGas) - } else { - dgas.Add(dgas, params.TxDataZeroGas) - } - } - - if err = self.UseGas(dgas); err != nil { + // Pay intrinsic gas + if err = self.UseGas(IntrinsicGas(self.msg)); err != nil { return nil, nil, InvalidTxError(err) } -- cgit