From 717bda63b157cbed226478a893f9261624b01c6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 14 Jun 2022 19:32:29 +0200 Subject: [PATCH] storage: Move control address logic to storage/ctladdr --- itests/deals_publish_test.go | 4 ++-- itests/deals_retry_deal_no_funds_test.go | 8 ++++---- markets/storageadapter/dealpublisher.go | 10 +++++----- node/builder_miner.go | 5 +++-- node/impl/storminer.go | 3 ++- node/modules/storageminer.go | 9 +++++---- storage/{ => ctladdr}/addresses.go | 6 +++++- storage/miner.go | 5 +++-- storage/wdpost/wdpost_run_test.go | 4 ++-- storage/wdpost/wdpost_sched.go | 6 +++--- 10 files changed, 34 insertions(+), 26 deletions(-) rename storage/{ => ctladdr}/addresses.go (98%) diff --git a/itests/deals_publish_test.go b/itests/deals_publish_test.go index 85358d972..b12fe31b7 100644 --- a/itests/deals_publish_test.go +++ b/itests/deals_publish_test.go @@ -22,7 +22,7 @@ import ( "github.com/filecoin-project/lotus/node" "github.com/filecoin-project/lotus/node/config" "github.com/filecoin-project/lotus/node/modules" - "github.com/filecoin-project/lotus/storage" + "github.com/filecoin-project/lotus/storage/ctladdr" ) func TestPublishDealsBatching(t *testing.T) { @@ -51,7 +51,7 @@ func TestPublishDealsBatching(t *testing.T) { MaxDealsPerMsg: maxDealsPerMsg, }), ), - node.Override(new(*storage.AddressSelector), modules.AddressSelector(&config.MinerAddressConfig{ + node.Override(new(*ctladdr.AddressSelector), modules.AddressSelector(&config.MinerAddressConfig{ DealPublishControl: []string{ publisherKey.Address.String(), }, diff --git a/itests/deals_retry_deal_no_funds_test.go b/itests/deals_retry_deal_no_funds_test.go index 612964c67..317538cf1 100644 --- a/itests/deals_retry_deal_no_funds_test.go +++ b/itests/deals_retry_deal_no_funds_test.go @@ -17,7 +17,7 @@ import ( "github.com/filecoin-project/lotus/node" "github.com/filecoin-project/lotus/node/config" "github.com/filecoin-project/lotus/node/modules" - "github.com/filecoin-project/lotus/storage" + "github.com/filecoin-project/lotus/storage/ctladdr" ) var ( @@ -52,7 +52,7 @@ func TestDealsRetryLackOfFunds(t *testing.T) { MaxDealsPerMsg: maxDealsPerMsg, }), ), - node.Override(new(*storage.AddressSelector), modules.AddressSelector(&config.MinerAddressConfig{ + node.Override(new(*ctladdr.AddressSelector), modules.AddressSelector(&config.MinerAddressConfig{ DealPublishControl: []string{ publishStorageDealKey.Address.String(), }, @@ -128,7 +128,7 @@ func TestDealsRetryLackOfFunds_blockInPublishDeal(t *testing.T) { MaxDealsPerMsg: maxDealsPerMsg, }), ), - node.Override(new(*storage.AddressSelector), modules.AddressSelector(&config.MinerAddressConfig{ + node.Override(new(*ctladdr.AddressSelector), modules.AddressSelector(&config.MinerAddressConfig{ DealPublishControl: []string{ publishStorageDealKey.Address.String(), }, @@ -201,7 +201,7 @@ func TestDealsRetryLackOfFunds_belowLimit(t *testing.T) { MaxDealsPerMsg: maxDealsPerMsg, }), ), - node.Override(new(*storage.AddressSelector), modules.AddressSelector(&config.MinerAddressConfig{ + node.Override(new(*ctladdr.AddressSelector), modules.AddressSelector(&config.MinerAddressConfig{ DealPublishControl: []string{ publishStorageDealKey.Address.String(), }, diff --git a/markets/storageadapter/dealpublisher.go b/markets/storageadapter/dealpublisher.go index a98da7140..c2864bdf9 100644 --- a/markets/storageadapter/dealpublisher.go +++ b/markets/storageadapter/dealpublisher.go @@ -23,7 +23,7 @@ import ( "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/node/config" - "github.com/filecoin-project/lotus/storage" + "github.com/filecoin-project/lotus/storage/ctladdr" ) type dealPublisherAPI interface { @@ -48,7 +48,7 @@ type dealPublisherAPI interface { // publish message with all deals in the queue. type DealPublisher struct { api dealPublisherAPI - as *storage.AddressSelector + as *ctladdr.AddressSelector ctx context.Context Shutdown context.CancelFunc @@ -99,8 +99,8 @@ type PublishMsgConfig struct { func NewDealPublisher( feeConfig *config.MinerFeeConfig, publishMsgCfg PublishMsgConfig, -) func(lc fx.Lifecycle, full api.FullNode, as *storage.AddressSelector) *DealPublisher { - return func(lc fx.Lifecycle, full api.FullNode, as *storage.AddressSelector) *DealPublisher { +) func(lc fx.Lifecycle, full api.FullNode, as *ctladdr.AddressSelector) *DealPublisher { + return func(lc fx.Lifecycle, full api.FullNode, as *ctladdr.AddressSelector) *DealPublisher { maxFee := abi.NewTokenAmount(0) if feeConfig != nil { maxFee = abi.TokenAmount(feeConfig.MaxPublishDealsFee) @@ -119,7 +119,7 @@ func NewDealPublisher( func newDealPublisher( dpapi dealPublisherAPI, - as *storage.AddressSelector, + as *ctladdr.AddressSelector, publishMsgCfg PublishMsgConfig, publishSpec *api.MessageSendSpec, ) *DealPublisher { diff --git a/node/builder_miner.go b/node/builder_miner.go index 3bfd06cca..b5c76598c 100644 --- a/node/builder_miner.go +++ b/node/builder_miner.go @@ -37,6 +37,7 @@ import ( "github.com/filecoin-project/lotus/node/modules/dtypes" "github.com/filecoin-project/lotus/node/repo" "github.com/filecoin-project/lotus/storage" + "github.com/filecoin-project/lotus/storage/ctladdr" "github.com/filecoin-project/lotus/storage/sectorblocks" "github.com/filecoin-project/lotus/storage/wdpost" ) @@ -51,7 +52,7 @@ var MinerNode = Options( Override(new(dtypes.NetworkName), modules.StorageNetworkName), // Mining / proving - Override(new(*storage.AddressSelector), modules.AddressSelector(nil)), + Override(new(*ctladdr.AddressSelector), modules.AddressSelector(nil)), ) func ConfigStorageMiner(c interface{}) Option { @@ -221,7 +222,7 @@ func ConfigStorageMiner(c interface{}) Option { ), Override(new(sectorstorage.Config), cfg.StorageManager()), - Override(new(*storage.AddressSelector), modules.AddressSelector(&cfg.Addresses)), + Override(new(*ctladdr.AddressSelector), modules.AddressSelector(&cfg.Addresses)), ) } diff --git a/node/impl/storminer.go b/node/impl/storminer.go index 2d79ec6a5..e658b8ef5 100644 --- a/node/impl/storminer.go +++ b/node/impl/storminer.go @@ -53,6 +53,7 @@ import ( "github.com/filecoin-project/lotus/miner" "github.com/filecoin-project/lotus/node/modules/dtypes" "github.com/filecoin-project/lotus/storage" + "github.com/filecoin-project/lotus/storage/ctladdr" "github.com/filecoin-project/lotus/storage/sectorblocks" "github.com/filecoin-project/lotus/storage/wdpost" ) @@ -90,7 +91,7 @@ type StorageMinerAPI struct { IStorageMgr sectorstorage.SectorManager `optional:"true"` stores.SectorIndex storiface.WorkerReturn `optional:"true"` - AddrSel *storage.AddressSelector + AddrSel *ctladdr.AddressSelector WdPoSt *wdpost.WindowPoStScheduler `optional:"true"` diff --git a/node/modules/storageminer.go b/node/modules/storageminer.go index 34ef48851..32ce294ce 100644 --- a/node/modules/storageminer.go +++ b/node/modules/storageminer.go @@ -70,6 +70,7 @@ import ( "github.com/filecoin-project/lotus/node/modules/helpers" "github.com/filecoin-project/lotus/node/repo" "github.com/filecoin-project/lotus/storage" + "github.com/filecoin-project/lotus/storage/ctladdr" "github.com/filecoin-project/lotus/storage/wdpost" ) @@ -151,9 +152,9 @@ func SectorIDCounter(ds dtypes.MetadataDS) sealing.SectorIDCounter { return &sidsc{sc} } -func AddressSelector(addrConf *config.MinerAddressConfig) func() (*storage.AddressSelector, error) { - return func() (*storage.AddressSelector, error) { - as := &storage.AddressSelector{} +func AddressSelector(addrConf *config.MinerAddressConfig) func() (*ctladdr.AddressSelector, error) { + return func() (*ctladdr.AddressSelector, error) { + as := &ctladdr.AddressSelector{} if addrConf == nil { return as, nil } @@ -214,7 +215,7 @@ type StorageMinerParams struct { Prover ffiwrapper.Prover GetSealingConfigFn dtypes.GetSealingConfigFunc Journal journal.Journal - AddrSel *storage.AddressSelector + AddrSel *ctladdr.AddressSelector Maddr dtypes.MinerAddress } diff --git a/storage/addresses.go b/storage/ctladdr/addresses.go similarity index 98% rename from storage/addresses.go rename to storage/ctladdr/addresses.go index 2c9b381cd..701fea933 100644 --- a/storage/addresses.go +++ b/storage/ctladdr/addresses.go @@ -1,8 +1,10 @@ -package storage +package ctladdr import ( "context" + logging "github.com/ipfs/go-log/v2" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" @@ -11,6 +13,8 @@ import ( "github.com/filecoin-project/lotus/chain/types" ) +var log = logging.Logger("ctladdr") + type addrSelectApi interface { WalletBalance(context.Context, address.Address) (types.BigInt, error) WalletHas(context.Context, address.Address) (bool, error) diff --git a/storage/miner.go b/storage/miner.go index 8c15f544d..6b6e7ae8c 100644 --- a/storage/miner.go +++ b/storage/miner.go @@ -34,6 +34,7 @@ import ( "github.com/filecoin-project/lotus/journal" "github.com/filecoin-project/lotus/node/config" "github.com/filecoin-project/lotus/node/modules/dtypes" + "github.com/filecoin-project/lotus/storage/ctladdr" ) var log = logging.Logger("storageminer") @@ -54,7 +55,7 @@ type Miner struct { sc sealing.SectorIDCounter verif ffiwrapper.Verifier prover ffiwrapper.Prover - addrSel *AddressSelector + addrSel *ctladdr.AddressSelector maddr address.Address @@ -139,7 +140,7 @@ func NewMiner(api fullNodeFilteredAPI, gsd dtypes.GetSealingConfigFunc, feeCfg config.MinerFeeConfig, journal journal.Journal, - as *AddressSelector) (*Miner, error) { + as *ctladdr.AddressSelector) (*Miner, error) { m := &Miner{ api: api, feeCfg: feeCfg, diff --git a/storage/wdpost/wdpost_run_test.go b/storage/wdpost/wdpost_run_test.go index d8a7df918..e757a8c14 100644 --- a/storage/wdpost/wdpost_run_test.go +++ b/storage/wdpost/wdpost_run_test.go @@ -32,7 +32,7 @@ import ( "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/extern/sector-storage/storiface" "github.com/filecoin-project/lotus/journal" - storage2 "github.com/filecoin-project/lotus/storage" + "github.com/filecoin-project/lotus/storage/ctladdr" ) type mockStorageMinerAPI struct { @@ -237,7 +237,7 @@ func TestWDPostDoPost(t *testing.T) { proofType: proofType, actor: postAct, journal: journal.NilJournal(), - addrSel: &storage2.AddressSelector{}, + addrSel: &ctladdr.AddressSelector{}, } di := &dline.Info{ diff --git a/storage/wdpost/wdpost_sched.go b/storage/wdpost/wdpost_sched.go index 0ed5b8ec9..81de65521 100644 --- a/storage/wdpost/wdpost_sched.go +++ b/storage/wdpost/wdpost_sched.go @@ -26,7 +26,7 @@ import ( "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" "github.com/filecoin-project/lotus/journal" "github.com/filecoin-project/lotus/node/config" - storage2 "github.com/filecoin-project/lotus/storage" + "github.com/filecoin-project/lotus/storage/ctladdr" ) var log = logging.Logger("wdpost") @@ -65,7 +65,7 @@ type NodeAPI interface { type WindowPoStScheduler struct { api NodeAPI feeCfg config.MinerFeeConfig - addrSel *storage2.AddressSelector + addrSel *ctladdr.AddressSelector prover storage.Prover verifier ffiwrapper.Verifier faultTracker sectorstorage.FaultTracker @@ -85,7 +85,7 @@ type WindowPoStScheduler struct { // NewWindowedPoStScheduler creates a new WindowPoStScheduler scheduler. func NewWindowedPoStScheduler(api NodeAPI, cfg config.MinerFeeConfig, - as *storage2.AddressSelector, + as *ctladdr.AddressSelector, sp storage.Prover, verif ffiwrapper.Verifier, ft sectorstorage.FaultTracker,