-
Notifications
You must be signed in to change notification settings - Fork 129
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
chore(lib/genesis): less dependencies on other packages #2795
Conversation
dot/core/helpers_test.go
Outdated
@@ -144,7 +167,7 @@ func getGssmrRuntimeCode(t *testing.T) (code []byte) { | |||
gssmrGenesis, err := genesis.NewGenesisFromJSONRaw(path) | |||
require.NoError(t, err) | |||
|
|||
trie, err := genesis.NewTrieFromGenesis(gssmrGenesis) | |||
trie, err := wasmer.NewTrieFromGenesis(*gssmrGenesis) |
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 moved to wasmer since it will need to run wasmer code to get the state version from the runtime code contained in the genesis.
lib/genesis/helpers.go
Outdated
@@ -16,8 +16,7 @@ import ( | |||
"github.com/ChainSafe/gossamer/dot/types" | |||
"github.com/ChainSafe/gossamer/lib/common" | |||
"github.com/ChainSafe/gossamer/lib/crypto" | |||
"github.com/ChainSafe/gossamer/lib/runtime" | |||
"github.com/ChainSafe/gossamer/lib/trie" | |||
"github.com/ChainSafe/gossamer/lib/runtime/constants" |
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.
New subpackage containing just a few hex trie keys, to avoid cycle dependency hell. Also an example why we need moare subpackages.
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.
@qdm12 the constants
package you introduce here just contains some constants that are only used by production code while initializing the node and building the Genesis struct, I would suggest moving those constants to lib/genesis
since they are specifically keys at the genesis file
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.
These are are used by both wasmer and genesis packages (and wasmer imports genesis). We can thus either:
- keep it as is in a separate dependency-free package
- duplicate the constants in both wasmer and genesis
But it feels a bit better to have them in that constants package, what do you think?
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.
Moved to lib/genesis/keys.go
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.
Also these constants are used by some tests in the wasmer package, not just production code.
1a6b2ee
to
227f81e
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.
nice stuff!
227f81e
to
bcb4229
Compare
d5eed9a
to
95ba320
Compare
f155179
to
edd1f99
Compare
f4d0030
to
81a9da0
Compare
- In dot/helpers_test.go - In dot/core/helpers_test.go - In dot/digest/helpers_test.go - In dot/rpc/helpers_test.go - In dot/rpc/modules/helpers_test.go - In dot/state/helpers_test.go - In lib/grandpa/helpers_test.go - In lib/babe/helpers_test.go
Co-authored-by: Eclésio Junior <[email protected]>
81a9da0
to
357cabe
Compare
357cabe
to
6b0f0eb
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!
🎉 This PR is included in version 0.7.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Changes
TLDR: clear up
lib/genesis
cycle dependency hell 🔥 onlib/runtime/wasmer
andlib/trie
That's gonna look like it's useless changes, but I actually hated my day working on this and it's really needed 😄
The reason is #2774 needs to run wasmer code to extract the state version from the runtime code in the genesis mapping.
And as it is, it makes lib/genesis import lib/runtime/wasmer which opens a whole can of worms of circular dependencies.
Anyway this fixes it and moves functions around such that
lib/genesis
does not importlib/runtime/wasmer
norlib/trie
anymore.lib/genesis
and inline them where neededhelpers_test.go
and unexport them. That way the Go production API is reduced and the lib/genesis imports are less. I know it's tempting to dedup the code, but when it comes to test helping functions we should 100% duplicate to avoid cycle dependency hell 👿NewGenesisBlockFromTrie
function aslib/trie
Trie
methodGenesisBlock()
(same thing, less genesis dependencies)NewTrieFromGenesis
function tolib/runtime/wasmer
since it will need in chore(all): version trie calls #2774 to use wasmer functions.lib/runtime/constants.go
tolib/genesis/constants.go
Tests
go test -tags integration github.com/ChainSafe/gossamer
Issues
Slow boat towards #2418
Primary Reviewer
@EclesioMeloJunior