-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(data): add contiguous sequntial data source PE-2810
Tries contiguous data source one at a time until it finds one that returns something. We currently instantiate this such that it tries a trusted gateway first (for performance reasons). However, eventually, it would be nice if we tried chunks first since chunks are the easiest data source to verify.
- Loading branch information
Showing
2 changed files
with
60 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import winston from 'winston'; | ||
|
||
import { ContiguousData, ContiguousDataSource } from '../types.js'; | ||
|
||
export class SequentialDataSource implements ContiguousDataSource { | ||
private log: winston.Logger; | ||
private dataSources: ContiguousDataSource[]; | ||
|
||
constructor({ | ||
log, | ||
dataSources, | ||
}: { | ||
log: winston.Logger; | ||
dataSources: ContiguousDataSource[]; | ||
}) { | ||
this.log = log.child({ class: 'SequentialDataSource' }); | ||
this.dataSources = dataSources; | ||
} | ||
|
||
async getData(txId: string): Promise<ContiguousData> { | ||
this.log.debug('Fetching contiguous data from data sources', { txId }); | ||
|
||
for (const dataSource of this.dataSources) { | ||
try { | ||
const data = await dataSource.getData(txId); | ||
return data; | ||
} catch (error: any) { | ||
this.log.debug('Error fetching contiguous data from data source', { | ||
txId, | ||
message: error.message, | ||
stack: error.stack, | ||
}); | ||
} | ||
} | ||
|
||
throw new Error('Unable to fetch contiguous data from any data source'); | ||
} | ||
} |