From 959fe371b050606c7dffa52bd4b1160f13562bb8 Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Wed, 7 Aug 2019 21:24:49 -0700 Subject: [PATCH] move storage miner keys to full node --- cmd/lotus-storage-miner/init.go | 15 +-------------- go.mod | 1 + node/modules/storageminer.go | 8 ++++---- storage/miner.go | 21 ++++++++++++++------- 4 files changed, 20 insertions(+), 25 deletions(-) diff --git a/cmd/lotus-storage-miner/init.go b/cmd/lotus-storage-miner/init.go index fcc55d1bf..eb135cd19 100644 --- a/cmd/lotus-storage-miner/init.go +++ b/cmd/lotus-storage-miner/init.go @@ -10,7 +10,6 @@ import ( "github.com/filecoin-project/go-lotus/chain/actors" "github.com/filecoin-project/go-lotus/chain/address" "github.com/filecoin-project/go-lotus/chain/types" - "github.com/filecoin-project/go-lotus/chain/wallet" lcli "github.com/filecoin-project/go-lotus/cli" "github.com/filecoin-project/go-lotus/node/repo" ) @@ -66,18 +65,6 @@ var initCmd = &cli.Command{ } defer lr.Close() - log.Info("Initializing wallet") - - ks, err := lr.KeyStore() - if err != nil { - return err - } - - wallet, err := wallet.NewWallet(ks) - if err != nil { - return err - } - log.Info("Initializing libp2p identity") p2pSk, err := lr.Libp2pIdentity() @@ -102,7 +89,7 @@ var initCmd = &cli.Command{ return err } - k, err := wallet.GenerateKey(types.KTSecp256k1) // TODO: review: is this right? + k, err := api.WalletNew(ctx, types.KTSecp256k1) if err != nil { return err } diff --git a/go.mod b/go.mod index 01fa1e6c3..b0e39b63f 100644 --- a/go.mod +++ b/go.mod @@ -62,6 +62,7 @@ require ( github.com/polydawn/refmt v0.0.0-20190731040541-eff0b363297a github.com/smartystreets/assertions v1.0.1 // indirect github.com/smartystreets/goconvey v0.0.0-20190710185942-9d28bd7c0945 // indirect + github.com/stretchr/objx v0.1.1 // indirect github.com/stretchr/testify v1.3.0 github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7 github.com/whyrusleeping/pubsub v0.0.0-20131020042734-02de8aa2db3d diff --git a/node/modules/storageminer.go b/node/modules/storageminer.go index b1ac6a17a..0cd005c2a 100644 --- a/node/modules/storageminer.go +++ b/node/modules/storageminer.go @@ -2,10 +2,11 @@ package modules import ( "context" + "path/filepath" + "github.com/ipfs/go-bitswap" "github.com/ipfs/go-bitswap/network" "github.com/libp2p/go-libp2p-core/routing" - "path/filepath" "github.com/ipfs/go-blockservice" "github.com/ipfs/go-datastore" @@ -18,7 +19,6 @@ import ( "github.com/filecoin-project/go-lotus/api" "github.com/filecoin-project/go-lotus/chain/address" "github.com/filecoin-project/go-lotus/chain/deals" - "github.com/filecoin-project/go-lotus/chain/wallet" "github.com/filecoin-project/go-lotus/lib/sectorbuilder" "github.com/filecoin-project/go-lotus/node/modules/dtypes" "github.com/filecoin-project/go-lotus/node/modules/helpers" @@ -81,13 +81,13 @@ func SectorBuilder(mctx helpers.MetricsCtx, lc fx.Lifecycle, sbc *sectorbuilder. return sb, nil } -func StorageMiner(mctx helpers.MetricsCtx, lc fx.Lifecycle, api api.FullNode, h host.Host, ds dtypes.MetadataDS, sb *sectorbuilder.SectorBuilder, w *wallet.Wallet) (*storage.Miner, error) { +func StorageMiner(mctx helpers.MetricsCtx, lc fx.Lifecycle, api api.FullNode, h host.Host, ds dtypes.MetadataDS, sb *sectorbuilder.SectorBuilder) (*storage.Miner, error) { maddr, err := minerAddrFromDS(ds) if err != nil { return nil, err } - sm, err := storage.NewMiner(api, maddr, h, ds, sb, w) + sm, err := storage.NewMiner(api, maddr, h, ds, sb) if err != nil { return nil, err } diff --git a/storage/miner.go b/storage/miner.go index ee90fa3b5..a303bef11 100644 --- a/storage/miner.go +++ b/storage/miner.go @@ -9,7 +9,6 @@ import ( "github.com/filecoin-project/go-lotus/chain/address" "github.com/filecoin-project/go-lotus/chain/store" "github.com/filecoin-project/go-lotus/chain/types" - "github.com/filecoin-project/go-lotus/chain/wallet" "github.com/ipfs/go-cid" "github.com/ipfs/go-datastore" logging "github.com/ipfs/go-log" @@ -26,8 +25,6 @@ type Miner struct { sb *sectorbuilder.SectorBuilder - w *wallet.Wallet - maddr address.Address worker address.Address @@ -49,16 +46,19 @@ type storageMinerApi interface { ChainWaitMsg(context.Context, cid.Cid) (*api.MsgWait, error) ChainNotify(context.Context) (<-chan *store.HeadChange, error) + + WalletBalance(context.Context, address.Address) (types.BigInt, error) + WalletSign(context.Context, address.Address, []byte) (*types.Signature, error) + WalletList(context.Context) ([]address.Address, error) } -func NewMiner(api storageMinerApi, addr address.Address, h host.Host, ds datastore.Batching, sb *sectorbuilder.SectorBuilder, w *wallet.Wallet) (*Miner, error) { +func NewMiner(api storageMinerApi, addr address.Address, h host.Host, ds datastore.Batching, sb *sectorbuilder.SectorBuilder) (*Miner, error) { return &Miner{ api: api, maddr: addr, h: h, ds: ds, sb: sb, - w: w, }, nil } @@ -138,7 +138,7 @@ func (m *Miner) commitSector(ctx context.Context, sinfo sectorbuilder.SectorSeal return errors.Wrap(err, "serializing commit sector message") } - sig, err := m.w.Sign(m.worker, data) + sig, err := m.api.WalletSign(ctx, m.worker, data) if err != nil { return errors.Wrap(err, "signing commit sector message") } @@ -173,10 +173,17 @@ func (m *Miner) runPreflightChecks(ctx context.Context) error { m.worker = worker - has, err := m.w.HasKey(worker) + addrs, err := m.api.WalletList(ctx) if err != nil { return errors.Wrap(err, "failed to check wallet for worker key") } + var has bool + for _, a := range addrs { + if a == worker { + has = true + break + } + } if !has { return errors.New("key for worker not found in local wallet")