forked from paritytech/substrate
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add consensus module * Fix runtime build error * Add api module * build all ok
- Loading branch information
Showing
17 changed files
with
1,404 additions
and
70 deletions.
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 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 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,21 @@ | ||
[package] | ||
name = "chainx-api" | ||
version = "0.1.0" | ||
authors = ["Chainpool <http://www.chainx.org>"] | ||
|
||
[dependencies] | ||
error-chain = "0.12" | ||
chainx-executor = { path = "../executor" } | ||
chainx-runtime = { path = "../runtime" } | ||
chainx-primitives = { path = "../primitives" } | ||
substrate-codec = { git = "https://github.com/chainx-org/substrate" } | ||
substrate-runtime-io = { git = "https://github.com/chainx-org/substrate" } | ||
substrate-runtime-executive = { git = "https://github.com/chainx-org/substrate" } | ||
substrate-runtime-primitives = { git = "https://github.com/chainx-org/substrate" } | ||
substrate-client = { git = "https://github.com/chainx-org/substrate" } | ||
substrate-primitives = { git = "https://github.com/chainx-org/substrate" } | ||
substrate-executor = { git = "https://github.com/chainx-org/substrate" } | ||
substrate-state-machine = { git = "https://github.com/chainx-org/substrate" } | ||
|
||
[dev-dependencies] | ||
substrate-keyring = { git = "https://github.com/chainx-org/substrate" } |
This file contains 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,115 @@ | ||
// Copyright 2018 chainpool. | ||
|
||
extern crate chainx_executor; | ||
extern crate chainx_primitives as primitives; | ||
extern crate chainx_runtime as runtime; | ||
extern crate substrate_codec as codec; | ||
extern crate substrate_runtime_io as runtime_io; | ||
extern crate substrate_client as client; | ||
extern crate substrate_executor as substrate_executor; | ||
extern crate substrate_runtime_executive; | ||
extern crate substrate_primitives; | ||
extern crate substrate_runtime_primitives as runtime_primitives; | ||
extern crate substrate_state_machine as state_machine; | ||
|
||
#[macro_use] | ||
extern crate error_chain; | ||
|
||
#[cfg(test)] | ||
extern crate substrate_keyring as keyring; | ||
|
||
|
||
use primitives::{ | ||
AccountId, Block, BlockId, Hash, Index, SessionKey, Timestamp, | ||
UncheckedExtrinsic, InherentData, | ||
}; | ||
use runtime::Address; | ||
|
||
error_chain! { | ||
errors { | ||
/// Unknown runtime code. | ||
UnknownRuntime { | ||
description("Unknown runtime code") | ||
display("Unknown runtime code") | ||
} | ||
/// Unknown block ID. | ||
UnknownBlock(b: String) { | ||
description("Unknown block") | ||
display("Unknown block {}", b) | ||
} | ||
/// Execution error. | ||
Execution(e: String) { | ||
description("Execution error") | ||
display("Execution error: {}", e) | ||
} | ||
/// Some other error. | ||
// TODO: allow to be specified as associated type of ChainXApi | ||
Other(e: Box<::std::error::Error + Send>) { | ||
description("Other error") | ||
display("Other error: {}", e.description()) | ||
} | ||
} | ||
} | ||
|
||
impl From<client::error::Error> for Error { | ||
fn from(e: client::error::Error) -> Error { | ||
match e { | ||
client::error::Error(client::error::ErrorKind::UnknownBlock(b), _) => Error::from_kind(ErrorKind::UnknownBlock(b)), | ||
client::error::Error(client::error::ErrorKind::Execution(e), _) => | ||
Error::from_kind(ErrorKind::Execution(format!("{}", e))), | ||
other => Error::from_kind(ErrorKind::Other(Box::new(other) as Box<_>)), | ||
} | ||
} | ||
} | ||
|
||
/// Build new blocks. | ||
pub trait BlockBuilder { | ||
/// Push an extrinsic onto the block. Fails if the extrinsic is invalid. | ||
fn push_extrinsic(&mut self, extrinsic: UncheckedExtrinsic) -> Result<()>; | ||
|
||
/// Bake the block with provided extrinsics. | ||
fn bake(self) -> Result<Block>; | ||
} | ||
|
||
/// Trait encapsulating the ChainX API. | ||
/// | ||
/// All calls should fail when the exact runtime is unknown. | ||
pub trait ChainXApi { | ||
/// The block builder for this API type. | ||
type BlockBuilder: BlockBuilder; | ||
|
||
/// Get session keys at a given block. | ||
fn session_keys(&self, at: &BlockId) -> Result<Vec<SessionKey>>; | ||
|
||
/// Get validators at a given block. | ||
fn validators(&self, at: &BlockId) -> Result<Vec<AccountId>>; | ||
|
||
/// Get the value of the randomness beacon at a given block. | ||
fn random_seed(&self, at: &BlockId) -> Result<Hash>; | ||
|
||
/// Get the timestamp registered at a block. | ||
fn timestamp(&self, at: &BlockId) -> Result<Timestamp>; | ||
|
||
/// Get the nonce (né index) of an account at a block. | ||
fn index(&self, at: &BlockId, account: AccountId) -> Result<Index>; | ||
|
||
/// Get the account id of an address at a block. | ||
fn lookup(&self, at: &BlockId, address: Address) -> Result<Option<AccountId>>; | ||
|
||
/// Evaluate a block. Returns true if the block is good, false if it is known to be bad, | ||
/// and an error if we can't evaluate for some reason. | ||
fn evaluate_block(&self, at: &BlockId, block: Block) -> Result<bool>; | ||
|
||
/// Build a block on top of the given, with inherent extrinsics pre-pushed. | ||
fn build_block(&self, at: &BlockId, inherent_data: InherentData) -> Result<Self::BlockBuilder>; | ||
|
||
/// Attempt to produce the (encoded) inherent extrinsics for a block being built upon the given. | ||
/// This may vary by runtime and will fail if a runtime doesn't follow the same API. | ||
fn inherent_extrinsics(&self, at: &BlockId, inherent_data: InherentData) -> Result<Vec<UncheckedExtrinsic>>; | ||
} | ||
|
||
/// Mark for all ChainX API implementations, that are making use of state data, stored locally. | ||
pub trait LocalChainXApi: ChainXApi {} | ||
|
||
/// Mark for all ChainX API implementations, that are fetching required state data from remote nodes. | ||
pub trait RemoteChainXApi: ChainXApi {} |
This file contains 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,29 @@ | ||
[package] | ||
name = "chainx-consensus" | ||
version = "0.1.0" | ||
authors = ["Chainpool <http://www.chainx.org>"] | ||
|
||
[dependencies] | ||
futures = "0.1.17" | ||
parking_lot = "0.4" | ||
tokio = "0.1.7" | ||
ed25519 = { git = "https://github.com/chainx-org/substrate" } | ||
error-chain = "0.12" | ||
log = "0.3" | ||
exit-future = "0.1" | ||
rhododendron = "0.3" | ||
substrate-bft = { git = "https://github.com/chainx-org/substrate" } | ||
substrate-codec = { git = "https://github.com/chainx-org/substrate" } | ||
substrate-primitives = { git = "https://github.com/chainx-org/substrate" } | ||
substrate-runtime-support = { git = "https://github.com/chainx-org/substrate" } | ||
substrate-client = { git = "https://github.com/chainx-org/substrate" } | ||
substrate-runtime-primitives = { git = "https://github.com/chainx-org/substrate" } | ||
substrate-network = { git = "https://github.com/chainx-org/substrate" } | ||
substrate-extrinsic-pool = { git = "https://github.com/chainx-org/substrate" } | ||
chainx-primitives = {path = "../primitives" } | ||
chainx-runtime = {path = "../runtime" } | ||
chainx-api = {path = "../api" } | ||
chainx-pool = {path = "../pool" } | ||
|
||
[dev-dependencies] | ||
substrate-keyring = { git = "https://github.com/chainx-org/substrate" } |
This file contains 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,41 @@ | ||
// Copyright 2018 Chainpool. | ||
|
||
//! Errors that can occur during the consensus process. | ||
|
||
use primitives::AuthorityId; | ||
|
||
error_chain! { | ||
links { | ||
ChainXApi(::chainx_api::Error, ::chainx_api::ErrorKind); | ||
Bft(::bft::Error, ::bft::ErrorKind); | ||
} | ||
|
||
errors { | ||
InvalidDutyRosterLength(expected: usize, got: usize) { | ||
description("Duty Roster had invalid length"), | ||
display("Invalid duty roster length: expected {}, got {}", expected, got), | ||
} | ||
NotValidator(id: AuthorityId) { | ||
description("Local account ID not a validator at this block."), | ||
display("Local account ID ({:?}) not a validator at this block.", id), | ||
} | ||
PrematureDestruction { | ||
description("Proposer destroyed before finishing proposing or evaluating"), | ||
display("Proposer destroyed before finishing proposing or evaluating"), | ||
} | ||
Timer(e: ::tokio::timer::Error) { | ||
description("Failed to register or resolve async timer."), | ||
display("Timer failed: {}", e), | ||
} | ||
Executor(e: ::futures::future::ExecuteErrorKind) { | ||
description("Unable to dispatch agreement future"), | ||
display("Unable to dispatch agreement future: {:?}", e), | ||
} | ||
} | ||
} | ||
|
||
impl From<::bft::InputStreamConcluded> for Error { | ||
fn from(err: ::bft::InputStreamConcluded) -> Self { | ||
::bft::Error::from(err).into() | ||
} | ||
} |
Oops, something went wrong.