Skip to content

Commit ca7fd53

Browse files
committed
feat: add sendAggregatedResponseV2 to aggregator
1 parent 3ca02bc commit ca7fd53

1 file changed

Lines changed: 34 additions & 1 deletion

File tree

aggregator/internal/pkg/aggregator.go

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,39 @@ func (agg *Aggregator) handleBlsAggServiceResponse(blsAggServiceResp blsagg.BlsA
299299
"batchIdentifierHash", "0x"+hex.EncodeToString(batchIdentifierHash[:]))
300300
}
301301

302+
// / Sends response to contract and waits for transaction receipt
303+
// / Returns error if it fails to send tx or receipt is not found
304+
func (agg *Aggregator) sendAggregatedResponseV2(batchMerkleRoot [32]byte, senderAddress [20]byte, nonSignerStakesAndSignature servicemanager.IBLSSignatureCheckerNonSignerStakesAndSignature) (*gethtypes.Receipt, error) {
305+
batchIdentifier := append(batchMerkleRoot[:], senderAddress[:]...)
306+
var batchIdentifierHash = *(*[32]byte)(crypto.Keccak256(batchIdentifier))
307+
308+
agg.walletMutex.Lock()
309+
agg.logger.Infof("- Locked Wallet Resources: Sending aggregated response for batch",
310+
"merkleRoot", hex.EncodeToString(batchMerkleRoot[:]),
311+
"senderAddress", hex.EncodeToString(senderAddress[:]),
312+
"batchIdentifierHash", hex.EncodeToString(batchIdentifierHash[:]))
313+
314+
txHash, err := agg.avsWriter.SendAggregatedResponseV2(batchMerkleRoot, senderAddress, nonSignerStakesAndSignature)
315+
if err != nil {
316+
agg.walletMutex.Unlock()
317+
agg.logger.Infof("- Unlocked Wallet Resources: Error sending aggregated response for batch %s. Error: %s", hex.EncodeToString(batchIdentifierHash[:]), err)
318+
return nil, err
319+
}
320+
321+
agg.walletMutex.Unlock()
322+
agg.logger.Infof("- Unlocked Wallet Resources: Sending aggregated response for batch %s", hex.EncodeToString(batchIdentifierHash[:]))
323+
324+
receipt, err := utils.WaitForTransactionReceipt(
325+
agg.AggregatorConfig.BaseConfig.EthRpcClient, context.Background(), *txHash)
326+
if err != nil {
327+
return nil, err
328+
}
329+
330+
agg.metrics.IncAggregatedResponses()
331+
332+
return receipt, nil
333+
}
334+
302335
// / Sends response to contract and waits for transaction receipt
303336
// / Returns error if it fails to send tx or receipt is not found
304337
func (agg *Aggregator) sendAggregatedResponse(batchMerkleRoot [32]byte, senderAddress [20]byte, nonSignerStakesAndSignature servicemanager.IBLSSignatureCheckerNonSignerStakesAndSignature) (*gethtypes.Receipt, error) {
@@ -311,7 +344,7 @@ func (agg *Aggregator) sendAggregatedResponse(batchMerkleRoot [32]byte, senderAd
311344
"senderAddress", hex.EncodeToString(senderAddress[:]),
312345
"batchIdentifierHash", hex.EncodeToString(batchIdentifierHash[:]))
313346

314-
txHash, err := agg.avsWriter.SendAggregatedResponse(batchMerkleRoot, senderAddress, nonSignerStakesAndSignature)
347+
txHash, err := agg.avsWriter.SendAggregatedResponse(batchMerkleRoot, nonSignerStakesAndSignature)
315348
if err != nil {
316349
agg.walletMutex.Unlock()
317350
agg.logger.Infof("- Unlocked Wallet Resources: Error sending aggregated response for batch %s. Error: %s", hex.EncodeToString(batchIdentifierHash[:]), err)

0 commit comments

Comments
 (0)