Skip to content
This repository has been archived by the owner on Dec 21, 2022. It is now read-only.

Change system fee to gas fee #1

Merged
merged 3 commits into from
Apr 16, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func PostCommands(cmds ...*cobra.Command) []*cobra.Command {
c.Flags().Uint64P(FlagAccountNumber, "a", 0, "The account number of the signing account (offline mode only)")
c.Flags().Uint64(FlagSequence, 0, "The sequence number of the signing account (offline mode only)")
c.Flags().String(FlagMemo, "", "Memo to send along with transaction")
c.Flags().String(FlagFees, "", "Fees to pay along with transaction; eg: 1"+types.DefaultBondDenom)
c.Flags().String(FlagFees, "0.0125"+types.DefaultBondDenom, "Fees to pay along with transaction; eg: 1"+types.DefaultBondDenom)
louisliu2048 marked this conversation as resolved.
Show resolved Hide resolved
c.Flags().String(FlagGasPrices, "", "Gas prices to determine the transaction fee (e.g. 1"+types.DefaultBondDenom+")")
c.Flags().String(FlagNode, "tcp://localhost:26657", "<host>:<port> to tendermint rpc interface for this chain")
c.Flags().Bool(FlagUseLedger, false, "Use a connected Ledger device")
Expand Down
3 changes: 2 additions & 1 deletion server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package server

import (
"fmt"
"github.com/cosmos/cosmos-sdk/types"
"os"
"runtime/pprof"

Expand Down Expand Up @@ -81,7 +82,7 @@ which accepts a path for the resulting pprof file.
cmd.Flags().String(flagTraceStore, "", "Enable KVStore tracing to an output file")
cmd.Flags().String(flagPruning, "syncable", "Pruning strategy: syncable, nothing, everything")
cmd.Flags().String(
louisliu2048 marked this conversation as resolved.
Show resolved Hide resolved
FlagMinGasPrices, "",
FlagMinGasPrices, "0.00000001"+types.DefaultBondDenom,
louisliu2048 marked this conversation as resolved.
Show resolved Hide resolved
"Minimum gas prices to accept for transactions; Any fee in a tx must meet this minimum (e.g. 0.01photino;0.0001stake)",
)
cmd.Flags().Uint64(FlagHaltHeight, 0, "Height at which to gracefully halt the chain and shutdown the node")
Expand Down
6 changes: 3 additions & 3 deletions types/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ func (logs ABCIMessageLogs) String() (str string) {
// TxResponse defines a structure containing relevant tx data and metadata. The
// tags are stringified and the log is JSON decoded.
type TxResponse struct {
Height int64 `json:"height,omitempty"`
Height int64 `json:"height"`
TxHash string `json:"txhash"`
Code uint32 `json:"code,omitempty"`
Data string `json:"data,omitempty"`
RawLog string `json:"raw_log,omitempty"`
Logs ABCIMessageLogs `json:"logs,omitempty"`
Info string `json:"info,omitempty"`
GasWanted int64 `json:"-"`
GasUsed int64 `json:"-"`
GasWanted int64 `json:"gas_wanted,omitempty"`
GasUsed int64 `json:"gas_used,omitempty"`
Codespace string `json:"codespace,omitempty"`
Tx Tx `json:"tx,omitempty"`
Timestamp string `json:"timestamp,omitempty"`
Expand Down
34 changes: 18 additions & 16 deletions x/auth/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ func NewAnteHandler(ak AccountKeeper, supplyKeeper types.SupplyKeeper,
}
}

//newCtx = SetGasMeter(simulate, ctx, stdTx.Fee.Gas)
newCtx = ctx.WithGasMeter(sdk.NewInfiniteGasMeter())
newCtx = SetGasMeter(simulate, ctx, stdTx.Fee.Gas)

// AnteHandlers must have their own defer/recover in order for the BaseApp
// to know how much gas was used! This is because the GasMeter is created in
Expand Down Expand Up @@ -119,10 +118,15 @@ func NewAnteHandler(ak AccountKeeper, supplyKeeper types.SupplyKeeper,
return newCtx, res, true
}

isFree := false
if isSystemFreeHandler != nil {
isFree = isSystemFreeHandler(ctx, stdTx.GetMsgs())
}


// deduct the fees
msgs := stdTx.GetMsgs()
if isSystemFreeHandler != nil && !isSystemFreeHandler(ctx, msgs) {
res = DeductFees(supplyKeeper, newCtx, signerAccs[0], sdk.GetSystemFee().ToCoins())
if !stdTx.Fee.Amount.IsZero() && !isFree {
res = DeductFees(supplyKeeper, newCtx, signerAccs[0], stdTx.Fee.Amount)
if !res.IsOK() {
return newCtx, res, true
}
Expand Down Expand Up @@ -156,19 +160,17 @@ func NewAnteHandler(ak AccountKeeper, supplyKeeper types.SupplyKeeper,
}

// *ABORT* the tx in case of failing to validate it in checkTx mode
if newCtx.IsCheckTx() && !simulate {
if validateMsgHandler != nil {
res := validateMsgHandler(newCtx, msgs)
if !res.IsOK() {
return newCtx, res, true
}
if newCtx.IsCheckTx() && !simulate && validateMsgHandler != nil {
res := validateMsgHandler(newCtx, stdTx.GetMsgs())
if !res.IsOK() {
return newCtx, res, true
}
}

//stat actual system fee
actualSysFee := sdk.GetSystemFee()
if isSystemFreeHandler != nil && isSystemFreeHandler(ctx, msgs) {
actualSysFee = sdk.ZeroFee()
actualSysFee := stdTx.Fee.Amount
if isFree {
actualSysFee = sdk.ZeroFee().ToCoins()
}

//fire systemFee event
Expand All @@ -178,7 +180,7 @@ func NewAnteHandler(ak AccountKeeper, supplyKeeper types.SupplyKeeper,
sdk.NewAttribute(sdk.AttributeKeyFee, actualSysFee.String()),
),
)
// TODO: tx tags (?), abandoned
// TODO: tx tags (?)
return newCtx, sdk.Result{GasWanted: stdTx.Fee.Gas, Events: ctx.EventManager().Events()}, false
}
}
Expand Down Expand Up @@ -412,7 +414,7 @@ func EnsureSufficientMempoolFees(ctx sdk.Context, stdFee StdFee) sdk.Result {
glDec := sdk.NewDec(int64(stdFee.Gas))
for i, gp := range minGasPrices {
fee := gp.Amount.Mul(glDec)
requiredFees[i] = sdk.NewCoin(gp.Denom, fee.Ceil().RoundInt())
requiredFees[i] = sdk.NewDecCoinFromDec(gp.Denom, fee)
}

if !stdFee.Amount.IsAnyGTE(requiredFees) {
Expand Down
2 changes: 1 addition & 1 deletion x/auth/types/stdtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var (
// NOTE: the first signature is the fee payer (Signatures must not be nil).
type StdTx struct {
Msgs []sdk.Msg `json:"msg" yaml:"msg"`
Fee StdFee `json:"-" yaml:"fee"`
Fee StdFee `json:"fee" yaml:"fee"`
Signatures []StdSignature `json:"signatures" yaml:"signatures"`
Memo string `json:"memo" yaml:"memo"`
}
Expand Down
3 changes: 2 additions & 1 deletion x/auth/types/txbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ func (bldr TxBuilder) BuildSignMsg(msgs []sdk.Msg) (StdSignMsg, error) {
fees = make(sdk.Coins, len(bldr.gasPrices))
for i, gp := range bldr.gasPrices {
fee := gp.Amount.Mul(glDec)
fees[i] = sdk.NewCoin(gp.Denom, fee.Ceil().RoundInt())
//fees[i] = sdk.NewCoin(gp.Denom, fee.Ceil().RoundInt())
louisliu2048 marked this conversation as resolved.
Show resolved Hide resolved
fees[i] = sdk.NewDecCoinFromDec(gp.Denom, fee)
}
}

Expand Down