Skip to content

Commit c6988ed

Browse files
authored
feat: F3 (#292)
* feat: F3 * f3 fixes * address review * winpost: Run on single node context * f3: Keep single node longer term * webui: Hide background tasks by default * make it possible to disable f3
1 parent 9d5a08e commit c6988ed

File tree

8 files changed

+398
-37
lines changed

8 files changed

+398
-37
lines changed

cmd/curio/tasks/tasks.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package tasks
33

44
import (
55
"context"
6+
"os"
67
"sort"
78
"strings"
89
"sync"
@@ -32,6 +33,7 @@ import (
3233
"github.com/filecoin-project/curio/lib/paths"
3334
"github.com/filecoin-project/curio/lib/slotmgr"
3435
"github.com/filecoin-project/curio/lib/storiface"
36+
"github.com/filecoin-project/curio/tasks/f3"
3537
"github.com/filecoin-project/curio/tasks/gc"
3638
"github.com/filecoin-project/curio/tasks/message"
3739
"github.com/filecoin-project/curio/tasks/metadata"
@@ -152,6 +154,11 @@ func StartTasks(ctx context.Context, dependencies *deps.Deps) (*harmonytask.Task
152154
inclCkTask := winning.NewInclusionCheckTask(db, full)
153155
activeTasks = append(activeTasks, winPoStTask, inclCkTask)
154156

157+
if os.Getenv("CURIO_DISABLE_F3") != "1" {
158+
f3Task := f3.NewF3Task(db, full, maddrs)
159+
activeTasks = append(activeTasks, f3Task)
160+
}
161+
155162
// Warn if also running a sealing task
156163
if cfg.Subsystems.EnableSealSDR || cfg.Subsystems.EnableSealSDRTrees || cfg.Subsystems.EnableSendPrecommitMsg || cfg.Subsystems.EnablePoRepProof || cfg.Subsystems.EnableMoveStorage || cfg.Subsystems.EnableSendCommitMsg || cfg.Subsystems.EnableUpdateEncode || cfg.Subsystems.EnableUpdateProve || cfg.Subsystems.EnableUpdateSubmit {
157164
log.Error("It's unsafe to run PoSt and sealing tasks concurrently.")

deps/apiinfo.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919

2020
"github.com/filecoin-project/curio/api"
2121

22+
lapi "github.com/filecoin-project/lotus/api"
2223
"github.com/filecoin-project/lotus/chain/types"
2324
cliutil "github.com/filecoin-project/lotus/cli/util"
2425
)
@@ -80,9 +81,13 @@ func GetFullNodeAPIV1Curio(ctx *cli.Context, ainfoCfg []string) (api.Chain, json
8081

8182
type contextKey string
8283

84+
var retryNodeKey = contextKey("retry-node")
85+
86+
// OnSingleNode returns a new context that will try to perform all calls on the same node.
87+
// If the backing node fails, the calls will be retried on a different node, and further calls will be made on that node.
8388
// Not thread safe
8489
func OnSingleNode(ctx context.Context) context.Context {
85-
return context.WithValue(ctx, contextKey("retry-node"), new(*int))
90+
return context.WithValue(ctx, retryNodeKey, new(*int))
8691
}
8792

8893
type httpHead struct {
@@ -96,7 +101,7 @@ var RPCErrors = jsonrpc.NewErrors()
96101
func newChainNodeRPCV1(ctx context.Context, addr string, requestHeader http.Header, opts ...jsonrpc.Option) (api.Chain, jsonrpc.ClientCloser, error) {
97102
var res api.ChainStruct
98103
closer, err := jsonrpc.NewMergeClient(ctx, addr, "Filecoin",
99-
api.GetInternalStructs(&res), requestHeader, append([]jsonrpc.Option{jsonrpc.WithErrors(RPCErrors)}, opts...)...)
104+
api.GetInternalStructs(&res), requestHeader, append([]jsonrpc.Option{jsonrpc.WithErrors(lapi.RPCErrors)}, opts...)...)
100105

101106
return &res, closer, err
102107
}
@@ -228,12 +233,11 @@ func FullNodeProxy[T api.Chain](ins []T, outstr *api.ChainStruct) {
228233

229234
// for calls that need to be performed on the same node
230235
// primarily for miner when calling create block and submit block subsequently
231-
key := contextKey("retry-node")
232-
if ctx.Value(key) != nil {
233-
if (*ctx.Value(key).(**int)) == nil {
234-
*ctx.Value(key).(**int) = preferredProvider
236+
if ctx.Value(retryNodeKey) != nil {
237+
if (*ctx.Value(retryNodeKey).(**int)) == nil {
238+
*ctx.Value(retryNodeKey).(**int) = preferredProvider
235239
} else {
236-
preferredProvider = *ctx.Value(key).(**int)
240+
preferredProvider = *ctx.Value(retryNodeKey).(**int)
237241
}
238242
}
239243

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ require (
2323
github.com/filecoin-project/go-commp-utils v0.1.4
2424
github.com/filecoin-project/go-commp-utils/nonffi v0.0.0-20240802040721-2a04ffc8ffe8
2525
github.com/filecoin-project/go-commp-utils/v2 v2.1.0
26+
github.com/filecoin-project/go-f3 v0.7.0
2627
github.com/filecoin-project/go-fil-commcid v0.2.0
2728
github.com/filecoin-project/go-fil-commp-hashhash v0.2.0
2829
github.com/filecoin-project/go-jsonrpc v0.6.1-0.20240820160949-2cfe810e5d2f
@@ -53,6 +54,7 @@ require (
5354
github.com/ipfs/go-ipld-cbor v0.2.0
5455
github.com/ipfs/go-log/v2 v2.5.1
5556
github.com/jackc/pgerrcode v0.0.0-20240316143900-6e2875d9b438
57+
github.com/jpillora/backoff v1.0.0
5658
github.com/kelseyhightower/envconfig v1.4.0
5759
github.com/libp2p/go-buffer-pool v0.1.0
5860
github.com/manifoldco/promptui v0.9.0
@@ -131,7 +133,6 @@ require (
131133
github.com/filecoin-project/go-amt-ipld/v4 v4.4.0 // indirect
132134
github.com/filecoin-project/go-clock v0.1.0 // indirect
133135
github.com/filecoin-project/go-crypto v0.1.0 // indirect
134-
github.com/filecoin-project/go-f3 v0.7.0 // indirect
135136
github.com/filecoin-project/go-hamt-ipld v0.1.5 // indirect
136137
github.com/filecoin-project/go-hamt-ipld/v2 v2.0.0 // indirect
137138
github.com/filecoin-project/go-hamt-ipld/v3 v3.4.0 // indirect
@@ -205,7 +206,6 @@ require (
205206
github.com/jessevdk/go-flags v1.4.0 // indirect
206207
github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901 // indirect
207208
github.com/josharian/intern v1.0.0 // indirect
208-
github.com/jpillora/backoff v1.0.0 // indirect
209209
github.com/kilic/bls12-381 v0.1.1-0.20220929213557-ca162e8a70f4 // indirect
210210
github.com/klauspost/compress v1.17.9 // indirect
211211
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CREATE TABLE f3_tasks (
2+
sp_id BIGINT PRIMARY KEY,
3+
task_id BIGINT UNIQUE,
4+
previous_ticket BYTEA,
5+
6+
FOREIGN KEY (task_id) REFERENCES harmony_task (id) ON DELETE SET NULL
7+
);

harmony/taskhelp/common.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package taskhelp
22

3+
import "strings"
4+
35
// SubsetIf returns a subset of the slice for which the predicate is true.
46
// It does not allocate memory, but rearranges the list in place.
57
// A non-zero list input will always return a non-zero list.
@@ -17,3 +19,14 @@ func SliceIfFound[T any](slice []T, f func(T) bool) ([]T, bool) {
1719
}
1820
return slice[:ct], true
1921
}
22+
23+
// BackgroundTask are tasks that:
24+
// * Always run in the background
25+
// * Never finish "successfully"
26+
func BackgroundTask(name string) string {
27+
return "bg:" + name
28+
}
29+
30+
func IsBackgroundTask(name string) bool {
31+
return strings.HasPrefix(name, "bg:")
32+
}

0 commit comments

Comments
 (0)