@@ -240,13 +240,7 @@ export class BundleDataClient {
240
240
) ;
241
241
}
242
242
243
- private async loadPersistedDataFromArweave (
244
- blockRangesForChains : number [ ] [ ]
245
- ) : Promise < LoadDataReturnValue | undefined > {
246
- if ( ! isDefined ( this . clients ?. arweaveClient ) ) {
247
- return undefined ;
248
- }
249
- const start = performance . now ( ) ;
243
+ private async getBundleDataFromArweave ( blockRangesForChains : number [ ] [ ] ) {
250
244
const persistedData = await this . clients . arweaveClient . getByTopic (
251
245
this . getArweaveBundleDataClientKey ( blockRangesForChains ) ,
252
246
BundleDataSS
@@ -256,6 +250,20 @@ export class BundleDataClient {
256
250
if ( ! isDefined ( persistedData ) || persistedData . length < 1 ) {
257
251
return undefined ;
258
252
}
253
+ return persistedData ;
254
+ }
255
+
256
+ private async loadPersistedDataFromArweave (
257
+ blockRangesForChains : number [ ] [ ]
258
+ ) : Promise < LoadDataReturnValue | undefined > {
259
+ if ( ! isDefined ( this . clients ?. arweaveClient ) ) {
260
+ return undefined ;
261
+ }
262
+ const start = performance . now ( ) ;
263
+ const persistedData = await this . getBundleDataFromArweave ( blockRangesForChains ) ;
264
+ if ( ! isDefined ( persistedData ) ) {
265
+ return undefined ;
266
+ }
259
267
260
268
// A converter function to account for the fact that our SuperStruct schema does not support numeric
261
269
// keys in records. Fundamentally, this is a limitation of superstruct itself.
@@ -435,24 +443,39 @@ export class BundleDataClient {
435
443
const hubPoolClient = this . clients . hubPoolClient ;
436
444
// Determine which bundle we should fetch from arweave, either the pending bundle or the latest
437
445
// executed one. Both should have arweave data but if for some reason the arweave data is missing,
438
- // this function will have to compute the bundle data from scratch which will be slow. We have to fallback
439
- // to computing the bundle from scratch since this function needs to return the full bundle data so that
440
- // it can be used to get the running balance proposed using its data.
441
- const bundleBlockRanges = getImpliedBundleBlockRanges (
446
+ // this function will load the bundle data from the most recent bundle data published to Arweave.
447
+
448
+ let bundleBlockRanges = getImpliedBundleBlockRanges (
442
449
hubPoolClient ,
443
450
this . clients . configStoreClient ,
444
451
hubPoolClient . hasPendingProposal ( )
445
452
? hubPoolClient . getLatestProposedRootBundle ( )
446
- : hubPoolClient . getLatestFullyExecutedRootBundle ( hubPoolClient . latestBlockSearched ) ! // ! because we know there is a bundle
453
+ : hubPoolClient . getNthFullyExecutedRootBundle ( - 1 ) !
447
454
) ;
448
- return {
449
- blockRanges : bundleBlockRanges ,
450
- bundleData : await this . loadData (
451
- bundleBlockRanges ,
452
- this . spokePoolClients ,
453
- true // this bundle data should have been published to arweave
454
- ) ,
455
- } ;
455
+ // Check if bundle data exists on arweave, otherwise fallback to last published bundle data. If the
456
+ // first bundle block range we are trying is the pending proposal, then we'll grab the most recently
457
+ // validated bundle, otherwise we'll grab the second most recently validated bundle.
458
+ let n = hubPoolClient . hasPendingProposal ( ) ? 1 : 2 ;
459
+
460
+ // eslint-disable-next-line no-constant-condition
461
+ while ( true ) {
462
+ const bundleDataOnArweave = await this . getBundleDataFromArweave ( bundleBlockRanges ) ;
463
+ if ( ! isDefined ( bundleDataOnArweave ) ) {
464
+ // Bundle data is not arweave, try the next most recently validated bundle.
465
+ bundleBlockRanges = getImpliedBundleBlockRanges (
466
+ hubPoolClient ,
467
+ this . clients . configStoreClient ,
468
+ hubPoolClient . getNthFullyExecutedRootBundle ( - n ) !
469
+ ) ;
470
+ } else {
471
+ return {
472
+ blockRanges : bundleBlockRanges ,
473
+ bundleData : await this . loadData ( bundleBlockRanges , this . spokePoolClients , true ) ,
474
+ } ;
475
+ }
476
+
477
+ n ++ ;
478
+ }
456
479
}
457
480
458
481
async getLatestPoolRebalanceRoot ( ) : Promise < { root : PoolRebalanceRoot ; blockRanges : number [ ] [ ] } > {
@@ -992,11 +1015,7 @@ export class BundleDataClient {
992
1015
}
993
1016
}
994
1017
} else {
995
- this . logger . warn ( {
996
- at : "BundleDataClient#loadDataFromScratch" ,
997
- message : "Detected duplicate fill" ,
998
- fill,
999
- } ) ;
1018
+ throw new Error ( "Duplicate fill detected" ) ;
1000
1019
}
1001
1020
return ;
1002
1021
}
@@ -1119,11 +1138,7 @@ export class BundleDataClient {
1119
1138
validatedBundleSlowFills . push ( matchedDeposit ) ;
1120
1139
}
1121
1140
} else {
1122
- this . logger . warn ( {
1123
- at : "BundleDataClient#loadDataFromScratch" ,
1124
- message : "Detected duplicate slow fill request" ,
1125
- slowFillRequest,
1126
- } ) ;
1141
+ throw new Error ( "Duplicate slow fill request detected." ) ;
1127
1142
}
1128
1143
return ;
1129
1144
}
0 commit comments