Register miner address from storageminer process
This commit is contained in:
parent
82c449c047
commit
eda26faf21
@ -194,7 +194,7 @@ func (tu *syncTestUtil) submitSourceBlock(to int, h int) {
|
|||||||
// -1 to match block.Height
|
// -1 to match block.Height
|
||||||
b.Header = tu.blocks[h-1].Header
|
b.Header = tu.blocks[h-1].Header
|
||||||
for _, msg := range tu.blocks[h-1].SecpkMessages {
|
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)
|
require.NoError(tu.t, err)
|
||||||
|
|
||||||
b.SecpkMessages = append(b.SecpkMessages, c)
|
b.SecpkMessages = append(b.SecpkMessages, c)
|
||||||
|
@ -123,6 +123,12 @@ var initCmd = &cli.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func configureStorageMiner(ctx context.Context, api api.FullNode, addr address.Address, peerid peer.ID) error {
|
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...
|
// This really just needs to be an api call at this point...
|
||||||
recp, err := api.ChainCall(ctx, &types.Message{
|
recp, err := api.ChainCall(ctx, &types.Message{
|
||||||
To: addr,
|
To: addr,
|
||||||
|
@ -56,7 +56,11 @@ func (m *Miner) Register(addr address.Address) error {
|
|||||||
defer m.lk.Unlock()
|
defer m.lk.Unlock()
|
||||||
|
|
||||||
if len(m.addresses) > 0 {
|
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)
|
m.addresses = append(m.addresses, addr)
|
||||||
|
@ -80,6 +80,7 @@ const (
|
|||||||
// storage miner
|
// storage miner
|
||||||
HandleDealsKey
|
HandleDealsKey
|
||||||
RunSectorServiceKey
|
RunSectorServiceKey
|
||||||
|
RegisterMinerKey
|
||||||
|
|
||||||
// daemon
|
// daemon
|
||||||
ExtractApiKey
|
ExtractApiKey
|
||||||
@ -238,6 +239,7 @@ func Online() Option {
|
|||||||
Override(new(*deals.Handler), deals.NewHandler),
|
Override(new(*deals.Handler), deals.NewHandler),
|
||||||
Override(HandleDealsKey, modules.HandleDeals),
|
Override(HandleDealsKey, modules.HandleDeals),
|
||||||
Override(RunSectorServiceKey, modules.RunSectorService),
|
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(types.KeyStore), modules.KeyStore),
|
||||||
|
|
||||||
Override(new(*modules.APIAlg), modules.APISecret),
|
Override(new(*dtypes.APIAlg), modules.APISecret),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func FullAPI(out *api.FullNode) Option {
|
func FullAPI(out *api.FullNode) Option {
|
||||||
return func(s *Settings) error {
|
return func(s *Settings) error {
|
||||||
resAPI := &impl.API{}
|
resAPI := &impl.FullNodeAPI{}
|
||||||
s.invokes[ExtractApiKey] = fx.Extract(resAPI)
|
s.invokes[ExtractApiKey] = fx.Extract(resAPI)
|
||||||
*out = resAPI
|
*out = resAPI
|
||||||
return nil
|
return nil
|
||||||
|
@ -3,6 +3,10 @@ package impl
|
|||||||
import (
|
import (
|
||||||
"context"
|
"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/gbrlsnchs/jwt/v3"
|
||||||
"github.com/libp2p/go-libp2p-core/host"
|
"github.com/libp2p/go-libp2p-core/host"
|
||||||
"github.com/libp2p/go-libp2p-core/network"
|
"github.com/libp2p/go-libp2p-core/network"
|
||||||
@ -10,16 +14,12 @@ import (
|
|||||||
ma "github.com/multiformats/go-multiaddr"
|
ma "github.com/multiformats/go-multiaddr"
|
||||||
"go.uber.org/fx"
|
"go.uber.org/fx"
|
||||||
"golang.org/x/xerrors"
|
"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 {
|
type CommonAPI struct {
|
||||||
fx.In
|
fx.In
|
||||||
|
|
||||||
APISecret *modules.APIAlg
|
APISecret *dtypes.APIAlg
|
||||||
Host host.Host
|
Host host.Host
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
|
|
||||||
var log = logging.Logger("node")
|
var log = logging.Logger("node")
|
||||||
|
|
||||||
type API struct {
|
type FullNodeAPI struct {
|
||||||
CommonAPI
|
CommonAPI
|
||||||
full.ChainAPI
|
full.ChainAPI
|
||||||
full.ClientAPI
|
full.ClientAPI
|
||||||
@ -24,8 +24,8 @@ type API struct {
|
|||||||
Miner *miner.Miner
|
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)
|
return a.Miner.Register(addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ api.FullNode = &API{}
|
var _ api.FullNode = &FullNodeAPI{}
|
||||||
|
@ -13,6 +13,7 @@ import (
|
|||||||
|
|
||||||
"github.com/filecoin-project/go-lotus/api"
|
"github.com/filecoin-project/go-lotus/api"
|
||||||
"github.com/filecoin-project/go-lotus/chain/types"
|
"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"
|
"github.com/filecoin-project/go-lotus/node/repo"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -29,13 +30,11 @@ func RecordValidator(ps peerstore.Peerstore) record.Validator {
|
|||||||
|
|
||||||
const JWTSecretName = "auth-jwt-private"
|
const JWTSecretName = "auth-jwt-private"
|
||||||
|
|
||||||
type APIAlg jwt.HMACSHA
|
|
||||||
|
|
||||||
type jwtPayload struct {
|
type jwtPayload struct {
|
||||||
Allow []string
|
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)
|
key, err := keystore.Get(JWTSecretName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn("Generating new API secret")
|
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
|
||||||
}
|
}
|
||||||
|
5
node/modules/dtypes/api.go
Normal file
5
node/modules/dtypes/api.go
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package dtypes
|
||||||
|
|
||||||
|
import "github.com/gbrlsnchs/jwt/v3"
|
||||||
|
|
||||||
|
type APIAlg jwt.HMACSHA
|
@ -125,3 +125,18 @@ func StagingDAG(mctx helpers.MetricsCtx, lc fx.Lifecycle, r repo.LockedRepo, rt
|
|||||||
|
|
||||||
return dag, nil
|
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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user