Skip to content

Commit 6b1a4ae

Browse files
fix: operator double signature (#1088)
1 parent d128869 commit 6b1a4ae

File tree

11 files changed

+44
-83
lines changed

11 files changed

+44
-83
lines changed

aggregator/internal/pkg/aggregator.go

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,6 @@ type Aggregator struct {
6767
// Stores the TaskResponse for each batch by batchIdentifierHash
6868
batchDataByIdentifierHash map[[32]byte]BatchData
6969

70-
// Stores if an operator already submitted a response for a batch
71-
// This is to avoid double submissions
72-
// struct{} is used as a placeholder because it is the smallest type
73-
// go does not have a set type
74-
operatorRespondedBatch map[uint32]map[eigentypes.Bytes32]struct{}
75-
7670
// This task index is to communicate with the local BLS
7771
// Service.
7872
// Note: In case of a reboot it can start from 0 again
@@ -146,7 +140,7 @@ func NewAggregator(aggregatorConfig config.AggregatorConfig) (*Aggregator, error
146140
return taskResponseDigest, nil
147141
}
148142

149-
operatorPubkeysService := oppubkeysserv.NewOperatorsInfoServiceInMemory(context.Background(), clients.AvsRegistryChainSubscriber, clients.AvsRegistryChainReader, nil, logger)
143+
operatorPubkeysService := oppubkeysserv.NewOperatorsInfoServiceInMemory(context.Background(), clients.AvsRegistryChainSubscriber, clients.AvsRegistryChainReader, nil, oppubkeysserv.Opts{}, logger)
150144
avsRegistryService := avsregistry.NewAvsRegistryServiceChainCaller(avsReader.ChainReader, operatorPubkeysService, logger)
151145
blsAggregationService := blsagg.NewBlsAggregatorService(avsRegistryService, hashFunction, logger)
152146

@@ -167,7 +161,6 @@ func NewAggregator(aggregatorConfig config.AggregatorConfig) (*Aggregator, error
167161
batchesIdxByIdentifierHash: batchesIdxByIdentifierHash,
168162
batchDataByIdentifierHash: batchDataByIdentifierHash,
169163
batchCreatedBlockByIdx: batchCreatedBlockByIdx,
170-
operatorRespondedBatch: make(map[uint32]map[eigentypes.Bytes32]struct{}),
171164
nextBatchIndex: nextBatchIndex,
172165
taskMutex: &sync.Mutex{},
173166
walletMutex: &sync.Mutex{},
@@ -220,12 +213,6 @@ func (agg *Aggregator) handleBlsAggServiceResponse(blsAggServiceResp blsagg.BlsA
220213
agg.taskMutex.Lock()
221214
batchIdentifierHash := agg.batchesIdentifierHashByIdx[blsAggServiceResp.TaskIndex]
222215
agg.logger.Error("BlsAggregationServiceResponse contains an error", "err", blsAggServiceResp.Err, "batchIdentifierHash", hex.EncodeToString(batchIdentifierHash[:]))
223-
agg.logger.Info("- Locking task mutex: Delete task from operator map", "taskIndex", blsAggServiceResp.TaskIndex)
224-
225-
// Remove task from the list of tasks
226-
delete(agg.operatorRespondedBatch, blsAggServiceResp.TaskIndex)
227-
228-
agg.logger.Info("- Unlocking task mutex: Delete task from operator map", "taskIndex", blsAggServiceResp.TaskIndex)
229216
agg.taskMutex.Unlock()
230217
return
231218
}
@@ -254,10 +241,6 @@ func (agg *Aggregator) handleBlsAggServiceResponse(blsAggServiceResp blsagg.BlsA
254241
batchIdentifierHash := agg.batchesIdentifierHashByIdx[blsAggServiceResp.TaskIndex]
255242
batchData := agg.batchDataByIdentifierHash[batchIdentifierHash]
256243
taskCreatedBlock := agg.batchCreatedBlockByIdx[blsAggServiceResp.TaskIndex]
257-
258-
// Delete the task from the map
259-
delete(agg.operatorRespondedBatch, blsAggServiceResp.TaskIndex)
260-
261244
agg.AggregatorConfig.BaseConfig.Logger.Info("- Unlocked Resources: Fetching merkle root")
262245
agg.taskMutex.Unlock()
263246

@@ -282,7 +265,6 @@ func (agg *Aggregator) handleBlsAggServiceResponse(blsAggServiceResp blsagg.BlsA
282265
agg.logger.Info("Aggregator successfully responded to task",
283266
"taskIndex", blsAggServiceResp.TaskIndex,
284267
"batchIdentifierHash", "0x"+hex.EncodeToString(batchIdentifierHash[:]))
285-
286268
return
287269
}
288270

aggregator/internal/pkg/server.go

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import (
77
"net/rpc"
88
"time"
99

10-
eigentypes "github.com/Layr-Labs/eigensdk-go/types"
11-
1210
"github.com/yetanotherco/aligned_layer/core/types"
1311
)
1412

@@ -74,26 +72,6 @@ func (agg *Aggregator) ProcessOperatorSignedTaskResponseV2(signedTaskResponse *t
7472
return nil
7573
}
7674

77-
// Note: we already have lock here
78-
agg.logger.Debug("- Checking if operator already responded")
79-
batchResponses, ok := agg.operatorRespondedBatch[taskIndex]
80-
if !ok {
81-
batchResponses = make(map[eigentypes.Bytes32]struct{})
82-
agg.operatorRespondedBatch[taskIndex] = batchResponses
83-
}
84-
85-
if _, ok := batchResponses[signedTaskResponse.OperatorId]; ok {
86-
*reply = 0
87-
agg.logger.Warn("Operator already responded, ignoring",
88-
"operatorId", hex.EncodeToString(signedTaskResponse.OperatorId[:]),
89-
"taskIndex", taskIndex, "batchMerkleRoot", hex.EncodeToString(signedTaskResponse.BatchMerkleRoot[:]))
90-
91-
agg.taskMutex.Unlock()
92-
return nil
93-
}
94-
95-
batchResponses[signedTaskResponse.OperatorId] = struct{}{}
96-
9775
// Don't wait infinitely if it can't answer
9876
// Create a context with a timeout of 5 seconds
9977
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
@@ -111,9 +89,7 @@ func (agg *Aggregator) ProcessOperatorSignedTaskResponseV2(signedTaskResponse *t
11189

11290
if err != nil {
11391
agg.logger.Warnf("BLS aggregation service error: %s", err)
114-
// remove operator from the list of operators that responded
115-
// so that it can try again
116-
delete(batchResponses, signedTaskResponse.OperatorId)
92+
// todo shouldn't we here close the channel with a reply = 1?
11793
} else {
11894
agg.logger.Info("BLS process succeeded")
11995
}

core/chainio/avs_reader.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ func NewAvsReaderFromConfig(baseConfig *config.BaseConfig, ecdsaConfig *config.E
4848
}
4949

5050
func (r *AvsReader) GetErc20Mock(tokenAddr gethcommon.Address) (*contractERC20Mock.ContractERC20Mock, error) {
51-
erc20Mock, err := contractERC20Mock.NewContractERC20Mock(tokenAddr, r.AvsContractBindings.ethClient)
51+
erc20Mock, err := contractERC20Mock.NewContractERC20Mock(tokenAddr, &r.AvsContractBindings.ethClient)
5252
if err != nil {
5353
// Retry with fallback client
54-
erc20Mock, err = contractERC20Mock.NewContractERC20Mock(tokenAddr, r.AvsContractBindings.ethClientFallback)
54+
erc20Mock, err = contractERC20Mock.NewContractERC20Mock(tokenAddr, &r.AvsContractBindings.ethClientFallback)
5555
if err != nil {
5656
r.logger.Error("Failed to fetch ERC20Mock contract", "err", err)
5757
}

core/chainio/avs_writer.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ type AvsWriter struct {
2323
AvsContractBindings *AvsServiceBindings
2424
logger logging.Logger
2525
Signer signer.Signer
26-
Client eth.Client
27-
ClientFallback eth.Client
26+
Client eth.InstrumentedClient
27+
ClientFallback eth.InstrumentedClient
2828
}
2929

3030
func NewAvsWriterFromConfig(baseConfig *config.BaseConfig, ecdsaConfig *config.EcdsaConfig) (*AvsWriter, error) {
@@ -119,7 +119,6 @@ func (w *AvsWriter) checkRespondToTaskFeeLimit(tx *types.Transaction, txOpts bin
119119
// Proceed to check values against simulated costs
120120
w.logger.Error("Failed to get batch state", "error", err)
121121
w.logger.Info("Proceeding with simulated cost checks")
122-
123122
return w.compareBalances(simulatedCost, aggregatorAddress, senderAddress)
124123
}
125124
}

core/chainio/bindings.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ import (
1212
type AvsServiceBindings struct {
1313
ServiceManager *csservicemanager.ContractAlignedLayerServiceManager
1414
ServiceManagerFallback *csservicemanager.ContractAlignedLayerServiceManager
15-
ethClient eth.Client
16-
ethClientFallback eth.Client
15+
ethClient eth.InstrumentedClient
16+
ethClientFallback eth.InstrumentedClient
1717
logger logging.Logger
1818
}
1919

20-
func NewAvsServiceBindings(serviceManagerAddr, blsOperatorStateRetrieverAddr gethcommon.Address, ethClient eth.Client, ethClientFallback eth.Client, logger logging.Logger) (*AvsServiceBindings, error) {
21-
contractServiceManager, err := csservicemanager.NewContractAlignedLayerServiceManager(serviceManagerAddr, ethClient)
20+
func NewAvsServiceBindings(serviceManagerAddr, blsOperatorStateRetrieverAddr gethcommon.Address, ethClient eth.InstrumentedClient, ethClientFallback eth.InstrumentedClient, logger logging.Logger) (*AvsServiceBindings, error) {
21+
contractServiceManager, err := csservicemanager.NewContractAlignedLayerServiceManager(serviceManagerAddr, &ethClient)
2222
if err != nil {
2323
logger.Error("Failed to fetch AlignedLayerServiceManager contract", "err", err)
2424
return nil, err
2525
}
2626

27-
contractServiceManagerFallback, err := csservicemanager.NewContractAlignedLayerServiceManager(serviceManagerAddr, ethClientFallback)
27+
contractServiceManagerFallback, err := csservicemanager.NewContractAlignedLayerServiceManager(serviceManagerAddr, &ethClientFallback)
2828
if err != nil {
2929
logger.Error("Failed to fetch AlignedLayerServiceManager contract", "err", err)
3030
return nil, err

core/config/base.go

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import (
99

1010
"github.com/Layr-Labs/eigensdk-go/chainio/clients/eth"
1111
sdklogging "github.com/Layr-Labs/eigensdk-go/logging"
12+
rpccalls "github.com/Layr-Labs/eigensdk-go/metrics/collectors/rpc_calls"
1213
sdkutils "github.com/Layr-Labs/eigensdk-go/utils"
14+
"github.com/prometheus/client_golang/prometheus"
1315
"github.com/urfave/cli/v2"
1416
)
1517

@@ -27,10 +29,10 @@ type BaseConfig struct {
2729
Logger sdklogging.Logger
2830
EthRpcUrl string
2931
EthWsUrl string
30-
EthRpcClient eth.Client
31-
EthRpcClientFallback eth.Client
32-
EthWsClient eth.Client
33-
EthWsClientFallback eth.Client
32+
EthRpcClient eth.InstrumentedClient
33+
EthRpcClientFallback eth.InstrumentedClient
34+
EthWsClient eth.InstrumentedClient
35+
EthWsClientFallback eth.InstrumentedClient
3436
EigenMetricsIpPortAddress string
3537
ChainId *big.Int
3638
}
@@ -96,12 +98,15 @@ func NewBaseConfig(configFilePath string) *BaseConfig {
9698
log.Fatal("Eth ws url or fallback is empty")
9799
}
98100

99-
ethWsClient, err := eth.NewClient(baseConfigFromYaml.EthWsUrl)
101+
reg := prometheus.NewRegistry()
102+
rpcCallsCollector := rpccalls.NewCollector("ethWs", reg)
103+
ethWsClient, err := eth.NewInstrumentedClient(baseConfigFromYaml.EthWsUrl, rpcCallsCollector)
100104
if err != nil {
101105
log.Fatal("Error initializing eth ws client: ", err)
102106
}
103-
104-
ethWsClientFallback, err := eth.NewClient(baseConfigFromYaml.EthWsUrlFallback)
107+
reg = prometheus.NewRegistry()
108+
rpcCallsCollector = rpccalls.NewCollector("ethWsFallback", reg)
109+
ethWsClientFallback, err := eth.NewInstrumentedClient(baseConfigFromYaml.EthWsUrlFallback, rpcCallsCollector)
105110
if err != nil {
106111
log.Fatal("Error initializing eth ws client fallback: ", err)
107112
}
@@ -110,12 +115,16 @@ func NewBaseConfig(configFilePath string) *BaseConfig {
110115
log.Fatal("Eth rpc url is empty")
111116
}
112117

113-
ethRpcClient, err := eth.NewClient(baseConfigFromYaml.EthRpcUrl)
118+
reg = prometheus.NewRegistry()
119+
rpcCallsCollector = rpccalls.NewCollector("ethRpc", reg)
120+
ethRpcClient, err := eth.NewInstrumentedClient(baseConfigFromYaml.EthRpcUrl, rpcCallsCollector)
114121
if err != nil {
115122
log.Fatal("Error initializing eth rpc client: ", err)
116123
}
117124

118-
ethRpcClientFallback, err := eth.NewClient(baseConfigFromYaml.EthRpcUrlFallback)
125+
reg = prometheus.NewRegistry()
126+
rpcCallsCollector = rpccalls.NewCollector("ethRpc", reg)
127+
ethRpcClientFallback, err := eth.NewInstrumentedClient(baseConfigFromYaml.EthRpcUrlFallback, rpcCallsCollector)
119128
if err != nil {
120129
log.Fatal("Error initializing eth rpc client fallback: ", err)
121130
}
@@ -136,10 +145,10 @@ func NewBaseConfig(configFilePath string) *BaseConfig {
136145
Logger: logger,
137146
EthRpcUrl: baseConfigFromYaml.EthRpcUrl,
138147
EthWsUrl: baseConfigFromYaml.EthWsUrl,
139-
EthRpcClient: ethRpcClient,
140-
EthRpcClientFallback: ethRpcClientFallback,
141-
EthWsClient: ethWsClient,
142-
EthWsClientFallback: ethWsClientFallback,
148+
EthRpcClient: *ethRpcClient,
149+
EthRpcClientFallback: *ethRpcClientFallback,
150+
EthWsClient: *ethWsClient,
151+
EthWsClientFallback: *ethWsClientFallback,
143152
EigenMetricsIpPortAddress: baseConfigFromYaml.EigenMetricsIpPortAddress,
144153
ChainId: chainId,
145154
}

core/utils/eth_client_utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
const maxRetries = 25
1616
const sleepTime = 5 * time.Second
1717

18-
func WaitForTransactionReceipt(client eth.Client, ctx context.Context, txHash gethcommon.Hash) (*types.Receipt, error) {
18+
func WaitForTransactionReceipt(client eth.InstrumentedClient, ctx context.Context, txHash gethcommon.Hash) (*types.Receipt, error) {
1919
for i := 0; i < maxRetries; i++ {
2020
receipt, err := client.TransactionReceipt(ctx, txHash)
2121
if err != nil {

go.mod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/yetanotherco/aligned_layer
33
go 1.22.2
44

55
require (
6-
github.com/Layr-Labs/eigensdk-go v0.1.9
6+
github.com/Layr-Labs/eigensdk-go v0.1.12
77
github.com/ethereum/go-ethereum v1.14.0
88
github.com/prometheus/client_golang v1.19.1
99
github.com/urfave/cli/v2 v2.27.1
@@ -91,5 +91,3 @@ require (
9191
gopkg.in/yaml.v3 v3.0.1 // indirect
9292
rsc.io/tmplfunc v0.0.3 // indirect
9393
)
94-
95-
replace github.com/Layr-Labs/eigensdk-go => github.com/yetanotherco/eigensdk-go v0.1.10-0.20240805154752-29f4d3457921

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOEl
44
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
55
github.com/DataDog/zstd v1.5.2 h1:vUG4lAyuPCXO0TLbXvPv7EB7cNK1QV/luu55UHLrrn8=
66
github.com/DataDog/zstd v1.5.2/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw=
7+
github.com/Layr-Labs/eigensdk-go v0.1.12 h1:Drf59iJLvnTm2Om9AwAyUMiZeJaTI8ZameIrnhjopSY=
8+
github.com/Layr-Labs/eigensdk-go v0.1.12/go.mod h1:XcLVDtlB1vOPj63D236b451+SC75B8gwgkpNhYHSxNs=
79
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
810
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
911
github.com/Microsoft/hcsshim v0.11.4 h1:68vKo2VN8DE9AdN4tnkWnmdhqdbpUFM8OF3Airm7fz8=
@@ -315,8 +317,6 @@ github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
315317
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
316318
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
317319
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
318-
github.com/yetanotherco/eigensdk-go v0.1.10-0.20240805154752-29f4d3457921 h1:bYER70hS8+Qx//uWWhm0+WymLTKHiqfbJkphteKUxPc=
319-
github.com/yetanotherco/eigensdk-go v0.1.10-0.20240805154752-29f4d3457921/go.mod h1:XcLVDtlB1vOPj63D236b451+SC75B8gwgkpNhYHSxNs=
320320
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
321321
github.com/yusufpapurcu/wmi v1.2.3 h1:E1ctvB7uKFMOJw3fdOW32DwGE9I7t++CRUEMKvFoFiw=
322322
github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=

operator/cmd/actions/deposit_into_strategy.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,23 +69,23 @@ func depositIntoStrategyMain(ctx *cli.Context) error {
6969
if err != nil {
7070
return err
7171
}
72-
w, err := wallet.NewPrivateKeyWallet(config.BaseConfig.EthRpcClient, signerFn,
72+
w, err := wallet.NewPrivateKeyWallet(&config.BaseConfig.EthRpcClient, signerFn,
7373
config.Operator.Address, config.BaseConfig.Logger)
7474

7575
if err != nil {
7676
return err
7777
}
7878

79-
txMgr := txmgr.NewSimpleTxManager(w, config.BaseConfig.EthRpcClient, config.BaseConfig.Logger,
79+
txMgr := txmgr.NewSimpleTxManager(w, &config.BaseConfig.EthRpcClient, config.BaseConfig.Logger,
8080
config.Operator.Address)
8181
eigenMetrics := metrics.NewNoopMetrics()
8282
eigenLayerWriter, err := elcontracts.BuildELChainWriter(delegationManagerAddr, avsDirectoryAddr,
83-
config.BaseConfig.EthRpcClient, config.BaseConfig.Logger, eigenMetrics, txMgr)
83+
&config.BaseConfig.EthRpcClient, config.BaseConfig.Logger, eigenMetrics, txMgr)
8484
if err != nil {
8585
return err
8686
}
8787

88-
_, err = eigenLayerWriter.DepositERC20IntoStrategy(context.Background(), strategyAddr, amount)
88+
_, err = eigenLayerWriter.DepositERC20IntoStrategy(context.Background(), strategyAddr, amount, true)
8989
if err != nil {
9090
config.BaseConfig.Logger.Errorf("Error depositing into strategy")
9191
return err

0 commit comments

Comments
 (0)