You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
One question that confused me is that:why we charge the gasWant fee but not the gasUsed fee?
Problem Definition
Since in the func (app *BaseApp) runTx(mode runTxMode, txBytes []byte, tx sdk.Tx) (gInfo sdk.GasInfo, result *sdk.Result, err error){}
function, we can get the gasWanted after run the app.anteHandler and we also get the gasUsed after we run the app.runMsgs, why not do something more to make the right gas charge.
Proposal
Here is my mind:
1、Add a WithdrawHandler type in cosmos-sdk/types/handler.go: type WithdrawHandler func(ctx Context, tx Tx, fee uint64)(newCtx Context, err error)
2、Add a withdrawHandler field for BaseApp in cosmos-sdk/baseapp/baseapp.go:
type BaseApp struct {
...
// set upon LoadVersion or LoadLatestVersion.
baseKey *sdk.KVStoreKey // Main KVStore in cms
withdrawHandler sdk.WithdrawHandler
anteHandler sdk.AnteHandler // ante handler for fee and auth
initChainer sdk.InitChainer // initialize state with validators and state blob
...
}
And add a SetWithdrawHandler func for the BaseApp struct:
func (app *BaseApp) SetWithdrawHandler(wh sdk.WithdrawHandler) {
if app.sealed {
panic("SetWithdrawHandler() on sealed BaseApp")
}
app.withdrawHandler = wh
}
3、Modify the runTx function in cosmos-sdk/baseapp/baseapp.go:
func (app *BaseApp) runTx(mode runTxMode, txBytes []byte, tx sdk.Tx) (gInfo sdk.GasInfo, result *sdk.Result, err error) {
...
// Attempt to execute all messages and only update state if all messages pass
// and we're in DeliverTx. Note, runMsgs will never return a reference to a
// Result if any single message fails or does not have a registered Handler.
result, err = app.runMsgs(runMsgCtx, msgs, mode)
if err == nil && mode == runTxModeDeliver {
msCache.Write()
}
// If the origin apps do not want to add a feeHandler, just ignore it, everything will still be ok
if app.withdrawHandler != nil {
gasUsed := runMsgCtx.GasMeter().GasConsumed()
if gasWanted > gasUsed {
app.withdrawHandler(runMsgCtx, tx, gasWanted - gasUsed)
// The withdraw Handler will do something like this:
// supplyKeeper.SendCoinsFromModuleToAccount(ctx, acc.GetAddress(), types.FeeCollectorName, fees)
}
// if gasUsed > gasWanted, it will fail and return when runMsgs
}
return gInfo, result, err
}
4、 Add a default withdrawHandler in x/auth module, the process has been describe in step 3.
For Admin Use
Not duplicate issue
Appropriate labels applied
Appropriate contributors tagged
Contributor assigned/self-assigned
The text was updated successfully, but these errors were encountered:
Currently, we charge the gas fee: gas_price * gas_wanted,not the gas_price * gas_used, that means the end user need to pay more money. The Ethereum platform only charge gas_used * gas_price and will return the money that unused.
Summary
One question that confused me is that:why we charge the gasWant fee but not the gasUsed fee?
Problem Definition
Since in the
func (app *BaseApp) runTx(mode runTxMode, txBytes []byte, tx sdk.Tx) (gInfo sdk.GasInfo, result *sdk.Result, err error){}
function, we can get the gasWanted after run the
app.anteHandler
and we also get the gasUsed after we run theapp.runMsgs
, why not do something more to make the right gas charge.Proposal
Here is my mind:
1、Add a WithdrawHandler type in cosmos-sdk/types/handler.go:
type WithdrawHandler func(ctx Context, tx Tx, fee uint64)(newCtx Context, err error)
2、Add a withdrawHandler field for BaseApp in cosmos-sdk/baseapp/baseapp.go:
And add a SetWithdrawHandler func for the BaseApp struct:
3、Modify the runTx function in cosmos-sdk/baseapp/baseapp.go:
4、 Add a default withdrawHandler in x/auth module, the process has been describe in step 3.
For Admin Use
The text was updated successfully, but these errors were encountered: