@@ -19,6 +19,7 @@ import (
19
19
20
20
"github.com/filecoin-project/curio/api"
21
21
22
+ lapi "github.com/filecoin-project/lotus/api"
22
23
"github.com/filecoin-project/lotus/chain/types"
23
24
cliutil "github.com/filecoin-project/lotus/cli/util"
24
25
)
@@ -80,9 +81,13 @@ func GetFullNodeAPIV1Curio(ctx *cli.Context, ainfoCfg []string) (api.Chain, json
80
81
81
82
type contextKey string
82
83
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.
83
88
// Not thread safe
84
89
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 ))
86
91
}
87
92
88
93
type httpHead struct {
@@ -96,7 +101,7 @@ var RPCErrors = jsonrpc.NewErrors()
96
101
func newChainNodeRPCV1 (ctx context.Context , addr string , requestHeader http.Header , opts ... jsonrpc.Option ) (api.Chain , jsonrpc.ClientCloser , error ) {
97
102
var res api.ChainStruct
98
103
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 ... )... )
100
105
101
106
return & res , closer , err
102
107
}
@@ -228,12 +233,11 @@ func FullNodeProxy[T api.Chain](ins []T, outstr *api.ChainStruct) {
228
233
229
234
// for calls that need to be performed on the same node
230
235
// 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
235
239
} else {
236
- preferredProvider = * ctx .Value (key ).(* * int )
240
+ preferredProvider = * ctx .Value (retryNodeKey ).(* * int )
237
241
}
238
242
}
239
243
0 commit comments