-
Notifications
You must be signed in to change notification settings - Fork 946
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
Refactoring sharding package for proposer/client separation #85
Refactoring sharding package for proposer/client separation #85
Conversation
Looks good! Two questions I'd like to discuss:
|
Good questions!
|
Just to be clear, I am OK with one sharding package. |
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.
Looks good to me. I like the interfaces you created and how the methods in collator and proposer simply take this interface as an argument. Thank you for putting this together and explaining your reasoning - I will do the same moving forward on future PRs.
sharding/client/smc.go
Outdated
|
||
// initSMC initializes the sharding manager contract bindings. | ||
// If the SMC does not exist, it will be deployed. | ||
func initSMC(c *shardingClient) (*contracts.SMC, error) { |
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.
Can we put this function in the client.go file? The client is the one that inits the SMC and it doesn't make sense for this file to exist at all if we only envision having a few functions or just 1 in it.
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.
Sure. I don't feel very strongly about having this method in its own file so I'll move it.
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.
Done
sharding/client/client.go
Outdated
package sharding | ||
|
||
//go:generate abigen --sol contracts/sharding_manager.sol --pkg contracts --out contracts/sharding_manager.go | ||
package client |
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.
Let's please rename this to sharding_client.go. client is ambiguous with the ethclient that is a part of the struct.
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 isn't related to the filename, but the package path. Do we need the redundancy of sharding/shardingclient/client.go?
Keep in mind, that it would only be used by the collator/proposer.
Personally, I don't think this conflicts with ethclient, but I see your point too.
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.
Let's revisit this in the future. I'm going to leave for 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.
Looks good after resolving @rauljordan feedbacks
sharding/client/client.go
Outdated
keystore *keystore.KeyStore // Keystore containing the single signer | ||
ctx *cli.Context // Command line context | ||
smc *contracts.SMC // The deployed sharding management contract | ||
// General Client for Collator. Communicates to Geth node via JSON RPC. |
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 not only for collator, it's for proposer and future actors too
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.
Done
// TODO: this function should store the collator's SMC index as a property | ||
// in the client's struct | ||
if err := joinCollatorPool(c); err != nil { | ||
smc, err := initSMC(c) |
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 don't know if executor node uses SMC, we might have to change this for phase 3
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 executor node won't use this client anyway, it doesn't need main chain communication, right?
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.
That's true
sharding/collator/smc.go
Outdated
|
||
// joinCollatorPool checks if the account is a collator in the SMC. If | ||
// the account is not in the set, it will deposit 100ETH into contract. | ||
func joinCollatorPool(c client.Client) error { |
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 a Collator specific function. Should we move it under collator.go
and delete smc.go
completely?
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.
Sure, sounds good to me
Travis failed some times, but tests pass so i'll merge anyway |
Refactoring sharding package for proposer/client separation
Refactoring sharding package for proposer/client separation align config with phase 1 spec update SMC to use 1000eth as collator deposit size fix deposit for collator_test fixed config test and added more test cases
Refactoring sharding package for proposer/client separation Former-commit-id: 9767017
Refactoring sharding package for proposer/client separation align config with phase 1 spec update SMC to use 1000eth as collator deposit size fix deposit for collator_test fixed config test and added more test cases Former-commit-id: d1c9341
Refactoring sharding package for proposer/client separation align config with phase 1 spec update SMC to use 1000eth as collator deposit size fix deposit for collator_test fixed config test and added more test cases Former-commit-id: 7fadb044ec7bb136964781ac271ce6abb4cff86f [formerly d1c9341] Former-commit-id: 9747bde
This builds on the work of @nisdas in #82.
Why refactor?
We started this package under the original sharding design that would have only a collator. Now that we need to split responsibilities into 2+ roles, it makes sense to keep things isolated in their own packages.
Following @nisdas's design along with suggestions in:
We split up the client aspect of the roles into a client package. This package is responsible for the actual communications (i.e. connecting to a running geth node, initializing the SMC, handling account unlocking). Then we can have a collator that is more focused in its own package with responsibilities such as listening for block headers, joining the collator pool, etc. Furthermore, we start the proposer package to run with its own responsibilities.
Why have
collator_client.go
andcollator.go
?Good question! At first, I didn't like this, but the
collator_client
could/should expose the public methods that thegeth/shardingcmd
can call (i.e.Start
andNewCollator
) while the interesting code lives incollator.go
. This felt helpful to separate for testing purposes, but I can be convinced out of this pattern if your argument is strong enough :)This supersedes (and includes) @nisdas's work in #82.
Closes #82
Closes #83
Required for #79 and #80
TODO (in future PR):
collator
sharding/client/testing