This repository has been 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.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* instant/manual seal unbounded queues are evil Apply suggestions from code review Co-Authored-By: Robert Habermeier <rphmeier@gmail.com> add fork tests, docs, remove todos moar docs Update client/consensus/manual-seal/src/rpc.rs Co-Authored-By: Robert Habermeier <rphmeier@gmail.com> remove unbound generic, parameter, docs, deps, code style changes Apply suggestions from code review Co-Authored-By: Tomasz Drwięga <tomusdrw@users.noreply.github.com> code style chnges remove unused deps, remove dep renames, check if block is empty before importing, use ? for error propagation fix tests log errors for instant seal use debug code style changes, updated copyright dates use txpool::Pool instead of BasicPool, code style changes fixed tests * fix tests * requested changes from review * check inherents len * rebase
- Loading branch information
1 parent
d56db2b
commit 03ffa5a
Showing
18 changed files
with
1,521 additions
and
469 deletions.
There are no files selected for viewing
Empty file.
Large diffs are not rendered by default.
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
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,32 @@ | ||
[package] | ||
name = "sc-consensus-manual-seal" | ||
version = "0.8.0" | ||
authors = ["Parity Technologies <admin@parity.io>"] | ||
description = "Manual sealing engine for Substrate" | ||
edition = "2018" | ||
|
||
[dependencies] | ||
derive_more = "0.99.2" | ||
futures = "0.3.1" | ||
jsonrpc-core = "14.0.5" | ||
jsonrpc-core-client = "14.0.5" | ||
jsonrpc-derive = "14.0.5" | ||
log = "0.4.8" | ||
parking_lot = "0.10" | ||
serde = { version = "1.0", features=["derive"] } | ||
|
||
sc-client = { path = "../../../client" } | ||
sc-client-api = { path = "../../../client/api" } | ||
sc-transaction-pool = { path = "../../transaction-pool", features = ["test-helpers"] } | ||
sp-blockchain = { path = "../../../primitives/blockchain" } | ||
sp-consensus = { package = "sp-consensus", path = "../../../primitives/consensus/common" } | ||
sp-inherents = { path = "../../../primitives/inherents" } | ||
sp-runtime = { path = "../../../primitives/runtime" } | ||
sp-transaction-pool = { path = "../../../primitives/transaction-pool" } | ||
|
||
[dev-dependencies] | ||
sc-basic-authorship = { path = "../../basic-authorship" } | ||
substrate-test-runtime-client = { path = "../../../test-utils/runtime/client" } | ||
tokio = { version = "0.2", features = ["rt-core", "macros"] } | ||
env_logger = "0.7.0" | ||
tempfile = "3.1.0" |
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,98 @@ | ||
// Copyright 2020 Parity Technologies (UK) Ltd. | ||
// This file is part of Substrate. | ||
|
||
// Substrate 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. | ||
|
||
// Substrate 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 Substrate. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
//! A manual sealing engine: the engine listens for rpc calls to seal blocks and create forks. | ||
//! This is suitable for a testing environment. | ||
use sp_consensus::{Error as ConsensusError, ImportResult}; | ||
use sp_blockchain::Error as BlockchainError; | ||
use sp_inherents::Error as InherentsError; | ||
use futures::channel::{oneshot, mpsc::SendError}; | ||
|
||
/// Error code for rpc | ||
mod codes { | ||
pub const SERVER_SHUTTING_DOWN: i64 = 10_000; | ||
pub const BLOCK_IMPORT_FAILED: i64 = 11_000; | ||
pub const EMPTY_TRANSACTION_POOL: i64 = 12_000; | ||
pub const BLOCK_NOT_FOUND: i64 = 13_000; | ||
pub const CONSENSUS_ERROR: i64 = 14_000; | ||
pub const INHERENTS_ERROR: i64 = 15_000; | ||
pub const BLOCKCHAIN_ERROR: i64 = 16_000; | ||
pub const UNKNOWN_ERROR: i64 = 20_000; | ||
} | ||
|
||
/// errors encountered by background block authorship task | ||
#[derive(Debug, derive_more::Display, derive_more::From)] | ||
pub enum Error { | ||
/// An error occurred while importing the block | ||
#[display(fmt = "Block import failed: {:?}", _0)] | ||
BlockImportError(ImportResult), | ||
/// Transaction pool is empty, cannot create a block | ||
#[display(fmt = "Transaction pool is empty, set create_empty to true,\ | ||
if you want to create empty blocks")] | ||
EmptyTransactionPool, | ||
/// encountered during creation of Proposer. | ||
#[display(fmt = "Consensus Error: {}", _0)] | ||
ConsensusError(ConsensusError), | ||
/// Failed to create Inherents data | ||
#[display(fmt = "Inherents Error: {}", _0)] | ||
InherentError(InherentsError), | ||
/// error encountered during finalization | ||
#[display(fmt = "Finalization Error: {}", _0)] | ||
BlockchainError(BlockchainError), | ||
/// Supplied parent_hash doesn't exist in chain | ||
#[display(fmt = "Supplied parent_hash: {} doesn't exist in chain", _0)] | ||
#[from(ignore)] | ||
BlockNotFound(String), | ||
/// Some string error | ||
#[display(fmt = "{}", _0)] | ||
#[from(ignore)] | ||
StringError(String), | ||
///send error | ||
#[display(fmt = "Consensus process is terminating")] | ||
Canceled(oneshot::Canceled), | ||
///send error | ||
#[display(fmt = "Consensus process is terminating")] | ||
SendError(SendError), | ||
/// Some other error. | ||
#[display(fmt="Other error: {}", _0)] | ||
Other(Box<dyn std::error::Error + Send>), | ||
} | ||
|
||
impl Error { | ||
fn to_code(&self) -> i64 { | ||
use Error::*; | ||
match self { | ||
BlockImportError(_) => codes::BLOCK_IMPORT_FAILED, | ||
BlockNotFound(_) => codes::BLOCK_NOT_FOUND, | ||
EmptyTransactionPool => codes::EMPTY_TRANSACTION_POOL, | ||
ConsensusError(_) => codes::CONSENSUS_ERROR, | ||
InherentError(_) => codes::INHERENTS_ERROR, | ||
BlockchainError(_) => codes::BLOCKCHAIN_ERROR, | ||
SendError(_) | Canceled(_) => codes::SERVER_SHUTTING_DOWN, | ||
_ => codes::UNKNOWN_ERROR | ||
} | ||
} | ||
} | ||
|
||
impl std::convert::From<Error> for jsonrpc_core::Error { | ||
fn from(error: Error) -> Self { | ||
jsonrpc_core::Error { | ||
code: jsonrpc_core::ErrorCode::ServerError(error.to_code()), | ||
message: format!("{}", error), | ||
data: None | ||
} | ||
} | ||
} |
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,64 @@ | ||
// Copyright 2019 Parity Technologies (UK) Ltd. | ||
// This file is part of Substrate. | ||
|
||
// Substrate 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. | ||
|
||
// Substrate 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 Substrate. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
//! Block finalization utilities | ||
|
||
use crate::rpc; | ||
use sp_runtime::{ | ||
Justification, | ||
traits::Block as BlockT, | ||
generic::BlockId, | ||
}; | ||
use std::sync::Arc; | ||
use sc_client_api::backend::Backend as ClientBackend; | ||
|
||
/// params for block finalization. | ||
pub struct FinalizeBlockParams<B: BlockT, CB> { | ||
/// hash of the block | ||
pub hash: <B as BlockT>::Hash, | ||
/// sender to report errors/success to the rpc. | ||
pub sender: rpc::Sender<()>, | ||
/// finalization justification | ||
pub justification: Option<Justification>, | ||
/// client backend | ||
pub backend: Arc<CB>, | ||
} | ||
|
||
/// finalizes a block in the backend with the given params. | ||
pub async fn finalize_block<B, CB>(params: FinalizeBlockParams<B, CB>) | ||
where | ||
B: BlockT, | ||
CB: ClientBackend<B>, | ||
{ | ||
let FinalizeBlockParams { | ||
hash, | ||
mut sender, | ||
justification, | ||
backend: back_end, | ||
.. | ||
} = params; | ||
|
||
match back_end.finalize_block(BlockId::Hash(hash), justification) { | ||
Err(e) => { | ||
log::warn!("Failed to finalize block {:?}", e); | ||
rpc::send_result(&mut sender, Err(e.into())) | ||
} | ||
Ok(()) => { | ||
log::info!("Successfully finalized block: {}", hash); | ||
rpc::send_result(&mut sender, Ok(())) | ||
} | ||
} | ||
} |
Oops, something went wrong.