Skip to content

Commit

Permalink
Make sp-keystore no_std-compatible and fix the `build-runtimes-po…
Browse files Browse the repository at this point in the history
…lkavm` CI job (#3363)

Fixes #3352
  • Loading branch information
koute authored Feb 18, 2024
1 parent 6185b00 commit b179b83
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 19 deletions.
1 change: 0 additions & 1 deletion .gitlab/pipeline/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,6 @@ build-runtimes-polkavm:
- SUBSTRATE_RUNTIME_TARGET=riscv cargo check -p westend-runtime
- SUBSTRATE_RUNTIME_TARGET=riscv cargo check -p rococo-runtime
- SUBSTRATE_RUNTIME_TARGET=riscv cargo check -p polkadot-test-runtime
allow_failure: true

.build-subkey:
stage: build
Expand Down
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions substrate/primitives/externalities/src/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,24 @@ macro_rules! decl_extension {
$vis struct $ext_name (pub $inner);

impl $crate::Extension for $ext_name {
fn as_mut_any(&mut self) -> &mut dyn std::any::Any {
fn as_mut_any(&mut self) -> &mut dyn core::any::Any {
self
}

fn type_id(&self) -> std::any::TypeId {
std::any::Any::type_id(self)
fn type_id(&self) -> core::any::TypeId {
core::any::Any::type_id(self)
}
}

impl std::ops::Deref for $ext_name {
impl core::ops::Deref for $ext_name {
type Target = $inner;

fn deref(&self) -> &Self::Target {
&self.0
}
}

impl std::ops::DerefMut for $ext_name {
impl core::ops::DerefMut for $ext_name {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
Expand All @@ -115,12 +115,12 @@ macro_rules! decl_extension {
$vis struct $ext_name;

impl $crate::Extension for $ext_name {
fn as_mut_any(&mut self) -> &mut dyn std::any::Any {
fn as_mut_any(&mut self) -> &mut dyn core::any::Any {
self
}

fn type_id(&self) -> std::any::TypeId {
std::any::Any::type_id(self)
fn type_id(&self) -> core::any::TypeId {
core::any::Any::type_id(self)
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions substrate/primitives/keystore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = ["derive"] }
parking_lot = { version = "0.12.1", default-features = false }
thiserror = "1.0"
parking_lot = { version = "0.12.1", default-features = false, optional = true }
sp-core = { path = "../core", default-features = false }
sp-externalities = { path = "../externalities", default-features = false }

Expand All @@ -28,7 +27,7 @@ rand_chacha = "0.2.2"

[features]
default = ["std"]
std = ["codec/std", "sp-core/std", "sp-externalities/std"]
std = ["codec/std", "dep:parking_lot", "sp-core/std", "sp-externalities/std"]

# This feature adds BLS crypto primitives.
# It should not be used in production since the implementation and interface may still
Expand Down
26 changes: 20 additions & 6 deletions substrate/primitives/keystore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

//! Keystore traits
#![cfg_attr(not(feature = "std"), no_std)]

extern crate alloc;

#[cfg(feature = "std")]
pub mod testing;

Expand All @@ -29,25 +33,35 @@ use sp_core::{
ecdsa, ed25519, sr25519,
};

use std::sync::Arc;
use alloc::{string::String, sync::Arc, vec::Vec};

/// Keystore error
#[derive(Debug, thiserror::Error)]
#[derive(Debug)]
pub enum Error {
/// Public key type is not supported
#[error("Key not supported: {0:?}")]
KeyNotSupported(KeyTypeId),
/// Validation error
#[error("Validation error: {0}")]
ValidationError(String),
/// Keystore unavailable
#[error("Keystore unavailable")]
Unavailable,
/// Programming errors
#[error("An unknown keystore error occurred: {0}")]
Other(String),
}

impl core::fmt::Display for Error {
fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::fmt::Result {
match self {
Error::KeyNotSupported(key_type) => write!(fmt, "Key not supported: {key_type:?}"),
Error::ValidationError(error) => write!(fmt, "Validation error: {error}"),
Error::Unavailable => fmt.write_str("Keystore unavailable"),
Error::Other(error) => write!(fmt, "An unknown keystore error occurred: {error}"),
}
}
}

#[cfg(feature = "std")]
impl std::error::Error for Error {}

/// Something that generates, stores and provides access to secret keys.
pub trait Keystore: Send + Sync {
/// Returns all the sr25519 public keys for the given key type.
Expand Down

0 comments on commit b179b83

Please sign in to comment.