diff --git a/node/impl/full/gas.go b/node/impl/full/gas.go index 54d9ef1b186..d0fae9afc5d 100644 --- a/node/impl/full/gas.go +++ b/node/impl/full/gas.go @@ -14,6 +14,7 @@ import ( "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/go-address" + "github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/abi/big" "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/runtime/exitcode" @@ -36,28 +37,11 @@ func (a *GasAPI) GasEstimateFeeCap(ctx context.Context, msg *types.Message, maxq tsk types.TipSetKey) (types.BigInt, error) { ts := a.Chain.GetHeaviestTipSet() - var act types.Actor - err := a.Stmgr.WithParentState(ts, a.Stmgr.WithActor(msg.From, stmgr.GetActor(&act))) - if err != nil { - return types.NewInt(0), xerrors.Errorf("getting actor: %w", err) - } - parentBaseFee := ts.Blocks()[0].ParentBaseFee increaseFactor := math.Pow(1.+1./float64(build.BaseFeeMaxChangeDenom), float64(maxqueueblks)) feeInFuture := types.BigMul(parentBaseFee, types.NewInt(uint64(increaseFactor*(1<<8)))) - feeInFuture = types.BigDiv(feeInFuture, types.NewInt(1<<8)) - - gasLimitBig := types.NewInt(uint64(msg.GasLimit)) - maxAccepted := types.BigDiv(act.Balance, types.NewInt(MaxSpendOnFeeDenom)) - expectedFee := types.BigMul(feeInFuture, gasLimitBig) - - out := feeInFuture - if types.BigCmp(expectedFee, maxAccepted) > 0 { - log.Warnf("Expected fee for message higher than tolerance: %s > %s, setting to tolerance", - types.FIL(expectedFee), types.FIL(maxAccepted)) - out = types.BigDiv(maxAccepted, gasLimitBig) - } + out := types.BigDiv(feeInFuture, types.NewInt(1<<8)) if msg.GasPremium != types.EmptyInt { out = types.BigAdd(out, msg.GasPremium) @@ -225,3 +209,24 @@ func (a *GasAPI) GasEstimateMessageGas(ctx context.Context, msg *types.Message, return msg, nil } + +func capGasFee(msg *types.Message, maxFee abi.TokenAmount) { + if maxFee.Equals(big.Zero()) { + maxFee = types.NewInt(build.FilecoinPrecision / 10) + } + + gl := types.NewInt(uint64(msg.GasLimit)) + totalFee := types.BigMul(msg.GasFeeCap, gl) + minerFee := types.BigMul(msg.GasPremium, gl) + + if totalFee.LessThanEqual(maxFee) { + return + } + + // scale chain/miner fee down proportionally to fit in our budget + // TODO: there are probably smarter things we can do here to optimize + // message inclusion latency + + msg.GasFeeCap = big.Div(maxFee, gl) + msg.GasPremium = big.Div(big.Div(big.Mul(minerFee, maxFee), totalFee), gl) +} diff --git a/node/impl/full/mpool.go b/node/impl/full/mpool.go index 735b982d05b..bfb7439bb9f 100644 --- a/node/impl/full/mpool.go +++ b/node/impl/full/mpool.go @@ -8,9 +8,6 @@ import ( "go.uber.org/fx" "golang.org/x/xerrors" - "github.com/filecoin-project/specs-actors/actors/abi" - "github.com/filecoin-project/specs-actors/actors/abi/big" - "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/chain/messagepool" "github.com/filecoin-project/lotus/chain/store" @@ -115,27 +112,6 @@ func (a *MpoolAPI) MpoolPush(ctx context.Context, smsg *types.SignedMessage) (ci return a.Mpool.Push(smsg) } -func capGasFee(msg *types.Message, maxFee abi.TokenAmount) { - if maxFee.Equals(big.Zero()) { - return - } - - gl := types.NewInt(uint64(msg.GasLimit)) - totalFee := types.BigMul(msg.GasFeeCap, gl) - minerFee := types.BigMul(msg.GasPremium, gl) - - if totalFee.LessThanEqual(maxFee) { - return - } - - // scale chain/miner fee down proportionally to fit in our budget - // TODO: there are probably smarter things we can do here to optimize - // message inclusion latency - - msg.GasFeeCap = big.Div(maxFee, gl) - msg.GasPremium = big.Div(big.Div(big.Mul(minerFee, maxFee), totalFee), gl) -} - func (a *MpoolAPI) MpoolPushMessage(ctx context.Context, msg *types.Message, spec *api.MessageSendSpec) (*types.SignedMessage, error) { { fromA, err := a.Stmgr.ResolveToKeyAddress(ctx, msg.From, nil)