diff options
author | obscuren <geffobscura@gmail.com> | 2015-04-09 02:47:32 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-04-09 02:47:32 +0800 |
commit | 6184781b49242b8029522612ad94cd45b508abc1 (patch) | |
tree | 4e8822e2000a885018e712b9cefb2a2ac3a512ca /core/state_transition.go | |
parent | a7750c929b926d164195fd4f7a7e2b4642c66173 (diff) | |
download | dexon-6184781b49242b8029522612ad94cd45b508abc1.tar.gz dexon-6184781b49242b8029522612ad94cd45b508abc1.tar.zst dexon-6184781b49242b8029522612ad94cd45b508abc1.zip |
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
Diffstat (limited to 'core/state_transition.go')
-rw-r--r-- | core/state_transition.go | 31 |
1 files changed, 15 insertions, 16 deletions
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) } |