mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-18 01:21:01 +00:00
Removal of execution strategies (#14387)
* Start * More work! * Moar * More changes * More fixes * More worrk * More fixes * More fixes to make it compile * Adds `NoOffchainStorage` * Pass the extensions * Small basti making small progress * Fix merge errors and remove `ExecutionContext` * Move registration of `ReadRuntimeVersionExt` to `ExecutionExtension` Instead of registering `ReadRuntimeVersionExt` in `sp-state-machine` it is moved to `ExecutionExtension` which provides the default extensions. * Fix compilation * Register the global extensions inside runtime api instance * Fixes * Fix `generate_initial_session_keys` by passing the keystore extension * Fix the grandpa tests * Fix more tests * Fix more tests * Don't set any heap pages if there isn't an override * Fix small fallout * FMT * Fix tests * More tests * Offchain worker custom extensions * More fixes * Make offchain tx pool creation reusable Introduces an `OffchainTransactionPoolFactory` for creating offchain transactions pools that can be registered in the runtime externalities context. This factory will be required for a later pr to make the creation of offchain transaction pools easier. * Fixes * Fixes * Set offchain transaction pool in BABE before using it in the runtime * Add the `offchain_tx_pool` to Grandpa as well * Fix the nodes * Print some error when using the old warnings * Fix merge issues * Fix compilation * Rename `babe_link` * Rename to `offchain_tx_pool_factory` * Cleanup * FMT * Fix benchmark name * Fix `try-runtime` * Remove `--execution` CLI args * Make clippy happy * Forward bls functions * Fix docs * Update UI tests * Update client/api/src/execution_extensions.rs Co-authored-by: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Koute <koute@users.noreply.github.com> * Update client/cli/src/params/import_params.rs Co-authored-by: Koute <koute@users.noreply.github.com> * Update client/api/src/execution_extensions.rs Co-authored-by: Koute <koute@users.noreply.github.com> * Pass the offchain storage to the MMR RPC * Update client/api/src/execution_extensions.rs Co-authored-by: Sebastian Kunert <skunert49@gmail.com> * Review comments * Fixes --------- Co-authored-by: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Co-authored-by: Koute <koute@users.noreply.github.com> Co-authored-by: Sebastian Kunert <skunert49@gmail.com>
This commit is contained in:
@@ -25,8 +25,8 @@ pub use http::SharedClient;
|
||||
use libp2p::{Multiaddr, PeerId};
|
||||
use sp_core::{
|
||||
offchain::{
|
||||
self, HttpError, HttpRequestId, HttpRequestStatus, OffchainStorage, OpaqueMultiaddr,
|
||||
OpaqueNetworkState, StorageKind, Timestamp,
|
||||
self, HttpError, HttpRequestId, HttpRequestStatus, OpaqueMultiaddr, OpaqueNetworkState,
|
||||
Timestamp,
|
||||
},
|
||||
OpaquePeerId,
|
||||
};
|
||||
@@ -36,110 +36,6 @@ mod http;
|
||||
|
||||
mod timestamp;
|
||||
|
||||
fn unavailable_yet<R: Default>(name: &str) -> R {
|
||||
tracing::error!(
|
||||
target: super::LOG_TARGET,
|
||||
"The {:?} API is not available for offchain workers yet. Follow \
|
||||
https://github.com/paritytech/substrate/issues/1458 for details",
|
||||
name
|
||||
);
|
||||
Default::default()
|
||||
}
|
||||
|
||||
const LOCAL_DB: &str = "LOCAL (fork-aware) DB";
|
||||
|
||||
/// Offchain DB reference.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Db<Storage> {
|
||||
/// Persistent storage database.
|
||||
persistent: Storage,
|
||||
}
|
||||
|
||||
impl<Storage: OffchainStorage> Db<Storage> {
|
||||
/// Create new instance of Offchain DB.
|
||||
pub fn new(persistent: Storage) -> Self {
|
||||
Self { persistent }
|
||||
}
|
||||
|
||||
/// Create new instance of Offchain DB, backed by given backend.
|
||||
pub fn factory_from_backend<Backend, Block>(
|
||||
backend: &Backend,
|
||||
) -> Option<Box<dyn sc_client_api::execution_extensions::DbExternalitiesFactory>>
|
||||
where
|
||||
Backend: sc_client_api::Backend<Block, OffchainStorage = Storage>,
|
||||
Block: sp_runtime::traits::Block,
|
||||
Storage: 'static,
|
||||
{
|
||||
sc_client_api::Backend::offchain_storage(backend).map(|db| Box::new(Self::new(db)) as _)
|
||||
}
|
||||
}
|
||||
|
||||
impl<Storage: OffchainStorage> offchain::DbExternalities for Db<Storage> {
|
||||
fn local_storage_set(&mut self, kind: StorageKind, key: &[u8], value: &[u8]) {
|
||||
tracing::debug!(
|
||||
target: "offchain-worker::storage",
|
||||
?kind,
|
||||
key = ?array_bytes::bytes2hex("", key),
|
||||
value = ?array_bytes::bytes2hex("", value),
|
||||
"Write",
|
||||
);
|
||||
match kind {
|
||||
StorageKind::PERSISTENT => self.persistent.set(STORAGE_PREFIX, key, value),
|
||||
StorageKind::LOCAL => unavailable_yet(LOCAL_DB),
|
||||
}
|
||||
}
|
||||
|
||||
fn local_storage_clear(&mut self, kind: StorageKind, key: &[u8]) {
|
||||
tracing::debug!(
|
||||
target: "offchain-worker::storage",
|
||||
?kind,
|
||||
key = ?array_bytes::bytes2hex("", key),
|
||||
"Clear",
|
||||
);
|
||||
match kind {
|
||||
StorageKind::PERSISTENT => self.persistent.remove(STORAGE_PREFIX, key),
|
||||
StorageKind::LOCAL => unavailable_yet(LOCAL_DB),
|
||||
}
|
||||
}
|
||||
|
||||
fn local_storage_compare_and_set(
|
||||
&mut self,
|
||||
kind: StorageKind,
|
||||
key: &[u8],
|
||||
old_value: Option<&[u8]>,
|
||||
new_value: &[u8],
|
||||
) -> bool {
|
||||
tracing::debug!(
|
||||
target: "offchain-worker::storage",
|
||||
?kind,
|
||||
key = ?array_bytes::bytes2hex("", key),
|
||||
new_value = ?array_bytes::bytes2hex("", new_value),
|
||||
old_value = ?old_value.as_ref().map(|s| array_bytes::bytes2hex("", s)),
|
||||
"CAS",
|
||||
);
|
||||
match kind {
|
||||
StorageKind::PERSISTENT =>
|
||||
self.persistent.compare_and_set(STORAGE_PREFIX, key, old_value, new_value),
|
||||
StorageKind::LOCAL => unavailable_yet(LOCAL_DB),
|
||||
}
|
||||
}
|
||||
|
||||
fn local_storage_get(&mut self, kind: StorageKind, key: &[u8]) -> Option<Vec<u8>> {
|
||||
let result = match kind {
|
||||
StorageKind::PERSISTENT => self.persistent.get(STORAGE_PREFIX, key),
|
||||
StorageKind::LOCAL => unavailable_yet(LOCAL_DB),
|
||||
};
|
||||
tracing::debug!(
|
||||
target: "offchain-worker::storage",
|
||||
?kind,
|
||||
key = ?array_bytes::bytes2hex("", key),
|
||||
result = ?result.as_ref().map(|s| array_bytes::bytes2hex("", s)),
|
||||
"Read",
|
||||
);
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
/// Asynchronous offchain API.
|
||||
///
|
||||
/// NOTE this is done to prevent recursive calls into the runtime
|
||||
@@ -329,7 +225,7 @@ mod tests {
|
||||
config::MultiaddrWithPeerId, types::ProtocolName, NetworkPeers, NetworkStateInfo,
|
||||
ReputationChange,
|
||||
};
|
||||
use sp_core::offchain::{DbExternalities, Externalities};
|
||||
use sp_core::offchain::{storage::OffchainDb, DbExternalities, Externalities, StorageKind};
|
||||
use std::time::SystemTime;
|
||||
|
||||
pub(super) struct TestNetwork();
|
||||
@@ -418,8 +314,8 @@ mod tests {
|
||||
AsyncApi::new(mock, false, shared_client)
|
||||
}
|
||||
|
||||
fn offchain_db() -> Db<LocalStorage> {
|
||||
Db::new(LocalStorage::new_test())
|
||||
fn offchain_db() -> OffchainDb<LocalStorage> {
|
||||
OffchainDb::new(LocalStorage::new_test())
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user