From d0147aa50f320c3aab826d55695c42b2c56ff490 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Wed, 12 Aug 2020 19:06:08 +0200 Subject: [PATCH 1/7] Add maxFee param to MpoolPushMessage --- api/api_full.go | 6 +++++- api/apistruct/struct.go | 14 +++++++------- chain/market/fundmgr.go | 4 ++-- cli/chain.go | 2 +- cli/send.go | 11 +++++++---- cmd/lotus-storage-miner/actor.go | 3 ++- cmd/lotus-storage-miner/init.go | 5 +++-- cmd/lotus-storage-miner/rewards.go | 8 +++++--- markets/storageadapter/client.go | 6 +++--- markets/storageadapter/provider.go | 5 +++-- node/impl/full/mpool.go | 27 ++++++++++++++++++++++++++- node/impl/full/multisig.go | 6 +++--- node/impl/paych/paych.go | 8 +++++--- paychmgr/manager.go | 3 ++- paychmgr/paych.go | 4 ++-- paychmgr/simple.go | 4 ++-- storage/adapter_storage_miner.go | 2 +- storage/miner.go | 2 +- storage/wdpost_run.go | 7 ++++--- 19 files changed, 84 insertions(+), 43 deletions(-) diff --git a/api/api_full.go b/api/api_full.go index 21fadbaa6..a644b6fc1 100644 --- a/api/api_full.go +++ b/api/api_full.go @@ -166,7 +166,11 @@ type FullNode interface { // MpoolPushMessage atomically assigns a nonce, signs, and pushes a message // to mempool. - MpoolPushMessage(context.Context, *types.Message) (*types.SignedMessage, error) + // maxFee is only used when GasFeeCap/GasPremium fields aren't specified + // + // When maxFee is set to 0, MpoolPushMessage will guess appropriate fee + // based on current chain conditions + MpoolPushMessage(ctx context.Context, msg *types.Message, maxFee abi.TokenAmount) (*types.SignedMessage, error) // MpoolGetNonce gets next nonce for the specified sender. // Note that this method may not be atomic. Use MpoolPushMessage instead. diff --git a/api/apistruct/struct.go b/api/apistruct/struct.go index 8fa5c69af..64dbc03b0 100644 --- a/api/apistruct/struct.go +++ b/api/apistruct/struct.go @@ -102,11 +102,11 @@ type FullNodeStruct struct { MpoolSelect func(context.Context, types.TipSetKey, float64) ([]*types.SignedMessage, error) `perm:"read"` - MpoolPending func(context.Context, types.TipSetKey) ([]*types.SignedMessage, error) `perm:"read"` - MpoolPush func(context.Context, *types.SignedMessage) (cid.Cid, error) `perm:"write"` - MpoolPushMessage func(context.Context, *types.Message) (*types.SignedMessage, error) `perm:"sign"` - MpoolGetNonce func(context.Context, address.Address) (uint64, error) `perm:"read"` - MpoolSub func(context.Context) (<-chan api.MpoolUpdate, error) `perm:"read"` + MpoolPending func(context.Context, types.TipSetKey) ([]*types.SignedMessage, error) `perm:"read"` + MpoolPush func(context.Context, *types.SignedMessage) (cid.Cid, error) `perm:"write"` + MpoolPushMessage func(context.Context, *types.Message, abi.TokenAmount) (*types.SignedMessage, error) `perm:"sign"` + MpoolGetNonce func(context.Context, address.Address) (uint64, error) `perm:"read"` + MpoolSub func(context.Context) (<-chan api.MpoolUpdate, error) `perm:"read"` MinerGetBaseInfo func(context.Context, address.Address, abi.ChainEpoch, types.TipSetKey) (*api.MiningBaseInfo, error) `perm:"read"` MinerCreateBlock func(context.Context, *api.BlockTemplate) (*types.BlockMsg, error) `perm:"write"` @@ -470,8 +470,8 @@ func (c *FullNodeStruct) MpoolPush(ctx context.Context, smsg *types.SignedMessag return c.Internal.MpoolPush(ctx, smsg) } -func (c *FullNodeStruct) MpoolPushMessage(ctx context.Context, msg *types.Message) (*types.SignedMessage, error) { - return c.Internal.MpoolPushMessage(ctx, msg) +func (c *FullNodeStruct) MpoolPushMessage(ctx context.Context, msg *types.Message, maxFee abi.TokenAmount) (*types.SignedMessage, error) { + return c.Internal.MpoolPushMessage(ctx, msg, maxFee) } func (c *FullNodeStruct) MpoolSub(ctx context.Context) (<-chan api.MpoolUpdate, error) { diff --git a/chain/market/fundmgr.go b/chain/market/fundmgr.go index b7673ab35..a0d778de6 100644 --- a/chain/market/fundmgr.go +++ b/chain/market/fundmgr.go @@ -60,7 +60,7 @@ func StartFundManager(lc fx.Lifecycle, api API) *FundMgr { type fundMgrAPI interface { StateMarketBalance(context.Context, address.Address, types.TipSetKey) (api.MarketBalance, error) - MpoolPushMessage(context.Context, *types.Message) (*types.SignedMessage, error) + MpoolPushMessage(context.Context, *types.Message, abi.TokenAmount) (*types.SignedMessage, error) StateLookupID(context.Context, address.Address, types.TipSetKey) (address.Address, error) } @@ -149,7 +149,7 @@ func (fm *FundMgr) EnsureAvailable(ctx context.Context, addr, wallet address.Add Value: toAdd, Method: builtin.MethodsMarket.AddBalance, Params: params, - }) + }, big.Zero()) if err != nil { return cid.Undef, err } diff --git a/cli/chain.go b/cli/chain.go index 003b3ccfc..d72f438a9 100644 --- a/cli/chain.go +++ b/cli/chain.go @@ -1007,7 +1007,7 @@ var slashConsensusFault = &cli.Command{ Params: enc, } - smsg, err := api.MpoolPushMessage(ctx, msg) + smsg, err := api.MpoolPushMessage(ctx, msg, big.Zero()) if err != nil { return err } diff --git a/cli/send.go b/cli/send.go index 60b34ea75..6ef2c4c4c 100644 --- a/cli/send.go +++ b/cli/send.go @@ -8,13 +8,16 @@ import ( "fmt" "reflect" + "github.com/urfave/cli/v2" + cbg "github.com/whyrusleeping/cbor-gen" + "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/lotus/api" "github.com/filecoin-project/lotus/chain/stmgr" "github.com/filecoin-project/lotus/chain/types" - "github.com/filecoin-project/specs-actors/actors/abi" - "github.com/urfave/cli/v2" - cbg "github.com/whyrusleeping/cbor-gen" ) var sendCmd = &cli.Command{ @@ -154,7 +157,7 @@ var sendCmd = &cli.Command{ } fmt.Println(sm.Cid()) } else { - sm, err := api.MpoolPushMessage(ctx, msg) + sm, err := api.MpoolPushMessage(ctx, msg, big.Zero()) if err != nil { return err } diff --git a/cmd/lotus-storage-miner/actor.go b/cmd/lotus-storage-miner/actor.go index dcc2106b5..96a38a015 100644 --- a/cmd/lotus-storage-miner/actor.go +++ b/cmd/lotus-storage-miner/actor.go @@ -7,6 +7,7 @@ import ( "github.com/urfave/cli/v2" "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/miner" "github.com/filecoin-project/lotus/chain/actors" @@ -81,7 +82,7 @@ var actorSetAddrsCmd = &cli.Command{ GasLimit: gasLimit, Method: 18, Params: params, - }) + }, big.Zero()) if err != nil { return err } diff --git a/cmd/lotus-storage-miner/init.go b/cmd/lotus-storage-miner/init.go index 5007a7120..af7a3fd04 100644 --- a/cmd/lotus-storage-miner/init.go +++ b/cmd/lotus-storage-miner/init.go @@ -28,6 +28,7 @@ import ( "github.com/filecoin-project/sector-storage/ffiwrapper" "github.com/filecoin-project/sector-storage/stores" "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/builtin/market" miner2 "github.com/filecoin-project/specs-actors/actors/builtin/miner" @@ -560,7 +561,7 @@ func configureStorageMiner(ctx context.Context, api lapi.FullNode, addr address. GasPremium: gasPrice, } - smsg, err := api.MpoolPushMessage(ctx, msg) + smsg, err := api.MpoolPushMessage(ctx, msg, big.Zero()) if err != nil { return err } @@ -640,7 +641,7 @@ func createStorageMiner(ctx context.Context, api lapi.FullNode, peerid peer.ID, GasPremium: gasPrice, } - signed, err := api.MpoolPushMessage(ctx, createStorageMinerMsg) + signed, err := api.MpoolPushMessage(ctx, createStorageMinerMsg, big.Zero()) if err != nil { return address.Undef, err } diff --git a/cmd/lotus-storage-miner/rewards.go b/cmd/lotus-storage-miner/rewards.go index 38a797dcc..bb6773bc1 100644 --- a/cmd/lotus-storage-miner/rewards.go +++ b/cmd/lotus-storage-miner/rewards.go @@ -5,11 +5,13 @@ import ( "github.com/urfave/cli/v2" + "github.com/filecoin-project/specs-actors/actors/abi/big" + "github.com/filecoin-project/specs-actors/actors/builtin" + "github.com/filecoin-project/specs-actors/actors/builtin/miner" + "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/types" lcli "github.com/filecoin-project/lotus/cli" - "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" ) var rewardsCmd = &cli.Command{ @@ -65,7 +67,7 @@ var rewardsRedeemCmd = &cli.Command{ Value: types.NewInt(0), Method: builtin.MethodsMiner.WithdrawBalance, Params: params, - }) + }, big.Zero()) if err != nil { return err } diff --git a/markets/storageadapter/client.go b/markets/storageadapter/client.go index 74e3f8394..b95c6fe17 100644 --- a/markets/storageadapter/client.go +++ b/markets/storageadapter/client.go @@ -6,8 +6,6 @@ import ( "bytes" "context" - "github.com/filecoin-project/lotus/chain/events/state" - "golang.org/x/xerrors" "github.com/filecoin-project/go-address" @@ -16,6 +14,7 @@ import ( "github.com/filecoin-project/go-fil-markets/storagemarket" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/events" + "github.com/filecoin-project/lotus/chain/events/state" "github.com/filecoin-project/lotus/chain/market" "github.com/filecoin-project/lotus/chain/stmgr" "github.com/filecoin-project/lotus/chain/store" @@ -24,6 +23,7 @@ import ( "github.com/filecoin-project/lotus/markets/utils" "github.com/filecoin-project/lotus/node/impl/full" "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" samarket "github.com/filecoin-project/specs-actors/actors/builtin/market" "github.com/filecoin-project/specs-actors/actors/builtin/miner" @@ -127,7 +127,7 @@ func (c *ClientNodeAdapter) AddFunds(ctx context.Context, addr address.Address, From: addr, Value: amount, Method: builtin.MethodsMarket.AddBalance, - }) + }, big.Zero()) if err != nil { return cid.Undef, err } diff --git a/markets/storageadapter/provider.go b/markets/storageadapter/provider.go index 3c19c8423..b67becefa 100644 --- a/markets/storageadapter/provider.go +++ b/markets/storageadapter/provider.go @@ -15,6 +15,7 @@ import ( "github.com/filecoin-project/go-fil-markets/shared" "github.com/filecoin-project/go-fil-markets/storagemarket" "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/builtin/market" "github.com/filecoin-project/specs-actors/actors/builtin/miner" @@ -79,7 +80,7 @@ func (n *ProviderNodeAdapter) PublishDeals(ctx context.Context, deal storagemark Value: types.NewInt(0), Method: builtin.MethodsMarket.PublishStorageDeals, Params: params, - }) + }, big.Zero()) if err != nil { return cid.Undef, err } @@ -177,7 +178,7 @@ func (n *ProviderNodeAdapter) AddFunds(ctx context.Context, addr address.Address From: addr, Value: amount, Method: builtin.MethodsMarket.AddBalance, - }) + }, big.Zero()) if err != nil { return cid.Undef, err } diff --git a/node/impl/full/mpool.go b/node/impl/full/mpool.go index cd6adef6d..870298b33 100644 --- a/node/impl/full/mpool.go +++ b/node/impl/full/mpool.go @@ -2,6 +2,8 @@ package full import ( "context" + "github.com/filecoin-project/specs-actors/actors/abi" + "github.com/filecoin-project/specs-actors/actors/abi/big" "github.com/ipfs/go-cid" "go.uber.org/fx" @@ -108,7 +110,28 @@ func (a *MpoolAPI) MpoolPush(ctx context.Context, smsg *types.SignedMessage) (ci return a.Mpool.Push(smsg) } -func (a *MpoolAPI) MpoolPushMessage(ctx context.Context, msg *types.Message) (*types.SignedMessage, error) { +func capGasFee(msg *types.Message, maxFee abi.TokenAmount) { + if maxFee.Equals(big.Zero()) { + return + } + + chainFee := types.BigMul(msg.GasFeeCap, types.NewInt(uint64(msg.GasLimit))) + minerFee := types.BigMul(msg.GasPremium, types.NewInt(uint64(msg.GasLimit))) + + if big.Add(chainFee, minerFee).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 + + totalFee := big.Add(chainFee, minerFee) + msg.GasFeeCap = big.Div(big.Mul(chainFee, maxFee), totalFee) + msg.GasPremium = big.Div(big.Mul(minerFee, maxFee), totalFee) +} + +func (a *MpoolAPI) MpoolPushMessage(ctx context.Context, msg *types.Message, maxFee abi.TokenAmount) (*types.SignedMessage, error) { { fromA, err := a.Stmgr.ResolveToKeyAddress(ctx, msg.From, nil) if err != nil { @@ -148,6 +171,8 @@ func (a *MpoolAPI) MpoolPushMessage(ctx context.Context, msg *types.Message) (*t msg.GasFeeCap = feeCap } + capGasFee(msg, maxFee) + return a.Mpool.PushWithNonce(ctx, msg.From, func(from address.Address, nonce uint64) (*types.SignedMessage, error) { msg.Nonce = nonce if msg.From.Protocol() == address.ID { diff --git a/node/impl/full/multisig.go b/node/impl/full/multisig.go index deb0d9856..9889c915c 100644 --- a/node/impl/full/multisig.go +++ b/node/impl/full/multisig.go @@ -78,7 +78,7 @@ func (a *MsigAPI) MsigCreate(ctx context.Context, req uint64, addrs []address.Ad } // send the message out to the network - smsg, err := a.MpoolAPI.MpoolPushMessage(ctx, &msg) + smsg, err := a.MpoolAPI.MpoolPushMessage(ctx, &msg, big.Zero()) if err != nil { return cid.Undef, err } @@ -122,7 +122,7 @@ func (a *MsigAPI) MsigPropose(ctx context.Context, msig address.Address, to addr Params: enc, } - smsg, err := a.MpoolAPI.MpoolPushMessage(ctx, msg) + smsg, err := a.MpoolAPI.MpoolPushMessage(ctx, msg, big.Zero()) if err != nil { return cid.Undef, xerrors.Errorf("failed to push message: %w", err) } @@ -236,7 +236,7 @@ func (a *MsigAPI) msigApproveOrCancel(ctx context.Context, operation api.MsigPro Params: enc, } - smsg, err := a.MpoolAPI.MpoolPushMessage(ctx, msg) + smsg, err := a.MpoolAPI.MpoolPushMessage(ctx, msg, big.Zero()) if err != nil { return cid.Undef, err } diff --git a/node/impl/paych/paych.go b/node/impl/paych/paych.go index 0f72e7c9e..7600270b5 100644 --- a/node/impl/paych/paych.go +++ b/node/impl/paych/paych.go @@ -4,13 +4,15 @@ import ( "context" "fmt" - "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/builtin/paych" "github.com/ipfs/go-cid" "go.uber.org/fx" "golang.org/x/xerrors" "github.com/filecoin-project/go-address" + "github.com/filecoin-project/specs-actors/actors/abi/big" + "github.com/filecoin-project/specs-actors/actors/builtin" + "github.com/filecoin-project/specs-actors/actors/builtin/paych" + "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/types" @@ -209,7 +211,7 @@ func (a *PaychAPI) PaychVoucherSubmit(ctx context.Context, ch address.Address, s Params: enc, } - smsg, err := a.MpoolPushMessage(ctx, msg) + smsg, err := a.MpoolPushMessage(ctx, msg, big.Zero()) if err != nil { return cid.Undef, err } diff --git a/paychmgr/manager.go b/paychmgr/manager.go index 96dd11f7a..b3f4c6f4f 100644 --- a/paychmgr/manager.go +++ b/paychmgr/manager.go @@ -2,6 +2,7 @@ package paychmgr import ( "context" + "github.com/filecoin-project/specs-actors/actors/abi" "sync" "github.com/filecoin-project/lotus/node/modules/helpers" @@ -44,7 +45,7 @@ type stateManagerAPI interface { // paychAPI defines the API methods needed by the payment channel manager type paychAPI interface { StateWaitMsg(ctx context.Context, msg cid.Cid, confidence uint64) (*api.MsgLookup, error) - MpoolPushMessage(ctx context.Context, msg *types.Message) (*types.SignedMessage, error) + MpoolPushMessage(ctx context.Context, msg *types.Message, maxFee abi.TokenAmount) (*types.SignedMessage, error) } // managerAPI defines all methods needed by the manager diff --git a/paychmgr/paych.go b/paychmgr/paych.go index 2f518c2f9..70674de3b 100644 --- a/paychmgr/paych.go +++ b/paychmgr/paych.go @@ -403,7 +403,7 @@ func (ca *channelAccessor) settle(ctx context.Context, ch address.Address) (cid. Value: types.NewInt(0), Method: builtin.MethodsPaych.Settle, } - smgs, err := ca.api.MpoolPushMessage(ctx, msg) + smgs, err := ca.api.MpoolPushMessage(ctx, msg, big.Zero()) if err != nil { return cid.Undef, err } @@ -433,7 +433,7 @@ func (ca *channelAccessor) collect(ctx context.Context, ch address.Address) (cid Method: builtin.MethodsPaych.Collect, } - smsg, err := ca.api.MpoolPushMessage(ctx, msg) + smsg, err := ca.api.MpoolPushMessage(ctx, msg, big.Zero()) if err != nil { return cid.Undef, err } diff --git a/paychmgr/simple.go b/paychmgr/simple.go index 2c92d7ccb..75e11092c 100644 --- a/paychmgr/simple.go +++ b/paychmgr/simple.go @@ -370,7 +370,7 @@ func (ca *channelAccessor) createPaych(ctx context.Context, from, to address.Add Params: enc, } - smsg, err := ca.api.MpoolPushMessage(ctx, msg) + smsg, err := ca.api.MpoolPushMessage(ctx, msg, big.Zero()) if err != nil { return cid.Undef, xerrors.Errorf("initializing paych actor: %w", err) } @@ -449,7 +449,7 @@ func (ca *channelAccessor) addFunds(ctx context.Context, channelInfo *ChannelInf Method: 0, } - smsg, err := ca.api.MpoolPushMessage(ctx, msg) + smsg, err := ca.api.MpoolPushMessage(ctx, msg, big.Zero()) if err != nil { return nil, err } diff --git a/storage/adapter_storage_miner.go b/storage/adapter_storage_miner.go index 119df69bc..361127943 100644 --- a/storage/adapter_storage_miner.go +++ b/storage/adapter_storage_miner.go @@ -249,7 +249,7 @@ func (s SealingAPIAdapter) SendMsg(ctx context.Context, from, to address.Address Params: params, } - smsg, err := s.delegate.MpoolPushMessage(ctx, &msg) + smsg, err := s.delegate.MpoolPushMessage(ctx, &msg, big.Zero()) if err != nil { return cid.Undef, err } diff --git a/storage/miner.go b/storage/miner.go index 13227ddaf..4346757cb 100644 --- a/storage/miner.go +++ b/storage/miner.go @@ -65,7 +65,7 @@ type storageMinerApi interface { StateMinerFaults(context.Context, address.Address, types.TipSetKey) (*abi.BitField, error) StateMinerRecoveries(context.Context, address.Address, types.TipSetKey) (*abi.BitField, error) - MpoolPushMessage(context.Context, *types.Message) (*types.SignedMessage, error) + MpoolPushMessage(context.Context, *types.Message, abi.TokenAmount) (*types.SignedMessage, error) ChainHead(context.Context) (*types.TipSet, error) ChainNotify(context.Context) (<-chan []*api.HeadChange, error) diff --git a/storage/wdpost_run.go b/storage/wdpost_run.go index 77cd60ce6..04ffe2606 100644 --- a/storage/wdpost_run.go +++ b/storage/wdpost_run.go @@ -10,6 +10,7 @@ import ( "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/builtin/miner" "github.com/filecoin-project/specs-actors/actors/crypto" @@ -177,7 +178,7 @@ func (s *WindowPoStScheduler) checkNextRecoveries(ctx context.Context, dlIdx uin Value: types.NewInt(0), } - sm, err := s.api.MpoolPushMessage(ctx, msg) + sm, err := s.api.MpoolPushMessage(ctx, msg, big.Zero()) if err != nil { return xerrors.Errorf("pushing message to mpool: %w", err) } @@ -259,7 +260,7 @@ func (s *WindowPoStScheduler) checkNextFaults(ctx context.Context, dlIdx uint64, Value: types.NewInt(0), // TODO: Is there a fee? } - sm, err := s.api.MpoolPushMessage(ctx, msg) + sm, err := s.api.MpoolPushMessage(ctx, msg, big.Zero()) if err != nil { return xerrors.Errorf("pushing message to mpool: %w", err) } @@ -456,7 +457,7 @@ func (s *WindowPoStScheduler) submitPost(ctx context.Context, proof *miner.Submi } // TODO: consider maybe caring about the output - sm, err := s.api.MpoolPushMessage(ctx, msg) + sm, err := s.api.MpoolPushMessage(ctx, msg, big.Zero()) if err != nil { return xerrors.Errorf("pushing message to mpool: %w", err) } From 6f890a3eddd93a730d2ac2ce3e898859bed3fdd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Wed, 12 Aug 2020 19:47:00 +0200 Subject: [PATCH 2/7] Miner fee config --- extern/storage-fsm/sealing.go | 11 ++++- extern/storage-fsm/states_sealing.go | 4 +- node/builder.go | 3 +- node/config/def.go | 20 +++++++- node/modules/storageminer.go | 74 ++++++++++++++-------------- storage/adapter_storage_miner.go | 17 +++---- storage/miner.go | 12 ++++- storage/wdpost_run.go | 7 ++- storage/wdpost_sched.go | 5 +- 9 files changed, 93 insertions(+), 60 deletions(-) diff --git a/extern/storage-fsm/sealing.go b/extern/storage-fsm/sealing.go index d15255696..a18a0b0b7 100644 --- a/extern/storage-fsm/sealing.go +++ b/extern/storage-fsm/sealing.go @@ -45,7 +45,7 @@ type SealingAPI interface { StateMinerPreCommitDepositForPower(context.Context, address.Address, miner.SectorPreCommitInfo, TipSetToken) (big.Int, error) StateMinerInitialPledgeCollateral(context.Context, address.Address, miner.SectorPreCommitInfo, TipSetToken) (big.Int, error) StateMarketStorageDeal(context.Context, abi.DealID, TipSetToken) (market.DealProposal, error) - SendMsg(ctx context.Context, from, to address.Address, method abi.MethodNum, value, gasPrice big.Int, gasLimit int64, params []byte) (cid.Cid, error) + SendMsg(ctx context.Context, from, to address.Address, method abi.MethodNum, value, maxFee abi.TokenAmount, params []byte) (cid.Cid, error) ChainHead(ctx context.Context) (TipSetToken, abi.ChainEpoch, error) ChainGetRandomness(ctx context.Context, tok TipSetToken, personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte) (abi.Randomness, error) ChainReadObj(context.Context, cid.Cid) ([]byte, error) @@ -53,6 +53,7 @@ type SealingAPI interface { type Sealing struct { api SealingAPI + feeCfg FeeConfig events Events maddr address.Address @@ -71,6 +72,11 @@ type Sealing struct { getSealDelay GetSealingDelayFunc } +type FeeConfig struct { + MaxPreCommitGasFee abi.TokenAmount + MaxCommitGasFee abi.TokenAmount +} + type UnsealedSectorMap struct { infos map[abi.SectorNumber]UnsealedSectorInfo mux sync.Mutex @@ -83,9 +89,10 @@ type UnsealedSectorInfo struct { pieceSizes []abi.UnpaddedPieceSize } -func New(api SealingAPI, events Events, maddr address.Address, ds datastore.Batching, sealer sectorstorage.SectorManager, sc SectorIDCounter, verif ffiwrapper.Verifier, pcp PreCommitPolicy, gsd GetSealingDelayFunc) *Sealing { +func New(api SealingAPI, fc FeeConfig, events Events, maddr address.Address, ds datastore.Batching, sealer sectorstorage.SectorManager, sc SectorIDCounter, verif ffiwrapper.Verifier, pcp PreCommitPolicy, gsd GetSealingDelayFunc) *Sealing { s := &Sealing{ api: api, + feeCfg: fc, events: events, maddr: maddr, diff --git a/extern/storage-fsm/states_sealing.go b/extern/storage-fsm/states_sealing.go index 11e8a39a5..d307b7638 100644 --- a/extern/storage-fsm/states_sealing.go +++ b/extern/storage-fsm/states_sealing.go @@ -184,7 +184,7 @@ func (m *Sealing) handlePreCommitting(ctx statemachine.Context, sector SectorInf deposit := big.Max(depositMinimum, collateral) log.Infof("submitting precommit for sector %d (deposit: %s): ", sector.SectorNumber, deposit) - mcid, err := m.api.SendMsg(ctx.Context(), waddr, m.maddr, builtin.MethodsMiner.PreCommitSector, deposit, big.NewInt(0), 0, enc.Bytes()) + mcid, err := m.api.SendMsg(ctx.Context(), waddr, m.maddr, builtin.MethodsMiner.PreCommitSector, deposit, m.feeCfg.MaxPreCommitGasFee, enc.Bytes()) if err != nil { return ctx.Send(SectorChainPreCommitFailed{xerrors.Errorf("pushing message to mpool: %w", err)}) } @@ -333,7 +333,7 @@ func (m *Sealing) handleCommitting(ctx statemachine.Context, sector SectorInfo) } // TODO: check seed / ticket are up to date - mcid, err := m.api.SendMsg(ctx.Context(), waddr, m.maddr, builtin.MethodsMiner.ProveCommitSector, collateral, big.NewInt(0), 0, enc.Bytes()) + mcid, err := m.api.SendMsg(ctx.Context(), waddr, m.maddr, builtin.MethodsMiner.ProveCommitSector, collateral, m.feeCfg.MaxCommitGasFee, enc.Bytes()) if err != nil { return ctx.Send(SectorCommitFailed{xerrors.Errorf("pushing message to mpool: %w", err)}) } diff --git a/node/builder.go b/node/builder.go index aa0a18626..f70072596 100644 --- a/node/builder.go +++ b/node/builder.go @@ -302,7 +302,7 @@ func Online() Option { Override(new(storage2.Prover), From(new(sectorstorage.SectorManager))), Override(new(*sectorblocks.SectorBlocks), sectorblocks.NewSectorBlocks), - Override(new(*storage.Miner), modules.StorageMiner), + Override(new(*storage.Miner), modules.StorageMiner(config.DefaultStorageMiner().Fees)), Override(new(dtypes.NetworkName), modules.StorageNetworkName), Override(new(dtypes.StagingMultiDstore), modules.StagingMultiDatastore), @@ -439,6 +439,7 @@ func ConfigStorageMiner(c interface{}) Option { ), Override(new(sectorstorage.SealerConfig), cfg.Storage), + Override(new(*storage.Miner), modules.StorageMiner(cfg.Fees)), ) } diff --git a/node/config/def.go b/node/config/def.go index b967ed6c3..4fd5a5bd2 100644 --- a/node/config/def.go +++ b/node/config/def.go @@ -7,6 +7,8 @@ import ( "github.com/ipfs/go-cid" sectorstorage "github.com/filecoin-project/sector-storage" + + "github.com/filecoin-project/lotus/chain/types" ) // Common is common config between full node and miner @@ -29,8 +31,10 @@ type FullNode struct { type StorageMiner struct { Common - Dealmaking DealmakingConfig - Storage sectorstorage.SealerConfig + Dealmaking DealmakingConfig + Storage sectorstorage.SealerConfig + Fees MinerFeeConfig + SealingDelay Duration } @@ -45,6 +49,12 @@ type DealmakingConfig struct { Filter string } +type MinerFeeConfig struct { + MaxPreCommitGasFee types.FIL + MaxCommitGasFee types.FIL + MaxWindowPoStGasFee types.FIL +} + // API contains configs for API endpoint type API struct { ListenAddress string @@ -143,6 +153,12 @@ func DefaultStorageMiner() *StorageMiner { ExpectedSealDuration: Duration(time.Hour * 12), }, + Fees: MinerFeeConfig{ + MaxPreCommitGasFee: types.FIL(types.FromFil(1)), + MaxCommitGasFee: types.FIL(types.FromFil(1)), + MaxWindowPoStGasFee: types.FIL(types.FromFil(50)), + }, + SealingDelay: Duration(time.Hour), } cfg.Common.API.ListenAddress = "/ip4/127.0.0.1/tcp/2345/http" diff --git a/node/modules/storageminer.go b/node/modules/storageminer.go index a0956d31c..ebb0c4986 100644 --- a/node/modules/storageminer.go +++ b/node/modules/storageminer.go @@ -142,43 +142,45 @@ func SectorIDCounter(ds dtypes.MetadataDS) sealing.SectorIDCounter { return &sidsc{sc} } -func StorageMiner(mctx helpers.MetricsCtx, lc fx.Lifecycle, api lapi.FullNode, h host.Host, ds dtypes.MetadataDS, sealer sectorstorage.SectorManager, sc sealing.SectorIDCounter, verif ffiwrapper.Verifier, gsd dtypes.GetSealingDelayFunc) (*storage.Miner, error) { - maddr, err := minerAddrFromDS(ds) - if err != nil { - return nil, err +func StorageMiner(fc config.MinerFeeConfig) func(mctx helpers.MetricsCtx, lc fx.Lifecycle, api lapi.FullNode, h host.Host, ds dtypes.MetadataDS, sealer sectorstorage.SectorManager, sc sealing.SectorIDCounter, verif ffiwrapper.Verifier, gsd dtypes.GetSealingDelayFunc) (*storage.Miner, error) { + return func(mctx helpers.MetricsCtx, lc fx.Lifecycle, api lapi.FullNode, h host.Host, ds dtypes.MetadataDS, sealer sectorstorage.SectorManager, sc sealing.SectorIDCounter, verif ffiwrapper.Verifier, gsd dtypes.GetSealingDelayFunc) (*storage.Miner, error) { + maddr, err := minerAddrFromDS(ds) + if err != nil { + return nil, err + } + + ctx := helpers.LifecycleCtx(mctx, lc) + + mi, err := api.StateMinerInfo(ctx, maddr, types.EmptyTSK) + if err != nil { + return nil, err + } + + worker, err := api.StateAccountKey(ctx, mi.Worker, types.EmptyTSK) + if err != nil { + return nil, err + } + + fps, err := storage.NewWindowedPoStScheduler(api, fc, sealer, sealer, maddr, worker) + if err != nil { + return nil, err + } + + sm, err := storage.NewMiner(api, maddr, worker, h, ds, sealer, sc, verif, gsd, fc) + if err != nil { + return nil, err + } + + lc.Append(fx.Hook{ + OnStart: func(context.Context) error { + go fps.Run(ctx) + return sm.Run(ctx) + }, + OnStop: sm.Stop, + }) + + return sm, nil } - - ctx := helpers.LifecycleCtx(mctx, lc) - - mi, err := api.StateMinerInfo(ctx, maddr, types.EmptyTSK) - if err != nil { - return nil, err - } - - worker, err := api.StateAccountKey(ctx, mi.Worker, types.EmptyTSK) - if err != nil { - return nil, err - } - - fps, err := storage.NewWindowedPoStScheduler(api, sealer, sealer, maddr, worker) - if err != nil { - return nil, err - } - - sm, err := storage.NewMiner(api, maddr, worker, h, ds, sealer, sc, verif, gsd) - if err != nil { - return nil, err - } - - lc.Append(fx.Hook{ - OnStart: func(context.Context) error { - go fps.Run(ctx) - return sm.Run(ctx) - }, - OnStop: sm.Stop, - }) - - return sm, nil } func HandleRetrieval(host host.Host, lc fx.Lifecycle, m retrievalmarket.RetrievalProvider) { diff --git a/storage/adapter_storage_miner.go b/storage/adapter_storage_miner.go index 361127943..8938996eb 100644 --- a/storage/adapter_storage_miner.go +++ b/storage/adapter_storage_miner.go @@ -237,19 +237,16 @@ func (s SealingAPIAdapter) StateMarketStorageDeal(ctx context.Context, dealID ab return deal.Proposal, nil } -//TODO: rename/remove gasPrice and gasLimit -func (s SealingAPIAdapter) SendMsg(ctx context.Context, from, to address.Address, method abi.MethodNum, value, gasPrice big.Int, gasLimit int64, params []byte) (cid.Cid, error) { +func (s SealingAPIAdapter) SendMsg(ctx context.Context, from, to address.Address, method abi.MethodNum, value, maxFee abi.TokenAmount, params []byte) (cid.Cid, error) { msg := types.Message{ - To: to, - From: from, - Value: value, - GasPremium: gasPrice, - GasLimit: gasLimit, - Method: method, - Params: params, + To: to, + From: from, + Value: value, + Method: method, + Params: params, } - smsg, err := s.delegate.MpoolPushMessage(ctx, &msg, big.Zero()) + smsg, err := s.delegate.MpoolPushMessage(ctx, &msg, maxFee) if err != nil { return cid.Undef, err } diff --git a/storage/miner.go b/storage/miner.go index 4346757cb..9d81f7e6c 100644 --- a/storage/miner.go +++ b/storage/miner.go @@ -24,6 +24,7 @@ import ( "github.com/filecoin-project/lotus/chain/events" "github.com/filecoin-project/lotus/chain/gen" "github.com/filecoin-project/lotus/chain/types" + "github.com/filecoin-project/lotus/node/config" "github.com/filecoin-project/lotus/node/modules/dtypes" sealing "github.com/filecoin-project/storage-fsm" ) @@ -32,6 +33,7 @@ var log = logging.Logger("storageminer") type Miner struct { api storageMinerApi + feeCfg config.MinerFeeConfig h host.Host sealer sectorstorage.SectorManager ds datastore.Batching @@ -81,9 +83,10 @@ type storageMinerApi interface { WalletHas(context.Context, address.Address) (bool, error) } -func NewMiner(api storageMinerApi, maddr, worker address.Address, h host.Host, ds datastore.Batching, sealer sectorstorage.SectorManager, sc sealing.SectorIDCounter, verif ffiwrapper.Verifier, gsd dtypes.GetSealingDelayFunc) (*Miner, error) { +func NewMiner(api storageMinerApi, maddr, worker address.Address, h host.Host, ds datastore.Batching, sealer sectorstorage.SectorManager, sc sealing.SectorIDCounter, verif ffiwrapper.Verifier, gsd dtypes.GetSealingDelayFunc, feeCfg config.MinerFeeConfig) (*Miner, error) { m := &Miner{ api: api, + feeCfg: feeCfg, h: h, sealer: sealer, ds: ds, @@ -108,10 +111,15 @@ func (m *Miner) Run(ctx context.Context) error { return xerrors.Errorf("getting miner info: %w", err) } + fc := sealing.FeeConfig{ + MaxPreCommitGasFee: abi.TokenAmount(m.feeCfg.MaxPreCommitGasFee), + MaxCommitGasFee: abi.TokenAmount(m.feeCfg.MaxCommitGasFee), + } + evts := events.NewEvents(ctx, m.api) adaptedAPI := NewSealingAPIAdapter(m.api) pcp := sealing.NewBasicPreCommitPolicy(adaptedAPI, miner.MaxSectorExpirationExtension-(miner.WPoStProvingPeriod*2), md.PeriodStart%miner.WPoStProvingPeriod) - m.sealing = sealing.New(adaptedAPI, NewEventsAdapter(evts), m.maddr, m.ds, m.sealer, m.sc, m.verif, &pcp, sealing.GetSealingDelayFunc(m.getSealDelay)) + m.sealing = sealing.New(adaptedAPI, fc, NewEventsAdapter(evts), m.maddr, m.ds, m.sealer, m.sc, m.verif, &pcp, sealing.GetSealingDelayFunc(m.getSealDelay)) go m.sealing.Run(ctx) //nolint:errcheck // logged intside the function diff --git a/storage/wdpost_run.go b/storage/wdpost_run.go index 04ffe2606..c91db9441 100644 --- a/storage/wdpost_run.go +++ b/storage/wdpost_run.go @@ -10,7 +10,6 @@ import ( "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/builtin/miner" "github.com/filecoin-project/specs-actors/actors/crypto" @@ -178,7 +177,7 @@ func (s *WindowPoStScheduler) checkNextRecoveries(ctx context.Context, dlIdx uin Value: types.NewInt(0), } - sm, err := s.api.MpoolPushMessage(ctx, msg, big.Zero()) + sm, err := s.api.MpoolPushMessage(ctx, msg, abi.TokenAmount(s.feeCfg.MaxWindowPoStGasFee)) if err != nil { return xerrors.Errorf("pushing message to mpool: %w", err) } @@ -260,7 +259,7 @@ func (s *WindowPoStScheduler) checkNextFaults(ctx context.Context, dlIdx uint64, Value: types.NewInt(0), // TODO: Is there a fee? } - sm, err := s.api.MpoolPushMessage(ctx, msg, big.Zero()) + sm, err := s.api.MpoolPushMessage(ctx, msg, abi.TokenAmount(s.feeCfg.MaxWindowPoStGasFee)) if err != nil { return xerrors.Errorf("pushing message to mpool: %w", err) } @@ -457,7 +456,7 @@ func (s *WindowPoStScheduler) submitPost(ctx context.Context, proof *miner.Submi } // TODO: consider maybe caring about the output - sm, err := s.api.MpoolPushMessage(ctx, msg, big.Zero()) + sm, err := s.api.MpoolPushMessage(ctx, msg, abi.TokenAmount(s.feeCfg.MaxWindowPoStGasFee)) if err != nil { return xerrors.Errorf("pushing message to mpool: %w", err) } diff --git a/storage/wdpost_sched.go b/storage/wdpost_sched.go index 8e3221ef9..8adfe2f76 100644 --- a/storage/wdpost_sched.go +++ b/storage/wdpost_sched.go @@ -2,6 +2,7 @@ package storage import ( "context" + "github.com/filecoin-project/lotus/node/config" "time" "go.opencensus.io/trace" @@ -23,6 +24,7 @@ const StartConfidence = 4 // TODO: config type WindowPoStScheduler struct { api storageMinerApi + feeCfg config.MinerFeeConfig prover storage.Prover faultTracker sectorstorage.FaultTracker proofType abi.RegisteredPoStProof @@ -41,7 +43,7 @@ type WindowPoStScheduler struct { //failLk sync.Mutex } -func NewWindowedPoStScheduler(api storageMinerApi, sb storage.Prover, ft sectorstorage.FaultTracker, actor address.Address, worker address.Address) (*WindowPoStScheduler, error) { +func NewWindowedPoStScheduler(api storageMinerApi, fc config.MinerFeeConfig, sb storage.Prover, ft sectorstorage.FaultTracker, actor address.Address, worker address.Address) (*WindowPoStScheduler, error) { mi, err := api.StateMinerInfo(context.TODO(), actor, types.EmptyTSK) if err != nil { return nil, xerrors.Errorf("getting sector size: %w", err) @@ -54,6 +56,7 @@ func NewWindowedPoStScheduler(api storageMinerApi, sb storage.Prover, ft sectors return &WindowPoStScheduler{ api: api, + feeCfg: fc, prover: sb, faultTracker: ft, proofType: rt, From 78eaac6534b999c1bcde63aa1e4ca5d2b6b041a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Wed, 12 Aug 2020 19:55:43 +0200 Subject: [PATCH 3/7] config: Test deafult toml roundtrip --- node/config/def_test.go | 54 +++++++++++++++++++++++++++++++++++++++++ node/config/load.go | 1 - 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 node/config/def_test.go diff --git a/node/config/def_test.go b/node/config/def_test.go new file mode 100644 index 000000000..d45bc6ec8 --- /dev/null +++ b/node/config/def_test.go @@ -0,0 +1,54 @@ +package config + +import ( + "bytes" + "fmt" + "reflect" + "strings" + "testing" + + "github.com/BurntSushi/toml" + "github.com/stretchr/testify/require" +) + +func TestDefaultFullNodeRoundtrip(t *testing.T) { + c := DefaultFullNode() + + var s string + { + buf := new(bytes.Buffer) + _, _ = buf.WriteString("# Default config:\n") + e := toml.NewEncoder(buf) + require.NoError(t, e.Encode(c)) + + s = buf.String() + } + + c2, err := FromReader(strings.NewReader(s), DefaultFullNode()) + require.NoError(t, err) + + fmt.Println(s) + + require.True(t, reflect.DeepEqual(c, c2)) +} + +func TestDefaultMinerRoundtrip(t *testing.T) { + c := DefaultStorageMiner() + + var s string + { + buf := new(bytes.Buffer) + _, _ = buf.WriteString("# Default config:\n") + e := toml.NewEncoder(buf) + require.NoError(t, e.Encode(c)) + + s = buf.String() + } + + c2, err := FromReader(strings.NewReader(s), DefaultStorageMiner()) + require.NoError(t, err) + + fmt.Println(s) + + require.True(t, reflect.DeepEqual(c, c2)) +} diff --git a/node/config/load.go b/node/config/load.go index b0786643f..61e6e8f97 100644 --- a/node/config/load.go +++ b/node/config/load.go @@ -53,5 +53,4 @@ func ConfigComment(t interface{}) ([]byte, error) { b = bytes.ReplaceAll(b, []byte("\n"), []byte("\n#")) b = bytes.ReplaceAll(b, []byte("#["), []byte("[")) return b, nil - } From 03c1776b43c31b1d56607bd85f10c57ba59d7f09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Wed, 12 Aug 2020 19:58:39 +0200 Subject: [PATCH 4/7] types: Add text (un)marshaler on FIL --- chain/types/fil.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/chain/types/fil.go b/chain/types/fil.go index 1d912d9c0..99a896e38 100644 --- a/chain/types/fil.go +++ b/chain/types/fil.go @@ -1,6 +1,7 @@ package types import ( + "encoding" "fmt" "math/big" "strings" @@ -27,6 +28,20 @@ func (f FIL) Format(s fmt.State, ch rune) { } } +func (f FIL) MarshalText() (text []byte, err error) { + return []byte(f.String()), nil +} + +func (f FIL) UnmarshalText(text []byte) error { + p, err := ParseFIL(string(text)) + if err != nil { + return err + } + + f.Int.Set(p.Int) + return nil +} + func ParseFIL(s string) (FIL, error) { suffix := strings.TrimLeft(s, ".1234567890") s = s[:len(s)-len(suffix)] @@ -61,3 +76,6 @@ func ParseFIL(s string) (FIL, error) { return FIL{r.Num()}, nil } + +var _ encoding.TextMarshaler = (*FIL)(nil) +var _ encoding.TextUnmarshaler = (*FIL)(nil) From 6fe743f3a91103b4e9311d26ce5a573a078be76b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Wed, 12 Aug 2020 20:03:07 +0200 Subject: [PATCH 5/7] Fix tests --- api/test/paych.go | 4 ++-- chain/market/fundmgr_test.go | 2 +- cmd/chain-noise/main.go | 3 ++- cmd/lotus-fountain/main.go | 7 ++++--- cmd/lotus-pcr/main.go | 14 ++++++++------ cmd/lotus-shed/verifreg.go | 19 ++++++++++--------- node/node_test.go | 2 +- paychmgr/mock_test.go | 3 ++- 8 files changed, 30 insertions(+), 24 deletions(-) diff --git a/api/test/paych.go b/api/test/paych.go index 85a89f18c..69ee2cf7a 100644 --- a/api/test/paych.go +++ b/api/test/paych.go @@ -221,7 +221,7 @@ func waitForBlocks(ctx context.Context, t *testing.T, bm *blockMiner, paymentRec To: builtin.BurntFundsActorAddr, From: receiverAddr, Value: types.NewInt(0), - }) + }, big.Zero()) if err != nil { t.Fatal(err) } @@ -307,7 +307,7 @@ func sendFunds(ctx context.Context, t *testing.T, sender TestNode, addr address. Value: amount, } - sm, err := sender.MpoolPushMessage(ctx, msg) + sm, err := sender.MpoolPushMessage(ctx, msg, big.Zero()) if err != nil { t.Fatal(err) } diff --git a/chain/market/fundmgr_test.go b/chain/market/fundmgr_test.go index 7010b3344..f2378d50c 100644 --- a/chain/market/fundmgr_test.go +++ b/chain/market/fundmgr_test.go @@ -36,7 +36,7 @@ func (fapi *fakeAPI) StateMarketBalance(context.Context, address.Address, types. return fapi.returnedBalance, fapi.returnedBalanceErr } -func (fapi *fakeAPI) MpoolPushMessage(ctx context.Context, msg *types.Message) (*types.SignedMessage, error) { +func (fapi *fakeAPI) MpoolPushMessage(ctx context.Context, msg *types.Message, maxFee abi.TokenAmount) (*types.SignedMessage, error) { fapi.receivedMessage = msg return &types.SignedMessage{ Message: *msg, diff --git a/cmd/chain-noise/main.go b/cmd/chain-noise/main.go index a8ce8a4fa..44131e11b 100644 --- a/cmd/chain-noise/main.go +++ b/cmd/chain-noise/main.go @@ -7,6 +7,7 @@ import ( "os" "time" + "github.com/filecoin-project/specs-actors/actors/abi/big" "github.com/filecoin-project/specs-actors/actors/crypto" "github.com/filecoin-project/go-address" @@ -79,7 +80,7 @@ func sendSmallFundsTxs(ctx context.Context, api api.FullNode, from address.Addre Value: types.NewInt(1), } - smsg, err := api.MpoolPushMessage(ctx, msg) + smsg, err := api.MpoolPushMessage(ctx, msg, big.Zero()) if err != nil { return err } diff --git a/cmd/lotus-fountain/main.go b/cmd/lotus-fountain/main.go index 7cbeec90e..dd8ad4935 100644 --- a/cmd/lotus-fountain/main.go +++ b/cmd/lotus-fountain/main.go @@ -23,6 +23,7 @@ import ( "github.com/filecoin-project/sector-storage/ffiwrapper" "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/builtin/power" @@ -279,7 +280,7 @@ func (h *handler) send(w http.ResponseWriter, r *http.Request) { Value: types.BigInt(h.sendPerRequest), From: h.from, To: to, - }) + }, big.Zero()) if err != nil { w.WriteHeader(400) _, _ = w.Write([]byte(err.Error())) @@ -350,7 +351,7 @@ func (h *handler) mkminer(w http.ResponseWriter, r *http.Request) { Value: types.BigInt(h.sendPerRequest), From: h.from, To: owner, - }) + }, big.Zero()) if err != nil { w.WriteHeader(400) w.Write([]byte("pushfunds: " + err.Error())) @@ -386,7 +387,7 @@ func (h *handler) mkminer(w http.ResponseWriter, r *http.Request) { Params: params, } - signed, err := h.api.MpoolPushMessage(r.Context(), createStorageMinerMsg) + signed, err := h.api.MpoolPushMessage(r.Context(), createStorageMinerMsg, big.Zero()) if err != nil { w.WriteHeader(400) w.Write([]byte(err.Error())) diff --git a/cmd/lotus-pcr/main.go b/cmd/lotus-pcr/main.go index 43b0b2ffc..eb7331746 100644 --- a/cmd/lotus-pcr/main.go +++ b/cmd/lotus-pcr/main.go @@ -19,15 +19,17 @@ import ( "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/specs-actors/actors/builtin" + "github.com/filecoin-project/specs-actors/actors/builtin/miner" + "github.com/filecoin-project/specs-actors/actors/runtime/exitcode" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/tools/stats" - "github.com/filecoin-project/specs-actors/actors/abi" - "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/actors/runtime/exitcode" ) var log = logging.Logger("main") @@ -204,7 +206,7 @@ type processTipSetApi interface { ChainGetParentReceipts(ctx context.Context, blockCid cid.Cid) ([]*types.MessageReceipt, error) StateMinerInitialPledgeCollateral(ctx context.Context, addr address.Address, precommitInfo miner.SectorPreCommitInfo, tsk types.TipSetKey) (types.BigInt, error) StateGetActor(ctx context.Context, actor address.Address, tsk types.TipSetKey) (*types.Actor, error) - MpoolPushMessage(ctx context.Context, msg *types.Message) (*types.SignedMessage, error) + MpoolPushMessage(ctx context.Context, msg *types.Message, maxFee abi.TokenAmount) (*types.SignedMessage, error) GasEstimateGasPremium(ctx context.Context, nblocksincl uint64, sender address.Address, gaslimit int64, tsk types.TipSetKey) (types.BigInt, error) WalletBalance(ctx context.Context, addr address.Address) (types.BigInt, error) } @@ -326,7 +328,7 @@ func ProcessTipset(ctx context.Context, api processTipSetApi, tipset *types.TipS failures := 0 refundSum.SetUint64(0) for _, msg := range messages { - if _, err = api.MpoolPushMessage(ctx, msg); err != nil { + if _, err = api.MpoolPushMessage(ctx, msg, big.Zero()); err != nil { log.Errorw("failed to MpoolPushMessage", "err", err, "msg", msg) failures = failures + 1 continue diff --git a/cmd/lotus-shed/verifreg.go b/cmd/lotus-shed/verifreg.go index e8e600fcb..e478e4472 100644 --- a/cmd/lotus-shed/verifreg.go +++ b/cmd/lotus-shed/verifreg.go @@ -3,19 +3,20 @@ package main import ( "fmt" - "github.com/filecoin-project/go-address" - "github.com/filecoin-project/lotus/build" "github.com/urfave/cli/v2" "golang.org/x/xerrors" - "github.com/filecoin-project/lotus/chain/types" - lcli "github.com/filecoin-project/lotus/cli" - - "github.com/filecoin-project/lotus/api/apibstore" - "github.com/filecoin-project/lotus/chain/actors" + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/specs-actors/actors/abi/big" "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" "github.com/filecoin-project/specs-actors/actors/util/adt" + + "github.com/filecoin-project/lotus/api/apibstore" + "github.com/filecoin-project/lotus/build" + "github.com/filecoin-project/lotus/chain/actors" + "github.com/filecoin-project/lotus/chain/types" + lcli "github.com/filecoin-project/lotus/cli" cbor "github.com/ipfs/go-ipld-cbor" ) @@ -75,7 +76,7 @@ var verifRegAddVerifierCmd = &cli.Command{ Params: params, } - smsg, err := api.MpoolPushMessage(ctx, msg) + smsg, err := api.MpoolPushMessage(ctx, msg, big.Zero()) if err != nil { return err } @@ -149,7 +150,7 @@ var verifRegVerifyClientCmd = &cli.Command{ Params: params, } - smsg, err := api.MpoolPushMessage(ctx, msg) + smsg, err := api.MpoolPushMessage(ctx, msg, big.Zero()) if err != nil { return err } diff --git a/node/node_test.go b/node/node_test.go index a0fa3461e..621cb0c9a 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -110,7 +110,7 @@ func testStorageNode(ctx context.Context, t *testing.T, waddr address.Address, a Value: types.NewInt(0), } - _, err = tnd.MpoolPushMessage(ctx, msg) + _, err = tnd.MpoolPushMessage(ctx, msg, big.Zero()) require.NoError(t, err) // start node diff --git a/paychmgr/mock_test.go b/paychmgr/mock_test.go index 6db357ecb..44dc5f1db 100644 --- a/paychmgr/mock_test.go +++ b/paychmgr/mock_test.go @@ -3,6 +3,7 @@ package paychmgr import ( "context" "fmt" + "github.com/filecoin-project/specs-actors/actors/abi" "sync" "github.com/filecoin-project/go-address" @@ -156,7 +157,7 @@ func (pchapi *mockPaychAPI) close() { } } -func (pchapi *mockPaychAPI) MpoolPushMessage(ctx context.Context, msg *types.Message) (*types.SignedMessage, error) { +func (pchapi *mockPaychAPI) MpoolPushMessage(ctx context.Context, msg *types.Message, maxFee abi.TokenAmount) (*types.SignedMessage, error) { pchapi.lk.Lock() defer pchapi.lk.Unlock() From fd4d2067a9079cdb0cd719784567e8ca90fdd52d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Wed, 12 Aug 2020 22:01:31 +0200 Subject: [PATCH 6/7] mpool: Fix capGasFee math --- node/impl/full/mpool.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/node/impl/full/mpool.go b/node/impl/full/mpool.go index 4f319026e..313f6c40c 100644 --- a/node/impl/full/mpool.go +++ b/node/impl/full/mpool.go @@ -115,10 +115,11 @@ func capGasFee(msg *types.Message, maxFee abi.TokenAmount) { return } - chainFee := types.BigMul(msg.GasFeeCap, types.NewInt(uint64(msg.GasLimit))) - minerFee := types.BigMul(msg.GasPremium, types.NewInt(uint64(msg.GasLimit))) + gl := types.BigMul(msg.GasPremium, types.NewInt(uint64(msg.GasLimit))) + totalFee := types.BigMul(msg.GasFeeCap, gl) + minerFee := types.BigMul(msg.GasPremium, gl) - if big.Add(chainFee, minerFee).LessThanEqual(maxFee) { + if totalFee.LessThanEqual(maxFee) { return } @@ -126,9 +127,8 @@ func capGasFee(msg *types.Message, maxFee abi.TokenAmount) { // TODO: there are probably smarter things we can do here to optimize // message inclusion latency - totalFee := big.Add(chainFee, minerFee) - msg.GasFeeCap = big.Div(big.Mul(chainFee, maxFee), totalFee) - msg.GasPremium = big.Div(big.Mul(minerFee, maxFee), totalFee) + 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, maxFee abi.TokenAmount) (*types.SignedMessage, error) { From 12f7e2d9bfed04bd2dd387851e98d86da3b7fe32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Wed, 12 Aug 2020 22:17:21 +0200 Subject: [PATCH 7/7] Use a struct for send metadata in MpoolPushMessage --- api/api_full.go | 2 +- api/apistruct/struct.go | 14 +++++++------- api/test/paych.go | 4 ++-- api/types.go | 17 +++++++++++++++++ chain/market/fundmgr.go | 4 ++-- chain/market/fundmgr_test.go | 2 +- cli/chain.go | 2 +- cli/send.go | 3 +-- cmd/chain-noise/main.go | 3 +-- cmd/lotus-fountain/main.go | 7 +++---- cmd/lotus-pcr/main.go | 5 ++--- cmd/lotus-shed/verifreg.go | 5 ++--- cmd/lotus-storage-miner/actor.go | 3 +-- cmd/lotus-storage-miner/init.go | 5 ++--- cmd/lotus-storage-miner/rewards.go | 3 +-- markets/storageadapter/client.go | 3 +-- markets/storageadapter/provider.go | 5 ++--- node/impl/full/mpool.go | 5 ++--- node/impl/full/multisig.go | 6 +++--- node/impl/paych/paych.go | 3 +-- node/node_test.go | 2 +- paychmgr/manager.go | 3 +-- paychmgr/mock_test.go | 3 +-- paychmgr/paych.go | 4 ++-- paychmgr/simple.go | 4 ++-- storage/adapter_storage_miner.go | 3 ++- storage/miner.go | 2 +- storage/wdpost_run.go | 7 ++++--- 28 files changed, 67 insertions(+), 62 deletions(-) diff --git a/api/api_full.go b/api/api_full.go index b1abaabd7..b83f6df65 100644 --- a/api/api_full.go +++ b/api/api_full.go @@ -174,7 +174,7 @@ type FullNode interface { // // When maxFee is set to 0, MpoolPushMessage will guess appropriate fee // based on current chain conditions - MpoolPushMessage(ctx context.Context, msg *types.Message, maxFee abi.TokenAmount) (*types.SignedMessage, error) + MpoolPushMessage(ctx context.Context, msg *types.Message, spec *MessageSendSpec) (*types.SignedMessage, error) // MpoolGetNonce gets next nonce for the specified sender. // Note that this method may not be atomic. Use MpoolPushMessage instead. diff --git a/api/apistruct/struct.go b/api/apistruct/struct.go index ad2eb0c80..4f16d56bb 100644 --- a/api/apistruct/struct.go +++ b/api/apistruct/struct.go @@ -104,11 +104,11 @@ type FullNodeStruct struct { MpoolSelect func(context.Context, types.TipSetKey, float64) ([]*types.SignedMessage, error) `perm:"read"` - MpoolPending func(context.Context, types.TipSetKey) ([]*types.SignedMessage, error) `perm:"read"` - MpoolPush func(context.Context, *types.SignedMessage) (cid.Cid, error) `perm:"write"` - MpoolPushMessage func(context.Context, *types.Message, abi.TokenAmount) (*types.SignedMessage, error) `perm:"sign"` - MpoolGetNonce func(context.Context, address.Address) (uint64, error) `perm:"read"` - MpoolSub func(context.Context) (<-chan api.MpoolUpdate, error) `perm:"read"` + MpoolPending func(context.Context, types.TipSetKey) ([]*types.SignedMessage, error) `perm:"read"` + MpoolPush func(context.Context, *types.SignedMessage) (cid.Cid, error) `perm:"write"` + MpoolPushMessage func(context.Context, *types.Message, *api.MessageSendSpec) (*types.SignedMessage, error) `perm:"sign"` + MpoolGetNonce func(context.Context, address.Address) (uint64, error) `perm:"read"` + MpoolSub func(context.Context) (<-chan api.MpoolUpdate, error) `perm:"read"` MinerGetBaseInfo func(context.Context, address.Address, abi.ChainEpoch, types.TipSetKey) (*api.MiningBaseInfo, error) `perm:"read"` MinerCreateBlock func(context.Context, *api.BlockTemplate) (*types.BlockMsg, error) `perm:"write"` @@ -472,8 +472,8 @@ func (c *FullNodeStruct) MpoolPush(ctx context.Context, smsg *types.SignedMessag return c.Internal.MpoolPush(ctx, smsg) } -func (c *FullNodeStruct) MpoolPushMessage(ctx context.Context, msg *types.Message, maxFee abi.TokenAmount) (*types.SignedMessage, error) { - return c.Internal.MpoolPushMessage(ctx, msg, maxFee) +func (c *FullNodeStruct) MpoolPushMessage(ctx context.Context, msg *types.Message, spec *api.MessageSendSpec) (*types.SignedMessage, error) { + return c.Internal.MpoolPushMessage(ctx, msg, spec) } func (c *FullNodeStruct) MpoolSub(ctx context.Context) (<-chan api.MpoolUpdate, error) { diff --git a/api/test/paych.go b/api/test/paych.go index 69ee2cf7a..1b1d4e438 100644 --- a/api/test/paych.go +++ b/api/test/paych.go @@ -221,7 +221,7 @@ func waitForBlocks(ctx context.Context, t *testing.T, bm *blockMiner, paymentRec To: builtin.BurntFundsActorAddr, From: receiverAddr, Value: types.NewInt(0), - }, big.Zero()) + }, nil) if err != nil { t.Fatal(err) } @@ -307,7 +307,7 @@ func sendFunds(ctx context.Context, t *testing.T, sender TestNode, addr address. Value: amount, } - sm, err := sender.MpoolPushMessage(ctx, msg, big.Zero()) + sm, err := sender.MpoolPushMessage(ctx, msg, nil) if err != nil { t.Fatal(err) } diff --git a/api/types.go b/api/types.go index a094e4ec1..8e8c32122 100644 --- a/api/types.go +++ b/api/types.go @@ -4,6 +4,7 @@ import ( "encoding/json" "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/miner" "github.com/libp2p/go-libp2p-core/peer" @@ -76,3 +77,19 @@ func NewApiMinerInfo(info *miner.MinerInfo) MinerInfo { return mi } + +type MessageSendSpec struct { + MaxFee abi.TokenAmount +} + +var DefaultMessageSendSpec = MessageSendSpec{ + MaxFee: big.Zero(), +} + +func (ms *MessageSendSpec) Get() MessageSendSpec { + if ms == nil { + return DefaultMessageSendSpec + } + + return *ms +} diff --git a/chain/market/fundmgr.go b/chain/market/fundmgr.go index a0d778de6..574e718a0 100644 --- a/chain/market/fundmgr.go +++ b/chain/market/fundmgr.go @@ -60,7 +60,7 @@ func StartFundManager(lc fx.Lifecycle, api API) *FundMgr { type fundMgrAPI interface { StateMarketBalance(context.Context, address.Address, types.TipSetKey) (api.MarketBalance, error) - MpoolPushMessage(context.Context, *types.Message, abi.TokenAmount) (*types.SignedMessage, error) + MpoolPushMessage(context.Context, *types.Message, *api.MessageSendSpec) (*types.SignedMessage, error) StateLookupID(context.Context, address.Address, types.TipSetKey) (address.Address, error) } @@ -149,7 +149,7 @@ func (fm *FundMgr) EnsureAvailable(ctx context.Context, addr, wallet address.Add Value: toAdd, Method: builtin.MethodsMarket.AddBalance, Params: params, - }, big.Zero()) + }, nil) if err != nil { return cid.Undef, err } diff --git a/chain/market/fundmgr_test.go b/chain/market/fundmgr_test.go index f2378d50c..d1b0fb7e6 100644 --- a/chain/market/fundmgr_test.go +++ b/chain/market/fundmgr_test.go @@ -36,7 +36,7 @@ func (fapi *fakeAPI) StateMarketBalance(context.Context, address.Address, types. return fapi.returnedBalance, fapi.returnedBalanceErr } -func (fapi *fakeAPI) MpoolPushMessage(ctx context.Context, msg *types.Message, maxFee abi.TokenAmount) (*types.SignedMessage, error) { +func (fapi *fakeAPI) MpoolPushMessage(ctx context.Context, msg *types.Message, spec *api.MessageSendSpec) (*types.SignedMessage, error) { fapi.receivedMessage = msg return &types.SignedMessage{ Message: *msg, diff --git a/cli/chain.go b/cli/chain.go index d72f438a9..22c35abb3 100644 --- a/cli/chain.go +++ b/cli/chain.go @@ -1007,7 +1007,7 @@ var slashConsensusFault = &cli.Command{ Params: enc, } - smsg, err := api.MpoolPushMessage(ctx, msg, big.Zero()) + smsg, err := api.MpoolPushMessage(ctx, msg, nil) if err != nil { return err } diff --git a/cli/send.go b/cli/send.go index 6ef2c4c4c..ecec42191 100644 --- a/cli/send.go +++ b/cli/send.go @@ -13,7 +13,6 @@ import ( "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/lotus/api" "github.com/filecoin-project/lotus/chain/stmgr" @@ -157,7 +156,7 @@ var sendCmd = &cli.Command{ } fmt.Println(sm.Cid()) } else { - sm, err := api.MpoolPushMessage(ctx, msg, big.Zero()) + sm, err := api.MpoolPushMessage(ctx, msg, nil) if err != nil { return err } diff --git a/cmd/chain-noise/main.go b/cmd/chain-noise/main.go index 44131e11b..1decd0c0f 100644 --- a/cmd/chain-noise/main.go +++ b/cmd/chain-noise/main.go @@ -7,7 +7,6 @@ import ( "os" "time" - "github.com/filecoin-project/specs-actors/actors/abi/big" "github.com/filecoin-project/specs-actors/actors/crypto" "github.com/filecoin-project/go-address" @@ -80,7 +79,7 @@ func sendSmallFundsTxs(ctx context.Context, api api.FullNode, from address.Addre Value: types.NewInt(1), } - smsg, err := api.MpoolPushMessage(ctx, msg, big.Zero()) + smsg, err := api.MpoolPushMessage(ctx, msg, nil) if err != nil { return err } diff --git a/cmd/lotus-fountain/main.go b/cmd/lotus-fountain/main.go index dd8ad4935..84538e61b 100644 --- a/cmd/lotus-fountain/main.go +++ b/cmd/lotus-fountain/main.go @@ -23,7 +23,6 @@ import ( "github.com/filecoin-project/sector-storage/ffiwrapper" "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/builtin/power" @@ -280,7 +279,7 @@ func (h *handler) send(w http.ResponseWriter, r *http.Request) { Value: types.BigInt(h.sendPerRequest), From: h.from, To: to, - }, big.Zero()) + }, nil) if err != nil { w.WriteHeader(400) _, _ = w.Write([]byte(err.Error())) @@ -351,7 +350,7 @@ func (h *handler) mkminer(w http.ResponseWriter, r *http.Request) { Value: types.BigInt(h.sendPerRequest), From: h.from, To: owner, - }, big.Zero()) + }, nil) if err != nil { w.WriteHeader(400) w.Write([]byte("pushfunds: " + err.Error())) @@ -387,7 +386,7 @@ func (h *handler) mkminer(w http.ResponseWriter, r *http.Request) { Params: params, } - signed, err := h.api.MpoolPushMessage(r.Context(), createStorageMinerMsg, big.Zero()) + signed, err := h.api.MpoolPushMessage(r.Context(), createStorageMinerMsg, nil) if err != nil { w.WriteHeader(400) w.Write([]byte(err.Error())) diff --git a/cmd/lotus-pcr/main.go b/cmd/lotus-pcr/main.go index eb7331746..fe75349a2 100644 --- a/cmd/lotus-pcr/main.go +++ b/cmd/lotus-pcr/main.go @@ -20,7 +20,6 @@ import ( "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/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/specs-actors/actors/runtime/exitcode" @@ -206,7 +205,7 @@ type processTipSetApi interface { ChainGetParentReceipts(ctx context.Context, blockCid cid.Cid) ([]*types.MessageReceipt, error) StateMinerInitialPledgeCollateral(ctx context.Context, addr address.Address, precommitInfo miner.SectorPreCommitInfo, tsk types.TipSetKey) (types.BigInt, error) StateGetActor(ctx context.Context, actor address.Address, tsk types.TipSetKey) (*types.Actor, error) - MpoolPushMessage(ctx context.Context, msg *types.Message, maxFee abi.TokenAmount) (*types.SignedMessage, error) + MpoolPushMessage(ctx context.Context, msg *types.Message, spec *api.MessageSendSpec) (*types.SignedMessage, error) GasEstimateGasPremium(ctx context.Context, nblocksincl uint64, sender address.Address, gaslimit int64, tsk types.TipSetKey) (types.BigInt, error) WalletBalance(ctx context.Context, addr address.Address) (types.BigInt, error) } @@ -328,7 +327,7 @@ func ProcessTipset(ctx context.Context, api processTipSetApi, tipset *types.TipS failures := 0 refundSum.SetUint64(0) for _, msg := range messages { - if _, err = api.MpoolPushMessage(ctx, msg, big.Zero()); err != nil { + if _, err = api.MpoolPushMessage(ctx, msg, nil); err != nil { log.Errorw("failed to MpoolPushMessage", "err", err, "msg", msg) failures = failures + 1 continue diff --git a/cmd/lotus-shed/verifreg.go b/cmd/lotus-shed/verifreg.go index e478e4472..6e24dc0b6 100644 --- a/cmd/lotus-shed/verifreg.go +++ b/cmd/lotus-shed/verifreg.go @@ -7,7 +7,6 @@ import ( "golang.org/x/xerrors" "github.com/filecoin-project/go-address" - "github.com/filecoin-project/specs-actors/actors/abi/big" "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" "github.com/filecoin-project/specs-actors/actors/util/adt" @@ -76,7 +75,7 @@ var verifRegAddVerifierCmd = &cli.Command{ Params: params, } - smsg, err := api.MpoolPushMessage(ctx, msg, big.Zero()) + smsg, err := api.MpoolPushMessage(ctx, msg, nil) if err != nil { return err } @@ -150,7 +149,7 @@ var verifRegVerifyClientCmd = &cli.Command{ Params: params, } - smsg, err := api.MpoolPushMessage(ctx, msg, big.Zero()) + smsg, err := api.MpoolPushMessage(ctx, msg, nil) if err != nil { return err } diff --git a/cmd/lotus-storage-miner/actor.go b/cmd/lotus-storage-miner/actor.go index 96a38a015..18e3796a3 100644 --- a/cmd/lotus-storage-miner/actor.go +++ b/cmd/lotus-storage-miner/actor.go @@ -7,7 +7,6 @@ import ( "github.com/urfave/cli/v2" "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/miner" "github.com/filecoin-project/lotus/chain/actors" @@ -82,7 +81,7 @@ var actorSetAddrsCmd = &cli.Command{ GasLimit: gasLimit, Method: 18, Params: params, - }, big.Zero()) + }, nil) if err != nil { return err } diff --git a/cmd/lotus-storage-miner/init.go b/cmd/lotus-storage-miner/init.go index af7a3fd04..56575c0ca 100644 --- a/cmd/lotus-storage-miner/init.go +++ b/cmd/lotus-storage-miner/init.go @@ -28,7 +28,6 @@ import ( "github.com/filecoin-project/sector-storage/ffiwrapper" "github.com/filecoin-project/sector-storage/stores" "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/builtin/market" miner2 "github.com/filecoin-project/specs-actors/actors/builtin/miner" @@ -561,7 +560,7 @@ func configureStorageMiner(ctx context.Context, api lapi.FullNode, addr address. GasPremium: gasPrice, } - smsg, err := api.MpoolPushMessage(ctx, msg, big.Zero()) + smsg, err := api.MpoolPushMessage(ctx, msg, nil) if err != nil { return err } @@ -641,7 +640,7 @@ func createStorageMiner(ctx context.Context, api lapi.FullNode, peerid peer.ID, GasPremium: gasPrice, } - signed, err := api.MpoolPushMessage(ctx, createStorageMinerMsg, big.Zero()) + signed, err := api.MpoolPushMessage(ctx, createStorageMinerMsg, nil) if err != nil { return address.Undef, err } diff --git a/cmd/lotus-storage-miner/rewards.go b/cmd/lotus-storage-miner/rewards.go index bb6773bc1..fa1fcb4dc 100644 --- a/cmd/lotus-storage-miner/rewards.go +++ b/cmd/lotus-storage-miner/rewards.go @@ -5,7 +5,6 @@ import ( "github.com/urfave/cli/v2" - "github.com/filecoin-project/specs-actors/actors/abi/big" "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/builtin/miner" @@ -67,7 +66,7 @@ var rewardsRedeemCmd = &cli.Command{ Value: types.NewInt(0), Method: builtin.MethodsMiner.WithdrawBalance, Params: params, - }, big.Zero()) + }, nil) if err != nil { return err } diff --git a/markets/storageadapter/client.go b/markets/storageadapter/client.go index b95c6fe17..f7627fa7a 100644 --- a/markets/storageadapter/client.go +++ b/markets/storageadapter/client.go @@ -23,7 +23,6 @@ import ( "github.com/filecoin-project/lotus/markets/utils" "github.com/filecoin-project/lotus/node/impl/full" "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" samarket "github.com/filecoin-project/specs-actors/actors/builtin/market" "github.com/filecoin-project/specs-actors/actors/builtin/miner" @@ -127,7 +126,7 @@ func (c *ClientNodeAdapter) AddFunds(ctx context.Context, addr address.Address, From: addr, Value: amount, Method: builtin.MethodsMarket.AddBalance, - }, big.Zero()) + }, nil) if err != nil { return cid.Undef, err } diff --git a/markets/storageadapter/provider.go b/markets/storageadapter/provider.go index b67becefa..788fd769a 100644 --- a/markets/storageadapter/provider.go +++ b/markets/storageadapter/provider.go @@ -15,7 +15,6 @@ import ( "github.com/filecoin-project/go-fil-markets/shared" "github.com/filecoin-project/go-fil-markets/storagemarket" "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/builtin/market" "github.com/filecoin-project/specs-actors/actors/builtin/miner" @@ -80,7 +79,7 @@ func (n *ProviderNodeAdapter) PublishDeals(ctx context.Context, deal storagemark Value: types.NewInt(0), Method: builtin.MethodsMarket.PublishStorageDeals, Params: params, - }, big.Zero()) + }, nil) if err != nil { return cid.Undef, err } @@ -178,7 +177,7 @@ func (n *ProviderNodeAdapter) AddFunds(ctx context.Context, addr address.Address From: addr, Value: amount, Method: builtin.MethodsMarket.AddBalance, - }, big.Zero()) + }, nil) if err != nil { return cid.Undef, err } diff --git a/node/impl/full/mpool.go b/node/impl/full/mpool.go index 313f6c40c..f77085d04 100644 --- a/node/impl/full/mpool.go +++ b/node/impl/full/mpool.go @@ -15,7 +15,6 @@ import ( "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/node/modules/dtypes" - "github.com/filecoin-project/specs-actors/actors/abi/big" ) type MpoolAPI struct { @@ -131,7 +130,7 @@ func capGasFee(msg *types.Message, maxFee abi.TokenAmount) { msg.GasPremium = big.Div(big.Div(big.Mul(minerFee, maxFee), totalFee), gl) } -func (a *MpoolAPI) MpoolPushMessage(ctx context.Context, msg *types.Message, maxFee abi.TokenAmount) (*types.SignedMessage, error) { +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) if err != nil { @@ -171,7 +170,7 @@ func (a *MpoolAPI) MpoolPushMessage(ctx context.Context, msg *types.Message, max msg.GasFeeCap = big.Add(feeCap, msg.GasPremium) } - capGasFee(msg, maxFee) + capGasFee(msg, spec.Get().MaxFee) sign := func(from address.Address, nonce uint64) (*types.SignedMessage, error) { msg.Nonce = nonce diff --git a/node/impl/full/multisig.go b/node/impl/full/multisig.go index 9889c915c..88ff4cdc9 100644 --- a/node/impl/full/multisig.go +++ b/node/impl/full/multisig.go @@ -78,7 +78,7 @@ func (a *MsigAPI) MsigCreate(ctx context.Context, req uint64, addrs []address.Ad } // send the message out to the network - smsg, err := a.MpoolAPI.MpoolPushMessage(ctx, &msg, big.Zero()) + smsg, err := a.MpoolAPI.MpoolPushMessage(ctx, &msg, nil) if err != nil { return cid.Undef, err } @@ -122,7 +122,7 @@ func (a *MsigAPI) MsigPropose(ctx context.Context, msig address.Address, to addr Params: enc, } - smsg, err := a.MpoolAPI.MpoolPushMessage(ctx, msg, big.Zero()) + smsg, err := a.MpoolAPI.MpoolPushMessage(ctx, msg, nil) if err != nil { return cid.Undef, xerrors.Errorf("failed to push message: %w", err) } @@ -236,7 +236,7 @@ func (a *MsigAPI) msigApproveOrCancel(ctx context.Context, operation api.MsigPro Params: enc, } - smsg, err := a.MpoolAPI.MpoolPushMessage(ctx, msg, big.Zero()) + smsg, err := a.MpoolAPI.MpoolPushMessage(ctx, msg, nil) if err != nil { return cid.Undef, err } diff --git a/node/impl/paych/paych.go b/node/impl/paych/paych.go index 7600270b5..abbd2b5a5 100644 --- a/node/impl/paych/paych.go +++ b/node/impl/paych/paych.go @@ -9,7 +9,6 @@ import ( "golang.org/x/xerrors" "github.com/filecoin-project/go-address" - "github.com/filecoin-project/specs-actors/actors/abi/big" "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/builtin/paych" @@ -211,7 +210,7 @@ func (a *PaychAPI) PaychVoucherSubmit(ctx context.Context, ch address.Address, s Params: enc, } - smsg, err := a.MpoolPushMessage(ctx, msg, big.Zero()) + smsg, err := a.MpoolPushMessage(ctx, msg, nil) if err != nil { return cid.Undef, err } diff --git a/node/node_test.go b/node/node_test.go index 621cb0c9a..030132e23 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -110,7 +110,7 @@ func testStorageNode(ctx context.Context, t *testing.T, waddr address.Address, a Value: types.NewInt(0), } - _, err = tnd.MpoolPushMessage(ctx, msg, big.Zero()) + _, err = tnd.MpoolPushMessage(ctx, msg, nil) require.NoError(t, err) // start node diff --git a/paychmgr/manager.go b/paychmgr/manager.go index b3f4c6f4f..6d8b8d912 100644 --- a/paychmgr/manager.go +++ b/paychmgr/manager.go @@ -2,7 +2,6 @@ package paychmgr import ( "context" - "github.com/filecoin-project/specs-actors/actors/abi" "sync" "github.com/filecoin-project/lotus/node/modules/helpers" @@ -45,7 +44,7 @@ type stateManagerAPI interface { // paychAPI defines the API methods needed by the payment channel manager type paychAPI interface { StateWaitMsg(ctx context.Context, msg cid.Cid, confidence uint64) (*api.MsgLookup, error) - MpoolPushMessage(ctx context.Context, msg *types.Message, maxFee abi.TokenAmount) (*types.SignedMessage, error) + MpoolPushMessage(ctx context.Context, msg *types.Message, maxFee *api.MessageSendSpec) (*types.SignedMessage, error) } // managerAPI defines all methods needed by the manager diff --git a/paychmgr/mock_test.go b/paychmgr/mock_test.go index 44dc5f1db..1cb66e1af 100644 --- a/paychmgr/mock_test.go +++ b/paychmgr/mock_test.go @@ -3,7 +3,6 @@ package paychmgr import ( "context" "fmt" - "github.com/filecoin-project/specs-actors/actors/abi" "sync" "github.com/filecoin-project/go-address" @@ -157,7 +156,7 @@ func (pchapi *mockPaychAPI) close() { } } -func (pchapi *mockPaychAPI) MpoolPushMessage(ctx context.Context, msg *types.Message, maxFee abi.TokenAmount) (*types.SignedMessage, error) { +func (pchapi *mockPaychAPI) MpoolPushMessage(ctx context.Context, msg *types.Message, spec *api.MessageSendSpec) (*types.SignedMessage, error) { pchapi.lk.Lock() defer pchapi.lk.Unlock() diff --git a/paychmgr/paych.go b/paychmgr/paych.go index 70674de3b..ba110b186 100644 --- a/paychmgr/paych.go +++ b/paychmgr/paych.go @@ -403,7 +403,7 @@ func (ca *channelAccessor) settle(ctx context.Context, ch address.Address) (cid. Value: types.NewInt(0), Method: builtin.MethodsPaych.Settle, } - smgs, err := ca.api.MpoolPushMessage(ctx, msg, big.Zero()) + smgs, err := ca.api.MpoolPushMessage(ctx, msg, nil) if err != nil { return cid.Undef, err } @@ -433,7 +433,7 @@ func (ca *channelAccessor) collect(ctx context.Context, ch address.Address) (cid Method: builtin.MethodsPaych.Collect, } - smsg, err := ca.api.MpoolPushMessage(ctx, msg, big.Zero()) + smsg, err := ca.api.MpoolPushMessage(ctx, msg, nil) if err != nil { return cid.Undef, err } diff --git a/paychmgr/simple.go b/paychmgr/simple.go index 75e11092c..b2f3c4404 100644 --- a/paychmgr/simple.go +++ b/paychmgr/simple.go @@ -370,7 +370,7 @@ func (ca *channelAccessor) createPaych(ctx context.Context, from, to address.Add Params: enc, } - smsg, err := ca.api.MpoolPushMessage(ctx, msg, big.Zero()) + smsg, err := ca.api.MpoolPushMessage(ctx, msg, nil) if err != nil { return cid.Undef, xerrors.Errorf("initializing paych actor: %w", err) } @@ -449,7 +449,7 @@ func (ca *channelAccessor) addFunds(ctx context.Context, channelInfo *ChannelInf Method: 0, } - smsg, err := ca.api.MpoolPushMessage(ctx, msg, big.Zero()) + smsg, err := ca.api.MpoolPushMessage(ctx, msg, nil) if err != nil { return nil, err } diff --git a/storage/adapter_storage_miner.go b/storage/adapter_storage_miner.go index 121fb82f9..1fccc361a 100644 --- a/storage/adapter_storage_miner.go +++ b/storage/adapter_storage_miner.go @@ -3,6 +3,7 @@ package storage import ( "bytes" "context" + "github.com/filecoin-project/lotus/api" "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" @@ -246,7 +247,7 @@ func (s SealingAPIAdapter) SendMsg(ctx context.Context, from, to address.Address Params: params, } - smsg, err := s.delegate.MpoolPushMessage(ctx, &msg, maxFee) + smsg, err := s.delegate.MpoolPushMessage(ctx, &msg, &api.MessageSendSpec{MaxFee: maxFee}) if err != nil { return cid.Undef, err } diff --git a/storage/miner.go b/storage/miner.go index c18c36cc6..006f01632 100644 --- a/storage/miner.go +++ b/storage/miner.go @@ -67,7 +67,7 @@ type storageMinerApi interface { StateMinerFaults(context.Context, address.Address, types.TipSetKey) (abi.BitField, error) StateMinerRecoveries(context.Context, address.Address, types.TipSetKey) (abi.BitField, error) - MpoolPushMessage(context.Context, *types.Message, abi.TokenAmount) (*types.SignedMessage, error) + MpoolPushMessage(context.Context, *types.Message, *api.MessageSendSpec) (*types.SignedMessage, error) ChainHead(context.Context) (*types.TipSet, error) ChainNotify(context.Context) (<-chan []*api.HeadChange, error) diff --git a/storage/wdpost_run.go b/storage/wdpost_run.go index 250445b69..e9e626533 100644 --- a/storage/wdpost_run.go +++ b/storage/wdpost_run.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "errors" + "github.com/filecoin-project/lotus/api" "time" "github.com/filecoin-project/go-bitfield" @@ -177,7 +178,7 @@ func (s *WindowPoStScheduler) checkNextRecoveries(ctx context.Context, dlIdx uin Value: types.NewInt(0), } - sm, err := s.api.MpoolPushMessage(ctx, msg, abi.TokenAmount(s.feeCfg.MaxWindowPoStGasFee)) + sm, err := s.api.MpoolPushMessage(ctx, msg, &api.MessageSendSpec{MaxFee: abi.TokenAmount(s.feeCfg.MaxWindowPoStGasFee)}) if err != nil { return xerrors.Errorf("pushing message to mpool: %w", err) } @@ -259,7 +260,7 @@ func (s *WindowPoStScheduler) checkNextFaults(ctx context.Context, dlIdx uint64, Value: types.NewInt(0), // TODO: Is there a fee? } - sm, err := s.api.MpoolPushMessage(ctx, msg, abi.TokenAmount(s.feeCfg.MaxWindowPoStGasFee)) + sm, err := s.api.MpoolPushMessage(ctx, msg, &api.MessageSendSpec{MaxFee: abi.TokenAmount(s.feeCfg.MaxWindowPoStGasFee)}) if err != nil { return xerrors.Errorf("pushing message to mpool: %w", err) } @@ -465,7 +466,7 @@ func (s *WindowPoStScheduler) submitPost(ctx context.Context, proof *miner.Submi } // TODO: consider maybe caring about the output - sm, err := s.api.MpoolPushMessage(ctx, msg, abi.TokenAmount(s.feeCfg.MaxWindowPoStGasFee)) + sm, err := s.api.MpoolPushMessage(ctx, msg, &api.MessageSendSpec{MaxFee: abi.TokenAmount(s.feeCfg.MaxWindowPoStGasFee)}) if err != nil { return xerrors.Errorf("pushing message to mpool: %w", err) }