block/state: gas price for block and tx

This commit is contained in:
Ethan Buchman
2015-03-18 02:12:03 -07:00
committed by Jae Kwon
parent 7a33aba6e5
commit f384d10a05
4 changed files with 30 additions and 15 deletions

View File

@@ -4,6 +4,7 @@ import (
"bytes"
"errors"
"fmt"
"math/big"
"time"
"github.com/tendermint/tendermint/account"
@@ -234,7 +235,7 @@ func (s *State) AdjustByOutputs(accounts map[string]*account.Account, outs []*bl
// If the tx is invalid, an error will be returned.
// Unlike AppendBlock(), state will not be altered.
func (s *State) ExecTx(tx_ blk.Tx) error {
func (s *State) ExecTx(tx_ blk.Tx, blk_ *blk.Block) error {
// TODO: do something with fees
fees := uint64(0)
@@ -296,8 +297,15 @@ func (s *State) ExecTx(tx_ blk.Tx) error {
}
accounts[string(tx.Address)] = outAcc
// TODO: fees
// inTotal -= fees
// ensure sufficient gas price
// we multiply to avoid dividing
bigProvidedFee := new(big.Int).Mul(big.NewInt(int64(tx.FeeLimit)), big.NewInt(int64(blk.GasPriceDivisor)))
bigMinFee := new(big.Int).Mul(big.NewInt(int64(blk_.GasPrice)), big.NewInt(int64(tx.GasLimit)))
if bigProvidedFee.Cmp(bigMinFee) < 0 {
return blk.ErrTxInsufficientGasPrice
}
inTotal -= tx.FeeLimit
// Good! Adjust accounts
s.AdjustByInputs(accounts, []*blk.TxInput{tx.Input})
@@ -306,6 +314,8 @@ func (s *State) ExecTx(tx_ blk.Tx) error {
// TODO: Run the contract call!
// TODO: refund some gas
return nil
case *blk.BondTx:
@@ -640,7 +650,7 @@ func (s *State) appendBlock(block *blk.Block, blockPartsHeader blk.PartSetHeader
// Commit each tx
for _, tx := range block.Data.Txs {
err := s.ExecTx(tx)
err := s.ExecTx(tx, block)
if err != nil {
return InvalidTxError{tx, err}
}

View File

@@ -183,7 +183,7 @@ func TestTxSequence(t *testing.T) {
tx := makeSendTx(sequence)
tx.Inputs[0].Signature = privAccounts[0].Sign(tx)
stateCopy := state.Copy()
err := stateCopy.ExecTx(tx)
err := stateCopy.ExecTx(tx, &blk.Block{})
if i == 1 {
// Sequence is good.
if err != nil {
@@ -242,7 +242,7 @@ func TestTxs(t *testing.T) {
}
tx.Inputs[0].Signature = privAccounts[0].Sign(tx)
err := state.ExecTx(tx)
err := state.ExecTx(tx, &blk.Block{})
if err != nil {
t.Errorf("Got error in executing send transaction, %v", err)
}
@@ -279,7 +279,7 @@ func TestTxs(t *testing.T) {
},
}
tx.Inputs[0].Signature = privAccounts[0].Sign(tx)
err := state.ExecTx(tx)
err := state.ExecTx(tx, &blk.Block{})
if err != nil {
t.Errorf("Got error in executing bond transaction, %v", err)
}