Struct sc_client_db::offchain::LocalStorage
source · pub struct LocalStorage { /* private fields */ }
Expand description
Offchain local storage
Implementations§
source§impl LocalStorage
impl LocalStorage
sourcepub fn new(db: Arc<dyn Database<DbHash>>) -> Self
pub fn new(db: Arc<dyn Database<DbHash>>) -> Self
Create offchain local storage with given KeyValueDB
backend.
Examples found in repository?
src/lib.rs (line 1155)
1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194
fn from_database(
db: Arc<dyn Database<DbHash>>,
canonicalization_delay: u64,
config: &DatabaseSettings,
should_init: bool,
) -> ClientResult<Self> {
let mut db_init_transaction = Transaction::new();
let requested_state_pruning = config.state_pruning.clone();
let state_meta_db = StateMetaDb(db.clone());
let map_e = sp_blockchain::Error::from_state_db;
let (state_db_init_commit_set, state_db) = StateDb::open(
state_meta_db,
requested_state_pruning,
!db.supports_ref_counting(),
should_init,
)
.map_err(map_e)?;
apply_state_commit(&mut db_init_transaction, state_db_init_commit_set);
let state_pruning_used = state_db.pruning_mode();
let is_archive_pruning = state_pruning_used.is_archive();
let blockchain = BlockchainDb::new(db.clone())?;
let storage_db =
StorageDb { db: db.clone(), state_db, prefix_keys: !db.supports_ref_counting() };
let offchain_storage = offchain::LocalStorage::new(db.clone());
let backend = Backend {
storage: Arc::new(storage_db),
offchain_storage,
blockchain,
canonicalization_delay,
import_lock: Default::default(),
is_archive: is_archive_pruning,
io_stats: FrozenForDuration::new(std::time::Duration::from_secs(1)),
state_usage: Arc::new(StateUsageStats::new()),
blocks_pruning: config.blocks_pruning,
genesis_state: RwLock::new(None),
shared_trie_cache: config.trie_cache_maximum_size.map(|maximum_size| {
SharedTrieCache::new(sp_trie::cache::CacheSize::Maximum(maximum_size))
}),
};
// Older DB versions have no last state key. Check if the state is available and set it.
let info = backend.blockchain.info();
if info.finalized_state.is_none() &&
info.finalized_hash != Default::default() &&
sc_client_api::Backend::have_state_at(
&backend,
info.finalized_hash,
info.finalized_number,
) {
backend.blockchain.update_meta(MetaUpdate {
hash: info.finalized_hash,
number: info.finalized_number,
is_best: info.finalized_hash == info.best_hash,
is_finalized: true,
with_state: true,
});
}
db.commit(db_init_transaction)?;
Ok(backend)
}
Trait Implementations§
source§impl Clone for LocalStorage
impl Clone for LocalStorage
source§fn clone(&self) -> LocalStorage
fn clone(&self) -> LocalStorage
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for LocalStorage
impl Debug for LocalStorage
source§impl OffchainStorage for LocalStorage
impl OffchainStorage for LocalStorage
source§fn set(&mut self, prefix: &[u8], key: &[u8], value: &[u8])
fn set(&mut self, prefix: &[u8], key: &[u8], value: &[u8])
Persist a value in storage under given key and prefix.
source§fn remove(&mut self, prefix: &[u8], key: &[u8])
fn remove(&mut self, prefix: &[u8], key: &[u8])
Clear a storage entry under given key and prefix.
Auto Trait Implementations§
impl !RefUnwindSafe for LocalStorage
impl Send for LocalStorage
impl Sync for LocalStorage
impl Unpin for LocalStorage
impl !UnwindSafe for LocalStorage
Blanket Implementations§
source§impl<T> CheckedConversion for T
impl<T> CheckedConversion for T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Convert
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T, Outer> IsWrappedBy<Outer> for Twhere
Outer: AsRef<T> + AsMut<T> + From<T>,
T: From<Outer>,
impl<T, Outer> IsWrappedBy<Outer> for Twhere
Outer: AsRef<T> + AsMut<T> + From<T>,
T: From<Outer>,
§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<T> SaturatedConversion for T
impl<T> SaturatedConversion for T
source§fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
source§fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
Consume self to return an equivalent value of
T
. Read moresource§impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
source§fn unchecked_into(self) -> T
fn unchecked_into(self) -> T
The counterpart to
unchecked_from
.source§impl<T, S> UniqueSaturatedInto<T> for Swhere
T: Bounded,
S: TryInto<T>,
impl<T, S> UniqueSaturatedInto<T> for Swhere
T: Bounded,
S: TryInto<T>,
source§fn unique_saturated_into(self) -> T
fn unique_saturated_into(self) -> T
Consume self to return an equivalent value of
T
.