Skip to content

Commit

Permalink
refactor aggregator to remove taskResponses map
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasArrachea committed Nov 15, 2024
1 parent 8a36b73 commit db657e7
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 23 deletions.
7 changes: 1 addition & 6 deletions aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ type Aggregator struct {
blsAggregationService blsagg.BlsAggregationService
tasks map[types.TaskIndex]cstaskmanager.IIncredibleSquaringTaskManagerTask
tasksMu sync.RWMutex
taskResponses map[types.TaskIndex]map[sdktypes.TaskResponseDigest]cstaskmanager.IIncredibleSquaringTaskManagerTaskResponse
taskResponsesMu sync.RWMutex
}

// NewAggregator creates a new Aggregator with the provided config.
Expand Down Expand Up @@ -156,7 +154,6 @@ func NewAggregator(c *config.Config) (*Aggregator, error) {
avsWriter: avsWriter,
blsAggregationService: blsAggregationService,
tasks: make(map[types.TaskIndex]cstaskmanager.IIncredibleSquaringTaskManagerTask),
taskResponses: make(map[types.TaskIndex]map[sdktypes.TaskResponseDigest]cstaskmanager.IIncredibleSquaringTaskManagerTaskResponse),
}, nil
}

Expand Down Expand Up @@ -225,9 +222,7 @@ func (agg *Aggregator) sendAggregatedResponseToContract(blsAggServiceResp blsagg
agg.tasksMu.RLock()
task := agg.tasks[blsAggServiceResp.TaskIndex]
agg.tasksMu.RUnlock()
agg.taskResponsesMu.RLock()
taskResponse := agg.taskResponses[blsAggServiceResp.TaskIndex][blsAggServiceResp.TaskResponseDigest]
agg.taskResponsesMu.RUnlock()
taskResponse, _ := blsAggServiceResp.TaskResponse.(cstaskmanager.IIncredibleSquaringTaskManagerTaskResponse)
_, err := agg.avsWriter.SendAggregatedResponse(context.Background(), task, taskResponse, nonSignerStakesAndSignature)
if err != nil {
agg.logger.Error("Aggregator failed to respond to task", "err", err)
Expand Down
1 change: 0 additions & 1 deletion aggregator/aggregator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ func createMockAggregator(
avsWriter: mockAvsWriter,
blsAggregationService: mockBlsAggregationService,
tasks: make(map[types.TaskIndex]cstaskmanager.IIncredibleSquaringTaskManagerTask),
taskResponses: make(map[types.TaskIndex]map[sdktypes.TaskResponseDigest]cstaskmanager.IIncredibleSquaringTaskManagerTaskResponse),
}
return aggregator, mockAvsWriter, mockBlsAggregationService, nil
}
Expand Down
17 changes: 1 addition & 16 deletions aggregator/rpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ import (
"net/rpc"

cstaskmanager "github.com/Layr-Labs/incredible-squaring-avs/contracts/bindings/IncredibleSquaringTaskManager"
"github.com/Layr-Labs/incredible-squaring-avs/core"

"github.com/Layr-Labs/eigensdk-go/crypto/bls"
"github.com/Layr-Labs/eigensdk-go/types"
sdktypes "github.com/Layr-Labs/eigensdk-go/types"
)

var (
Expand Down Expand Up @@ -50,21 +48,8 @@ type SignedTaskResponse struct {
func (agg *Aggregator) ProcessSignedTaskResponse(signedTaskResponse *SignedTaskResponse, reply *bool) error {
agg.logger.Infof("Received signed task response: %#v", signedTaskResponse)
taskIndex := signedTaskResponse.TaskResponse.ReferenceTaskIndex
taskResponseDigest, err := core.GetTaskResponseDigest(&signedTaskResponse.TaskResponse)
if err != nil {
agg.logger.Error("Failed to get task response digest", "err", err)
return TaskResponseDigestNotFoundError500
}
agg.taskResponsesMu.Lock()
if _, ok := agg.taskResponses[taskIndex]; !ok {
agg.taskResponses[taskIndex] = make(map[sdktypes.TaskResponseDigest]cstaskmanager.IIncredibleSquaringTaskManagerTaskResponse)
}
if _, ok := agg.taskResponses[taskIndex][taskResponseDigest]; !ok {
agg.taskResponses[taskIndex][taskResponseDigest] = signedTaskResponse.TaskResponse
}
agg.taskResponsesMu.Unlock()

err = agg.blsAggregationService.ProcessNewSignature(
err := agg.blsAggregationService.ProcessNewSignature(
context.Background(), taskIndex, signedTaskResponse.TaskResponse,
&signedTaskResponse.BlsSignature, signedTaskResponse.OperatorId,
)
Expand Down

0 comments on commit db657e7

Please sign in to comment.