Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Clean up Consensus Service traits and infrastructure #1021

Open
gnunicorn opened this issue Oct 26, 2018 · 10 comments
Open

Clean up Consensus Service traits and infrastructure #1021

gnunicorn opened this issue Oct 26, 2018 · 10 comments
Assignees
Labels
I7-refactor Code needs refactoring.
Milestone

Comments

@gnunicorn
Copy link
Contributor

gnunicorn commented Oct 26, 2018

Following #911, most consensus infrastructure was extracted into substrate-consensus-common or the respective consensus engine. However for the integration substrate-service and substrate-network still contain a few traits and a generic implementation of the OfflineTracker. The interfaces should be cleaned up and - as much as possible - moved into and provided by substrate-consensus-common and in-turn be exposed by the specific engines.

@gnunicorn gnunicorn added I7-refactor Code needs refactoring. F5-task labels Oct 29, 2018
@gnunicorn gnunicorn added this to the As-and-when milestone Oct 29, 2018
@bkchr
Copy link
Member

bkchr commented Nov 8, 2018

While doing this, the consensus::BlockImport should also be moved. Currently consensus::BlockImport is implemented for the client in client.rs. Move the implementation into consensus-common where the trait is defined.

@rphmeier
Copy link
Contributor

While doing this, the consensus::BlockImport should also be moved. Currently consensus::BlockImport is implemented for the client in client.rs. Move the implementation into consensus-common where the trait is defined.

Do you mean that we should move BlockImport and related types into client? If so, I disagree -- BlockImport is an interface that shouldn't bring all client code with it.

What's wrong with the dependency chain client <- consensus-common? Why should consensus-common need to be aware of client?

@bkchr
Copy link
Member

bkchr commented Nov 20, 2018

For example the transaction-pool is also depending on the client and not in the reverse order. In this case I wanted to move the TransactionPool runtime api into the transaction-pool crate, but that does not work currently as the TransactionPool api is also required in the client.

@rphmeier
Copy link
Contributor

That seems like a different issue -- how does it relate to consensus?

@bkchr
Copy link
Member

bkchr commented Nov 20, 2018

Consensus use the function in Client that requires the TransactionPool api.

@bkchr
Copy link
Member

bkchr commented Nov 20, 2018

It is the execute_and_import_block function in the Client.

@gnunicorn
Copy link
Contributor Author

I think this is a question of general architecture and purpose of consensus-common. At the moment quite a few crates contain consensus.rs-files which provide mostly glue of the consensus common to their respective API, e.g. in service, which links to this issue.

For many crates in substrate we opted for a primitives-style approach, where we have a super thin almost-no-dependencies crate that provides traits and super general impls (if useful) that others than link to and can use their interface for. However, this isn't the case here. I didn't opt for calling consensus a primitives-crate because I was thinking of consensus-common to become the "catchall" for all consensus-code that is common across many consensus-algorithms and that they can reuse - like the offline tracker or the proposer code base. That though requires that common becomes a "fat" crate with dependencies onto many other crates throughout the project rather than the slimmer primitives-approach.

I can understand the urge to keep the dependency tree of the specific consensus crates slimmer and them potentially providing all the necessary parts themselves, but in practice this isn't actually possible because many other crates do actually provide glue that they are then bound to - e.g #1158. By moving most of it into common I was hoping for that to become more explicit and over time make no other crate directly bind to any common implementation anymore.

I am also okay with splitting up consensus-common into this bundle and a second super slim consensus-primitives that only provides the basic traits and aim for no non-consensus-substrate-crate to have consensus-common as a dependency (but allow node to do that). What do you think @rphmeier , @bkchr ?

@rphmeier
Copy link
Contributor

That sounds reasonable. So consensus-common would hold things like basic proposers or perhaps networking/import-queue logic useful for consensus algorithms, while consensus-primitives would contain traits and types that even the client could depend upon.

@rphmeier
Copy link
Contributor

rphmeier commented Nov 27, 2018

It is the execute_and_import_block function in the Client.

@bkchr

It seems like a bigger error that execute_and_import_block requires TaggedTransactionQueue at all. The implication is that we can't import blocks from any chains which don't implement this API, which is not the goal of substrate at all. Every API that is not Core should not be needed to import blocks at all.

BlockImport should remain defined in consensus-primitives so that consensus algorithm implementations don't need to link the substrate-client crate.

gnunicorn added a commit that referenced this issue Nov 27, 2018
* Remove Proposer from Service

Refs #1021, #1158
@bkchr
Copy link
Member

bkchr commented Nov 28, 2018

Yeah, I'm also for keeping BlockImport in consensus-primitives.
If execute_and_import_block is the problem, I'm okay with keeping BlockImport implemented in client.rs. Then we should tackle execute_and_import_block and remove the dependency on TaggedTransactionQueue.

@gavofyork gavofyork removed the F5-task label Dec 18, 2018
lamafab pushed a commit to lamafab/substrate that referenced this issue Jun 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
I7-refactor Code needs refactoring.
Projects
None yet
Development

No branches or pull requests

5 participants