-
Notifications
You must be signed in to change notification settings - Fork 396
Expand file tree
/
Copy pathretryable.go
More file actions
201 lines (185 loc) · 7.43 KB
/
retryable.go
File metadata and controls
201 lines (185 loc) · 7.43 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
package chainio
import (
"context"
"github.com/rs/zerolog/log"
"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)
}
/*
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) 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)
}
/*
BatcherBalancesRetryable
Get the balance of a batcher 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)
}
/*
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) {
filterNewBatchV3_func := func() (*servicemanager.ContractAlignedLayerServiceManagerNewBatchV3Iterator, error) {
return s.AvsContractBindings.ServiceManager.FilterNewBatchV3(opts, batchMerkleRoot)
}
return retry.RetryWithData(filterNewBatchV3_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.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)
}
/*
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) {
log.Info().Msg("Subscribing to NewBatchV3")
return serviceManager.WatchNewBatchV3(opts, newTaskCreatedChan, batchMerkleRoot)
}
return retry.RetryWithData(subscribe_func, config)
}