Skip to content

SimulatedBackendClient: Fix validation error for eth_getBlockByNumber type checks - #7763

Merged
prashantkumar1982 merged 9 commits into
developfrom
bug-56284-simulated_backend_fix
Oct 27, 2022
Merged

SimulatedBackendClient: Fix validation error for eth_getBlockByNumber type checks#7763
prashantkumar1982 merged 9 commits into
developfrom
bug-56284-simulated_backend_fix

Conversation

@prashantkumar1982

@prashantkumar1982 prashantkumar1982 commented Oct 25, 2022

Copy link
Copy Markdown
Contributor

Context: https://app.shortcut.com/chainlinklabs/story/56284/simulatedbackendclient-is-making-incorrect-type-assumptions-for-eth-getblockbynumber?stories_sort_by=id&stories_group_by=epic_id

#1 I had to refactor, and move Block, Transaction and TxType structures from evm.gas package to evm.types package, to avoid a circular import dependency.
#2 eth_getBlockByNumber call verification should allow the result type to be Head or Block. Both are valid now.

@github-actions

Copy link
Copy Markdown
Contributor

I see that you haven't updated any CHANGELOG files. Would it make sense to do so?

@prashantkumar1982 prashantkumar1982 changed the title SimulatedBackendClient: Minor fix in validating type for eth_getBlockByNumber SimulatedBackendClient: Fix validation error for eth_getBlockByNumber type checks Oct 26, 2022
@prashantkumar1982
prashantkumar1982 marked this pull request as ready for review October 26, 2022 01:04
@github-actions

github-actions Bot commented Oct 26, 2022

Copy link
Copy Markdown
Contributor

Solana Smoke Test Results

1 tests   1 ✔️  4m 38s ⏱️
1 suites  0 💤
1 files    0

Results for commit 12a3667.

♻️ This comment has been updated with latest results.

@github-actions

github-actions Bot commented Oct 26, 2022

Copy link
Copy Markdown
Contributor

EVM Smoke Test Results

34 tests   34 ✔️  6m 22s ⏱️
  1 suites    0 💤
  1 files      0

Results for commit 12a3667.

♻️ This comment has been updated with latest results.

Comment thread core/chains/evm/client/simulated_backend_client.go Outdated
Comment on lines -477 to -479
if isFullTx {
return errors.New("SimulatedBackendClient doesn't support full transactions for eth_getBlockByNumber")
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I thought this would be OK to leave this in, since using *evmtypes.Block with isFullTx==false is a valid thing to do normally. Was it actively causing a problem?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

BlockHistoryEstimator always calls this with isFullTx = true.
See here:

Method: "eth_getBlockByNumber",
Args: []interface{}{Int64ToHex(i), true},
Result: &evmtypes.Block{},

So if we allow this to fail on isFullTx==true, then BlockHistoryEstimator can't use the SimulatedBackendClient.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I was thinking that returning an error for that unsupported case could be a feature, since without an error the dev could be misled to believe there are just empty blocks without txs 🤷 I don't know the surrounding context well though

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I understand, but this is a test utility.
If a dev uses that feature for a test, but then makes incorrect assumptions, then they are just writing an invalid test.
Assuming that they got empty blocks without Tx is their fault, as this is a test class, and they should be setting this to respond with the right Txs that they expect.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

But why set them up for failure in the first place? This code does not support that call. Why is it better to return the wrong answer than to refuse to answer?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I understand, but this is a test utility.

Also, I fundamentally disagree with having lower standards for test utilities. It is a burden on development and undermines our ability to actually confirm production quality with the tests.

@prashantkumar1982 prashantkumar1982 Oct 27, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is not setting them up for failure or a lower standard for test utility.
Previously, aka before *evmtypes.Block was introduced, we always had isFullTx = False in all our production use-cases. So whoever wrote this simulated client, explicitly returned an error if that was true.
Now BlockHistoryEstimator actually sets isFullTx = true for a genuine case. So we removed that check, as it is no longer a correct assumption.

You could surely add the check back with conditional logic, saying if it is *evmtypes.Head, and isFullTx=True, then return an error.
But that check is not guarding or setting a higher bar for tests.

A developer who uses this SimulatedClient for testing has to know that it is a test utility, and it will only behave as it is set up to behave. It will return exactly the Blocks that the tester configured it to return. That specific check on IsFullTx cannot help or protect anyone if they're writing an invalid test case.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

it will only behave as it is set up to behave.

I think there is some confusion here. This code as written will never return txes. It cannot be configured by the caller in the current state to do that. Which test exactly is using this utility and requesting full blocks? It would only be valid to do that if you happen to require all empty blocks for your test case.

@prashantkumar1982
prashantkumar1982 merged commit 4f21638 into develop Oct 27, 2022
@prashantkumar1982
prashantkumar1982 deleted the bug-56284-simulated_backend_fix branch October 27, 2022 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants