mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 10:31:04 +00:00
Refactor key management (#3296)
* Add Call type to extensible transactions. Cleanup some naming * Merge Resource and BlockExhausted into just Exhausted * Fix * Another fix * Call * Some fixes * Fix srml tests. * Fix all tests. * Refactor crypto so each application of it has its own type. * Introduce new AuthorityProvider API into Aura This will eventually allow for dynamic determination of authority keys and avoid having to set them directly on CLI. * Introduce authority determinator for Babe. Experiment with modular consensus API. * Work in progress to introduce KeyTypeId and avoid polluting API with validator IDs * Finish up drafting imonline * Rework offchain workers API. * Rework API implementation. * Make it compile for wasm, simplify app_crypto. * Fix compilation of im-online. * Fix compilation of im-online. * Fix more compilation errors. * Make it compile. * Fixing tests. * Rewrite `keystore` * Fix session tests * Bring back `TryFrom`'s' * Fix `srml-grandpa` * Fix `srml-aura` * Fix consensus babe * More fixes * Make service generate keys from dev_seed * Build fixes * Remove offchain tests * More fixes and cleanups * Fixes finality grandpa * Fix `consensus-aura` * Fix cli * Fix `node-cli` * Fix chain_spec builder * Fix doc tests * Add authority getter for grandpa. * Test fix * Fixes * Make keystore accessible from the runtime * Move app crypto to its own crate * Update `Cargo.lock` * Make the crypto stuff usable from the runtime * Adds some runtime crypto tests * Use last finalized block for grandpa authority * Fix warning * Adds `SessionKeys` runtime api * Remove `FinalityPair` and `ConsensusPair` * Minor governance tweaks to get it inline with docs. * Make the governance be up to date with the docs. * Build fixes. * Generate the inital session keys * Failing keystore is a hard error * Make babe work again * Fix grandpa * Fix tests * Disable `keystore` in consensus critical stuff * Build fix. * ImOnline supports multiple authorities at once. * Update core/application-crypto/src/ed25519.rs * Merge branch 'master' into gav-in-progress * Remove unneeded code for now. * Some `session` testing * Support querying the public keys * Cleanup offchain * Remove warnings * More cleanup * Apply suggestions from code review Co-Authored-By: Benjamin Kampmann <ben.kampmann@googlemail.com> * More cleanups * JSONRPC API for setting keys. Also, rename traits::KeyStore* -> traits::BareCryptoStore* * Bad merge * Fix integration tests * Fix test build * Test fix * Fixes * Warnings * Another warning * Bump version.
This commit is contained in:
@@ -20,66 +20,59 @@ use std::{
|
||||
marker::PhantomData, collections::{HashSet, BTreeMap, HashMap}, sync::Arc,
|
||||
panic::UnwindSafe, result, cell::RefCell, rc::Rc,
|
||||
};
|
||||
use crate::error::Error;
|
||||
use log::{info, trace, warn};
|
||||
use futures::channel::mpsc;
|
||||
use parking_lot::{Mutex, RwLock};
|
||||
use primitives::NativeOrEncoded;
|
||||
use sr_primitives::{
|
||||
Justification,
|
||||
generic::{BlockId, SignedBlock},
|
||||
};
|
||||
use consensus::{
|
||||
Error as ConsensusError, BlockImportParams,
|
||||
ImportResult, BlockOrigin, ForkChoiceStrategy,
|
||||
well_known_cache_keys::Id as CacheKeyId,
|
||||
SelectChain, self,
|
||||
};
|
||||
use sr_primitives::traits::{
|
||||
Block as BlockT, Header as HeaderT, Zero, NumberFor,
|
||||
ApiRef, ProvideRuntimeApi, SaturatedConversion, One, DigestFor,
|
||||
};
|
||||
use sr_primitives::generic::DigestItem;
|
||||
use sr_primitives::BuildStorage;
|
||||
use crate::runtime_api::{
|
||||
CallRuntimeAt, ConstructRuntimeApi, Core as CoreApi, ProofRecorder,
|
||||
InitializeBlock,
|
||||
};
|
||||
use codec::{Encode, Decode};
|
||||
use hash_db::{Hasher, Prefix};
|
||||
use primitives::{
|
||||
Blake2Hasher, H256, ChangesTrieConfiguration, convert_hash,
|
||||
NeverNativeValue, ExecutionContext
|
||||
NeverNativeValue, ExecutionContext,
|
||||
storage::{StorageKey, StorageData, well_known_keys}, NativeOrEncoded
|
||||
};
|
||||
use substrate_telemetry::{telemetry, SUBSTRATE_INFO};
|
||||
use sr_primitives::{
|
||||
Justification, BuildStorage,
|
||||
generic::{BlockId, SignedBlock, DigestItem},
|
||||
traits::{
|
||||
Block as BlockT, Header as HeaderT, Zero, NumberFor,
|
||||
ApiRef, ProvideRuntimeApi, SaturatedConversion, One, DigestFor,
|
||||
},
|
||||
};
|
||||
use primitives::storage::{StorageKey, StorageData};
|
||||
use primitives::storage::well_known_keys;
|
||||
use codec::{Encode, Decode};
|
||||
use state_machine::{
|
||||
DBValue, Backend as StateBackend, CodeExecutor, ChangesTrieAnchorBlockId,
|
||||
ExecutionStrategy, ExecutionManager, prove_read, prove_child_read,
|
||||
ChangesTrieRootsStorage, ChangesTrieStorage,
|
||||
key_changes, key_changes_proof, OverlayedChanges, NeverOffchainExt,
|
||||
};
|
||||
use hash_db::{Hasher, Prefix};
|
||||
|
||||
use crate::backend::{
|
||||
self, BlockImportOperation, PrunableStateChangesTrieStorage,
|
||||
StorageCollection, ChildStorageCollection
|
||||
};
|
||||
use crate::blockchain::{
|
||||
self, Info as ChainInfo, Backend as ChainBackend,
|
||||
HeaderBackend as ChainHeaderBackend, ProvideCache, Cache,
|
||||
};
|
||||
use crate::call_executor::{CallExecutor, LocalCallExecutor};
|
||||
use executor::{RuntimeVersion, RuntimeInfo};
|
||||
use crate::notifications::{StorageNotifications, StorageEventStream};
|
||||
use crate::light::{call_executor::prove_execution, fetcher::ChangesProof};
|
||||
use crate::cht;
|
||||
use crate::error;
|
||||
use crate::in_mem;
|
||||
use crate::block_builder::{self, api::BlockBuilder as BlockBuilderAPI};
|
||||
use crate::genesis;
|
||||
use substrate_telemetry::{telemetry, SUBSTRATE_INFO};
|
||||
|
||||
use log::{info, trace, warn};
|
||||
use consensus::{
|
||||
Error as ConsensusError, BlockImportParams,
|
||||
ImportResult, BlockOrigin, ForkChoiceStrategy,
|
||||
well_known_cache_keys::Id as CacheKeyId,
|
||||
SelectChain, self,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
runtime_api::{
|
||||
CallRuntimeAt, ConstructRuntimeApi, Core as CoreApi, ProofRecorder,
|
||||
InitializeBlock,
|
||||
},
|
||||
backend::{
|
||||
self, BlockImportOperation, PrunableStateChangesTrieStorage,
|
||||
StorageCollection, ChildStorageCollection
|
||||
},
|
||||
blockchain::{
|
||||
self, Info as ChainInfo, Backend as ChainBackend,
|
||||
HeaderBackend as ChainHeaderBackend, ProvideCache, Cache,
|
||||
},
|
||||
call_executor::{CallExecutor, LocalCallExecutor},
|
||||
notifications::{StorageNotifications, StorageEventStream},
|
||||
light::{call_executor::prove_execution, fetcher::ChangesProof},
|
||||
block_builder::{self, api::BlockBuilder as BlockBuilderAPI},
|
||||
error::Error,
|
||||
cht, error, in_mem, genesis
|
||||
};
|
||||
|
||||
/// Type that implements `futures::Stream` of block import events.
|
||||
pub type ImportNotifications<Block> = mpsc::UnboundedReceiver<BlockImportNotification<Block>>;
|
||||
@@ -260,6 +253,7 @@ impl<H> PrePostHeader<H> {
|
||||
pub fn new_in_mem<E, Block, S, RA>(
|
||||
executor: E,
|
||||
genesis_storage: S,
|
||||
keystore: Option<primitives::traits::BareCryptoStorePtr>,
|
||||
) -> error::Result<Client<
|
||||
in_mem::Backend<Block, Blake2Hasher>,
|
||||
LocalCallExecutor<in_mem::Backend<Block, Blake2Hasher>, E>,
|
||||
@@ -270,7 +264,7 @@ pub fn new_in_mem<E, Block, S, RA>(
|
||||
S: BuildStorage,
|
||||
Block: BlockT<Hash=H256>,
|
||||
{
|
||||
new_with_backend(Arc::new(in_mem::Backend::new()), executor, genesis_storage)
|
||||
new_with_backend(Arc::new(in_mem::Backend::new()), executor, genesis_storage, keystore)
|
||||
}
|
||||
|
||||
/// Create a client with the explicitly provided backend.
|
||||
@@ -279,6 +273,7 @@ pub fn new_with_backend<B, E, Block, S, RA>(
|
||||
backend: Arc<B>,
|
||||
executor: E,
|
||||
build_genesis_storage: S,
|
||||
keystore: Option<primitives::traits::BareCryptoStorePtr>,
|
||||
) -> error::Result<Client<B, LocalCallExecutor<B, E>, Block, RA>>
|
||||
where
|
||||
E: CodeExecutor<Blake2Hasher> + RuntimeInfo,
|
||||
@@ -286,10 +281,24 @@ pub fn new_with_backend<B, E, Block, S, RA>(
|
||||
Block: BlockT<Hash=H256>,
|
||||
B: backend::LocalBackend<Block, Blake2Hasher>
|
||||
{
|
||||
let call_executor = LocalCallExecutor::new(backend.clone(), executor);
|
||||
let call_executor = LocalCallExecutor::new(backend.clone(), executor, keystore);
|
||||
Client::new(backend, call_executor, build_genesis_storage, Default::default())
|
||||
}
|
||||
|
||||
/// Figure out the block type for a given type (for now, just a `Client`).
|
||||
pub trait BlockOf {
|
||||
/// The type of the block.
|
||||
type Type: BlockT<Hash=H256>;
|
||||
}
|
||||
|
||||
impl<B, E, Block, RA> BlockOf for Client<B, E, Block, RA> where
|
||||
B: backend::Backend<Block, Blake2Hasher>,
|
||||
E: CallExecutor<Block, Blake2Hasher>,
|
||||
Block: BlockT<Hash=H256>,
|
||||
{
|
||||
type Type = Block;
|
||||
}
|
||||
|
||||
impl<B, E, Block, RA> Client<B, E, Block, RA> where
|
||||
B: backend::Backend<Block, Blake2Hasher>,
|
||||
E: CallExecutor<Block, Blake2Hasher>,
|
||||
@@ -362,7 +371,8 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
|
||||
pub fn storage(&self, id: &BlockId<Block>, key: &StorageKey) -> error::Result<Option<StorageData>> {
|
||||
Ok(self.state_at(id)?
|
||||
.storage(&key.0).map_err(|e| error::Error::from_state(Box::new(e)))?
|
||||
.map(StorageData))
|
||||
.map(StorageData)
|
||||
)
|
||||
}
|
||||
|
||||
/// Given a `BlockId` and a key, return the value under the hash in that block.
|
||||
@@ -1414,6 +1424,8 @@ impl<B, E, Block, RA> CallRuntimeAt<Block> for Client<B, E, Block, RA> where
|
||||
context: ExecutionContext,
|
||||
recorder: &Option<Rc<RefCell<ProofRecorder<Block>>>>,
|
||||
) -> error::Result<NativeOrEncoded<R>> {
|
||||
let enable_keystore = context.enable_keystore();
|
||||
|
||||
let manager = match context {
|
||||
ExecutionContext::BlockConstruction =>
|
||||
self.execution_strategies.block_construction.get_manager(),
|
||||
@@ -1443,6 +1455,7 @@ impl<B, E, Block, RA> CallRuntimeAt<Block> for Client<B, E, Block, RA> where
|
||||
native_call,
|
||||
offchain_extensions.as_mut(),
|
||||
recorder,
|
||||
enable_keystore,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user