@@ -67,6 +67,9 @@ type Aggregator struct {
6767 // Stores the TaskResponse for each batch by batchIdentifierHash
6868 batchDataByIdentifierHash map [[32 ]byte ]BatchData
6969
70+ // Stores the start time for each batch of the aggregator by task index
71+ batchStartTimeByIdx map [uint32 ]time.Time
72+
7073 // This task index is to communicate with the local BLS
7174 // Service.
7275 // Note: In case of a reboot it can start from 0 again
@@ -78,6 +81,7 @@ type Aggregator struct {
7881 // - batchCreatedBlockByIdx
7982 // - batchDataByIdentifierHash
8083 // - nextBatchIndex
84+ // - batchStartTimeByIdx
8185 taskMutex * sync.Mutex
8286
8387 // Mutex to protect ethereum wallet
@@ -124,6 +128,7 @@ func NewAggregator(aggregatorConfig config.AggregatorConfig) (*Aggregator, error
124128 batchesIdxByIdentifierHash := make (map [[32 ]byte ]uint32 )
125129 batchDataByIdentifierHash := make (map [[32 ]byte ]BatchData )
126130 batchCreatedBlockByIdx := make (map [uint32 ]uint64 )
131+ batchStartTimeByIdx := make (map [uint32 ]time.Time )
127132
128133 chainioConfig := sdkclients.BuildAllConfig {
129134 EthHttpUrl : aggregatorConfig .BaseConfig .EthRpcUrl ,
@@ -172,6 +177,7 @@ func NewAggregator(aggregatorConfig config.AggregatorConfig) (*Aggregator, error
172177 batchesIdxByIdentifierHash : batchesIdxByIdentifierHash ,
173178 batchDataByIdentifierHash : batchDataByIdentifierHash ,
174179 batchCreatedBlockByIdx : batchCreatedBlockByIdx ,
180+ batchStartTimeByIdx : batchStartTimeByIdx ,
175181 nextBatchIndex : nextBatchIndex ,
176182 taskMutex : & sync.Mutex {},
177183 walletMutex : & sync.Mutex {},
@@ -233,6 +239,7 @@ func (agg *Aggregator) handleBlsAggServiceResponse(blsAggServiceResp blsagg.BlsA
233239 batchIdentifierHash := agg .batchesIdentifierHashByIdx [blsAggServiceResp .TaskIndex ]
234240 batchData := agg .batchDataByIdentifierHash [batchIdentifierHash ]
235241 taskCreatedBlock := agg .batchCreatedBlockByIdx [blsAggServiceResp .TaskIndex ]
242+ taskCreatedAt := agg .batchStartTimeByIdx [blsAggServiceResp .TaskIndex ]
236243 agg .taskMutex .Unlock ()
237244 agg .AggregatorConfig .BaseConfig .Logger .Info ("- Unlocked Resources: Fetching task data" )
238245
@@ -266,6 +273,9 @@ func (agg *Aggregator) handleBlsAggServiceResponse(blsAggServiceResp blsagg.BlsA
266273
267274 agg .telemetry .LogQuorumReached (batchData .BatchMerkleRoot )
268275
276+ // Only observe quorum reached if successful
277+ agg .metrics .ObserveTaskQuorumReached (time .Since (taskCreatedAt ))
278+
269279 agg .logger .Info ("Threshold reached" , "taskIndex" , blsAggServiceResp .TaskIndex ,
270280 "batchIdentifierHash" , "0x" + hex .EncodeToString (batchIdentifierHash [:]))
271281
@@ -320,6 +330,8 @@ func (agg *Aggregator) sendAggregatedResponse(batchIdentifierHash [32]byte, batc
320330 agg .metrics .IncBumpedGasPriceForAggregatedResponse ()
321331 agg .telemetry .BumpedTaskGasPrice (batchMerkleRoot , bumpedGasPrice .String ())
322332 }
333+
334+ startTime := time .Now ()
323335 receipt , err := agg .avsWriter .SendAggregatedResponse (
324336 batchIdentifierHash ,
325337 batchMerkleRoot ,
@@ -338,6 +350,9 @@ func (agg *Aggregator) sendAggregatedResponse(batchIdentifierHash [32]byte, batc
338350 return nil , err
339351 }
340352
353+ // We only send the latency metric if the response is successul
354+ agg .metrics .ObserveLatencyForRespondToTask (time .Since (startTime ))
355+
341356 agg .walletMutex .Unlock ()
342357 agg .logger .Infof ("- Unlocked Wallet Resources: Sending aggregated response for batch %s" , hex .EncodeToString (batchIdentifierHash [:]))
343358
@@ -383,6 +398,7 @@ func (agg *Aggregator) AddNewTask(batchMerkleRoot [32]byte, senderAddress [20]by
383398 BatchMerkleRoot : batchMerkleRoot ,
384399 SenderAddress : senderAddress ,
385400 }
401+ agg .batchStartTimeByIdx [batchIndex ] = time .Now ()
386402 agg .logger .Info (
387403 "Task Info added in aggregator:" ,
388404 "Task" , batchIndex ,
@@ -447,6 +463,7 @@ func (agg *Aggregator) ClearTasksFromMaps() {
447463 delete (agg .batchCreatedBlockByIdx , i )
448464 delete (agg .batchesIdentifierHashByIdx , i )
449465 delete (agg .batchDataByIdentifierHash , batchIdentifierHash )
466+ delete (agg .batchStartTimeByIdx , i )
450467 } else {
451468 agg .logger .Warn ("Task not found in maps" , "taskIndex" , i )
452469 }
0 commit comments