@@ -32,18 +32,20 @@ pub use crate::trie::{
3232 update:: TrieUpdateValuePtr , KeyForStateChanges , PartialStorage , ShardTries , Trie , TrieChanges ,
3333 WrappedTrieChanges ,
3434} ;
35+ use std:: ops:: Deref ;
36+ use std:: pin:: Pin ;
3537
3638mod db;
3739pub mod migrations;
3840pub mod test_utils;
3941mod trie;
4042
4143pub struct Store {
42- storage : Arc < dyn Database > ,
44+ storage : Pin < Arc < dyn Database > > ,
4345}
4446
4547impl Store {
46- pub fn new ( storage : Arc < dyn Database > ) -> Store {
48+ pub fn new ( storage : Pin < Arc < dyn Database > > ) -> Store {
4749 Store { storage }
4850 }
4951
@@ -134,14 +136,14 @@ impl Store {
134136
135137/// Keeps track of current changes to the database and can commit all of them to the database.
136138pub struct StoreUpdate {
137- storage : Arc < dyn Database > ,
139+ storage : Pin < Arc < dyn Database > > ,
138140 transaction : DBTransaction ,
139141 /// Optionally has reference to the trie to clear cache on the commit.
140142 tries : Option < ShardTries > ,
141143}
142144
143145impl StoreUpdate {
144- pub fn new ( storage : Arc < dyn Database > ) -> Self {
146+ pub fn new ( storage : Pin < Arc < dyn Database > > ) -> Self {
145147 let transaction = storage. transaction ( ) ;
146148 StoreUpdate { storage, transaction, tries : None }
147149 }
@@ -178,8 +180,8 @@ impl StoreUpdate {
178180 self . tries = Some ( tries) ;
179181 } else {
180182 debug_assert_eq ! (
181- self . tries. as_ref( ) . unwrap( ) . tries . as_ref( ) as * const _,
182- tries. tries . as_ref( ) as * const _
183+ self . tries. as_ref( ) . unwrap( ) . caches . as_ref( ) as * const _,
184+ tries. caches . as_ref( ) as * const _
183185 ) ;
184186 }
185187 }
@@ -215,8 +217,8 @@ impl StoreUpdate {
215217 ) ;
216218 if let Some ( tries) = self . tries {
217219 assert_eq ! (
218- tries. get_store( ) . storage. as_ref ( ) as * const _,
219- self . storage. as_ref ( ) as * const _
220+ tries. get_store( ) . storage. deref ( ) as * const _,
221+ self . storage. deref ( ) as * const _
220222 ) ;
221223 tries. update_cache ( & self . transaction ) ?;
222224 }
@@ -255,7 +257,7 @@ pub fn read_with_cache<'a, T: BorshDeserialize + 'a>(
255257}
256258
257259pub fn create_store ( path : & str ) -> Arc < Store > {
258- let db = Arc :: new ( RocksDB :: new ( path) . expect ( "Failed to open the database" ) ) ;
260+ let db = Arc :: pin ( RocksDB :: new ( path) . expect ( "Failed to open the database" ) ) ;
259261 Arc :: new ( Store :: new ( db) )
260262}
261263
0 commit comments