Skip to content
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

feat: lotus-provider: WinningPoSt support #11410

Merged
merged 25 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f27d54b
feat: lpwinning: Initial task layout
magik6k Nov 9, 2023
f4d8671
lpwinning: More scribbling around adder
magik6k Nov 10, 2023
f30a7db
lpwinning: adder done
magik6k Nov 10, 2023
49c56e4
lpwinning: basic CanAccept
magik6k Nov 10, 2023
b9625da
lpwinning: implement WinPostTask.Do
magik6k Nov 10, 2023
2a4ce7d
lpwinning: wire up winningPoSt
magik6k Nov 10, 2023
d719db3
lpwinning: fix PoSt prover gen
magik6k Nov 10, 2023
8b41013
lpwindow: Fix recover schema
magik6k Nov 11, 2023
f2ef006
lotus-miner: add config for disabling winning post
magik6k Nov 11, 2023
8744312
lotus-provider: Make from-miner work offline
magik6k Nov 11, 2023
7efc4e4
lotus-provider: Somewhat less broken from-miner
magik6k Nov 11, 2023
339e062
lotus-provider: Encode storage rpc secret correctly in from-miner
magik6k Nov 11, 2023
30cf227
lpwinning: select lowest epoch task id for mining task
magik6k Nov 11, 2023
aa87f3c
lpwinning: Make block production work
magik6k Nov 11, 2023
10032a1
lpwinning: Handle null-block mining more correctly
magik6k Nov 11, 2023
63b130a
lpwinning: limit new base rate
magik6k Nov 14, 2023
68cef72
migrate-fix
snadrus Nov 14, 2023
1a9e3cf
Merge pull request #11418 from filecoin-project/sturdy-migrate-fixes
magik6k Nov 15, 2023
98099cc
harmonytask: remember machine
snadrus Nov 13, 2023
aed9a6d
sql startup fix, better errors
magik6k Nov 15, 2023
c1edae6
gen fix
snadrus Nov 13, 2023
9b4a3ba
fix circleci and fiximports
snadrus Nov 14, 2023
0d90430
better storageRpcSecret errormsg
snadrus Nov 14, 2023
3947327
mod tidy
magik6k Nov 15, 2023
fceabdb
make gen
magik6k Nov 15, 2023
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
4 changes: 0 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1018,31 +1018,27 @@ workflows:
suite: utest-unit-cli
target: "./cli/... ./cmd/... ./api/..."
get-params: true
executor: golang-2xl
- test:
name: test-unit-node
requires:
- build
suite: utest-unit-node
target: "./node/..."


- test:
name: test-unit-rest
requires:
- build
suite: utest-unit-rest
target: "./blockstore/... ./build/... ./chain/... ./conformance/... ./gateway/... ./journal/... ./lib/... ./markets/... ./paychmgr/... ./provider/... ./tools/..."

executor: golang-2xl
- test:
name: test-unit-storage
requires:
- build
suite: utest-unit-storage
target: "./storage/... ./extern/..."


- test:
go-test-flags: "-run=TestMulticoreSDR"
requires:
Expand Down
2 changes: 0 additions & 2 deletions .circleci/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -567,8 +567,6 @@ workflows:
suite: utest-[[ $suite ]]
target: "[[ $pkgs ]]"
[[if eq $suite "unit-cli"]]get-params: true[[end]]
[[if eq $suite "unit-cli"]]executor: golang-2xl[[end]]
[[- if eq $suite "unit-rest"]]executor: golang-2xl[[end]]
[[- end]]
- test:
go-test-flags: "-run=TestMulticoreSDR"
Expand Down
4 changes: 2 additions & 2 deletions cli/util/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func GetAPIInfoMulti(ctx *cli.Context, t repo.RepoType) ([]APIInfo, error) {
}
}

return []APIInfo{}, fmt.Errorf("could not determine API endpoint for node type: %v", t.Type())
return []APIInfo{}, fmt.Errorf("could not determine API endpoint for node type: %v. Try setting environment variable: %s", t.Type(), primaryEnv)
}

func GetAPIInfo(ctx *cli.Context, t repo.RepoType) (APIInfo, error) {
Expand Down Expand Up @@ -168,7 +168,7 @@ func GetRawAPIMultiV2(ctx *cli.Context, ainfoCfg []string, version string) ([]Ht
var httpHeads []HttpHead

if len(ainfoCfg) == 0 {
return httpHeads, xerrors.Errorf("could not get API info: none configured. \nConsider getting base.toml with './lotus-provider config get base >base.toml' \nthen adding \n[APIs] \n FULLNODE_API_INFO = [\" result_from lotus auth api-info --perm=admin \"]\n and updating it with './lotus-provider config set base.toml'")
return httpHeads, xerrors.Errorf("could not get API info: none configured. \nConsider getting base.toml with './lotus-provider config get base >/tmp/base.toml' \nthen adding \n[APIs] \n ChainApiInfo = [\" result_from lotus auth api-info --perm=admin \"]\n and updating it with './lotus-provider config set /tmp/base.toml'")
}
for _, i := range ainfoCfg {
ainfo := ParseApiInfo(i)
Expand Down
36 changes: 28 additions & 8 deletions cmd/lotus-provider/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ import (
"strings"

"github.com/BurntSushi/toml"
"github.com/ipfs/go-datastore"
"github.com/samber/lo"
"github.com/urfave/cli/v2"
"golang.org/x/xerrors"

"github.com/filecoin-project/go-address"

cliutil "github.com/filecoin-project/lotus/cli/util"
"github.com/filecoin-project/lotus/lib/harmony/harmonydb"
"github.com/filecoin-project/lotus/node/config"
Expand All @@ -33,6 +36,12 @@ var configMigrateCmd = &cli.Command{
Value: "~/.lotusminer",
Usage: fmt.Sprintf("Specify miner repo path. flag(%s) and env(LOTUS_STORAGE_PATH) are DEPRECATION, will REMOVE SOON", FlagMinerRepoDeprecation),
},
&cli.StringFlag{
Name: "repo",
EnvVars: []string{"LOTUS_PATH"},
Hidden: true,
Value: "~/.lotus",
},
&cli.StringFlag{
Name: "to-layer",
Aliases: []string{"t"},
Expand Down Expand Up @@ -117,14 +126,20 @@ func fromMiner(cctx *cli.Context) (err error) {
}

// Populate Miner Address
sm, cc, err := cliutil.GetStorageMinerAPI(cctx)
mmeta, err := lr.Datastore(ctx, "/metadata")
if err != nil {
return xerrors.Errorf("opening miner metadata datastore: %w", err)
}
defer mmeta.Close()

maddrBytes, err := mmeta.Get(ctx, datastore.NewKey("miner-address"))
if err != nil {
return fmt.Errorf("could not get storageMiner API: %w", err)
return xerrors.Errorf("getting miner address datastore entry: %w", err)
}
defer cc()
addr, err := sm.ActorAddress(ctx)

addr, err := address.NewFromBytes(maddrBytes)
if err != nil {
return fmt.Errorf("could not read actor address: %w", err)
return xerrors.Errorf("parsing miner actor address: %w", err)
}

lpCfg.Addresses.MinerAddresses = []string{addr.String()}
Expand All @@ -137,15 +152,20 @@ func fromMiner(cctx *cli.Context) (err error) {
if err != nil {
return xerrors.Errorf("error getting JWTSecretName: %w", err)
}
lpCfg.Apis.StorageRPCSecret = base64.RawStdEncoding.EncodeToString(js.PrivateKey)

lpCfg.Apis.StorageRPCSecret = base64.StdEncoding.EncodeToString(js.PrivateKey)

// Populate API Key
_, header, err := cliutil.GetRawAPI(cctx, repo.FullNode, "v0")
if err != nil {
return fmt.Errorf("cannot read API: %w", err)
}

lpCfg.Apis.ChainApiInfo = []string{header.Get("Authorization")[7:]}
ainfo, err := cliutil.GetAPIInfo(&cli.Context{}, repo.FullNode)
if err != nil {
return xerrors.Errorf("could not get API info for FullNode: %w", err)
}
lpCfg.Apis.ChainApiInfo = []string{header.Get("Authorization")[7:] + ":" + ainfo.Addr}

// Enable WindowPoSt
lpCfg.Subsystems.EnableWindowPost = true
Expand All @@ -161,7 +181,7 @@ environment variable LOTUS_WORKER_WINDOWPOST.
}

if !lo.Contains(titles, "base") {
_, err = db.Exec(ctx, "INSERT INTO harmony_config (title, config) VALUES ('base', '')", "base")
_, err = db.Exec(ctx, "INSERT INTO harmony_config (title, config) VALUES ('base', '')")
Copy link
Collaborator

Choose a reason for hiding this comment

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

We probably should have the migrator enable:
lpCfg.Subsystems.EnableWinningPost = true
And add a comment about diabling it in lotus-miner

if err != nil {
return err
}
Expand Down
11 changes: 10 additions & 1 deletion cmd/lotus-provider/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"github.com/filecoin-project/lotus/node/modules/dtypes"
"github.com/filecoin-project/lotus/node/repo"
"github.com/filecoin-project/lotus/provider"
"github.com/filecoin-project/lotus/provider/lpwinning"
"github.com/filecoin-project/lotus/storage/paths"
"github.com/filecoin-project/lotus/storage/sealer"
"github.com/filecoin-project/lotus/storage/sealer/ffiwrapper"
Expand Down Expand Up @@ -204,7 +205,10 @@ var runCmd = &cli.Command{

sa, err := StorageAuth(cfg.Apis.StorageRPCSecret)
if err != nil {
return xerrors.Errorf("parsing Apis.StorageRPCSecret config: %w", err)
return xerrors.Errorf(`'%w' while parsing the config toml's
[Apis]
StorageRPCSecret=%v
Get it with: jq .PrivateKey ~/.lotus-miner/keystore/MF2XI2BNNJ3XILLQOJUXMYLUMU`, err, cfg.Apis.StorageRPCSecret)
}

al := alerting.NewAlertingSystem(j)
Expand Down Expand Up @@ -251,6 +255,11 @@ var runCmd = &cli.Command{
}
activeTasks = append(activeTasks, wdPostTask, wdPoStSubmitTask, derlareRecoverTask)
}

if cfg.Subsystems.EnableWinningPost {
winPoStTask := lpwinning.NewWinPostTask(cfg.Subsystems.WinningPostMaxTasks, db, lw, verif, full, maddrs)
activeTasks = append(activeTasks, winPoStTask)
}
}
taskEngine, err := harmonytask.New(db, activeTasks, listenAddr)
if err != nil {
Expand Down
10 changes: 10 additions & 0 deletions documentation/en/default-lotus-miner-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,16 @@
# env var: LOTUS_SUBSYSTEMS_DISABLEWINDOWPOST
#DisableWindowPoSt = false

# When winning post is disabled, the miner process will NOT attempt to mine
# blocks. This should only be set when there's an external process mining
# blocks on behalf of the miner.
# When disabled and no external block producers are configured, all potential
# block rewards will be missed!
#
# type: bool
# env var: LOTUS_SUBSYSTEMS_DISABLEWINNINGPOST
#DisableWinningPoSt = false


[Dealmaking]
# When enabled, the miner can accept online deals
Expand Down
3 changes: 3 additions & 0 deletions documentation/en/default-lotus-provider-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
# type: bool
#EnableWinningPost = false

# type: int
#WinningPostMaxTasks = 0


[Fees]
# type: types.FIL
Expand Down
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,6 @@ github.com/filecoin-project/go-state-types v0.0.0-20201102161440-c8033295a1fc/go
github.com/filecoin-project/go-state-types v0.1.0/go.mod h1:ezYnPf0bNkTsDibL/psSz5dy4B5awOJ/E7P2Saeep8g=
github.com/filecoin-project/go-state-types v0.1.6/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q=
github.com/filecoin-project/go-state-types v0.1.10/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q=
github.com/filecoin-project/go-state-types v0.11.1/go.mod h1:SyNPwTsU7I22gL2r0OAPcImvLoTVfgRwdK/Y5rR1zz8=
github.com/filecoin-project/go-state-types v0.11.2-0.20230712101859-8f37624fa540/go.mod h1:SyNPwTsU7I22gL2r0OAPcImvLoTVfgRwdK/Y5rR1zz8=
github.com/filecoin-project/go-state-types v0.12.5 h1:VQ2N2T3JeUDdIHEo/xhjnT7Q218Wl0UYIyglqT7Z9Ck=
github.com/filecoin-project/go-state-types v0.12.5/go.mod h1:iJTqGdWDvzXhuVf64Lw0hzt4TIoitMo0VgHdxdjNDZI=
Expand Down
4 changes: 2 additions & 2 deletions lib/harmony/harmonydb/sql/20230823.sql
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ create table wdpost_proofs
create table wdpost_recovery_tasks
(
task_id bigint not null
constraint wdpost_partition_tasks_pk
constraint wdpost_recovery_tasks_pk
primary key,
sp_id bigint not null,
proving_period_start bigint not null,
deadline_index bigint not null,
partition_index bigint not null,
constraint wdpost_partition_tasks_identity_key
constraint wdpost_recovery_tasks_identity_key
unique (sp_id, proving_period_start, deadline_index, partition_index)
);
39 changes: 39 additions & 0 deletions lib/harmony/harmonydb/sql/20231110.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
create table mining_tasks
snadrus marked this conversation as resolved.
Show resolved Hide resolved
(
task_id bigint not null
constraint mining_tasks_pk
primary key,
sp_id bigint not null,
epoch bigint not null,
base_compute_time timestamp not null,

won bool not null default false,
mined_cid text,
mined_header jsonb,
mined_at timestamp,

submitted_at timestamp,

constraint mining_tasks_sp_epoch
unique (sp_id, epoch)
);

create table mining_base_block
(
id bigserial not null
constraint mining_base_block_pk
primary key,
task_id bigint not null
constraint mining_base_block_mining_tasks_task_id_fk
references mining_tasks
on delete cascade,
sp_id bigint,
block_cid text not null,

no_win bool not null default false,

constraint mining_base_block_pk2
unique (sp_id, task_id, block_cid)
);

CREATE UNIQUE INDEX mining_base_block_cid_k ON mining_base_block (sp_id, block_cid) WHERE no_win = false;
1 change: 1 addition & 0 deletions lib/harmony/harmonydb/sql/20231113.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE harmony_task_history ADD COLUMN completed_by_host_and_port varchar(300) NOT NULL;
16 changes: 9 additions & 7 deletions lib/harmony/harmonytask/harmonytask.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ type TaskEngine struct {
follows map[string][]followStruct
lastFollowTime time.Time
lastCleanup atomic.Value
hostAndPort string
}
type followStruct struct {
f func(TaskID, AddTaskFunc) (bool, error)
Expand All @@ -129,13 +130,14 @@ func New(
}
ctx, grace := context.WithCancel(context.Background())
e := &TaskEngine{
ctx: ctx,
grace: grace,
db: db,
reg: reg,
ownerID: reg.Resources.MachineID, // The current number representing "hostAndPort"
taskMap: make(map[string]*taskTypeHandler, len(impls)),
follows: make(map[string][]followStruct),
ctx: ctx,
grace: grace,
db: db,
reg: reg,
ownerID: reg.Resources.MachineID, // The current number representing "hostAndPort"
taskMap: make(map[string]*taskTypeHandler, len(impls)),
follows: make(map[string][]followStruct),
hostAndPort: hostnameAndPort,
}
e.lastCleanup.Store(time.Now())
for _, c := range impls {
Expand Down
4 changes: 2 additions & 2 deletions lib/harmony/harmonytask/task_type_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ func (h *taskTypeHandler) recordCompletion(tID TaskID, workStart time.Time, done
}
}
_, err = tx.Exec(`INSERT INTO harmony_task_history
(task_id, name, posted, work_start, work_end, result, err)
VALUES ($1, $2, $3, $4, $5, $6, $7)`, tID, h.Name, postedTime, workStart, workEnd, done, result)
(task_id, name, posted, work_start, work_end, result, by_host_and_port, err)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)`, tID, h.Name, postedTime, workStart, workEnd, done, h.TaskEngine.hostAndPort, result)
if err != nil {
return false, fmt.Errorf("could not write history: %w", err)
}
Expand Down
Loading