This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Polkadot service #82
Merged
Merged
Polkadot service #82
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
f22cbda
Block import notifications
arkpar a7e3f9d
Build fix
arkpar 197aaf2
Consensus messages supported in the networking
arkpar 9cb9410
Started consensus service
arkpar 6147304
Merge branch 'master' of github.com:paritytech/polkadot into ark-cons…
arkpar e96486e
Merge branch 'master' of github.com:paritytech/polkadot into ark-cons…
arkpar 0d5fe7c
BFT service
arkpar c808a91
Transaction propagation
arkpar b0f85b0
Polkadot service
arkpar 158a000
CLI integration
arkpar 1bbee71
Merge branch 'master' of github.com:paritytech/polkadot into ark-cons…
arkpar dd30b9c
Build fix
arkpar 41e28f6
Added signatures validation
arkpar 7c0ea3d
Removed executor argument
arkpar da31b51
Refactored steam loops; Queue size increased
arkpar 9e38d2d
Limit queue size
arkpar 884d3a1
Fixed doc comment
arkpar 153b93b
Merge branch 'master' of github.com:paritytech/polkadot into ark-cons…
arkpar a82a2e3
Fixed wasm build
arkpar 1572f14
Fixed wasm build
arkpar a4f656f
Check id properly
arkpar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
CLI integration
- Loading branch information
commit 158a0004edfcb567ef4575b3bad2fa3651642e1f
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,11 +24,11 @@ use std::sync::Arc; | |
| use futures::{future, Future, Stream, Sink, Async, Canceled}; | ||
| use parking_lot::Mutex; | ||
| use substrate_network as net; | ||
| use tokio_core::reactor::Core; | ||
| use tokio_core::reactor; | ||
| use client::BlockchainEvents; | ||
| use substrate_keyring::Keyring; | ||
| use primitives::{Hash, AuthorityId}; | ||
| use primitives::block::{Id as BlockId, HeaderHash}; | ||
| use primitives::block::{Id as BlockId, HeaderHash, Header}; | ||
| use polkadot_primitives::parachain::{BlockData, Extrinsic, CandidateReceipt}; | ||
| use polkadot_api::PolkadotApi; | ||
| use bft::{self, BftService}; | ||
|
|
@@ -86,28 +86,29 @@ struct Network(Arc<net::ConsensusService>); | |
|
|
||
| impl Service { | ||
| /// Create and start a new instance. | ||
| pub fn new<C>(client: Arc<C>, network: Arc<net::ConsensusService>, transaction_pool: Arc<Mutex<TransactionPool>>) -> Service | ||
| pub fn new<C>(client: Arc<C>, network: Arc<net::ConsensusService>, transaction_pool: Arc<Mutex<TransactionPool>>, best_header: &Header) -> Service | ||
| where C: BlockchainEvents + bft::BlockImport + bft::Authorities + PolkadotApi + Send + Sync + 'static | ||
| { | ||
| let best_header = best_header.clone(); | ||
| let thread = thread::spawn(move || { | ||
| let mut core = Core::new().expect("tokio::Core could not be created"); | ||
| let mut core = reactor::Core::new().expect("tokio::Core could not be created"); | ||
| let key = Arc::new(Keyring::One.into()); | ||
| let factory = ProposerFactory { | ||
| client: client.clone(), | ||
| transaction_pool: transaction_pool.clone(), | ||
| network: Network(network.clone()), | ||
| }; | ||
| let bft_service = BftService::new(client.clone(), key, factory); | ||
| // Kickstart BFT agreement on start. | ||
| if let Err(e) = Self::run_bft(&bft_service, network.clone(), &*client, core.handle(), &best_header) { | ||
| debug!("Error starting initial BFT agreement: {:?}", e); | ||
| } | ||
| loop { | ||
| let key = Arc::new(Keyring::One.into()); | ||
| let factory = ProposerFactory { | ||
| client: client.clone(), | ||
| transaction_pool: transaction_pool.clone(), | ||
| network: Network(network.clone()), | ||
| }; | ||
| let bft_service = BftService::new(client.clone(), key, factory); | ||
| let handle = core.handle(); | ||
| let start_bft = client.import_notification_stream().map(|notification| { | ||
| let hash = notification.header.hash(); | ||
| let authorities = client.authorities(&BlockId::Hash(hash))?; | ||
| let input = network.bft_messages() | ||
| .filter_map(move |message| Self::process_message(message, &authorities, hash.clone())) | ||
| .map_err(|_| bft::InputStreamConcluded.into()); | ||
| let output = BftSink { network: network.clone(), _e: Default::default() }; | ||
| bft_service.build_upon(¬ification.header, input, output, handle.clone()) | ||
| if let Err(e) = Self::run_bft(&bft_service, network.clone(), &*client, handle.clone(), ¬ification.header) { | ||
| debug!("Error starting BFT agreement: {:?}", e); | ||
| } | ||
| }).map_err(|e| debug!("BFT agreement error: {:?}", e)); | ||
| if let Err(_e) = core.run(start_bft.into_future()) { | ||
| debug!("BFT event loop stopped"); | ||
|
|
@@ -116,10 +117,23 @@ impl Service { | |
| } | ||
| }); | ||
| Service { | ||
| thread: Some(thread), | ||
| thread: Some(thread) | ||
| } | ||
| } | ||
|
|
||
| fn run_bft<C, P>(bft_service: &BftService<P, C>, network: Arc<net::ConsensusService>, client: &C, handle: reactor::Handle, header: &Header) -> Result<(), <P as bft::ProposerFactory>::Error> where | ||
|
||
| C: bft::Authorities + bft::BlockImport + Send + Sync + 'static, | ||
| P: bft::ProposerFactory + 'static, | ||
| { | ||
| let hash = header.hash(); | ||
| let authorities = client.authorities(&BlockId::Hash(hash))?; | ||
| let input = network.bft_messages() | ||
| .filter_map(move |message| Self::process_message(message, &authorities, hash.clone())) | ||
| .map_err(|_| bft::InputStreamConcluded.into()); | ||
| let output = BftSink { network: network.clone(), _e: Default::default() }; | ||
| bft_service.build_upon(&header, input, output, handle.clone()) | ||
| } | ||
|
|
||
| fn process_message(msg: net::BftMessage, authorities: &[AuthorityId], parent_hash: HeaderHash) -> Option<bft::Communication> { | ||
|
||
| // TODO: check all signatures | ||
| Some(match msg { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
instead of doing this in a loop, couldn't we do
let bft_starter = client.import_notification_stream().for_each(|notification| ...)andcore.run(bft_starter)?