Config for default max gas fee

This commit is contained in:
Łukasz Magiera 2020-10-29 20:50:04 +01:00
parent 7d02cd6679
commit ae7889f830
7 changed files with 62 additions and 9 deletions

View File

@ -59,8 +59,6 @@ var MaxUntrustedActorPendingMessages = 10
var MaxNonceGap = uint64(4)
var DefaultMaxFee = abi.TokenAmount(types.MustParseFIL("0.007"))
var (
ErrMessageTooBig = errors.New("message too big")
@ -183,9 +181,15 @@ func ComputeMinRBF(curPrem abi.TokenAmount) abi.TokenAmount {
return types.BigAdd(minPrice, types.NewInt(1))
}
func CapGasFee(msg *types.Message, maxFee abi.TokenAmount) {
func CapGasFee(mff dtypes.DefaultMaxFeeFunc, msg *types.Message, maxFee abi.TokenAmount) {
if maxFee.Equals(big.Zero()) {
maxFee = DefaultMaxFee
mf, err := mff()
if err != nil {
log.Errorf("failed to get default max gas fee: %+v", err)
mf = big.Zero()
}
maxFee = mf
}
gl := types.NewInt(uint64(msg.GasLimit))

View File

@ -19,6 +19,7 @@ import (
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/messagepool"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/node/config"
)
var mpoolCmd = &cli.Command{
@ -434,7 +435,12 @@ var mpoolReplaceCmd = &cli.Command{
msg.GasPremium = big.Max(retm.GasPremium, minRBF)
msg.GasFeeCap = big.Max(retm.GasFeeCap, msg.GasPremium)
messagepool.CapGasFee(&msg, mss.Get().MaxFee)
mff := func() (abi.TokenAmount, error) {
return abi.TokenAmount(config.DefaultDefaultMaxFee), nil
}
messagepool.CapGasFee(mff, &msg, mss.Get().MaxFee)
} else {
msg.GasLimit = cctx.Int64("gas-limit")
msg.GasPremium, err = types.BigFromString(cctx.String("gas-premium"))

View File

@ -268,6 +268,7 @@ func Online() Option {
Override(new(*chain.Syncer), modules.NewSyncer),
Override(new(exchange.Client), exchange.NewClient),
Override(new(*messagepool.MessagePool), modules.MessagePool),
Override(new(dtypes.DefaultMaxFeeFunc), modules.NewDefaultMaxFeeFunc),
Override(new(modules.Genesis), modules.ErrorGenesis),
Override(new(dtypes.AfterGenesisSet), modules.SetGenesis),

View File

@ -23,6 +23,7 @@ type FullNode struct {
Client Client
Metrics Metrics
Wallet Wallet
Fees FeeConfig
}
// // Common
@ -115,6 +116,10 @@ type Wallet struct {
DisableLocal bool
}
type FeeConfig struct {
DefaultMaxFee types.FIL
}
func defCommon() Common {
return Common{
API: API{
@ -142,10 +147,15 @@ func defCommon() Common {
}
var DefaultDefaultMaxFee = types.MustParseFIL("0.007")
// DefaultFullNode returns the default config
func DefaultFullNode() *FullNode {
return &FullNode{
Common: defCommon(),
Fees: FeeConfig{
DefaultMaxFee: DefaultDefaultMaxFee,
},
}
}

View File

@ -23,6 +23,7 @@ import (
"github.com/filecoin-project/lotus/chain/stmgr"
"github.com/filecoin-project/lotus/chain/store"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/node/modules/dtypes"
)
type GasModuleAPI interface {
@ -34,9 +35,10 @@ type GasModuleAPI interface {
// Injection (for example with a thin RPC client).
type GasModule struct {
fx.In
Stmgr *stmgr.StateManager
Chain *store.ChainStore
Mpool *messagepool.MessagePool
Stmgr *stmgr.StateManager
Chain *store.ChainStore
Mpool *messagepool.MessagePool
GetMaxFee dtypes.DefaultMaxFeeFunc
}
var _ GasModuleAPI = (*GasModule)(nil)
@ -291,7 +293,7 @@ func (m *GasModule) GasEstimateMessageGas(ctx context.Context, msg *types.Messag
msg.GasFeeCap = feeCap
}
messagepool.CapGasFee(msg, spec.Get().MaxFee)
messagepool.CapGasFee(m.GetMaxFee, msg, spec.Get().MaxFee)
return msg, nil
}

View File

@ -15,11 +15,13 @@ import (
"golang.org/x/xerrors"
"github.com/filecoin-project/go-jsonrpc/auth"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/lotus/api/apistruct"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/lib/addrutil"
"github.com/filecoin-project/lotus/node/config"
"github.com/filecoin-project/lotus/node/modules/dtypes"
"github.com/filecoin-project/lotus/node/repo"
)
@ -105,3 +107,28 @@ func DrandBootstrap(ds dtypes.DrandSchedule) (dtypes.DrandBootstrap, error) {
}
return res, nil
}
func NewDefaultMaxFeeFunc(r repo.LockedRepo) dtypes.DefaultMaxFeeFunc {
return func() (out abi.TokenAmount, err error) {
err = readNodeCfg(r, func(cfg *config.FullNode) {
out = abi.TokenAmount(cfg.Fees.DefaultMaxFee)
})
return
}
}
func readNodeCfg(r repo.LockedRepo, accessor func(node *config.FullNode)) error {
raw, err := r.Config()
if err != nil {
return err
}
cfg, ok := raw.(*config.FullNode)
if !ok {
return xerrors.New("expected config.FullNode")
}
accessor(cfg)
return nil
}

View File

@ -5,6 +5,7 @@ import (
"sync"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
)
type MpoolLocker struct {
@ -33,3 +34,5 @@ func (ml *MpoolLocker) TakeLock(ctx context.Context, a address.Address) (func(),
<-lk
}, nil
}
type DefaultMaxFeeFunc func() (abi.TokenAmount, error)