@@ -11,6 +11,7 @@ import (
11
11
"github.com/lightninglabs/lndclient"
12
12
"github.com/lightninglabs/neutrino/cache/lru"
13
13
"github.com/lightninglabs/taproot-assets/asset"
14
+ "github.com/lightninglabs/taproot-assets/fn"
14
15
"github.com/lightninglabs/taproot-assets/proof"
15
16
"github.com/lightninglabs/taproot-assets/rfq"
16
17
"github.com/lightninglabs/taproot-assets/tapchannel"
@@ -49,6 +50,7 @@ type LndRpcChainBridge struct {
49
50
lnd * lndclient.LndServices
50
51
51
52
blockTimestampCache * lru.Cache [uint32 , cacheableTimestamp ]
53
+ retryConfig fn.RetryConfig
52
54
53
55
assetStore * tapdb.AssetStore
54
56
}
@@ -63,7 +65,8 @@ func NewLndRpcChainBridge(lnd *lndclient.LndServices,
63
65
blockTimestampCache : lru.NewCache [uint32 , cacheableTimestamp ](
64
66
maxNumBlocksInCache ,
65
67
),
66
- assetStore : assetStore ,
68
+ retryConfig : fn .DefaultRetryConfig (),
69
+ assetStore : assetStore ,
67
70
}
68
71
}
69
72
@@ -112,39 +115,56 @@ func (l *LndRpcChainBridge) RegisterBlockEpochNtfn(
112
115
func (l * LndRpcChainBridge ) GetBlock (ctx context.Context ,
113
116
hash chainhash.Hash ) (* wire.MsgBlock , error ) {
114
117
115
- block , err := l .lnd .ChainKit .GetBlock (ctx , hash )
116
- if err != nil {
117
- return nil , fmt .Errorf ("unable to retrieve block: %w" , err )
118
- }
119
-
120
- return block , nil
118
+ return fn .RetryFuncN (
119
+ ctx , l .retryConfig , func () (* wire.MsgBlock , error ) {
120
+ block , err := l .lnd .ChainKit .GetBlock (ctx , hash )
121
+ if err != nil {
122
+ return nil , fmt .Errorf (
123
+ "unable to retrieve block: %w" , err ,
124
+ )
125
+ }
126
+ return block , nil
127
+ },
128
+ )
121
129
}
122
130
123
131
// GetBlockHeader returns a block header given its hash.
124
132
func (l * LndRpcChainBridge ) GetBlockHeader (ctx context.Context ,
125
133
hash chainhash.Hash ) (* wire.BlockHeader , error ) {
126
134
127
- header , err := l .lnd .ChainKit .GetBlockHeader (ctx , hash )
128
- if err != nil {
129
- return nil , fmt .Errorf ("unable to retrieve block header: %w" ,
130
- err )
131
- }
132
-
133
- return header , nil
135
+ return fn .RetryFuncN (
136
+ ctx , l .retryConfig , func () (* wire.BlockHeader , error ) {
137
+ header , err := l .lnd .ChainKit .GetBlockHeader (ctx , hash )
138
+ if err != nil {
139
+ return nil , fmt .Errorf (
140
+ "unable to retrieve block " +
141
+ "header: %w" , err ,
142
+ )
143
+ }
144
+ return header , nil
145
+ },
146
+ )
134
147
}
135
148
136
149
// GetBlockHash returns the hash of the block in the best blockchain at the
137
150
// given height.
138
151
func (l * LndRpcChainBridge ) GetBlockHash (ctx context.Context ,
139
152
blockHeight int64 ) (chainhash.Hash , error ) {
140
153
141
- blockHash , err := l .lnd .ChainKit .GetBlockHash (ctx , blockHeight )
142
- if err != nil {
143
- return chainhash.Hash {}, fmt .Errorf ("unable to retrieve " +
144
- "block hash: %w" , err )
145
- }
146
-
147
- return blockHash , nil
154
+ return fn .RetryFuncN (
155
+ ctx , l .retryConfig , func () (chainhash.Hash , error ) {
156
+ blockHash , err := l .lnd .ChainKit .GetBlockHash (
157
+ ctx , blockHeight ,
158
+ )
159
+ if err != nil {
160
+ return chainhash.Hash {}, fmt .Errorf (
161
+ "unable to retrieve block hash: %w" ,
162
+ err ,
163
+ )
164
+ }
165
+ return blockHash , nil
166
+ },
167
+ )
148
168
}
149
169
150
170
// VerifyBlock returns an error if a block (with given header and height) is not
@@ -184,12 +204,17 @@ func (l *LndRpcChainBridge) VerifyBlock(ctx context.Context,
184
204
185
205
// CurrentHeight return the current height of the main chain.
186
206
func (l * LndRpcChainBridge ) CurrentHeight (ctx context.Context ) (uint32 , error ) {
187
- _ , bestHeight , err := l .lnd .ChainKit .GetBestBlock (ctx )
188
- if err != nil {
189
- return 0 , fmt .Errorf ("unable to grab block height: %w" , err )
190
- }
191
-
192
- return uint32 (bestHeight ), nil
207
+ return fn .RetryFuncN (
208
+ ctx , l .retryConfig , func () (uint32 , error ) {
209
+ _ , bestHeight , err := l .lnd .ChainKit .GetBestBlock (ctx )
210
+ if err != nil {
211
+ return 0 , fmt .Errorf (
212
+ "unable to grab block height: %w" , err ,
213
+ )
214
+ }
215
+ return uint32 (bestHeight ), nil
216
+ },
217
+ )
193
218
}
194
219
195
220
// GetBlockTimestamp returns the timestamp of the block at the given height.
@@ -207,7 +232,11 @@ func (l *LndRpcChainBridge) GetBlockTimestamp(ctx context.Context,
207
232
return int64 (cacheTS )
208
233
}
209
234
210
- hash , err := l .lnd .ChainKit .GetBlockHash (ctx , int64 (height ))
235
+ hash , err := fn .RetryFuncN (
236
+ ctx , l .retryConfig , func () (chainhash.Hash , error ) {
237
+ return l .lnd .ChainKit .GetBlockHash (ctx , int64 (height ))
238
+ },
239
+ )
211
240
if err != nil {
212
241
return 0
213
242
}
@@ -229,14 +258,27 @@ func (l *LndRpcChainBridge) GetBlockTimestamp(ctx context.Context,
229
258
func (l * LndRpcChainBridge ) PublishTransaction (ctx context.Context ,
230
259
tx * wire.MsgTx , label string ) error {
231
260
232
- return l .lnd .WalletKit .PublishTransaction (ctx , tx , label )
261
+ _ , err := fn .RetryFuncN (
262
+ ctx , l .retryConfig , func () (struct {}, error ) {
263
+ return struct {}{}, l .lnd .WalletKit .PublishTransaction (
264
+ ctx , tx , label ,
265
+ )
266
+ },
267
+ )
268
+ return err
233
269
}
234
270
235
271
// EstimateFee returns a fee estimate for the confirmation target.
236
272
func (l * LndRpcChainBridge ) EstimateFee (ctx context.Context ,
237
273
confTarget uint32 ) (chainfee.SatPerKWeight , error ) {
238
274
239
- return l .lnd .WalletKit .EstimateFeeRate (ctx , int32 (confTarget ))
275
+ return fn .RetryFuncN (
276
+ ctx , l .retryConfig , func () (chainfee.SatPerKWeight , error ) {
277
+ return l .lnd .WalletKit .EstimateFeeRate (
278
+ ctx , int32 (confTarget ),
279
+ )
280
+ },
281
+ )
240
282
}
241
283
242
284
// GenFileChainLookup generates a chain lookup interface for the given
0 commit comments