From 6ca5caef31b092926f82d0f4911ba131f2be4fe7 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Tue, 8 Dec 2020 20:51:27 +0100 Subject: [PATCH] Refactor DefaultMessageSendSpec Signed-off-by: Jakub Sztandera --- api/types.go | 14 -------------- chain/messagepool/messagepool.go | 15 ++++++++++++++- cli/mpool.go | 2 +- node/impl/full/gas.go | 2 +- storage/wdpost_run.go | 2 +- 5 files changed, 17 insertions(+), 18 deletions(-) diff --git a/api/types.go b/api/types.go index 1318c7f43..28141b83a 100644 --- a/api/types.go +++ b/api/types.go @@ -6,7 +6,6 @@ import ( datatransfer "github.com/filecoin-project/go-data-transfer" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/lotus/build" "github.com/ipfs/go-cid" "github.com/libp2p/go-libp2p-core/peer" @@ -51,19 +50,6 @@ type MessageSendSpec struct { MaxFee abi.TokenAmount } -var DefaultMessageSendSpec = MessageSendSpec{ - // MaxFee of 0.1FIL - MaxFee: abi.NewTokenAmount(int64(build.FilecoinPrecision) / 10), -} - -func (ms *MessageSendSpec) Get() MessageSendSpec { - if ms == nil { - return DefaultMessageSendSpec - } - - return *ms -} - type DataTransferChannel struct { TransferID datatransfer.TransferID Status datatransfer.Status diff --git a/chain/messagepool/messagepool.go b/chain/messagepool/messagepool.go index 806882a15..1e5c25587 100644 --- a/chain/messagepool/messagepool.go +++ b/chain/messagepool/messagepool.go @@ -181,7 +181,20 @@ func ComputeMinRBF(curPrem abi.TokenAmount) abi.TokenAmount { return types.BigAdd(minPrice, types.NewInt(1)) } -func CapGasFee(mff dtypes.DefaultMaxFeeFunc, msg *types.Message, maxFee abi.TokenAmount) { +func CapGasFee(mff dtypes.DefaultMaxFeeFunc, msg *types.Message, sendSepc *api.MessageSendSpec) { + var maxFee abi.TokenAmount + if sendSepc != nil { + maxFee = sendSepc.MaxFee + } + if maxFee.Int == nil || maxFee.Equals(big.Zero()) { + mf, err := mff() + if err != nil { + log.Errorf("failed to get default max gas fee: %+v", err) + mf = big.Zero() + } + maxFee = mf + } + if maxFee.Equals(big.Zero()) { mf, err := mff() if err != nil { diff --git a/cli/mpool.go b/cli/mpool.go index fe36c0c7d..d30b85f4f 100644 --- a/cli/mpool.go +++ b/cli/mpool.go @@ -446,7 +446,7 @@ var mpoolReplaceCmd = &cli.Command{ return abi.TokenAmount(config.DefaultDefaultMaxFee), nil } - messagepool.CapGasFee(mff, &msg, mss.Get().MaxFee) + messagepool.CapGasFee(mff, &msg, mss) } else { if cctx.IsSet("gas-limit") { msg.GasLimit = cctx.Int64("gas-limit") diff --git a/node/impl/full/gas.go b/node/impl/full/gas.go index 13c344599..189512a65 100644 --- a/node/impl/full/gas.go +++ b/node/impl/full/gas.go @@ -301,7 +301,7 @@ func (m *GasModule) GasEstimateMessageGas(ctx context.Context, msg *types.Messag msg.GasFeeCap = feeCap } - messagepool.CapGasFee(m.GetMaxFee, msg, spec.Get().MaxFee) + messagepool.CapGasFee(m.GetMaxFee, msg, spec) return msg, nil } diff --git a/storage/wdpost_run.go b/storage/wdpost_run.go index cbc07cf77..346ffc38d 100644 --- a/storage/wdpost_run.go +++ b/storage/wdpost_run.go @@ -812,7 +812,7 @@ func (s *WindowPoStScheduler) setSender(ctx context.Context, msg *types.Message, return msg.RequiredFunds(), nil } - messagepool.CapGasFee(mff, msg, big.Min(big.Sub(avail, msg.Value), msg.RequiredFunds())) + messagepool.CapGasFee(mff, msg, &api.MessageSendSpec{MaxFee: big.Min(big.Sub(avail, msg.Value), msg.RequiredFunds())}) } return nil }