-
-
Notifications
You must be signed in to change notification settings - Fork 188
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
[WIP] Extend GasFeeController to poll for network status #609
Conversation
d02f93f
to
118fda6
Compare
118fda6
to
ab9a949
Compare
const currentAccountIsEIP1559Compatible = | ||
this.getCurrentAccountEIP1559Compatibility?.() ?? true; | ||
private async getEIP1559Compatibility(): Promise<boolean> { | ||
try { |
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.
This try/catch was copied from _fetchGasFeeEstimateData
so that we could use the same behavior in poll
.
5867e8f
to
7ce8597
Compare
|
The tests for GasFeeController are currently lacking in a few ways: * `nock` is being used to test that requests are being used to obtain data; however, GasFeeController takes functions as arguments which can be used to stub out those requests, thereby removing the need for `nock`. * The logic within `getGasFeeEstimatesAndStartPolling` is not being fully exercised, specifically the polling code. * There are no tests for `disconnectPoller`. * There are no explicit tests for `stopPolling`. * The logic within `_fetchGasFeeEstimateData` is not being fully exercised, specifically with regard to how the result of `getChainId` changes the URL that ends up being hit for both EIP-1559 and non-EIP-1559 flows. * There are tests categorized under a `getChainId` describe block which are actually for `_fetchGasFeeEstimateData`. This commit attempts to address these issues so that future changes to GasFeeController do not break existing behavior.
We would like to introduce another fallback to how we estimate gas fees in a future commit — namely, we want to use `eth_feeHistory` for EIP-1559 networks if the usual API is down. To do this, the existing code around gas fee estimates needs to be refactored. This is the first in a two-part refactor, extracting the majority of the code in `GasFeeController._fetchGasFeeEstimateData` to `gas-util`. In addition to making room for more changes, this also allows us to test this code in isolation from the polling code that already exists in GasFeeController. Note that I am using the term "suggestions" to encompass the data that `_fetchGasFeeEstimateData` returns. This is because `gasFeeEstimates` is an intermediate value that can also be packaged with `estimatedGasFeeTimeBounds`, so "estimates" could be confusing. Also, I replaced "fetch" with "determine" as in the future we may be performing calculations that APIs have done for us in the past ("fetch" seems like a more low-level action).
7ce8597
to
e655c35
Compare
@@ -0,0 +1,28 @@ | |||
import { BN } from 'ethereumjs-util'; |
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.
See https://gitlab.com/ConsenSys/codefi/products/metaswap/gas-api/-/blob/017436f628b2d5967f6e8734780a9114f9e58af9/src/server.ts#L186 and https://gitlab.com/ConsenSys/codefi/products/metaswap/gas-api/-/blob/017436f628b2d5967f6e8734780a9114f9e58af9/src/eip1559/feeHistory.ts#L152 for the original source.
The tests for GasFeeController are currently lacking in a few ways: * `nock` is being used to test that requests are being used to obtain data; however, GasFeeController takes functions as arguments which can be used to stub out those requests, thereby removing the need for `nock`. * The logic within `getGasFeeEstimatesAndStartPolling` is not being fully exercised, specifically the polling code. * There are no tests for `disconnectPoller`. * There are no explicit tests for `stopPolling`. * The logic within `_fetchGasFeeEstimateData` is not being fully exercised, specifically with regard to how the result of `getChainId` changes the URL that ends up being hit for both EIP-1559 and non-EIP-1559 flows. * There are tests categorized under a `getChainId` describe block which are actually for `_fetchGasFeeEstimateData`. This commit attempts to address these issues so that future changes to GasFeeController do not break existing behavior.
b864f9e
to
6873f34
Compare
e655c35
to
a741072
Compare
The tests for GasFeeController are currently lacking in a few ways: * `nock` is being used to test that requests are being used to obtain data; however, GasFeeController takes functions as arguments which can be used to stub out those requests, thereby removing the need for `nock`. * The logic within `getGasFeeEstimatesAndStartPolling` is not being fully exercised, specifically the polling code. * There are no tests for `disconnectPoller`. * There are no explicit tests for `stopPolling`. * The logic within `_fetchGasFeeEstimateData` is not being fully exercised, specifically with regard to how the result of `getChainId` changes the URL that ends up being hit for both EIP-1559 and non-EIP-1559 flows. * There are tests categorized under a `getChainId` describe block which are actually for `_fetchGasFeeEstimateData`. This commit attempts to address these issues so that future changes to GasFeeController do not break existing behavior.
6873f34
to
709d386
Compare
If we are on an EIP-1559-supported network and the Metaswap API fails for some reason, fall back to using `eth_feeHistory` to calculate gas estimates (which the API uses anyway). This code is more or less taken from the code for the API ([1]). [1]: https://gitlab.com/ConsenSys/codefi/products/metaswap/gas-api/-/blob/eae6927b1a0c445e02cb3cba9e9e6b0f35857a12/src/eip1559/feeHistory.ts
709d386
to
b4f23df
Compare
When a user is about to send a transaction or is looking at a swap quote, we would like to inform them if the network is busy so that we can push them to use a lower fee setting. GasFeeController already provides a way to poll for fee estimates, which we employ on transaction preview screens. This commit updates the polling code so that we also gauge network status as we pull estimates. This is done by hitting another endpoint in the MetaSwap API which specifically gives us a base fee threshold we can use to determine whether the network is busy (falling back to using `eth_feeHistory` if the API is not available).
5e18a39
to
888b63d
Compare
This may end up being obsoleted by #632. I'll leave this open until that's merged. |
fbbc906
to
46c3788
Compare
Closing since we can now use |
## network Congestion weight this adds the new field used by metamask for network congestion ### metamask references https://github.com/MetaMask/controllers/pull/632/files MetaMask/core#609 MetaMask/metamask-extension#13044
When a user is about to send a transaction or is looking at a swap
quote, we would like to inform them if the network is busy so that we
can push them to use a lower fee setting. GasFeeController already
provides a way to poll for fee estimates, which we employ on transaction
preview screens. This commit updates the polling code so that we also
gauge network status as we pull estimates. This is done by hitting
another endpoint in the MetaSwap API which specifically gives us a base
fee threshold we can use to determine whether the network is busy
(falling back to using
eth_feeHistory
if the API is not available).References MetaMask/metamask-extension#11307.