diff --git a/chain/messagepool/messagepool.go b/chain/messagepool/messagepool.go index 79ab572ba..8c8a8af15 100644 --- a/chain/messagepool/messagepool.go +++ b/chain/messagepool/messagepool.go @@ -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)) diff --git a/cli/mpool.go b/cli/mpool.go index 8f3e937b6..4979f6ddc 100644 --- a/cli/mpool.go +++ b/cli/mpool.go @@ -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")) diff --git a/node/builder.go b/node/builder.go index bb039cb76..e33e1e469 100644 --- a/node/builder.go +++ b/node/builder.go @@ -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), diff --git a/node/config/def.go b/node/config/def.go index 1298ed45a..9a2850f92 100644 --- a/node/config/def.go +++ b/node/config/def.go @@ -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, + }, } } diff --git a/node/impl/full/gas.go b/node/impl/full/gas.go index e0cbd2192..5d21121ee 100644 --- a/node/impl/full/gas.go +++ b/node/impl/full/gas.go @@ -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 } diff --git a/node/modules/core.go b/node/modules/core.go index a695d8651..823b0131e 100644 --- a/node/modules/core.go +++ b/node/modules/core.go @@ -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 +} diff --git a/node/modules/dtypes/mpool.go b/node/modules/dtypes/mpool.go index 1c64449f8..df96b8d0e 100644 --- a/node/modules/dtypes/mpool.go +++ b/node/modules/dtypes/mpool.go @@ -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)