Use sign_with in consensus (#6008)

* Add derive_more to sp_core

* Convert Vec to Signature

* Use sign_with in AURA and BABE

* Signing errors

* Update slots to return consensus result

* Fix use

* Clone public key

* Match block_params

* WIP

* Use to_public_crypto_pair

* Pass public key only to block import params

* Address PR review

* Fix consensus RPC

* Fix babe tests

* adjust uses

* Fix line widths
This commit is contained in:
Rakan Alhneiti
2020-05-15 17:03:52 +02:00
committed by GitHub
parent 7a8d59199e
commit f36f57b0bf
12 changed files with 115 additions and 50 deletions
@@ -34,7 +34,11 @@ pub use codec;
#[cfg(feature = "std")]
pub use serde;
#[doc(hidden)]
pub use sp_std::{ops::Deref, vec::Vec};
pub use sp_std::{
convert::TryFrom,
ops::Deref,
vec::Vec,
};
pub mod ed25519;
pub mod sr25519;
@@ -457,6 +461,14 @@ macro_rules! app_crypto_signature_common {
impl $crate::AppSignature for Signature {
type Generic = $sig;
}
impl $crate::TryFrom<$crate::Vec<u8>> for Signature {
type Error = ();
fn try_from(data: $crate::Vec<u8>) -> Result<Self, Self::Error> {
Ok(<$sig>::try_from(data.as_slice())?.into())
}
}
}
}
@@ -17,7 +17,7 @@
//! Error types in Consensus
use sp_version::RuntimeVersion;
use sp_core::ed25519::{Public, Signature};
use sp_core::ed25519::Public;
use std::error;
/// Result type alias.
@@ -49,7 +49,7 @@ pub enum Error {
CannotPropose,
/// Error checking signature
#[display(fmt="Message signature {:?} by {:?} is invalid.", _0, _1)]
InvalidSignature(Signature, Public),
InvalidSignature(Vec<u8>, Vec<u8>),
/// Invalid authorities set received from the runtime.
#[display(fmt="Current state of blockchain has invalid authorities set")]
InvalidAuthoritiesSet,
@@ -80,6 +80,9 @@ pub enum Error {
#[display(fmt="Chain lookup failed: {}", _0)]
#[from(ignore)]
ChainLookup(String),
/// Signing failed
#[display(fmt="Failed to sign using key: {:?}. Reason: {}", _0, _1)]
CannotSign(Vec<u8>, String)
}
impl error::Error for Error {
+1
View File
@@ -13,6 +13,7 @@ documentation = "https://docs.rs/sp-core"
targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
derive_more = "0.99.2"
sp-std = { version = "2.0.0-dev", default-features = false, path = "../std" }
codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] }
log = { version = "0.4.8", default-features = false }
+6 -1
View File
@@ -32,17 +32,22 @@ use std::{
pub use sp_externalities::{Externalities, ExternalitiesExt};
/// BareCryptoStore error
#[derive(Debug)]
#[derive(Debug, derive_more::Display)]
pub enum BareCryptoStoreError {
/// Public key type is not supported
#[display(fmt="Key not supported: {:?}", _0)]
KeyNotSupported(KeyTypeId),
/// Pair not found for public key and KeyTypeId
#[display(fmt="Pair was not found: {}", _0)]
PairNotFound(String),
/// Validation error
#[display(fmt="Validation error: {}", _0)]
ValidationError(String),
/// Keystore unavailable
#[display(fmt="Keystore unavailable")]
Unavailable,
/// Programming errors
#[display(fmt="An unknown keystore error occurred: {}", _0)]
Other(String)
}