Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Add check for missing block data to gas-oracle #151

Merged
merged 7 commits into from
Jun 24, 2022
Merged

Conversation

vponline
Copy link
Contributor

@vponline vponline commented Jun 23, 2022

This fixes a bug where block is null (or undefined) which causes the gas oracle to fail with an unexpected error stopping the Airseeker and adds tests for this case.

{
    "errorType": "Runtime.UnhandledPromiseRejection",
    "errorMessage": "TypeError: Cannot read property 'transactions' of null",
    "reason": {
        "errorType": "TypeError",
        "errorMessage": "Cannot read property 'transactions' of null",
        "stack": [
            "TypeError: Cannot read property 'transactions' of null",
            "    at /var/task/dist/gas-oracle.js:118:54",
            "    at Array.reduce (<anonymous>)",
            "    at /var/task/dist/gas-oracle.js:115:61",
            "    at step (/var/task/dist/gas-oracle.js:44:23)",
            "    at Object.next (/var/task/dist/gas-oracle.js:25:53)",
            "    at fulfilled (/var/task/dist/gas-oracle.js:16:58)",
            "    at processTicksAndRejections (internal/process/task_queues.js:95:5)"
        ]
    },
    "promise": {},
    "stack": [
        "Runtime.UnhandledPromiseRejection: TypeError: Cannot read property 'transactions' of null",
        "    at process.<anonymous> (/var/runtime/index.js:35:15)",
        "    at process.emit (events.js:400:28)",
        "    at process.emit (domain.js:475:12)",
        "    at processPromiseRejections (internal/process/promises.js:245:33)",
        "    at processTicksAndRejections (internal/process/task_queues.js:96:32)"
    ]
}

@vponline vponline self-assigned this Jun 23, 2022
@vponline vponline requested a review from a team June 23, 2022 10:29
src/gas-oracle.ts Outdated Show resolved Hide resolved
@aquarat aquarat self-requested a review June 23, 2022 11:34
Copy link
Contributor

@aquarat aquarat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's a bigger issue here and that is that a bug in this component caused the Airseeker execution to end.

I think it might be a good idea to add an error check/try-catch around:
in https://github.com/API3-CTT/airseeker/blob/46f87c8b02b5207277cd2bc91a6a73b04f353699/src/update-beacons.ts#L185
with a fallback to conventional pricing.

We should expect EVM RPC endpoints to give us unexpected data because (1) good practice to expect the worst and (2) we're operating across under-served chains with new implementations.

Also, separately, we may want to add import 'source-map-support/register'; to this application to make debugging in future easier. Size won't be an issue because we're running it ourselves.

(I didn't realise Github could quote lines inline like this^, cool!)

@vponline
Copy link
Contributor Author

vponline commented Jun 23, 2022

I think it might be a good idea to add an error check/try-catch around:

Thanks for checking and good catch @aquarat !

Could this be wrapped in a go-function with 0 retries? I'm asking because I just finished a task to replace all try-catches in Airnode with promise-utils go? I'm not sure if there are any plans to replace try-catches here, though.

@aquarat
Copy link
Contributor

aquarat commented Jun 23, 2022

Could this be wrapped in a go-function with 0 retries? I'm asking because I just finished a task to replace all try-catches in Airnode with promise-utils go?

I really like the go utils approach to error handling... it's very C/Go like and satisfies @Siegrift 's suggestion of keeping "unhappy paths" indented and the happy path as left as possible. I say great idea :)

@Siegrift
Copy link
Contributor

Also, separately, we may want to add import 'source-map-support/register'; to this application to make debugging in future easier. Size won't be an issue because we're running it ourselves.

I think this is something we should consider for all Airnode, Airkeeper and Airseeker in the future.

@vponline
Copy link
Contributor Author

Ok I've done a bit of a refactor, here are the additions:

  1. added source-map-support/register
  2. extracted fallback gas price fetching into a new function: getFallbackGasPrice
  3. added go-wrapper and fallback gas price logic to update-beacons.ts if getOracleGasPrice fails
  4. added tests for the above

Please let me know what you think.

src/fetch-beacon-data.ts Outdated Show resolved Hide resolved
@vponline vponline force-pushed the gas-oracle-fix branch 3 times, most recently from ade39cf to 134c6f2 Compare June 23, 2022 17:55
Copy link
Contributor

@aquarat aquarat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment 😄

src/update-beacons.ts Outdated Show resolved Hide resolved
@aquarat aquarat self-requested a review June 24, 2022 12:09
Copy link
Contributor

@aquarat aquarat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really neat 🥇 (and I think it'll be both efficient and robust).
Thanks again 😄

@vponline vponline merged commit 2faee57 into main Jun 24, 2022
@vponline vponline deleted the gas-oracle-fix branch June 24, 2022 20:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants