Skip to content
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

Use chainId for incoming transactions controller #9583

Merged
merged 1 commit into from
Oct 31, 2020

Conversation

Gudahtt
Copy link
Member

@Gudahtt Gudahtt commented Oct 13, 2020

The incoming transactions controller now uses the chainId for the current network instead of the networkId. This ensures that custom RPC endpoints for the built-in supported networks do correctly receive incoming transactions.

As part of this change, the incoming transactions controller will also cease keeping track of the "last block fetched" for networks that are not supported. This piece of state never really represented the last block fetched, as no blocks were fetched for any such networks. It been removed.

@metamaskbot
Copy link
Collaborator

Builds ready [979e881]
Page Load Metrics (403 ± 47 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint309342168
domContentLoaded3005854019747
load3025864039747
domInteractive3005854019747

@Gudahtt Gudahtt force-pushed the use-chain-id-in-incoming-transactions-controller branch from 979e881 to 05f4a0a Compare October 13, 2020 18:30
@Gudahtt Gudahtt marked this pull request as ready for review October 13, 2020 18:43
@Gudahtt Gudahtt requested a review from a team as a code owner October 13, 2020 18:43
@Gudahtt Gudahtt requested a review from kumavis October 13, 2020 18:43
@metamaskbot
Copy link
Collaborator

Builds ready [05f4a0a]
Page Load Metrics (404 ± 51 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint298137126
domContentLoaded31465840210651
load31565940410651
domInteractive31465840210651

@Gudahtt Gudahtt force-pushed the use-chain-id-in-incoming-transactions-controller branch from 05f4a0a to e974580 Compare October 14, 2020 19:29
@Gudahtt Gudahtt force-pushed the use-chain-id-in-incoming-transactions-controller branch from e974580 to afa60a0 Compare October 28, 2020 06:42
@metamaskbot
Copy link
Collaborator

Builds ready [afa60a0]
Page Load Metrics (397 ± 59 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint28503452
domContentLoaded29359639512359
load29559839712359
domInteractive29359539512359

@Gudahtt
Copy link
Member Author

Gudahtt commented Oct 28, 2020

I'm going to move most of these unit test changes to a separate PR, and get that merged ahead of this. These changes deserve separate explanation. I'll put this in draft until then.

@Gudahtt Gudahtt marked this pull request as draft October 28, 2020 07:14
@Gudahtt Gudahtt force-pushed the use-chain-id-in-incoming-transactions-controller branch from afa60a0 to 83aa309 Compare October 29, 2020 03:23
@metamaskbot
Copy link
Collaborator

Builds ready [83aa309]
Page Load Metrics (482 ± 62 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint3097442010
domContentLoaded31871448012861
load31971648212862
domInteractive31771348012861

Gudahtt added a commit that referenced this pull request Oct 29, 2020
The shared mocks used previously in the incoming transaction controller
tests have been replaced with functions that can generate a new mock
for each test.

We should avoid ever sharing mocks between tests. It's quite easy for
a mock to get accidentally mutated or not correctly "reset" for the
next test, leading to test inter-dependencies and misleading results.

In particular, it is unsafe to share a `sinon` fake (e.g. a spy or
stub) because they can't be fully reset between tests. Or at least it's
difficult to reset them property, and it can't be done while also
following their recommendations for preventing memory leaks.

The spy API and all related state can be reset with `resetHistory`,
which can be called between each test. However `sinon` also recommends
calling `restore` after each test, and this will cause `sinon` to drop
its internal reference to the fake object, meaning any subsequent call
to `resetHistory` would fail. This is intentional, as it's required to
prevent memory from building up during the test run, but it also means
that sharing `sinon` fakes is particularly difficult to do safely.

Instead we should never share mocks in the first place, which has other
benefits anyway.

This was discovered while writing tests for #9583. I mistakenly
believed that `sinon.restore()` would reset the spy state, and this was
responsible for many hours of debugging test failures.
Gudahtt added a commit that referenced this pull request Oct 29, 2020
Unit tests have been added to the incoming transactions controller to
ensure that block updates are correctly resulting in state updates when
incoming transactions are enabled. All other events that trigger state
updates are tested as well.

The tests were written to be minimally dependent upon implementation
details of the controller itself. `nock` was used to mock the API
response from Etherscan. Each event is triggered asynchronously by
`sinon`, as in production they are likely only triggered
asynchronously.

This was extracted from #9583

This PR includes a new `waitUntilCalled` module meant to help with
writing asynchronous tests. It allows you to wait until a stub has been
called.
Gudahtt added a commit that referenced this pull request Oct 29, 2020
The shared mocks used previously in the incoming transaction controller
tests have been replaced with functions that can generate a new mock
for each test.

We should avoid ever sharing mocks between tests. It's quite easy for
a mock to get accidentally mutated or not correctly "reset" for the
next test, leading to test inter-dependencies and misleading results.

In particular, it is unsafe to share a `sinon` fake (e.g. a spy or
stub) because they can't be fully reset between tests. Or at least it's
difficult to reset them property, and it can't be done while also
following their recommendations for preventing memory leaks.

The spy API and all related state can be reset with `resetHistory`,
which can be called between each test. However `sinon` also recommends
calling `restore` after each test, and this will cause `sinon` to drop
its internal reference to the fake object, meaning any subsequent call
to `resetHistory` would fail. This is intentional, as it's required to
prevent memory from building up during the test run, but it also means
that sharing `sinon` fakes is particularly difficult to do safely.

Instead we should never share mocks in the first place, which has other
benefits anyway.

This was discovered while writing tests for #9583. I mistakenly
believed that `sinon.restore()` would reset the spy state, and this was
responsible for many hours of debugging test failures.
Gudahtt added a commit that referenced this pull request Oct 29, 2020
Unit tests have been added to the incoming transactions controller to
ensure that block updates are correctly resulting in state updates when
incoming transactions are enabled. All other events that trigger state
updates are tested as well.

The tests were written to be minimally dependent upon implementation
details of the controller itself. `nock` was used to mock the API
response from Etherscan. Each event is triggered asynchronously by
`sinon`, as in production they are likely only triggered
asynchronously.

This was extracted from #9583

This PR includes a new `waitUntilCalled` module meant to help with
writing asynchronous tests. It allows you to wait until a stub has been
called.
Gudahtt added a commit that referenced this pull request Oct 30, 2020
Unit tests have been added to the incoming transactions controller to
ensure that block updates are correctly resulting in state updates when
incoming transactions are enabled. All other events that trigger state
updates are tested as well.

The tests were written to be minimally dependent upon implementation
details of the controller itself. `nock` was used to mock the API
response from Etherscan. Each event is triggered asynchronously by
`sinon`, as in production they are likely only triggered
asynchronously.

This was extracted from #9583

This PR includes a new `wait-until-called` module meant to help with
writing asynchronous tests. It allows you to wait until a stub has been
called.
@Gudahtt Gudahtt force-pushed the use-chain-id-in-incoming-transactions-controller branch from 83aa309 to a9cf635 Compare October 30, 2020 18:05
@metamaskbot
Copy link
Collaborator

Builds ready [a9cf635]
Page Load Metrics (473 ± 65 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint3111143168
domContentLoaded27973447013464
load28073647313565
domInteractive27873447013464

The incoming transactions controller now uses the `chainId` for the
current network instead of the `networkId`. This ensures that custom
RPC endpoints for the built-in supported networks do correctly receive
incoming transactions.

As part of this change, the incoming transactions controller will also
cease keeping track of the "last block fetched" for networks that are
not supported. This piece of state never really represented the last
block fetched, as _no_ blocks were fetched for any such networks. It
been removed.
@Gudahtt Gudahtt force-pushed the use-chain-id-in-incoming-transactions-controller branch from a9cf635 to 89cbc8a Compare October 30, 2020 18:35
@Gudahtt Gudahtt marked this pull request as ready for review October 30, 2020 18:37
@Gudahtt
Copy link
Member Author

Gudahtt commented Oct 30, 2020

@rekmarks This is finally now ready for review again!

@metamaskbot
Copy link
Collaborator

Builds ready [89cbc8a]
Page Load Metrics (380 ± 47 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint308444178
domContentLoaded2516303789747
load2536313809847
domInteractive2516293789747

Copy link
Member

@rekmarks rekmarks left a comment

Choose a reason for hiding this comment

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

Excellent!

@Gudahtt Gudahtt merged commit 55bff07 into develop Oct 31, 2020
@Gudahtt Gudahtt deleted the use-chain-id-in-incoming-transactions-controller branch October 31, 2020 00:58
@github-actions github-actions bot locked and limited conversation to collaborators Oct 31, 2020
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