-
Notifications
You must be signed in to change notification settings - Fork 327
Feat/OPDATA-4973 adhoc testing endpoint #4284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
mmcallister-cll
wants to merge
6
commits into
main
Choose a base branch
from
feat/OPDATA-4973-adhoc-testing-endpoint
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+350
−111
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c7f4d46
OPDATA-4973 add address-adhoc endpoint to multi-address-list for diag…
mmcallister-cll 0920006
add changeset
mmcallister-cll b15a24e
remove copy pasta comment
mmcallister-cll 1898a97
update to latest framework version
mmcallister-cll 9fa5266
rename address-adhoc to address-debug
mmcallister-cll 62bef07
put back existing EA framework to avoid dependency spiral
mmcallister-cll File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,5 @@ | ||
| --- | ||
| '@chainlink/multi-address-list-adapter': minor | ||
| --- | ||
|
|
||
| added address-debug endpoint |
14 changes: 14 additions & 0 deletions
14
packages/composites/multi-address-list/src/endpoint/address-debug.ts
This file contains hidden or 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,14 @@ | ||
| import { PoRAddressEndpoint } from '@chainlink/external-adapter-framework/adapter/por' | ||
| import { addressDebugTransport } from '../transport/address-debug' | ||
| import { customInputValidation, inputParameters } from './address' | ||
|
|
||
| /** | ||
| * This endpoint is meant to be used for debug/diagnostic | ||
| * purposes and not for production feeds. | ||
| */ | ||
| export const endpoint = new PoRAddressEndpoint({ | ||
| name: 'address-debug', | ||
| transport: addressDebugTransport, | ||
| inputParameters, | ||
| customInputValidation, | ||
| }) |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| export { endpoint as address } from './address' | ||
| export { endpoint as addressDebug } from './address-debug' |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,13 +1,13 @@ | ||
| import { expose, ServerInstance } from '@chainlink/external-adapter-framework' | ||
| import { config } from './config' | ||
| import { address } from './endpoint' | ||
| import { PoRAdapter } from '@chainlink/external-adapter-framework/adapter/por' | ||
| import { config } from './config' | ||
| import { address, addressDebug } from './endpoint' | ||
|
|
||
| export const adapter = new PoRAdapter({ | ||
| defaultEndpoint: address.name, | ||
| name: 'MULTI_ADDRESS_LIST', | ||
| config, | ||
| endpoints: [address], | ||
| endpoints: [address, addressDebug], | ||
| }) | ||
|
|
||
| export const server = (): Promise<ServerInstance | undefined> => expose(adapter) |
64 changes: 64 additions & 0 deletions
64
packages/composites/multi-address-list/src/transport/address-debug.ts
This file contains hidden or 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,64 @@ | ||
| import { EndpointContext } from '@chainlink/external-adapter-framework/adapter' | ||
| import { ResponseCache } from '@chainlink/external-adapter-framework/cache/response' | ||
| import { TransportDependencies } from '@chainlink/external-adapter-framework/transports' | ||
| import { AdapterResponse, makeLogger, sleep } from '@chainlink/external-adapter-framework/util' | ||
| import { Requester } from '@chainlink/external-adapter-framework/util/requester' | ||
| import { BaseEndpointTypes } from '../endpoint/address' | ||
| import { AddressListTransportTypes, BaseAddressListTransport, RequestParams } from './common' | ||
|
|
||
| const logger = makeLogger('BaseAddressListTransport') | ||
|
|
||
| export class AddressDebugTransport extends BaseAddressListTransport { | ||
| name!: string | ||
| responseCache!: ResponseCache<AddressListTransportTypes> | ||
| requester!: Requester | ||
| settings!: AddressListTransportTypes['Settings'] | ||
| activeParams: RequestParams[] = [] | ||
|
|
||
| async initialize( | ||
| dependencies: TransportDependencies<AddressListTransportTypes>, | ||
| adapterSettings: AddressListTransportTypes['Settings'], | ||
| endpointName: string, | ||
| transportName: string, | ||
| ): Promise<void> { | ||
| await super.initialize(dependencies, adapterSettings, endpointName, transportName) | ||
| this.requester = dependencies.requester | ||
| this.settings = adapterSettings | ||
| } | ||
|
|
||
| async backgroundHandler( | ||
| context: EndpointContext<AddressListTransportTypes>, | ||
| entries: RequestParams[], | ||
| ) { | ||
| await Promise.all(entries.map(async (param) => this.handleRequest(param))) | ||
| await sleep(context.adapterSettings.BACKGROUND_EXECUTE_MS) | ||
| } | ||
|
|
||
| async handleRequest(param: RequestParams) { | ||
| let response: AdapterResponse<BaseEndpointTypes['Response']> | ||
| try { | ||
| response = await this._handleRequest(param) | ||
| } catch (e) { | ||
| const errorMessage = e instanceof Error ? e.message : 'Unknown error occurred' | ||
| logger.error(e, errorMessage) | ||
| response = { | ||
| statusCode: 502, | ||
| errorMessage, | ||
| timestamps: { | ||
| providerDataRequestedUnixMs: 0, | ||
| providerDataReceivedUnixMs: 0, | ||
| providerIndicatedTimeUnixMs: undefined, | ||
| }, | ||
| } | ||
| } | ||
| await this.responseCache.write(this.name, [{ params: param, response }]) | ||
| } | ||
|
|
||
| async _handleRequest( | ||
| param: RequestParams, | ||
| ): Promise<AdapterResponse<BaseEndpointTypes['Response']>> { | ||
| return this.getAggregatedAddressList(param) | ||
| } | ||
| } | ||
|
|
||
| export const addressDebugTransport = new AddressDebugTransport() | ||
This file contains hidden or 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
90 changes: 90 additions & 0 deletions
90
packages/composites/multi-address-list/src/transport/common.ts
This file contains hidden or 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,90 @@ | ||
| import { ResponseCache } from '@chainlink/external-adapter-framework/cache/response' | ||
| import { SubscriptionTransport } from '@chainlink/external-adapter-framework/transports/abstract/subscription' | ||
| import { makeLogger } from '@chainlink/external-adapter-framework/util' | ||
| import { Requester } from '@chainlink/external-adapter-framework/util/requester' | ||
| import { BaseEndpointTypes, inputParameters } from '../endpoint/address' | ||
|
|
||
| const logger = makeLogger('BaseAddressListTransport') | ||
|
|
||
| export type AddressListTransportTypes = BaseEndpointTypes | ||
| export type RequestParams = typeof inputParameters.validated | ||
|
|
||
| interface PoRAdapterResponse { | ||
| data: { | ||
| result: { | ||
| network: string | ||
| chainId: string | ||
| address: string | ||
| }[] | ||
| } | ||
| statusCode: number | ||
| result: null | ||
| timestamps: { | ||
| providerDataRequestedUnixMs: number | ||
| providerDataReceivedUnixMs: number | ||
| } | ||
| } | ||
|
|
||
| export abstract class BaseAddressListTransport extends SubscriptionTransport<AddressListTransportTypes> { | ||
| name!: string | ||
| responseCache!: ResponseCache<AddressListTransportTypes> | ||
| requester!: Requester | ||
| settings!: AddressListTransportTypes['Settings'] | ||
| activeParams: RequestParams[] = [] | ||
|
|
||
| async getAggregatedAddressList(params: RequestParams) { | ||
| const providerDataRequestedUnixMs = Date.now() | ||
|
|
||
| const addresses = await this.fetchSourceAddresses(params) | ||
| logger.info(`Fetched ${addresses.length} addresses`) | ||
|
|
||
| const response = { | ||
| data: { | ||
| result: addresses, | ||
| }, | ||
| statusCode: 200, | ||
| result: null, | ||
| timestamps: { | ||
| providerDataRequestedUnixMs, | ||
| providerDataReceivedUnixMs: Date.now(), | ||
| providerIndicatedTimeUnixMs: undefined, | ||
| }, | ||
| } | ||
| return response | ||
| } | ||
|
|
||
| async fetchSourceAddresses(params: RequestParams) { | ||
| const { chainId, network, ...sources } = params | ||
|
|
||
| const promises = Object.entries(sources) | ||
| .filter(([_, sourceParams]) => sourceParams) | ||
| .map(async ([sourceName, sourceParams]) => { | ||
| // customInputValidation ensures that if the source EA is present in the input params, the corresponding env variable is also present | ||
| const adapterUrl = `${sourceName.toUpperCase()}_ADAPTER_URL` as keyof typeof this.settings | ||
| const requestConfig = { | ||
| url: this.settings[adapterUrl] as string, | ||
| method: 'POST', | ||
| data: { | ||
| data: { | ||
| ...sourceParams, | ||
| chainId, | ||
| network, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| const sourceResponse = await this.requester.request<PoRAdapterResponse>( | ||
| JSON.stringify(requestConfig), | ||
| requestConfig, | ||
| ) | ||
| return sourceResponse.response.data.data.result | ||
| }) | ||
|
|
||
| const addresses = await Promise.all(promises) | ||
| return addresses.flat() | ||
| } | ||
|
|
||
| getSubscriptionTtlFromConfig(adapterSettings: AddressListTransportTypes['Settings']): number { | ||
| return adapterSettings.WARMUP_SUBSCRIPTION_TTL | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should make this a subscription transport if it is just for debug
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So foreground? If yes then i think I'll probably redo this PR a different way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok gonna move this back to draft then since it was just something i was trying to get in off-sprint for on call