-
Notifications
You must be signed in to change notification settings - Fork 863
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
reduce use of global quorum config #2805
reduce use of global quorum config #2805
Conversation
8279e4e
to
9eb1dcb
Compare
...um/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolTest.java
Show resolved
Hide resolved
9960c9a
to
2591f11
Compare
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.
Getting rid of changing the value in tests should fix the flakiness. It's not perfect ie still having different ways of getting the flag value but it's better than it was.
@shemnon Given that you raised the issue, do you want to have a look at this PR? |
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 reduces the use of, but does not eliminate the static field configuration. While it reduces the window for test flakiness. And its presence still makes it possible that new flakiness could be introduced unless we are very vigilant in the side effects. I think there is still room to eliminate it by changing a few classes from static methods to instance classes provided via Dependency Injection.
ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/GraphQLDataFetchers.java
Outdated
Show resolved
Hide resolved
...api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetCode.java
Outdated
Show resolved
Hide resolved
ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/TransactionGoQuorumTest.java
Show resolved
Hide resolved
445eb95
to
b6dd25e
Compare
b6dd25e
to
c0cd715
Compare
The second commit that fully eradicates the flag touches a lot of files. I think I prefer the "mostly gone" version. Can we memoize it so once it's set it can't be changed - that would prevent accidental misuse? |
@shemnon could you have another superficial look at the updated PR? The code surface required to be touched turned out to be quite large. And in light of looming tickets like the separation of privacy into a plugin, we (revenant) feel that threading all those extra objects through the call stack is not an improvement of the codebase. If we would instead just take the first of the two commits, and add a getter and a write once setter for the static |
The value of this bug is to go from |
I'll take a deeper look tonight, but making storage dependent on the genesis config doesn't look like a good solution. |
Add I think we need to refactor the main culprit first: the static methods on Once that is in place the few remaining instances can be inferred from other data. The TransactionSimulator can infer it from the presence of privacy parameters and then goquorum privacy parameters. The transaction can infer it from an empty chainId (the TransactionDecoder will guarantee that). The various controller builders can get it directly from the genesis config, which will be available as a field during their execution. |
The issue that this is 100% safe for concurrent testing is easy to achieve without reducing that static flag use to zero. The first commit (2591f11) already uses mocking to test the
It is already dependent, the PR just made that explicit. Storage needs to parse transactions which depends on the quorum flag which is stored in the genesis.
I considered this. It would be nicer code than what we have. But it would be a larger refactor: it would touch more or less all the places that the current PR touches but in a less mechanical way. And without further changes it would not decouple the storage classes from transaction decoding (and thus the quorum flag). This mostly results from us not having decoupled the ability to read, write, and (in-memory) represent transactions. Thus as soon as you do one of these, you need the quorum flag--even if you never use it because you do not parse transactions. |
Consider two simultaneous tests, one decoding a mainnet encoded transaction and one decoding a goquorum private transaction. The r values overlap and only the static field is used to declare one mainnet and one goquorum. It is not 100% safe to use a static field for such a basic operation. |
c0cd715
to
5752224
Compare
When protecting the quorum flag from being changed during runtime like I proposed in the most recent commit, no tests could run concurrently with different flag values. Tests could not even change the quorum flag at all. Instead, tests have to use mocks, static injection, or slightly adapt the tested class to locally overwrite the quorum config value. In the current code base, three test classes are playing with the static quorum flag. Changing them is much more economical than changing 200+ files as in the previous version of this PR. |
That's like the Global Interpreter Lock in Python. We can do better. |
I don't think any solution is going to "look good" unless something like Dagger is adopted, so the DI framework handles the plumbing of strange config settings to the far corners of the app. Adding another hack (like single threading the static value) isn't any better than the current situation. |
5752224
to
c40a6fc
Compare
We have two problems:
This PR fixes 1 but does nothing (good) on 2. I think we all agree that to fix this in a non-ugly way we need to solve the dependency injection problem. Which is a much bigger task and requires some careful coordination with turning parts of the codebase into plugins. Can we merge this fix to get rid of flaky tests and discuss the proper way to deal with the issue afterwards? Actually merging would of course require dealing with the other comments you made on first. But I would prefer to delay the polishing after we agreed what to do in principle. |
I think we should have another maintainer look at this. I'm not comfortable approving it but I'm not blocking it either. |
c40a6fc
to
6793cbd
Compare
After chats with revenant and @lucassaldanha we came to the conclusion that we dislike the protected static global variant of the PR a little less than the code churning one. |
6793cbd
to
388f01d
Compare
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.
mock investigation
config/src/main/java/org/hyperledger/besu/config/GoQuorumOptions.java
Outdated
Show resolved
Hide resolved
...um/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolTest.java
Show resolved
Hide resolved
...um/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolTest.java
Outdated
Show resolved
Hide resolved
...um/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolTest.java
Show resolved
Hide resolved
...um/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolTest.java
Outdated
Show resolved
Hide resolved
...um/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolTest.java
Show resolved
Hide resolved
I'm happy once the TransactionPoolTest gets cleaned up. |
The use of the org.hyperledger.besu.config.GoQuorumOptions static variable is ugly. In particular does changing its value during tests cause flaky tests. To ameliorate the issue this commit - removes unused code that did rely on GoQuorumOptions - removes access to GoQuorumOptions deep in the call stack by looking it up in the transaction validator instead - change the TransactionDecoder to explicitly take the goQuorumCompatbility flag as an argument where access to the transaction validator is not easy - rewriting all tests that did change the GoQuorumOptions by mocking the option change instead. Signed-off-by: Taccat Isid <taccatisid@protonmail.com>
Signed-off-by: Taccat Isid <taccatisid@protonmail.com>
Signed-off-by: Taccat Isid <taccatisid@protonmail.com>
Signed-off-by: Taccat Isid <taccatisid@protonmail.com>
388f01d
to
aae58d6
Compare
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.
LGTM
SonarCloud Quality Gate failed. |
This also fixes #2813 |
* reduce use of global quorum config The use of the org.hyperledger.besu.config.GoQuorumOptions static variable is ugly. In particular does changing its value during tests cause flaky tests. To ameliorate the issue this commit - removes unused code that did rely on GoQuorumOptions - removes access to GoQuorumOptions deep in the call stack by looking it up in the transaction validator instead - change the TransactionDecoder to explicitly take the goQuorumCompatbility flag as an argument where access to the transaction validator is not easy - rewriting all tests that did change the GoQuorumOptions by mocking the option change instead. Signed-off-by: Taccat Isid <taccatisid@protonmail.com> * protect access to GoQuorum flag by getter and write once setter Signed-off-by: Taccat Isid <taccatisid@protonmail.com> * deduce goQuorum flag from privacyOptions Signed-off-by: Taccat Isid <taccatisid@protonmail.com> * remove unnecessary mocks from TransactionPoolTest Signed-off-by: Taccat Isid <taccatisid@protonmail.com> Co-authored-by: Sally MacFarlane <sally.macfarlane@consensys.net>
* reduce use of global quorum config The use of the org.hyperledger.besu.config.GoQuorumOptions static variable is ugly. In particular does changing its value during tests cause flaky tests. To ameliorate the issue this commit - removes unused code that did rely on GoQuorumOptions - removes access to GoQuorumOptions deep in the call stack by looking it up in the transaction validator instead - change the TransactionDecoder to explicitly take the goQuorumCompatbility flag as an argument where access to the transaction validator is not easy - rewriting all tests that did change the GoQuorumOptions by mocking the option change instead. Signed-off-by: Taccat Isid <taccatisid@protonmail.com> * protect access to GoQuorum flag by getter and write once setter Signed-off-by: Taccat Isid <taccatisid@protonmail.com> * deduce goQuorum flag from privacyOptions Signed-off-by: Taccat Isid <taccatisid@protonmail.com> * remove unnecessary mocks from TransactionPoolTest Signed-off-by: Taccat Isid <taccatisid@protonmail.com> Co-authored-by: Sally MacFarlane <sally.macfarlane@consensys.net>
PR description
The use of the org.hyperledger.besu.config.GoQuorumOptions static variable is ugly. In particular does changing its value during tests cause flaky tests. To ameliorate the issue this PR
Signed-off-by: Taccat Isid taccatisid@protonmail.com
Fixed Issue(s)
fixes #2775.
Changelog