Skip to content

PDP only cluster init #483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ RUN git submodule update --init
RUN go mod download

# Stage 2: Install Lotus binary
FROM ghcr.io/filecoin-shipyard/lotus-containers:lotus-v1.32.1-devnet AS lotus-test
FROM ghcr.io/filecoin-shipyard/lotus-containers:lotus-v1.32.2-devnet AS lotus-test

# Stage 3: Build the final image
FROM myoung34/github-runner AS curio-github-runner
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ build_lotus?=0
curio_docker_user?=curio
curio_base_image=$(curio_docker_user)/curio-all-in-one:latest-debug
ffi_from_source?=0
lotus_version?=v1.32.1
lotus_version?=v1.32.2

ifeq ($(build_lotus),1)
# v1: building lotus image with provided lotus version
Expand Down
10 changes: 9 additions & 1 deletion cmd/curio/config_new.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ var configNewCmd = &cli.Command{
Hidden: true,
Value: "~/.lotus",
},
&cli.BoolFlag{
Name: "pdp",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe empty? This option will apply to more than just pdp

Usage: "initiate a PDP only cluster",
},
},
Action: func(cctx *cli.Context) error {
if cctx.Args().Len() < 1 {
if !cctx.Bool("pdp") && cctx.Args().Len() < 1 {
return xerrors.New("must specify at least one SP actor address. Use 'lotus-shed miner create' or use 'curio guided-setup'")
}

Expand All @@ -54,6 +58,10 @@ var configNewCmd = &cli.Command{
return err
}

if cctx.Bool("pdp") {
return deps.CreatePDPConfig(ctx, db, fmt.Sprintf("%s:%s", string(token), ainfo.Addr))
}

return deps.CreateMinerConfig(ctx, full, db, cctx.Args().Slice(), fmt.Sprintf("%s:%s", string(token), ainfo.Addr))
},
}
122 changes: 120 additions & 2 deletions cmd/curio/guidedsetup/guidedsetup.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,20 @@ var GuidedsetupCmd = &cli.Command{
}

newOrMigrate(&migrationData)
if migrationData.init {
if migrationData.init && !migrationData.initPDP {
say(header, "This interactive tool creates a new miner actor and creates the basic configuration layer for it.")
say(notice, "This process is partially idempotent. Once a new miner actor has been created and subsequent steps fail, the user need to run 'curio config new-cluster < miner ID >' to finish the configuration.")
for _, step := range newMinerSteps {
step(&migrationData)
}
} else if !migrationData.init && migrationData.initPDP {
say(header, "This interactive tool creates a new PDP only provider and creates the basic configuration layer for it.")
for _, step := range newPDPSteps {
step(&migrationData)
}
} else if migrationData.init && migrationData.initPDP {
say(header, "This interactive tool does not support creating a new miner and PDP only provider at the same time.")
os.Exit(1)
} else {
say(header, "This interactive tool migrates lotus-miner to Curio in 5 minutes.")
say(notice, "Each step needs your confirmation and can be reversed. Press Ctrl+C to exit at any time.")
Expand Down Expand Up @@ -149,7 +157,8 @@ func newOrMigrate(d *MigrationData) {
Label: d.T("I want to:"),
Items: []string{
d.T("Migrate from existing Lotus-Miner"),
d.T("Create a new miner")},
d.T("Create a new miner"),
d.T("Create a PDP only provider")},
Templates: d.selectTemplates,
}).Run()
if err != nil {
Expand All @@ -159,6 +168,9 @@ func newOrMigrate(d *MigrationData) {
if i == 1 {
d.init = true
}
if i == 2 {
d.initPDP = true
}
}

type migrationStep func(*MigrationData)
Expand All @@ -185,6 +197,14 @@ var newMinerSteps = []newMinerStep{
afterRan,
}

type newPDPStep func(data *MigrationData)

var newPDPSteps = []newPDPStep{
pdp,
doc,
afterRan,
}

type MigrationData struct {
T func(key message.Reference, a ...interface{}) string
say func(style lipgloss.Style, key message.Reference, a ...interface{})
Expand All @@ -202,6 +222,7 @@ type MigrationData struct {
sender address.Address
ssize string
init bool
initPDP bool
}

func complete(d *MigrationData) {
Expand Down Expand Up @@ -786,3 +807,100 @@ func getDBDetails(d *MigrationData) {
}
}
}

func pdp(d *MigrationData) {
// Setup and connect to YugabyteDB
getDBDetails(d)

// Check that we don't have a miner address
var titles []struct {
Title string `db:"title"`
Config string `db:"config"`
}

var configs []string

err := d.DB.Select(d.ctx, &titles, `SELECT title, config FROM harmony_config WHERE LENGTH(config) > 0`)
if err != nil {
d.say(notice, "Cannot reach the DB: %s", err.Error())
os.Exit(1)
}

curioConfig := config.DefaultCurioConfig()

for _, t := range titles {
_, err := deps.LoadConfigWithUpgrades(t.Config, curioConfig)
if err != nil {
d.say(notice, "Cannot parse config %s: %s", t.Title, err.Error())
os.Exit(1)
}
configs = append(configs, t.Title)
}

if len(curioConfig.Addresses) > 0 {
if curioConfig.Addresses[0].MinerAddresses[0] != "" {
d.say(notice, "Miner address already exists in the config. Cannot initiate a new PDP only cluster")
os.Exit(1)
}
}

curioConfig = config.DefaultCurioConfig()
curioConfig.Addresses = append(curioConfig.Addresses, config.CurioAddresses{
PreCommitControl: []string{},
CommitControl: []string{},
DealPublishControl: []string{},
TerminateControl: []string{},
DisableOwnerFallback: false,
DisableWorkerFallback: false,
MinerAddresses: []string{},
BalanceManager: config.DefaultBalanceManager(),
})

sk, err := io.ReadAll(io.LimitReader(rand.Reader, 32))
if err != nil {
d.say(notice, "Failed to generate random bytes for secret: %s", err.Error())
os.Exit(1)
}

// Get full node API
full, closer, err := cliutil.GetFullNodeAPIV1(d.cctx)
if err != nil {
d.say(notice, "Error connecting to full node API: %s", err.Error())
os.Exit(1)
}
d.full = full
d.closers = append(d.closers, closer)

ainfo, err := cliutil.GetAPIInfo(d.cctx, repo.FullNode)
if err != nil {
d.say(notice, "Failed to get API info for FullNode: %w", err)
d.say(notice, "Please do not run guided-setup again as miner creation is not idempotent. You need to run 'curio config new-cluster %s' to finish the configuration", d.MinerID.String())
os.Exit(1)
}

token, err := d.full.AuthNew(d.ctx, lapi.AllPermissions)
if err != nil {
d.say(notice, "Failed to verify the auth token from daemon node: %s", err.Error())
d.say(notice, "Please do not run guided-setup again as miner creation is not idempotent. You need to run 'curio config new-cluster %s' to finish the configuration", d.MinerID.String())
os.Exit(1)
}

curioConfig.Apis.StorageRPCSecret = base64.StdEncoding.EncodeToString(sk)

curioConfig.Apis.ChainApiInfo = append(curioConfig.Apis.ChainApiInfo, fmt.Sprintf("%s:%s", string(token), ainfo.Addr))

if !lo.Contains(configs, "base") {
cb, err := config.ConfigUpdate(curioConfig, config.DefaultCurioConfig(), config.Commented(true), config.DefaultKeepUncommented(), config.NoEnv())
if err != nil {
d.say(notice, "Failed to generate default config: %s", err.Error())
os.Exit(1)
}
_, err = d.DB.Exec(d.ctx, "INSERT INTO harmony_config (title, config) VALUES ('base', $1)", string(cb))
if err != nil {
d.say(notice, "Failed to insert 'base' config layer in database: %s", err.Error())
os.Exit(1)
}
}

stepCompleted(d, d.T("Initialization steps complete"))
}
44 changes: 44 additions & 0 deletions deps/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -719,3 +719,47 @@ func CreateMinerConfig(ctx context.Context, full CreateMinerConfigChainAPI, db *
fmt.Printf("The base layer has been updated with miner[s] %s\n", miners)
return nil
}
func CreatePDPConfig(ctx context.Context, db *harmonydb.DB, info string) error {
var titles []string
err := db.Select(ctx, &titles, `SELECT title FROM harmony_config WHERE LENGTH(config) > 0`)
if err != nil {
return fmt.Errorf("cannot reach the db. Ensure that Yugabyte flags are set correctly to"+
" reach Yugabyte: %s", err.Error())
}

// setup config
curioConfig := config.DefaultCurioConfig()
curioConfig.Addresses = append(curioConfig.Addresses, config.CurioAddresses{
PreCommitControl: []string{},
CommitControl: []string{},
DealPublishControl: []string{},
TerminateControl: []string{},
DisableOwnerFallback: false,
DisableWorkerFallback: false,
MinerAddresses: []string{},
BalanceManager: config.DefaultBalanceManager(),
})

sk, err := io.ReadAll(io.LimitReader(rand.Reader, 32))
if err != nil {
return err
}

curioConfig.Apis.StorageRPCSecret = base64.StdEncoding.EncodeToString(sk)

curioConfig.Apis.ChainApiInfo = append(curioConfig.Apis.ChainApiInfo, info)
if !lo.Contains(titles, "base") {
cb, err := config.ConfigUpdate(curioConfig, config.DefaultCurioConfig(), config.Commented(true), config.DefaultKeepUncommented(), config.NoEnv())
if err != nil {
return xerrors.Errorf("Failed to generate default config: %w", err)
}
cfg := string(cb)
_, err = db.Exec(ctx, "INSERT INTO harmony_config (title, config) VALUES ('base', $1)", cfg)
if err != nil {
return xerrors.Errorf("failed to insert the 'base' into the database: %w", err)
}
fmt.Println("The base layer has been created for PDP only provider")
return nil
}
return xerrors.Errorf("base layer already exists")
}
2 changes: 1 addition & 1 deletion docker/curio/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,5 @@ if [ ! -f $CURIO_REPO_PATH/.init.curio ]; then
fi

echo Starting curio node ...
exec curio run --nosync --name devnet --layers seal,post,market,gui
exec curio run --nosync --name devnet --layers market,gui

Loading