Register miner address from storageminer process

This commit is contained in:
Łukasz Magiera 2019-08-20 19:19:24 +02:00
parent 82c449c047
commit eda26faf21
9 changed files with 47 additions and 16 deletions

View File

@ -194,7 +194,7 @@ func (tu *syncTestUtil) submitSourceBlock(to int, h int) {
// -1 to match block.Height
b.Header = tu.blocks[h-1].Header
for _, msg := range tu.blocks[h-1].SecpkMessages {
c, err := tu.nds[to].(*impl.API).ChainAPI.Chain.PutMessage(msg)
c, err := tu.nds[to].(*impl.FullNodeAPI).ChainAPI.Chain.PutMessage(msg)
require.NoError(tu.t, err)
b.SecpkMessages = append(b.SecpkMessages, c)

View File

@ -123,6 +123,12 @@ var initCmd = &cli.Command{
}
func configureStorageMiner(ctx context.Context, api api.FullNode, addr address.Address, peerid peer.ID) error {
// We may be one of genesis miners, start mining before trying to do any chain operations
// (otherwise our messages won't be mined)
if err := api.MinerRegister(ctx, addr); err != nil {
return err
}
// This really just needs to be an api call at this point...
recp, err := api.ChainCall(ctx, &types.Message{
To: addr,

View File

@ -56,7 +56,11 @@ func (m *Miner) Register(addr address.Address) error {
defer m.lk.Unlock()
if len(m.addresses) > 0 {
return errors.New("mining with more than one storage miner instance not supported yet") // TODO !
if len(m.addresses) > 1 || m.addresses[0] != addr {
return errors.New("mining with more than one storage miner instance not supported yet") // TODO !
}
log.Warnf("miner.Register called more than once for actor '%s'", addr)
}
m.addresses = append(m.addresses, addr)

View File

@ -80,6 +80,7 @@ const (
// storage miner
HandleDealsKey
RunSectorServiceKey
RegisterMinerKey
// daemon
ExtractApiKey
@ -238,6 +239,7 @@ func Online() Option {
Override(new(*deals.Handler), deals.NewHandler),
Override(HandleDealsKey, modules.HandleDeals),
Override(RunSectorServiceKey, modules.RunSectorService),
Override(RegisterMinerKey, modules.RegisterMiner),
),
)
}
@ -306,13 +308,13 @@ func Repo(r repo.Repo) Option {
Override(new(types.KeyStore), modules.KeyStore),
Override(new(*modules.APIAlg), modules.APISecret),
Override(new(*dtypes.APIAlg), modules.APISecret),
)
}
func FullAPI(out *api.FullNode) Option {
return func(s *Settings) error {
resAPI := &impl.API{}
resAPI := &impl.FullNodeAPI{}
s.invokes[ExtractApiKey] = fx.Extract(resAPI)
*out = resAPI
return nil

View File

@ -3,6 +3,10 @@ package impl
import (
"context"
"github.com/filecoin-project/go-lotus/api"
"github.com/filecoin-project/go-lotus/build"
"github.com/filecoin-project/go-lotus/node/modules/dtypes"
"github.com/gbrlsnchs/jwt/v3"
"github.com/libp2p/go-libp2p-core/host"
"github.com/libp2p/go-libp2p-core/network"
@ -10,16 +14,12 @@ import (
ma "github.com/multiformats/go-multiaddr"
"go.uber.org/fx"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-lotus/api"
"github.com/filecoin-project/go-lotus/build"
"github.com/filecoin-project/go-lotus/node/modules"
)
type CommonAPI struct {
fx.In
APISecret *modules.APIAlg
APISecret *dtypes.APIAlg
Host host.Host
}

View File

@ -12,7 +12,7 @@ import (
var log = logging.Logger("node")
type API struct {
type FullNodeAPI struct {
CommonAPI
full.ChainAPI
full.ClientAPI
@ -24,8 +24,8 @@ type API struct {
Miner *miner.Miner
}
func (a *API) MinerRegister(ctx context.Context, addr address.Address) error {
func (a *FullNodeAPI) MinerRegister(ctx context.Context, addr address.Address) error {
return a.Miner.Register(addr)
}
var _ api.FullNode = &API{}
var _ api.FullNode = &FullNodeAPI{}

View File

@ -13,6 +13,7 @@ import (
"github.com/filecoin-project/go-lotus/api"
"github.com/filecoin-project/go-lotus/chain/types"
"github.com/filecoin-project/go-lotus/node/modules/dtypes"
"github.com/filecoin-project/go-lotus/node/repo"
)
@ -29,13 +30,11 @@ func RecordValidator(ps peerstore.Peerstore) record.Validator {
const JWTSecretName = "auth-jwt-private"
type APIAlg jwt.HMACSHA
type jwtPayload struct {
Allow []string
}
func APISecret(keystore types.KeyStore, lr repo.LockedRepo) (*APIAlg, error) {
func APISecret(keystore types.KeyStore, lr repo.LockedRepo) (*dtypes.APIAlg, error) {
key, err := keystore.Get(JWTSecretName)
if err != nil {
log.Warn("Generating new API secret")
@ -69,5 +68,5 @@ func APISecret(keystore types.KeyStore, lr repo.LockedRepo) (*APIAlg, error) {
}
}
return (*APIAlg)(jwt.NewHS256(key.PrivateKey)), nil
return (*dtypes.APIAlg)(jwt.NewHS256(key.PrivateKey)), nil
}

View File

@ -0,0 +1,5 @@
package dtypes
import "github.com/gbrlsnchs/jwt/v3"
type APIAlg jwt.HMACSHA

View File

@ -125,3 +125,18 @@ func StagingDAG(mctx helpers.MetricsCtx, lc fx.Lifecycle, r repo.LockedRepo, rt
return dag, nil
}
func RegisterMiner(lc fx.Lifecycle, ds dtypes.MetadataDS, api api.FullNode) error {
minerAddr, err := minerAddrFromDS(ds)
if err != nil {
return err
}
lc.Append(fx.Hook{
OnStart: func(ctx context.Context) error {
log.Infof("registering miner '%s' with full node", minerAddr)
return api.MinerRegister(ctx, minerAddr)
},
})
return nil
}