lp migrator fixes
This commit is contained in:
parent
02d3e24d38
commit
b0cb4b56d6
@ -26,6 +26,7 @@ var configCmd = &cli.Command{
|
|||||||
configListCmd,
|
configListCmd,
|
||||||
configViewCmd,
|
configViewCmd,
|
||||||
configRmCmd,
|
configRmCmd,
|
||||||
|
configMigrateCmd,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,6 +226,10 @@ func getConfig(cctx *cli.Context, db *harmonydb.DB) (*config.LotusProviderConfig
|
|||||||
if strings.Contains(err.Error(), sql.ErrNoRows.Error()) {
|
if strings.Contains(err.Error(), sql.ErrNoRows.Error()) {
|
||||||
return nil, fmt.Errorf("missing layer '%s' ", layer)
|
return nil, fmt.Errorf("missing layer '%s' ", layer)
|
||||||
}
|
}
|
||||||
|
if layer == "base" {
|
||||||
|
return nil, errors.New(`lotus-provider defaults to a layer named 'base'.
|
||||||
|
Either use 'migrate' command or edit a base.toml and upload it with: lotus-provider config set base.toml`)
|
||||||
|
}
|
||||||
return nil, fmt.Errorf("could not read layer '%s': %w", layer, err)
|
return nil, fmt.Errorf("could not read layer '%s': %w", layer, err)
|
||||||
}
|
}
|
||||||
meta, err := toml.Decode(text, &lp)
|
meta, err := toml.Decode(text, &lp)
|
||||||
|
@ -3,27 +3,28 @@ package main
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/base64"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/BurntSushi/toml"
|
"github.com/BurntSushi/toml"
|
||||||
|
"github.com/samber/lo"
|
||||||
|
"github.com/urfave/cli/v2"
|
||||||
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
cliutil "github.com/filecoin-project/lotus/cli/util"
|
cliutil "github.com/filecoin-project/lotus/cli/util"
|
||||||
"github.com/filecoin-project/lotus/lib/harmony/harmonydb"
|
"github.com/filecoin-project/lotus/lib/harmony/harmonydb"
|
||||||
"github.com/filecoin-project/lotus/node/config"
|
"github.com/filecoin-project/lotus/node/config"
|
||||||
|
"github.com/filecoin-project/lotus/node/modules"
|
||||||
"github.com/filecoin-project/lotus/node/repo"
|
"github.com/filecoin-project/lotus/node/repo"
|
||||||
"github.com/samber/lo"
|
|
||||||
"github.com/urfave/cli/v2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var providerCmd = &cli.Command{
|
var configMigrateCmd = &cli.Command{
|
||||||
Name: "provider",
|
|
||||||
Description: "Run a lotus-provider helper",
|
|
||||||
Subcommands: []*cli.Command{
|
|
||||||
{
|
|
||||||
Name: "from-miner",
|
Name: "from-miner",
|
||||||
Description: "Express a database config from an existing miner.",
|
Description: "Express a database config (for lotus-provider) from an existing miner.",
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: FlagMinerRepo,
|
Name: FlagMinerRepo,
|
||||||
@ -35,12 +36,15 @@ var providerCmd = &cli.Command{
|
|||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "layer",
|
Name: "layer",
|
||||||
Aliases: []string{"l"},
|
Aliases: []string{"l"},
|
||||||
Usage: "The layer name for this data push. 'base' is recommended for single-miner setup. Overwrites.",
|
Usage: "The layer name for this data push. 'base' is recommended for single-miner setup.",
|
||||||
|
},
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: "overwrite",
|
||||||
|
Aliases: []string{"o"},
|
||||||
|
Usage: "Use this with layer to overwrite an existing layer",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: fromMiner,
|
Action: fromMiner,
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -49,7 +53,7 @@ const (
|
|||||||
|
|
||||||
const FlagMinerRepoDeprecation = "storagerepo"
|
const FlagMinerRepoDeprecation = "storagerepo"
|
||||||
|
|
||||||
func fromMiner(cctx *cli.Context) error {
|
func fromMiner(cctx *cli.Context) (err error) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
r, err := repo.NewFS(cctx.String(FlagMinerRepo))
|
r, err := repo.NewFS(cctx.String(FlagMinerRepo))
|
||||||
@ -85,7 +89,7 @@ func fromMiner(cctx *cli.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var titles []string
|
var titles []string
|
||||||
err = db.Select(ctx, &titles, `SELECT title FROM harmony_config`)
|
err = db.Select(ctx, &titles, `SELECT title FROM harmony_config WHERE LENGTH(config) > 0`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("miner cannot reach the db. Ensure the config toml's HarmonyDB entry"+
|
return fmt.Errorf("miner cannot reach the db. Ensure the config toml's HarmonyDB entry"+
|
||||||
" is setup to reach Yugabyte correctly: %s", err.Error())
|
" is setup to reach Yugabyte correctly: %s", err.Error())
|
||||||
@ -93,6 +97,10 @@ func fromMiner(cctx *cli.Context) error {
|
|||||||
name := cctx.String("layer")
|
name := cctx.String("layer")
|
||||||
if name == "" {
|
if name == "" {
|
||||||
name = fmt.Sprintf("mig%d", len(titles))
|
name = fmt.Sprintf("mig%d", len(titles))
|
||||||
|
} else {
|
||||||
|
if lo.Contains(titles, name) && !cctx.Bool("overwrite") {
|
||||||
|
return errors.New("the overwrite flag is needed to replace existing layer: " + name)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
msg := "Layer " + name + ` created. `
|
msg := "Layer " + name + ` created. `
|
||||||
|
|
||||||
@ -121,8 +129,15 @@ func fromMiner(cctx *cli.Context) error {
|
|||||||
|
|
||||||
lpCfg.Addresses.MinerAddresses = []string{addr.String()}
|
lpCfg.Addresses.MinerAddresses = []string{addr.String()}
|
||||||
|
|
||||||
// TODO Apis.StorageSecret storage repo and reading the rpc secret
|
ks, err := lr.KeyStore()
|
||||||
//lr.??
|
if err != nil {
|
||||||
|
return xerrors.Errorf("keystore err: %w", err)
|
||||||
|
}
|
||||||
|
js, err := ks.Get(modules.JWTSecretName)
|
||||||
|
if err != nil {
|
||||||
|
return xerrors.Errorf("error getting JWTSecretName: %w", err)
|
||||||
|
}
|
||||||
|
lpCfg.Apis.StorageRPCSecret = base64.RawStdEncoding.EncodeToString(js.PrivateKey)
|
||||||
|
|
||||||
// Populate API Key
|
// Populate API Key
|
||||||
_, header, err := cliutil.GetRawAPI(cctx, repo.FullNode, "v0")
|
_, header, err := cliutil.GetRawAPI(cctx, repo.FullNode, "v0")
|
||||||
@ -130,11 +145,14 @@ func fromMiner(cctx *cli.Context) error {
|
|||||||
return fmt.Errorf("cannot read API: %w", err)
|
return fmt.Errorf("cannot read API: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
lpCfg.Apis.FULLNODE_API_INFO = []string{header.Get("Authorization")[7:]}
|
lpCfg.Apis.ChainApiInfo = []string{header.Get("Authorization")[7:]}
|
||||||
|
|
||||||
// Enable WindowPoSt
|
// Enable WindowPoSt
|
||||||
lpCfg.Subsystems.EnableWindowPost = true
|
lpCfg.Subsystems.EnableWindowPost = true
|
||||||
msg += `\nBefore running lotus-provider, ensure any miner/worker answering of WindowPost is disabled.\n`
|
msg += `\nBefore running lotus-provider, ensure any miner/worker answering of WindowPost is disabled by
|
||||||
|
(on Miner) DisableBuiltinWindowPoSt=true and (on Workers) not enabling windowpost on CLI or via
|
||||||
|
environment variable LOTUS_WORKER_WINDOWPOST.
|
||||||
|
`
|
||||||
|
|
||||||
// Express as configTOML
|
// Express as configTOML
|
||||||
configTOML := &bytes.Buffer{}
|
configTOML := &bytes.Buffer{}
|
||||||
@ -148,6 +166,7 @@ func fromMiner(cctx *cli.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = db.Exec(ctx, "INSERT INTO harmony_config (title, config) VALUES ($1, $2)", name, configTOML.String())
|
_, err = db.Exec(ctx, "INSERT INTO harmony_config (title, config) VALUES ($1, $2)", name, configTOML.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
@ -196,7 +196,7 @@ var runCmd = &cli.Command{
|
|||||||
}
|
}
|
||||||
defer j.Close()
|
defer j.Close()
|
||||||
|
|
||||||
full, fullCloser, err := cliutil.GetFullNodeAPIV1LotusProvider(cctx, cfg.Apis.FULLNODE_API_INFO)
|
full, fullCloser, err := cliutil.GetFullNodeAPIV1LotusProvider(cctx, cfg.Apis.ChainApiInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,6 @@ func main() {
|
|||||||
FevmAnalyticsCmd,
|
FevmAnalyticsCmd,
|
||||||
mismatchesCmd,
|
mismatchesCmd,
|
||||||
blockCmd,
|
blockCmd,
|
||||||
providerCmd,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
app := &cli.App{
|
app := &cli.App{
|
||||||
|
@ -77,8 +77,8 @@ type LotusProviderConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ApisConfig struct {
|
type ApisConfig struct {
|
||||||
// FULLNODE_API_INFO is the API endpoint for the Lotus daemon.
|
// ChainApiInfo is the API endpoint for the Lotus daemon.
|
||||||
FULLNODE_API_INFO []string
|
ChainApiInfo []string
|
||||||
|
|
||||||
// RPC Secret for the storage subsystem.
|
// RPC Secret for the storage subsystem.
|
||||||
// If integrating with lotus-miner this must match the value from
|
// If integrating with lotus-miner this must match the value from
|
||||||
|
Loading…
Reference in New Issue
Block a user