diff --git a/app/submodule/mpool/mpool_api.go b/app/submodule/mpool/mpool_api.go index bb2debf722..8c6b8f8ad2 100644 --- a/app/submodule/mpool/mpool_api.go +++ b/app/submodule/mpool/mpool_api.go @@ -15,19 +15,19 @@ import ( var _ v1api.IMessagePool = &MessagePoolAPI{} -//MessagePoolAPI messsage pool api implement +// MessagePoolAPI messsage pool api implement type MessagePoolAPI struct { pushLocks *messagepool.MpoolLocker mp *MessagePoolSubmodule } -//MpoolDeleteByAdress delete msg in mpool of addr +// MpoolDeleteByAdress delete msg in mpool of addr func (a *MessagePoolAPI) MpoolDeleteByAdress(ctx context.Context, addr address.Address) error { return a.mp.MPool.DeleteByAdress(addr) } -//MpoolPublish publish message of address +// MpoolPublish publish message of address func (a *MessagePoolAPI) MpoolPublishByAddr(ctx context.Context, addr address.Address) error { return a.mp.MPool.PublishMsgForWallet(ctx, addr) } @@ -76,7 +76,7 @@ func (a *MessagePoolAPI) MpoolSelect(ctx context.Context, tsk types.TipSetKey, t return a.mp.MPool.SelectMessages(ctx, ts, ticketQuality) } -//MpoolSelects The batch selection message is used when multiple blocks need to select messages at the same time +// MpoolSelects The batch selection message is used when multiple blocks need to select messages at the same time func (a *MessagePoolAPI) MpoolSelects(ctx context.Context, tsk types.TipSetKey, ticketQualitys []float64) ([][]*types.SignedMessage, error) { ts, err := a.mp.chain.API().ChainGetTipSet(ctx, tsk) if err != nil { @@ -227,8 +227,9 @@ func (a *MessagePoolAPI) MpoolPushMessage(ctx context.Context, msg *types.Messag return nil, fmt.Errorf("mpool push: getting origin balance: %w", err) } - if b.LessThan(msg.Value) { - return nil, fmt.Errorf("mpool push: not enough funds: %s < %s", b, msg.Value) + requiredFunds := big.Add(msg.Value, msg.RequiredFunds()) + if b.LessThan(requiredFunds) { + return nil, fmt.Errorf("mpool push: not enough funds: %s < %s", b, requiredFunds) } // Sign and push the message diff --git a/pkg/messagepool/gas.go b/pkg/messagepool/gas.go index 46e528158a..3980cd4031 100644 --- a/pkg/messagepool/gas.go +++ b/pkg/messagepool/gas.go @@ -222,8 +222,8 @@ func (mp *MessagePool) GasEstimateGasLimit(ctx context.Context, msgIn *types.Mes func (mp *MessagePool) evalMessageGasLimit(ctx context.Context, msgIn *types.Message, priorMsgs []types.ChainMsg, ts *types.TipSet) (int64, error) { msg := *msgIn msg.GasLimit = constants.BlockGasLimit - msg.GasFeeCap = big.NewInt(int64(constants.MinimumBaseFee) + 1) - msg.GasPremium = big.NewInt(1) + msg.GasFeeCap = big.Zero() + msg.GasPremium = big.Zero() // Try calling until we find a height with no migration. var res *vm.Ret diff --git a/pkg/statemanger/call.go b/pkg/statemanger/call.go index 33f148ace3..7eea675488 100644 --- a/pkg/statemanger/call.go +++ b/pkg/statemanger/call.go @@ -15,6 +15,7 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/go-state-types/big" acrypto "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/venus/pkg/crypto" "github.com/ipfs/go-cid" @@ -35,6 +36,10 @@ func (s *Stmgr) CallWithGas(ctx context.Context, msg *types.Message, priorMsgs [ view *state.View ) + // Copy the message as we'll be modifying the nonce. + msgCopy := *msg + msg = &msgCopy + if ts == nil { ts = s.cs.GetHead() // Search back till we find a height with no fork, or we reach the beginning. @@ -148,6 +153,19 @@ func (s *Stmgr) CallWithGas(ctx context.Context, msg *types.Message, priorMsgs [ }, } } + + // If the fee cap is set to zero, make gas free. + if msg.GasFeeCap.NilOrZero() { + // Now estimate with a new VM with no base fee. + vmOption.BaseFee = big.Zero() + vmOption.PRoot = stateRoot + + vmi, err = fvm.NewVM(ctx, vmOption) + if err != nil { + return nil, fmt.Errorf("failed to set up estimation vm: %w", err) + } + } + return vmi.ApplyMessage(ctx, msgApply) }