Skip to content

Add timeout + default setting to Arbitrum RPC requests #3675

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/stale-houses-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@chainlink/glv-token-adapter': patch
---

RPC Timeout + timing debug logs
1 change: 1 addition & 0 deletions packages/composites/glv-token/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This document was generated automatically. Please see [README Generator](../../s
| :-------: | :--------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :----: | :-----: | :------------------------------------------: |
| ✅ | ARBITRUM_RPC_URL | RPC url of Arbitrum node | string | | |
| ✅ | ARBITRUM_CHAIN_ID | The chain id to connect to | number | | `42161` |
| | ARBITRUM_RPC_TIMEOUT_MS | The amount of time the RPC request to the Arbitrum node should wait before timing out. | number | | `5000` |
| ✅ | DATASTORE_CONTRACT_ADDRESS | Address of Data Store contract | string | | `0xFD70de6b91282D8017aA4E741e9Ae325CAb992d8` |
| ✅ | GLV_READER_CONTRACT_ADDRESS | Address of Glv Reader Contract | string | | `0x6a9505D0B44cFA863d9281EA5B0b34cB36243b45` |
| ✅ | TIINGO_ADAPTER_URL | URL of Tiingo EA | string | | |
Expand Down
6 changes: 6 additions & 0 deletions packages/composites/glv-token/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ export const config = new AdapterConfig(
type: 'string',
required: true,
},
ARBITRUM_RPC_TIMEOUT_MS: {
description:
'The amount of time the RPC request to the Arbitrum node should wait before timing out.',
type: 'number',
default: 5_000,
},
ARBITRUM_CHAIN_ID: {
description: 'The chain id to connect to',
type: 'number',
Expand Down
18 changes: 14 additions & 4 deletions packages/composites/glv-token/src/transport/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@ export abstract class BaseGlvTransport<
): Promise<void> {
await super.initialize(dependencies, adapterSettings, endpointName, transportName)
this.settings = adapterSettings
this.provider = new ethers.providers.JsonRpcProvider(
adapterSettings.ARBITRUM_RPC_URL,
adapterSettings.ARBITRUM_CHAIN_ID,
)
const conn = {
url: adapterSettings.ARBITRUM_RPC_URL,
timeout: adapterSettings.ARBITRUM_RPC_TIMEOUT_MS,
}
this.provider = new ethers.providers.JsonRpcProvider(conn, adapterSettings.ARBITRUM_CHAIN_ID)
this.requester = dependencies.requester

this.glvReaderContract = new ethers.Contract(
Expand Down Expand Up @@ -148,10 +149,13 @@ export abstract class BaseGlvTransport<
const providerDataRequestedUnixMs = Date.now()
const glv_address = param.glv

let start = Date.now()
const glvInfo = await this.glvReaderContract.getGlvInfo(
this.settings.DATASTORE_CONTRACT_ADDRESS,
glv_address,
)
let end = Date.now() - start
logger.debug(`Fetched glv info in ${end}ms`)

const glv: glvInformation = {
glvToken: glvInfo.glv.glvToken,
Expand Down Expand Up @@ -190,10 +194,13 @@ export abstract class BaseGlvTransport<
glv_address,
]

start = Date.now()
const [[maximizedPriceRaw], [minimizedPriceRaw]] = await Promise.all([
this.glvReaderContract.getGlvTokenPrice(...glvTokenPriceContractParams, true),
this.glvReaderContract.getGlvTokenPrice(...glvTokenPriceContractParams, false),
])
end = Date.now() - start
logger.info(`Fetched glv token price in ${end}ms`)

const maximizedPrice = Number(utils.formatUnits(maximizedPriceRaw, SIGNED_PRICE_DECIMALS))
const minimizedPrice = Number(utils.formatUnits(minimizedPriceRaw, SIGNED_PRICE_DECIMALS))
Expand Down Expand Up @@ -226,6 +233,7 @@ export abstract class BaseGlvTransport<
const priceProviders: Record<string, string[]> = {}
const promises = []

const start = Date.now()
for (let i = 0; i < sources.length; i++) {
const source = sources[i]
const assetPromises = assets.map(async (asset) => {
Expand Down Expand Up @@ -270,6 +278,8 @@ export abstract class BaseGlvTransport<
}

await Promise.all(promises)
const end = Date.now() - start
logger.debug(`Fetched prices in ${end}ms`)

this.validateRequiredResponses(priceProviders, sources, assets, dataRequestedTimestamp)

Expand Down
Loading