Merge pull request #129 from filecoin-project/feat/no-miner-wallet

move storage miner keys to full node
This commit is contained in:
Whyrusleeping 2019-08-08 11:00:34 -07:00 committed by GitHub
commit c1f81efde9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 23 additions and 25 deletions

View File

@ -107,6 +107,7 @@ type FullNode interface {
// wallet // wallet
WalletNew(context.Context, string) (address.Address, error) WalletNew(context.Context, string) (address.Address, error)
WalletHas(context.Context, address.Address) (bool, error)
WalletList(context.Context) ([]address.Address, error) WalletList(context.Context) ([]address.Address, error)
WalletBalance(context.Context, address.Address) (types.BigInt, error) WalletBalance(context.Context, address.Address) (types.BigInt, error)
WalletSign(context.Context, address.Address, []byte) (*types.Signature, error) WalletSign(context.Context, address.Address, []byte) (*types.Signature, error)

View File

@ -56,6 +56,7 @@ type FullNodeStruct struct {
MinerCreateBlock func(context.Context, address.Address, *types.TipSet, []types.Ticket, types.ElectionProof, []*types.SignedMessage) (*chain.BlockMsg, error) `perm:"write"` MinerCreateBlock func(context.Context, address.Address, *types.TipSet, []types.Ticket, types.ElectionProof, []*types.SignedMessage) (*chain.BlockMsg, error) `perm:"write"`
WalletNew func(context.Context, string) (address.Address, error) `perm:"write"` WalletNew func(context.Context, string) (address.Address, error) `perm:"write"`
WalletHas func(context.Context, address.Address) (bool, error) `perm:"write"`
WalletList func(context.Context) ([]address.Address, error) `perm:"write"` WalletList func(context.Context) ([]address.Address, error) `perm:"write"`
WalletBalance func(context.Context, address.Address) (types.BigInt, error) `perm:"read"` WalletBalance func(context.Context, address.Address) (types.BigInt, error) `perm:"read"`
WalletSign func(context.Context, address.Address, []byte) (*types.Signature, error) `perm:"sign"` WalletSign func(context.Context, address.Address, []byte) (*types.Signature, error) `perm:"sign"`
@ -173,6 +174,10 @@ func (c *FullNodeStruct) WalletNew(ctx context.Context, typ string) (address.Add
return c.Internal.WalletNew(ctx, typ) return c.Internal.WalletNew(ctx, typ)
} }
func (c *FullNodeStruct) WalletHas(ctx context.Context, addr address.Address) (bool, error) {
return c.Internal.WalletHas(ctx, addr)
}
func (c *FullNodeStruct) WalletList(ctx context.Context) ([]address.Address, error) { func (c *FullNodeStruct) WalletList(ctx context.Context) ([]address.Address, error) {
return c.Internal.WalletList(ctx) return c.Internal.WalletList(ctx)
} }

View File

@ -10,7 +10,6 @@ import (
"github.com/filecoin-project/go-lotus/chain/actors" "github.com/filecoin-project/go-lotus/chain/actors"
"github.com/filecoin-project/go-lotus/chain/address" "github.com/filecoin-project/go-lotus/chain/address"
"github.com/filecoin-project/go-lotus/chain/types" "github.com/filecoin-project/go-lotus/chain/types"
"github.com/filecoin-project/go-lotus/chain/wallet"
lcli "github.com/filecoin-project/go-lotus/cli" lcli "github.com/filecoin-project/go-lotus/cli"
"github.com/filecoin-project/go-lotus/node/repo" "github.com/filecoin-project/go-lotus/node/repo"
) )
@ -66,18 +65,6 @@ var initCmd = &cli.Command{
} }
defer lr.Close() 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") log.Info("Initializing libp2p identity")
p2pSk, err := lr.Libp2pIdentity() p2pSk, err := lr.Libp2pIdentity()
@ -102,7 +89,7 @@ var initCmd = &cli.Command{
return err return err
} }
k, err := wallet.GenerateKey(types.KTSecp256k1) // TODO: review: is this right? k, err := api.WalletNew(ctx, types.KTSecp256k1)
if err != nil { if err != nil {
return err return err
} }

1
go.mod
View File

@ -62,6 +62,7 @@ require (
github.com/polydawn/refmt v0.0.0-20190731040541-eff0b363297a github.com/polydawn/refmt v0.0.0-20190731040541-eff0b363297a
github.com/smartystreets/assertions v1.0.1 // indirect github.com/smartystreets/assertions v1.0.1 // indirect
github.com/smartystreets/goconvey v0.0.0-20190710185942-9d28bd7c0945 // 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/stretchr/testify v1.3.0
github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7 github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7
github.com/whyrusleeping/pubsub v0.0.0-20131020042734-02de8aa2db3d github.com/whyrusleeping/pubsub v0.0.0-20131020042734-02de8aa2db3d

View File

@ -244,6 +244,10 @@ func (a *FullNodeAPI) WalletNew(ctx context.Context, typ string) (address.Addres
return a.Wallet.GenerateKey(typ) return a.Wallet.GenerateKey(typ)
} }
func (a *FullNodeAPI) WalletHas(ctx context.Context, addr address.Address) (bool, error) {
return a.Wallet.HasKey(addr)
}
func (a *FullNodeAPI) WalletList(ctx context.Context) ([]address.Address, error) { func (a *FullNodeAPI) WalletList(ctx context.Context) ([]address.Address, error) {
return a.Wallet.ListAddrs() return a.Wallet.ListAddrs()
} }

View File

@ -2,10 +2,11 @@ package modules
import ( import (
"context" "context"
"path/filepath"
"github.com/ipfs/go-bitswap" "github.com/ipfs/go-bitswap"
"github.com/ipfs/go-bitswap/network" "github.com/ipfs/go-bitswap/network"
"github.com/libp2p/go-libp2p-core/routing" "github.com/libp2p/go-libp2p-core/routing"
"path/filepath"
"github.com/ipfs/go-blockservice" "github.com/ipfs/go-blockservice"
"github.com/ipfs/go-datastore" "github.com/ipfs/go-datastore"
@ -18,7 +19,6 @@ import (
"github.com/filecoin-project/go-lotus/api" "github.com/filecoin-project/go-lotus/api"
"github.com/filecoin-project/go-lotus/chain/address" "github.com/filecoin-project/go-lotus/chain/address"
"github.com/filecoin-project/go-lotus/chain/deals" "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/lib/sectorbuilder"
"github.com/filecoin-project/go-lotus/node/modules/dtypes" "github.com/filecoin-project/go-lotus/node/modules/dtypes"
"github.com/filecoin-project/go-lotus/node/modules/helpers" "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 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) maddr, err := minerAddrFromDS(ds)
if err != nil { if err != nil {
return nil, err 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 { if err != nil {
return nil, err return nil, err
} }

View File

@ -9,7 +9,6 @@ import (
"github.com/filecoin-project/go-lotus/chain/address" "github.com/filecoin-project/go-lotus/chain/address"
"github.com/filecoin-project/go-lotus/chain/store" "github.com/filecoin-project/go-lotus/chain/store"
"github.com/filecoin-project/go-lotus/chain/types" "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-cid"
"github.com/ipfs/go-datastore" "github.com/ipfs/go-datastore"
logging "github.com/ipfs/go-log" logging "github.com/ipfs/go-log"
@ -26,8 +25,6 @@ type Miner struct {
sb *sectorbuilder.SectorBuilder sb *sectorbuilder.SectorBuilder
w *wallet.Wallet
maddr address.Address maddr address.Address
worker address.Address worker address.Address
@ -49,16 +46,19 @@ type storageMinerApi interface {
ChainWaitMsg(context.Context, cid.Cid) (*api.MsgWait, error) ChainWaitMsg(context.Context, cid.Cid) (*api.MsgWait, error)
ChainNotify(context.Context) (<-chan *store.HeadChange, 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)
WalletHas(context.Context, address.Address) (bool, 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{ return &Miner{
api: api, api: api,
maddr: addr, maddr: addr,
h: h, h: h,
ds: ds, ds: ds,
sb: sb, sb: sb,
w: w,
}, nil }, nil
} }
@ -138,7 +138,7 @@ func (m *Miner) commitSector(ctx context.Context, sinfo sectorbuilder.SectorSeal
return errors.Wrap(err, "serializing commit sector message") 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 { if err != nil {
return errors.Wrap(err, "signing commit sector message") return errors.Wrap(err, "signing commit sector message")
} }
@ -173,7 +173,7 @@ func (m *Miner) runPreflightChecks(ctx context.Context) error {
m.worker = worker m.worker = worker
has, err := m.w.HasKey(worker) has, err := m.api.WalletHas(ctx, worker)
if err != nil { if err != nil {
return errors.Wrap(err, "failed to check wallet for worker key") return errors.Wrap(err, "failed to check wallet for worker key")
} }