Skip to content

Commit

Permalink
winpost: Run on single node context
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k committed Oct 22, 2024
1 parent 50b756e commit bb46ed3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
15 changes: 9 additions & 6 deletions deps/apiinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,13 @@ func GetFullNodeAPIV1Curio(ctx *cli.Context, ainfoCfg []string) (api.Chain, json

type contextKey string

var retryNodeKey = contextKey("retry-node")

// OnSingleNode returns a new context that will try to perform all calls on the same node.
// If the backing node fails, the calls will be retried on a different node, and further calls will be made on that node.
// Not thread safe
func OnSingleNode(ctx context.Context) context.Context {
return context.WithValue(ctx, contextKey("retry-node"), new(*int))
return context.WithValue(ctx, retryNodeKey, new(*int))
}

type httpHead struct {
Expand Down Expand Up @@ -229,12 +233,11 @@ func FullNodeProxy[T api.Chain](ins []T, outstr *api.ChainStruct) {

// for calls that need to be performed on the same node
// primarily for miner when calling create block and submit block subsequently
key := contextKey("retry-node")
if ctx.Value(key) != nil {
if (*ctx.Value(key).(**int)) == nil {
*ctx.Value(key).(**int) = preferredProvider
if ctx.Value(retryNodeKey) != nil {
if (*ctx.Value(retryNodeKey).(**int)) == nil {
*ctx.Value(retryNodeKey).(**int) = preferredProvider
} else {
preferredProvider = *ctx.Value(key).(**int)
preferredProvider = *ctx.Value(retryNodeKey).(**int)
}
}

Expand Down
5 changes: 3 additions & 2 deletions tasks/winning/winning_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
prooftypes "github.com/filecoin-project/go-state-types/proof"

"github.com/filecoin-project/curio/build"
"github.com/filecoin-project/curio/deps"
"github.com/filecoin-project/curio/harmony/harmonydb"
"github.com/filecoin-project/curio/harmony/harmonytask"
"github.com/filecoin-project/curio/harmony/resources"
Expand Down Expand Up @@ -95,7 +96,7 @@ func NewWinPostTask(max int, db *harmonydb.DB, remote *paths.Remote, verifier st
func (t *WinPostTask) Do(taskID harmonytask.TaskID, stillOwned func() bool) (done bool, err error) {
log.Debugw("WinPostTask.Do()", "taskID", taskID)

ctx := context.TODO()
ctx := deps.OnSingleNode(context.Background())

type BlockCID struct {
CID string
Expand Down Expand Up @@ -397,7 +398,7 @@ func (t *WinPostTask) Do(taskID harmonytask.TaskID, stillOwned func() bool) (don
{
uts := base.TipSet.MinTimestamp() + build.BlockDelaySecs*(uint64(base.AddRounds)+1)

blockMsg, err = t.api.MinerCreateBlock(context.TODO(), &api.BlockTemplate{
blockMsg, err = t.api.MinerCreateBlock(ctx, &api.BlockTemplate{
Miner: maddr,
Parents: base.TipSet.Key(),
Ticket: ticket,
Expand Down

0 comments on commit bb46ed3

Please sign in to comment.