66 "time"
77
88 "github.com/Layr-Labs/eigensdk-go/logging"
9+ retry "github.com/yetanotherco/aligned_layer/core"
910 "github.com/yetanotherco/aligned_layer/core/types"
1011)
1112
@@ -16,11 +17,6 @@ type AggregatorRpcClient struct {
1617 logger logging.Logger
1718}
1819
19- const (
20- MaxRetries = 10
21- RetryInterval = 10 * time .Second
22- )
23-
2420func NewAggregatorRpcClient (aggregatorIpPortAddr string , logger logging.Logger ) (* AggregatorRpcClient , error ) {
2521 client , err := rpc .DialHTTP ("tcp" , aggregatorIpPortAddr )
2622 if err != nil {
@@ -34,31 +30,29 @@ func NewAggregatorRpcClient(aggregatorIpPortAddr string, logger logging.Logger)
3430 }, nil
3531}
3632
37- // SendSignedTaskResponseToAggregator is the method called by operators via RPC to send
38- // their signed task response.
39- func (c * AggregatorRpcClient ) SendSignedTaskResponseToAggregator (signedTaskResponse * types.SignedTaskResponse ) {
40- var reply uint8
41- for retries := 0 ; retries < MaxRetries ; retries ++ {
33+ func SendSignedTaskResponse (c * AggregatorRpcClient , signedTaskResponse * types.SignedTaskResponse ) func () (uint8 , error ) {
34+ send_task_func := func () (uint8 , error ) {
35+ var reply uint8
4236 err := c .rpcClient .Call ("Aggregator.ProcessOperatorSignedTaskResponseV2" , signedTaskResponse , & reply )
4337 if err != nil {
4438 c .logger .Error ("Received error from aggregator" , "err" , err )
4539 if errors .Is (err , rpc .ErrShutdown ) {
4640 c .logger .Error ("Aggregator is shutdown. Reconnecting..." )
47- client , err := rpc .DialHTTP ("tcp" , c .aggregatorIpPortAddr )
48- if err != nil {
49- c .logger .Error ("Could not reconnect to aggregator" , "err" , err )
50- time .Sleep (RetryInterval )
51- } else {
52- c .rpcClient = client
53- c .logger .Info ("Reconnected to aggregator" )
54- }
55- } else {
56- c .logger .Infof ("Received error from aggregator: %s. Retrying ProcessOperatorSignedTaskResponseV2 RPC call..." , err )
57- time .Sleep (RetryInterval )
5841 }
5942 } else {
6043 c .logger .Info ("Signed task response header accepted by aggregator." , "reply" , reply )
61- return
6244 }
45+ return reply , err
6346 }
47+ return send_task_func
48+ }
49+
50+ // SendSignedTaskResponseToAggregator is the method called by operators via RPC to send
51+ // their signed task response.
52+ func (c * AggregatorRpcClient ) SendSignedTaskResponseToAggregatorRetryable (signedTaskResponse * types.SignedTaskResponse ) (uint8 , error ) {
53+ config := retry .DefaultRetryConfig ()
54+ config .NumRetries = 10
55+ config .Multiplier = 1 // Constant retry interval
56+ config .InitialInterval = 10 * time .Second
57+ return retry .RetryWithData (SendSignedTaskResponse (c , signedTaskResponse ), config )
6458}
0 commit comments