-
Notifications
You must be signed in to change notification settings - Fork 844
refactor: share EVM rpc package #4786
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
base: master
Are you sure you want to change the base?
refactor: share EVM rpc package #4786
Conversation
alarso16
left a comment
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.
Don't we need to register the types for our tests? I think that was the only thing preventing us from using the geth rpc package
The only place we registered was in an additional main file just in subnet-evm, and that was for test retrying for flakes. I removed that as we should not be doing test retries in the monorepo, and should just skip flaky tests entirely if they're flaky. Is there registration anywhere else? |
No, we didn't just retry failed tests. They also registered |
I don't think this is true. There are two places in this PR where I removed
Are there other important places in which I removed it? |
|
If This can alternately be done with func testCChainAndSubnetEVM(t *testing.T, testFn func(*testing.T)) {
fn := func() error {
testFn(t)
return nil
}
t.Run("cchain", func(t *testing.T) {
_ = emulate.CChain(fn)
})
t.Run("subnetEVM", func(t *testing.T) {
_ = emulate.SubnetEVM(fn)
})
}
func TestFoo(t *testing.T) {
testCorethAndSubnetEVM(t, testFoo)
}
func testFoo(t *testing.T) {
// this is where the actual testing occurs; i.e. just rename any existing TestFoo to testFoo
}
func TestBar(t *testing.T) {
testCorethAndSubnetEVM(t, testBar)
}
func testBar(t *testing.T) {
// as with testFoo()
}The linter is going to tell you to call |
|
I believe we have decided to enforce that we don't want cyclic dependencies between |
Yeah I am trying this right now and was about to comment about the cyclic imports. The shared I definitely think this + in conjunction with some sort of test main would be a good model for how to combine packages while testing separately. I've committed a new |
graft/evm/libevmtest/testmain.go
Outdated
| if cchainCode != 0 { | ||
| return cchainCode | ||
| } | ||
| if subnetCode != 0 { | ||
| return subnetCode | ||
| } |
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.
| if cchainCode != 0 { | |
| return cchainCode | |
| } | |
| if subnetCode != 0 { | |
| return subnetCode | |
| } | |
| if cchainCode != 0 || subnetCode != 0 { | |
| return 1 | |
| } |
Don't just apply this, but is there any reason we care about the specific code?
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.
Not really, -- more work could be done to determine which of the two test variants failed, by returning extra information in these if cases.
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.
I am going to apply this but leave the comment open if you have further comments.
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.
I just learned Go does not have a ternary operator. Lame. 5 lines could be one!
graft/evm/libevmtest/testmain.go
Outdated
| func RunWithAll(m *testing.M) int { | ||
| fmt.Println("=== Running tests with both C-Chain and Subnet-EVM ===") | ||
|
|
||
| fmt.Println("\n--- Running C-Chain variant ---") |
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.
Why do you prefix all these with newlines?
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.
So there can be a blank line in between these two lines.
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.
it's just for style
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.
I think you shouldn't. Run go test -v ./... to see how go does it (there's no blank lines)
Co-authored-by: Austin Larson <[email protected]> Signed-off-by: Jonathan Oppenheimer <[email protected]>
Co-authored-by: Austin Larson <[email protected]> Signed-off-by: Jonathan Oppenheimer <[email protected]>
| github.com/Microsoft/go-winio v0.6.1 // indirect | ||
| github.com/StephenButtolph/canoto v0.17.3 // indirect | ||
| github.com/VictoriaMetrics/fastcache v1.12.1 // indirect | ||
| github.com/ava-labs/avalanchego/graft/coreth v0.0.0-20251203215505-70148edc6eca // indirect |
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.
Open question: Will this indirect dependency cause a giant headache down the road?
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.
I can't foresee any issue - do you have something in mind. It's because of importing emulate which imports each of the two repositories.
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.
The reason that we didn't want to allow evm to import coreth is because of the dependency tree. Even if it doesn't import it directly, this doesn't seem to avoid the problem
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.
I thought we didn't want to allow graft/evm to import coreth because it would prevent a direct uplift to vms/evm. An indirect dependency (esp that is a result of importing vms/evm itself) doesn't prevent tthat. What are your concerns regarding the dependency tree?
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.
Why is this in a separate file? You should be able to just keep the test there, since any conflicts when updating will be easier to see
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.
Because it has to be in a separate package, rpc_test to prevent import cycles.
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.
and if we change the whole old test file to be in rpc_test it doesn't work as a tonnn more stuff would either need to get exported to be accessible, or moved. This was the minimal change I could make.
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 is also why https://github.com/ava-labs/avalanchego/blob/72ea713ecc8af00b4264ec28bfe32cb054d622f4/graft/evm/rpc/testing.go exists now.
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.
Ahhh, I didn't realize that you didn't change all of the tests to run in that package.
Co-authored-by: Austin Larson <[email protected]> Signed-off-by: Jonathan Oppenheimer <[email protected]>
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 works, but some of the package management stuff feels hacky. I don't have any better solutions, so maybe get an opinion from @ARR4N or @ceyonur. I'm not confident enough that this is the route we want to take to give a real approval
My concerns are:
- Importing coreth and subnet-evm was intended to be avoided in this package, but it has to be done to enable registrations. Part of this messiness is because we decided not to directly import coreth and subnet-evm, but it would be simpler if we could (see @ARR4N's suggestion above)
- This makes the dependency tree between the four modules a strongly connected graph, which is less than ideal. Would it be better to move the coreth/subnet-evm type registrations into the
evmpackage first? - Running two separate packages of tests in the same folder is quite gross (tbh didn't even know Go supports it)
Why this should be merged
The subnet-evm
rpcpackage was practically identical to the corethrpcpackage. It makes no sense to maintain two copies of this code. This also makes moving to libevm'srpcpackage far easier, to look in one location and see what needs to be libevmified.How this works
graft/evm/rpc/directory structurecoreth/rpcto the shared locationgithub.com/gorilla/websocket v1.5.0github.com/deckarep/golang-set/v2 v2.1.0golang.org/x/time v0.12.0TestNotifyto work with standard libevm typesI also added
main_test.gowith aTestMainthat automatically runs all RPC tests twice - once with C-Chain type registration and once with Subnet-EVM type registration.This works by putting
TestMaininpackage rpc_test(an external test package) instead ofpackage rpc, which lets us import theemulatepackage without creating a circular dependency. We can then useemulate.CChain()andemulate.SubnetEVM()to properly register/cleanup types between test runs.Thus when you run
go test(which also automatically happens via CI -- you can check for yourself!), it:emulate.CChain()emulate.SubnetEVM()How this was tested
CI
Need to be documented in RELEASES.md?
No