-
Notifications
You must be signed in to change notification settings - Fork 396
Expand file tree
/
Copy pathretryable.go
More file actions
240 lines (222 loc) · 9.29 KB
/
retryable.go
File metadata and controls
240 lines (222 loc) · 9.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
package chainio
import (
"context"
"math/big"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/event"
servicemanager "github.com/yetanotherco/aligned_layer/contracts/bindings/AlignedLayerServiceManager"
retry "github.com/yetanotherco/aligned_layer/core"
)
// |---AVS_WRITER---|
/*
RespondToTaskV2Retryable
Send a transaction to the AVS contract to respond to a task.
- All errors are considered Transient Errors
- Retry times (3 retries): 12 sec (1 Blocks), 24 sec (2 Blocks), 48 sec (4 Blocks)
- NOTE: Contract call reverts are not considered `PermanentError`'s as block reorg's may lead to contract call revert in which case the aggregator should retry.
*/
func (w *AvsWriter) RespondToTaskV2Retryable(opts *bind.TransactOpts, batchMerkleRoot [32]byte, senderAddress common.Address, nonSignerStakesAndSignature servicemanager.IBLSSignatureCheckerNonSignerStakesAndSignature, config *retry.RetryParams) (*types.Transaction, error) {
respondToTaskV2_func := func() (*types.Transaction, error) {
// Try with main connection
tx, err := w.AvsContractBindings.ServiceManager.RespondToTaskV2(opts, batchMerkleRoot, senderAddress, nonSignerStakesAndSignature)
if err != nil {
// If error try with fallback
tx, err = w.AvsContractBindings.ServiceManagerFallback.RespondToTaskV2(opts, batchMerkleRoot, senderAddress, nonSignerStakesAndSignature)
}
return tx, err
}
return retry.RetryWithData(respondToTaskV2_func, config)
}
/*
RespondToTaskV2Retryable
Send a transaction to the AVS contract to respond to a task.
- All errors are considered Transient Errors
- Retry times (3 retries): 12 sec (1 Blocks), 24 sec (2 Blocks), 48 sec (4 Blocks)
- NOTE: Contract call reverts are not considered `PermanentError`'s as block reorg's may lead to contract call revert in which case the aggregator should retry.
*/
func (w *AvsWriter) BatchesStateRetryable(opts *bind.CallOpts, arg0 [32]byte, config *retry.RetryParams) (struct {
TaskCreatedBlock uint32
Responded bool
RespondToTaskFeeLimit *big.Int
}, error) {
batchesState_func := func() (struct {
TaskCreatedBlock uint32
Responded bool
RespondToTaskFeeLimit *big.Int
}, error) {
// Try with main connection
state, err := w.AvsContractBindings.ServiceManager.BatchesState(opts, arg0)
if err != nil {
// If error try with fallback connection
state, err = w.AvsContractBindings.ServiceManagerFallback.BatchesState(opts, arg0)
}
return state, err
}
return retry.RetryWithData(batchesState_func, config)
}
/*
BatchesStateRetryable
Get the state of a batch from the AVS contract.
- All errors are considered Transient Errors
- Retry times (3 retries): 1 sec, 2 sec, 4 sec
*/
func (w *AvsWriter) BatcherBalancesRetryable(opts *bind.CallOpts, senderAddress common.Address, config *retry.RetryParams) (*big.Int, error) {
batcherBalances_func := func() (*big.Int, error) {
// Try with main connection
batcherBalance, err := w.AvsContractBindings.ServiceManager.BatchersBalances(opts, senderAddress)
if err != nil {
// If error try with fallback connection
batcherBalance, err = w.AvsContractBindings.ServiceManagerFallback.BatchersBalances(opts, senderAddress)
}
return batcherBalance, err
}
return retry.RetryWithData(batcherBalances_func, config)
}
/*
BalanceAtRetryable
Get the balance of aggregatorAddress at blockNumber.
If blockNumber is nil, it gets the latest balance.
TODO: it gets the balance from an Address, not necessarily an aggregator. The name of the parameter should be changed.
- All errors are considered Transient Errors
- Retry times (3 retries): 1 sec, 2 sec, 4 sec.
*/
func (w *AvsWriter) BalanceAtRetryable(ctx context.Context, aggregatorAddress common.Address, blockNumber *big.Int, config *retry.RetryParams) (*big.Int, error) {
balanceAt_func := func() (*big.Int, error) {
// Try with main connection
aggregatorBalance, err := w.Client.BalanceAt(ctx, aggregatorAddress, blockNumber)
if err != nil {
// If error try with fallback connection
aggregatorBalance, err = w.ClientFallback.BalanceAt(ctx, aggregatorAddress, blockNumber)
}
return aggregatorBalance, err
}
return retry.RetryWithData(balanceAt_func, config)
}
// |---AVS_SUBSCRIBER---|
/*
BlockNumberRetryable
Get the latest block number from Ethereum
- All errors are considered Transient Errors
- Retry times (3 retries): 1 sec, 2 sec, 4 sec.
*/
func (s *AvsSubscriber) BlockNumberRetryable(ctx context.Context, config *retry.RetryParams) (uint64, error) {
latestBlock_func := func() (uint64, error) {
// Try with main connection
latestBlock, err := s.AvsContractBindings.ethClient.BlockNumber(ctx)
if err != nil {
// If error try with fallback connection
latestBlock, err = s.AvsContractBindings.ethClientFallback.BlockNumber(ctx)
}
return latestBlock, err
}
return retry.RetryWithData(latestBlock_func, config)
}
/*
FilterBatchV2Retryable
Get NewBatchV2 logs from the AVS contract.
- All errors are considered Transient Errors
- Retry times (3 retries): 1 sec, 2 sec, 4 sec.
*/
func (s *AvsSubscriber) FilterBatchV2Retryable(opts *bind.FilterOpts, batchMerkleRoot [][32]byte, config *retry.RetryParams) (*servicemanager.ContractAlignedLayerServiceManagerNewBatchV2Iterator, error) {
filterNewBatchV2_func := func() (*servicemanager.ContractAlignedLayerServiceManagerNewBatchV2Iterator, error) {
return s.AvsContractBindings.ServiceManager.FilterNewBatchV2(opts, batchMerkleRoot)
}
return retry.RetryWithData(filterNewBatchV2_func, config)
}
/*
FilterBatchV3Retryable
Get NewBatchV3 logs from the AVS contract.
- All errors are considered Transient Errors
- Retry times (3 retries): 1 sec, 2 sec, 4 sec.
*/
func (s *AvsSubscriber) FilterBatchV3Retryable(opts *bind.FilterOpts, batchMerkleRoot [][32]byte, config *retry.RetryParams) (*servicemanager.ContractAlignedLayerServiceManagerNewBatchV3Iterator, error) {
filterNewBatchV2_func := func() (*servicemanager.ContractAlignedLayerServiceManagerNewBatchV3Iterator, error) {
return s.AvsContractBindings.ServiceManager.FilterNewBatchV3(opts, batchMerkleRoot)
}
return retry.RetryWithData(filterNewBatchV2_func, config)
}
/*
BatchesStateRetryable
Get the state of a batch from the AVS contract.
- All errors are considered Transient Errors
- Retry times (3 retries): 1 sec, 2 sec, 4 sec
*/
func (s *AvsSubscriber) BatchesStateRetryable(opts *bind.CallOpts, arg0 [32]byte, config *retry.RetryParams) (struct {
TaskCreatedBlock uint32
Responded bool
RespondToTaskFeeLimit *big.Int
}, error) {
batchState_func := func() (struct {
TaskCreatedBlock uint32
Responded bool
RespondToTaskFeeLimit *big.Int
}, error) {
return s.AvsContractBindings.ServiceManager.ContractAlignedLayerServiceManagerCaller.BatchesState(opts, arg0)
}
return retry.RetryWithData(batchState_func, config)
}
/*
SubscribeNewHeadRetryable
Subscribe to new heads from the Ethereum node.
- All errors are considered Transient Errors
- Retry times (3 retries): 1 sec, 2 sec, 4 sec.
*/
func (s *AvsSubscriber) SubscribeNewHeadRetryable(ctx context.Context, c chan<- *types.Header, config *retry.RetryParams) (ethereum.Subscription, error) {
subscribeNewHead_func := func() (ethereum.Subscription, error) {
// Try with main connection
sub, err := s.AvsContractBindings.ethClient.SubscribeNewHead(ctx, c)
if err != nil {
// If error try with fallback connection
sub, err = s.AvsContractBindings.ethClientFallback.SubscribeNewHead(ctx, c)
}
return sub, err
}
return retry.RetryWithData(subscribeNewHead_func, config)
}
/*
SubscribeToNewTasksV2Retryable
Subscribe to NewBatchV2 logs from the AVS contract.
- All errors are considered Transient Errors
- Retry times (3 retries): 1 sec, 2 sec, 4 sec.
*/
func SubscribeToNewTasksV2Retryable(
opts *bind.WatchOpts,
serviceManager *servicemanager.ContractAlignedLayerServiceManager,
newTaskCreatedChan chan *servicemanager.ContractAlignedLayerServiceManagerNewBatchV2,
batchMerkleRoot [][32]byte,
config *retry.RetryParams,
) (event.Subscription, error) {
return retry.RetryWithData(SubscribeToNewTasksV2(opts, serviceManager, newTaskCreatedChan, batchMerkleRoot), retry.DefaultRetryConfig())
}
func SubscribeToNewTasksV3(
opts *bind.WatchOpts,
serviceManager *servicemanager.ContractAlignedLayerServiceManager,
newTaskCreatedChan chan *servicemanager.ContractAlignedLayerServiceManagerNewBatchV3,
batchMerkleRoot [][32]byte,
) func() (event.Subscription, error) {
subscribe_func := func() (event.Subscription, error) {
return serviceManager.WatchNewBatchV3(opts, newTaskCreatedChan, batchMerkleRoot)
}
return retry.RetryWithData(subscribe_func, config)
}
/*
SubscribeToNewTasksV3Retryable
Subscribe to NewBatchV3 logs from the AVS contract.
- All errors are considered Transient Errors
- Retry times (3 retries): 1 sec, 2 sec, 4 sec.
*/
func SubscribeToNewTasksV3Retryable(
opts *bind.WatchOpts,
serviceManager *servicemanager.ContractAlignedLayerServiceManager,
newTaskCreatedChan chan *servicemanager.ContractAlignedLayerServiceManagerNewBatchV3,
batchMerkleRoot [][32]byte,
config *retry.RetryParams,
) (event.Subscription, error) {
subscribe_func := func() (event.Subscription, error) {
return serviceManager.WatchNewBatchV3(opts, newTaskCreatedChan, batchMerkleRoot)
}
return retry.RetryWithData(subscribe_func, config)
}