@@ -4,15 +4,14 @@ import (
44 "context"
55 "encoding/hex"
66 "fmt"
7- "net/http"
8- "net/rpc"
9- "strings"
10- "time"
11-
127 "github.com/Layr-Labs/eigensdk-go/crypto/bls"
138 eigentypes "github.com/Layr-Labs/eigensdk-go/types"
149 retry "github.com/yetanotherco/aligned_layer/core"
1510 "github.com/yetanotherco/aligned_layer/core/types"
11+ "net/http"
12+ "net/rpc"
13+ "strings"
14+ "time"
1615)
1716
1817func (agg * Aggregator ) ServeOperators () error {
@@ -37,53 +36,13 @@ func (agg *Aggregator) ServeOperators() error {
3736 return err
3837}
3938
40- // Waits for the arrival of task associated with signedTaskResponse and returns true on success or false on failure
41- // If the task is not present in the internal map, it will try to fetch it from logs and retry.
42- // The number of retries is specified by `waitForEventRetries`, and the waiting time between each by `waitForEventSleepSeconds`
43- func (agg * Aggregator ) waitForTaskAndFetchIfLost (signedTaskResponse * types.SignedTaskResponse ) bool {
44- for i := 0 ; i < waitForEventRetries ; i ++ {
45- // Lock
46- agg .taskMutex .Lock ()
47- agg .AggregatorConfig .BaseConfig .Logger .Info ("- Locked Resources: Check if task is present" )
48- _ , ok := agg .batchesIdxByIdentifierHash [signedTaskResponse .BatchIdentifierHash ]
49- // Unlock
50- agg .logger .Info ("- Unlocked Resources: Check if task is present" )
51- agg .taskMutex .Unlock ()
52- if ok {
53- return true
54- }
55-
56- // Task was not found in internal map, let's try to fetch it from logs
57- agg .logger .Info ("Trying to fetch missed task from logs..." )
58- batch , err := agg .avsReader .GetPendingBatchFromMerkleRoot (signedTaskResponse .BatchMerkleRoot )
59-
60- if err == nil && batch != nil {
61- agg .logger .Info ("Found missed task in logs with merkle root 0x%e" , batch .BatchMerkleRoot )
62- // Adding new task will fail only if it already exists
63- agg .AddNewTask (batch .BatchMerkleRoot , batch .SenderAddress , batch .TaskCreatedBlock )
64- return true
65- }
66-
67- if err != nil {
68- agg .logger .Warn ("Error fetching task from logs: %v" , err )
69- }
70-
71- if batch == nil {
72- agg .logger .Info ("Task not found in logs" )
73- }
74-
75- // Task was not found, wait and retry
76- time .Sleep (waitForEventSleepSeconds )
77- }
78-
79- return false
80- }
81-
82- // Aggregator Methods
39+ // ~~ AGGREGATOR METHODS ~~
8340// This is the list of methods that the Aggregator exposes to the Operator
8441// The Operator can call these methods to interact with the Aggregator
8542// This methods are automatically registered by the RPC server
86- // This takes a response an adds it to the internal. If reaching the quorum, it sends the aggregated signatures to ethereum
43+
44+ // Takes a response from an operator and process it. After processing the response, the associated task may reach quorum, triggering a BLS service response.
45+ // If the task related to the response is not known to the aggregator (not stored in internal map), it will try to fetch it from the logs.
8746// Returns:
8847// - 0: Success
8948// - 1: Error
@@ -93,25 +52,26 @@ func (agg *Aggregator) ProcessOperatorSignedTaskResponseV2(signedTaskResponse *t
9352 "SenderAddress" , "0x" + hex .EncodeToString (signedTaskResponse .SenderAddress [:]),
9453 "BatchIdentifierHash" , "0x" + hex .EncodeToString (signedTaskResponse .BatchIdentifierHash [:]),
9554 "operatorId" , hex .EncodeToString (signedTaskResponse .OperatorId [:]))
96- taskIndex := uint32 ( 0 )
55+
9756 taskIndex , err := agg .GetTaskIndex (signedTaskResponse .BatchIdentifierHash )
9857
9958 if err != nil {
100- agg .logger .Warn ("Task not found in the internal map, operator signature will be lost. Batch may not reach quorum" )
101- * reply = 1
102- return nil
103- }
104-
105- agg .taskMutex .Lock ()
106- agg .AggregatorConfig .BaseConfig .Logger .Info ("- Locked Resources: Get task taskIndex" )
107- taskIndex , ok := agg .batchesIdxByIdentifierHash [signedTaskResponse .BatchIdentifierHash ]
108- // Unlock
109- agg .AggregatorConfig .BaseConfig .Logger .Info ("- Unlocked Resources: Get task taskIndex" )
110- agg .taskMutex .Unlock ()
111- if ! ok {
112- agg .logger .Errorf ("Unexpected error fetching for task with merkle root 0x%x" , signedTaskResponse .BatchMerkleRoot )
113- * reply = 1
114- return nil
59+ agg .logger .Warn ("Task not found in the internal map, might have been missed. Trying to fetch it from logs" )
60+ batch , err := agg .avsReader .GetPendingBatchFromMerkleRoot (signedTaskResponse .BatchMerkleRoot )
61+ if err != nil {
62+ agg .logger .Warn ("Pending task with merkle root 0x%x not found in logs" )
63+ * reply = 1
64+ return nil
65+ }
66+ agg .logger .Info ("Task was found in the logs, adding it to the internal map" )
67+ agg .AddNewTask (batch .BatchMerkleRoot , batch .SenderAddress , batch .TaskCreatedBlock )
68+ taskIndex , err = agg .GetTaskIndex (signedTaskResponse .BatchIdentifierHash )
69+ if err != nil {
70+ // This shouldn't happen, since we just added the task
71+ agg .logger .Error ("Unexpected error trying to get taskIndex from internal map" )
72+ * reply = 1
73+ return nil
74+ }
11575 }
11676
11777 agg .telemetry .LogOperatorResponse (signedTaskResponse .BatchMerkleRoot , signedTaskResponse .OperatorId )
@@ -194,11 +154,11 @@ func (agg *Aggregator) ProcessNewSignature(ctx context.Context, taskIndex uint32
194154func (agg * Aggregator ) GetTaskIndex (batchIdentifierHash [32 ]byte ) (uint32 , error ) {
195155 getTaskIndex_func := func () (uint32 , error ) {
196156 agg .taskMutex .Lock ()
197- agg .AggregatorConfig .BaseConfig .Logger .Info ("- Locked Resources: Starting processing of Response " )
157+ agg .AggregatorConfig .BaseConfig .Logger .Info ("- Locked Resources: Get task index " )
198158 taskIndex , ok := agg .batchesIdxByIdentifierHash [batchIdentifierHash ]
159+ agg .taskMutex .Unlock ()
160+ agg .logger .Info ("- Unlocked Resources: Get task index" )
199161 if ! ok {
200- agg .taskMutex .Unlock ()
201- agg .logger .Info ("- Unlocked Resources: Task not found in the internal map" )
202162 return taskIndex , fmt .Errorf ("Task not found in the internal map" )
203163 } else {
204164 return taskIndex , nil
0 commit comments