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
Preparing light client structure [v2] #150
Merged
Merged
Changes from 3 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
79f5e0a
light client structure + remote call requests
svyatonik 20688c0
moved else
svyatonik 4c0b599
Remote + Local Backend/PolkadotApi traits
svyatonik 218b2ed
removed redundant header_hash
svyatonik f4070e2
introduce FetchChecker for Fetcher
svyatonik 6e04fb8
extracted LocalPolkadorApi to full submodule
svyatonik 5901a2a
Future as Fetcher result
svyatonik 7661c9f
fixed tests compilation
svyatonik d65c8d5
Merge branch 'master' into light_init
svyatonik cfe2cae
fixed tests after merge
svyatonik c681974
Merge branch 'master' into light_init
svyatonik 0d7e6ac
Merge branch 'master' into light_init
svyatonik 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
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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 |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| // Copyright 2017 Parity Technologies (UK) Ltd. | ||
| // This file is part of Polkadot. | ||
|
|
||
| // Polkadot is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
|
|
||
| // Polkadot is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU General Public License for more details. | ||
|
|
||
| // You should have received a copy of the GNU General Public License | ||
| // along with Polkadot. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| //! Strongly typed API for light Polkadot client. | ||
|
|
||
| use std::sync::Arc; | ||
| use client::backend::{Backend, RemoteBackend}; | ||
| use client::{Client, CallExecutor}; | ||
| use codec::Slicable; | ||
| use state_machine; | ||
| use primitives::{AccountId, BlockId, Hash, Index, SessionKey, Timestamp}; | ||
| use primitives::parachain::DutyRoster; | ||
| use runtime::{Block, UncheckedExtrinsic}; | ||
| use {PolkadotApi, RemotePolkadotApi, BlockBuilder, CheckedBlockId, CheckedId, Result, ErrorKind}; | ||
|
|
||
| /// Remote polkadot API implementation. | ||
| pub struct RemotePolkadotApiWrapper<B: Backend, E: CallExecutor>(pub Arc<Client<B, E>>); | ||
|
|
||
| /// Block builder for light client. | ||
| pub struct LightBlockBuilder; | ||
|
|
||
| impl<B: Backend, E: CallExecutor> PolkadotApi for RemotePolkadotApiWrapper<B, E> | ||
| where ::client::error::Error: From<<<B as Backend>::State as state_machine::backend::Backend>::Error> | ||
| { | ||
| type CheckedBlockId = CheckedId; | ||
| type BlockBuilder = LightBlockBuilder; | ||
|
|
||
| fn check_id(&self, id: BlockId) -> Result<CheckedId> { | ||
| Ok(CheckedId(id)) | ||
| } | ||
|
|
||
| fn session_keys(&self, at: &CheckedId) -> Result<Vec<SessionKey>> { | ||
| self.0.executor().call(at.block_id(), "authorities", &[]) | ||
| .and_then(|r| Vec::<SessionKey>::decode(&mut &r.return_data[..]) | ||
| .ok_or("error decoding session keys".into())) | ||
| .map_err(Into::into) | ||
| } | ||
|
|
||
| fn validators(&self, _at: &CheckedId) -> Result<Vec<AccountId>> { | ||
| Err(ErrorKind::UnknownRuntime.into()) | ||
| } | ||
|
|
||
| fn random_seed(&self, _at: &Self::CheckedBlockId) -> Result<Hash> { | ||
| Err(ErrorKind::UnknownRuntime.into()) | ||
| } | ||
|
|
||
| fn duty_roster(&self, _at: &CheckedId) -> Result<DutyRoster> { | ||
| Err(ErrorKind::UnknownRuntime.into()) | ||
| } | ||
|
|
||
| fn timestamp(&self, _at: &CheckedId) -> Result<Timestamp> { | ||
| Err(ErrorKind::UnknownRuntime.into()) | ||
| } | ||
|
|
||
| fn evaluate_block(&self, _at: &CheckedId, _block: Block) -> Result<()> { | ||
| Err(ErrorKind::UnknownRuntime.into()) | ||
| } | ||
|
|
||
| fn index(&self, _at: &CheckedId, _account: AccountId) -> Result<Index> { | ||
| Err(ErrorKind::UnknownRuntime.into()) | ||
| } | ||
|
|
||
| fn build_block(&self, _parent: &CheckedId, _timestamp: Timestamp) -> Result<Self::BlockBuilder> { | ||
| Err(ErrorKind::UnknownRuntime.into()) | ||
| } | ||
| } | ||
|
|
||
| impl<B: RemoteBackend, E: CallExecutor> RemotePolkadotApi for RemotePolkadotApiWrapper<B, E> | ||
| where ::client::error::Error: From<<<B as Backend>::State as state_machine::backend::Backend>::Error> | ||
| {} | ||
|
|
||
| impl BlockBuilder for LightBlockBuilder { | ||
| fn push_extrinsic(&mut self, _extrinsic: UncheckedExtrinsic) -> Result<()> { | ||
| Err(ErrorKind::UnknownRuntime.into()) | ||
| } | ||
|
|
||
| fn bake(self) -> Block { | ||
| unimplemented!() | ||
| } | ||
| } |
Oops, something went wrong.
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.
nit: since light clients are meant to be first-class we should also put the full client implementation in a submodule
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.
thanks, will do
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.
Tried to do this, but actually full client could be backed by db backend (which is already in the separate crate, named
db, not the full) and in-memory backend (which I guess could be renamed toTestBackend). So there's actually nothing to move to thefullsubmodule right now, except for db crate.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.
impl<B: LocalBackend> PolkadotApi for Client<B, LocalCallExecutor<B, NativeExecutor<LocalDispatch>>>looks like it could go in afullmodule.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.
right. missed that you're talking about Api, not about the client