Moved all gas and payment values to uint64 to make sure we are safe here

This commit is contained in:
Ethan Frey 2017-08-04 14:11:01 +02:00
parent 2f4f875dd4
commit 640f06998a
11 changed files with 24 additions and 24 deletions

View File

@ -99,14 +99,14 @@ type CheckResult struct {
Data data.Bytes Data data.Bytes
Log string Log string
// GasAllocated is the maximum units of work we allow this tx to perform // GasAllocated is the maximum units of work we allow this tx to perform
GasAllocated uint GasAllocated uint64
// GasPayment is the total fees for this tx (or other source of payment) // GasPayment is the total fees for this tx (or other source of payment)
GasPayment uint GasPayment uint64
} }
// NewCheck sets the gas used and the response data but no more info // NewCheck sets the gas used and the response data but no more info
// these are the most common info needed to be set by the Handler // these are the most common info needed to be set by the Handler
func NewCheck(gasAllocated uint, log string) CheckResult { func NewCheck(gasAllocated uint64, log string) CheckResult {
return CheckResult{ return CheckResult{
GasAllocated: gasAllocated, GasAllocated: gasAllocated,
Log: log, Log: log,
@ -129,7 +129,7 @@ type DeliverResult struct {
Data data.Bytes Data data.Bytes
Log string Log string
Diff []*abci.Validator Diff []*abci.Validator
GasUsed uint GasUsed uint64
} }
var _ Result = DeliverResult{} var _ Result = DeliverResult{}

View File

@ -103,11 +103,11 @@ func (PriceHandler) DeliverTx(ctx basecoin.Context, store state.SimpleDB,
// PriceShowTx lets us bounce back a given fee/gas on CheckTx // PriceShowTx lets us bounce back a given fee/gas on CheckTx
type PriceShowTx struct { type PriceShowTx struct {
GasAllocated uint GasAllocated uint64
GasPayment uint GasPayment uint64
} }
func NewPriceShowTx(gasAllocated, gasPayment uint) basecoin.Tx { func NewPriceShowTx(gasAllocated, gasPayment uint64) basecoin.Tx {
return PriceShowTx{GasAllocated: gasAllocated, GasPayment: gasPayment}.Wrap() return PriceShowTx{GasAllocated: gasAllocated, GasPayment: gasPayment}.Wrap()
} }

View File

@ -77,7 +77,7 @@ func runAllDelivers(ctx basecoin.Context, store state.SimpleDB, txs []basecoin.T
func combineChecks(all []basecoin.CheckResult) basecoin.CheckResult { func combineChecks(all []basecoin.CheckResult) basecoin.CheckResult {
datas := make([]data.Bytes, len(all)) datas := make([]data.Bytes, len(all))
logs := make([]string, len(all)) logs := make([]string, len(all))
var allocated, payments uint var allocated, payments uint64
for i, r := range all { for i, r := range all {
datas[i] = r.Data datas[i] = r.Data
logs[i] = r.Log logs[i] = r.Log
@ -97,7 +97,7 @@ func combineChecks(all []basecoin.CheckResult) basecoin.CheckResult {
func combineDelivers(all []basecoin.DeliverResult) basecoin.DeliverResult { func combineDelivers(all []basecoin.DeliverResult) basecoin.DeliverResult {
datas := make([]data.Bytes, len(all)) datas := make([]data.Bytes, len(all))
logs := make([]string, len(all)) logs := make([]string, len(all))
var used uint var used uint64
var diffs []*abci.Validator var diffs []*abci.Validator
for i, r := range all { for i, r := range all {
datas[i] = r.Data datas[i] = r.Data

View File

@ -43,8 +43,8 @@ func TestMultiplexer(t *testing.T) {
cases := [...]struct { cases := [...]struct {
tx basecoin.Tx tx basecoin.Tx
valid bool valid bool
gasAllocated uint gasAllocated uint64
gasPayment uint gasPayment uint64
log string log string
data data.Bytes data data.Bytes
}{ }{

View File

@ -16,9 +16,9 @@ const (
//NameCoin - name space of the coin module //NameCoin - name space of the coin module
NameCoin = "coin" NameCoin = "coin"
// CostSend is GasAllocation per input/output // CostSend is GasAllocation per input/output
CostSend = uint(10) CostSend = uint64(10)
// CostCredit is GasAllocation of a credit allocation // CostCredit is GasAllocation of a credit allocation
CostCredit = uint(20) CostCredit = uint64(20)
) )
// Handler includes an accountant // Handler includes an accountant
@ -53,7 +53,7 @@ func (h Handler) CheckTx(ctx basecoin.Context, store state.SimpleDB,
switch t := tx.Unwrap().(type) { switch t := tx.Unwrap().(type) {
case SendTx: case SendTx:
// price based on inputs and outputs // price based on inputs and outputs
used := uint(len(t.Inputs) + len(t.Outputs)) used := uint64(len(t.Inputs) + len(t.Outputs))
return basecoin.NewCheck(used*CostSend, ""), h.checkSendTx(ctx, store, t) return basecoin.NewCheck(used*CostSend, ""), h.checkSendTx(ctx, store, t)
case CreditTx: case CreditTx:
// default price of 20, constant work // default price of 20, constant work

View File

@ -110,7 +110,7 @@ func TestCheckDeliverSendTx(t *testing.T) {
tx basecoin.Tx tx basecoin.Tx
perms []basecoin.Actor perms []basecoin.Actor
final []money // nil for error final []money // nil for error
cost uint // gas allocated (if not error) cost uint64 // gas allocated (if not error)
}{ }{
{ {
[]money{{addr1, moreCoins}}, []money{{addr1, moreCoins}},
@ -175,7 +175,7 @@ func TestCheckDeliverSendTx(t *testing.T) {
assert.Nil(err, "%d: %+v", i, err) assert.Nil(err, "%d: %+v", i, err)
assert.Nil(err2, "%d: %+v", i, err2) assert.Nil(err2, "%d: %+v", i, err2)
// make sure proper gas is set // make sure proper gas is set
assert.Equal(uint(0), cres.GasPayment, "%d", i) assert.Equal(uint64(0), cres.GasPayment, "%d", i)
assert.Equal(tc.cost, cres.GasAllocated, "%d", i) assert.Equal(tc.cost, cres.GasAllocated, "%d", i)
// make sure the final balances are correct // make sure the final balances are correct
for _, f := range tc.final { for _, f := range tc.final {

View File

@ -55,14 +55,14 @@ func (h SimpleFeeMiddleware) CheckTx(ctx basecoin.Context, store state.SimpleDB,
return res, err return res, err
} }
var paid, used uint var paid, used uint64
if !fee.Fee.IsZero() { // now, try to make a IPC call to coins... if !fee.Fee.IsZero() { // now, try to make a IPC call to coins...
send := coin.NewSendOneTx(fee.Payer, h.Collector, coin.Coins{fee.Fee}) send := coin.NewSendOneTx(fee.Payer, h.Collector, coin.Coins{fee.Fee})
sendRes, err := next.CheckTx(ctx, store, send) sendRes, err := next.CheckTx(ctx, store, send)
if err != nil { if err != nil {
return res, err return res, err
} }
paid = uint(fee.Fee.Amount) paid = uint64(fee.Fee.Amount)
used = sendRes.GasAllocated used = sendRes.GasAllocated
} }

View File

@ -71,7 +71,7 @@ func TestFeeChecks(t *testing.T) {
left coin.Coins left coin.Coins
collected coin.Coins collected coin.Coins
// expected gas allocated // expected gas allocated
expectedCost uint expectedCost uint64
}{ }{
// make sure it works with no fee (control group) // make sure it works with no fee (control group)
{true, app1, act1, false, act1, zero, mixed, nil, 0}, {true, app1, act1, false, act1, zero, mixed, nil, 0},

View File

@ -10,9 +10,9 @@ const (
//NameRole - name space of the roles module //NameRole - name space of the roles module
NameRole = "role" NameRole = "role"
// CostCreate is the cost to create a new role // CostCreate is the cost to create a new role
CostCreate = uint(40) CostCreate = uint64(40)
// CostAssume is the cost to assume a role as part of a tx // CostAssume is the cost to assume a role as part of a tx
CostAssume = uint(5) CostAssume = uint64(5)
) )
// Handler allows us to create new roles // Handler allows us to create new roles

View File

@ -44,7 +44,7 @@ func TestCreateRole(t *testing.T) {
assert.Nil(err, "%d/%s: %+v", i, tc.role, err) assert.Nil(err, "%d/%s: %+v", i, tc.role, err)
assert.Nil(err2, "%d/%s: %+v", i, tc.role, err2) assert.Nil(err2, "%d/%s: %+v", i, tc.role, err2)
assert.Equal(roles.CostCreate, cres.GasAllocated) assert.Equal(roles.CostCreate, cres.GasAllocated)
assert.Equal(uint(0), cres.GasPayment) assert.Equal(uint64(0), cres.GasPayment)
} else { } else {
assert.NotNil(err, "%d/%s", i, tc.role) assert.NotNil(err, "%d/%s", i, tc.role)
assert.NotNil(err2, "%d/%s", i, tc.role) assert.NotNil(err2, "%d/%s", i, tc.role)

View File

@ -99,8 +99,8 @@ func TestAssumeRole(t *testing.T) {
assert.Nil(err, "%d: %+v", i, err) assert.Nil(err, "%d: %+v", i, err)
assert.Nil(err2, "%d: %+v", i, err2) assert.Nil(err2, "%d: %+v", i, err2)
// make sure we charge for each role // make sure we charge for each role
assert.Equal(roles.CostAssume*uint(len(tc.roles)), cres.GasAllocated) assert.Equal(roles.CostAssume*uint64(len(tc.roles)), cres.GasAllocated)
assert.Equal(uint(0), cres.GasPayment) assert.Equal(uint64(0), cres.GasPayment)
} else { } else {
assert.NotNil(err, "%d", i) assert.NotNil(err, "%d", i)
assert.NotNil(err2, "%d", i) assert.NotNil(err2, "%d", i)