-
Notifications
You must be signed in to change notification settings - Fork 396
Expand file tree
/
Copy pathrpc_client.go
More file actions
58 lines (51 loc) · 1.86 KB
/
rpc_client.go
File metadata and controls
58 lines (51 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package operator
import (
"errors"
"net/rpc"
"time"
"github.com/Layr-Labs/eigensdk-go/logging"
retry "github.com/yetanotherco/aligned_layer/core"
"github.com/yetanotherco/aligned_layer/core/types"
)
// AggregatorRpcClient is the client to communicate with the aggregator via RPC
type AggregatorRpcClient struct {
rpcClient *rpc.Client
aggregatorIpPortAddr string
logger logging.Logger
}
func NewAggregatorRpcClient(aggregatorIpPortAddr string, logger logging.Logger) (*AggregatorRpcClient, error) {
client, err := rpc.DialHTTP("tcp", aggregatorIpPortAddr)
if err != nil {
return nil, err
}
return &AggregatorRpcClient{
rpcClient: client,
aggregatorIpPortAddr: aggregatorIpPortAddr,
logger: logger,
}, nil
}
func SendSignedTaskResponse(c *AggregatorRpcClient, signedTaskResponse *types.SignedTaskResponse) func() (uint8, error) {
send_task_func := func() (uint8, error) {
var reply uint8
err := c.rpcClient.Call("Aggregator.ProcessOperatorSignedTaskResponseV2", signedTaskResponse, &reply)
if err != nil {
c.logger.Error("Received error from aggregator", "err", err)
if errors.Is(err, rpc.ErrShutdown) {
c.logger.Error("Aggregator is shutdown. Reconnecting...")
}
} else {
c.logger.Info("Signed task response header accepted by aggregator.", "reply", reply)
}
return reply, err
}
return send_task_func
}
// SendSignedTaskResponseToAggregator is the method called by operators via RPC to send
// their signed task response.
func (c *AggregatorRpcClient) SendSignedTaskResponseToAggregatorRetryable(signedTaskResponse *types.SignedTaskResponse) (uint8, error) {
config := retry.DefaultRetryConfig()
config.NumRetries = 10
config.Multiplier = 1 // Constant retry interval
config.InitialInterval = 10 * time.Second
return retry.RetryWithData(SendSignedTaskResponse(c, signedTaskResponse), config)
}