@@ -11,6 +11,7 @@ use crate::networks::{ChainConfig, Height};
1111use crate :: rpc:: eth:: { eth_tx_from_signed_eth_message, types:: EthHash } ;
1212use crate :: shim:: clock:: ChainEpoch ;
1313use crate :: shim:: { executor:: Receipt , message:: Message , version:: NetworkVersion } ;
14+ use crate :: utils:: ShallowClone ;
1415use crate :: utils:: db:: { BlockstoreExt , CborStoreExt } ;
1516use crate :: {
1617 blocks:: { CachingBlockHeader , Tipset , TipsetKey , TxMeta } ,
@@ -76,7 +77,7 @@ pub struct ChainStore<DB> {
7677 f3_finalized_tipset : Arc < RwLock < Option < Tipset > > > ,
7778
7879 /// Used as a cache for tipset `lookbacks`.
79- chain_index : Arc < ChainIndex < Arc < DB > > > ,
80+ chain_index : ChainIndex < DB > ,
8081
8182 /// Tracks blocks for the purpose of forming tipsets.
8283 tipset_tracker : TipsetTracker < DB > ,
@@ -144,22 +145,20 @@ where
144145 } ;
145146 let heaviest_tipset = Arc :: new ( RwLock :: new ( head) ) ;
146147 let f3_finalized_tipset: Arc < RwLock < Option < Tipset > > > = Default :: default ( ) ;
147- let chain_index = Arc :: new (
148- ChainIndex :: new ( db. clone ( ) ) . with_is_tipset_finalized ( Box :: new ( {
149- let chain_finality = chain_config. policy . chain_finality ;
150- let heaviest_tipset = heaviest_tipset. clone ( ) ;
151- let f3_finalized_tipset = f3_finalized_tipset. clone ( ) ;
152- move |ts| {
153- let finalized = f3_finalized_tipset
154- . read ( )
155- . as_ref ( )
156- . map ( |ts| ts. epoch ( ) )
157- . unwrap_or_default ( )
158- . max ( heaviest_tipset. read ( ) . epoch ( ) - chain_finality) ;
159- ts. epoch ( ) <= finalized
160- }
161- } ) ) ,
162- ) ;
148+ let chain_index = ChainIndex :: new ( db. clone ( ) ) . with_is_tipset_finalized ( Arc :: new ( {
149+ let chain_finality = chain_config. policy . chain_finality ;
150+ let heaviest_tipset = heaviest_tipset. clone ( ) ;
151+ let f3_finalized_tipset = f3_finalized_tipset. clone ( ) ;
152+ move |ts| {
153+ let finalized = f3_finalized_tipset
154+ . read ( )
155+ . as_ref ( )
156+ . map ( |ts| ts. epoch ( ) )
157+ . unwrap_or_default ( )
158+ . max ( heaviest_tipset. read ( ) . epoch ( ) - chain_finality) ;
159+ ts. epoch ( ) <= finalized
160+ }
161+ } ) ) ;
163162 let cs = Self {
164163 head_changes_tx : publisher,
165164 chain_index,
@@ -290,7 +289,7 @@ where
290289 }
291290
292291 /// Returns the chain index
293- pub fn chain_index ( & self ) -> & Arc < ChainIndex < Arc < DB > > > {
292+ pub fn chain_index ( & self ) -> & ChainIndex < DB > {
294293 & self . chain_index
295294 }
296295
@@ -393,7 +392,7 @@ where
393392 /// is usually 900. The `heaviest_tipset` is a reference point in the
394393 /// blockchain. It must be a child of the look-back tipset.
395394 pub fn get_lookback_tipset_for_round (
396- chain_index : & Arc < ChainIndex < Arc < DB > > > ,
395+ chain_index : & ChainIndex < DB > ,
397396 chain_config : & Arc < ChainConfig > ,
398397 heaviest_tipset : & Tipset ,
399398 round : ChainEpoch ,
@@ -417,8 +416,8 @@ where
417416 let beacon = Arc :: new ( chain_config. get_beacon_schedule ( genesis_timestamp) ) ;
418417 let ExecutedTipset { state_root, .. } = crate :: state_manager:: apply_block_messages (
419418 genesis_timestamp,
420- Arc :: clone ( chain_index) ,
421- Arc :: clone ( chain_config) ,
419+ chain_index. shallow_clone ( ) ,
420+ chain_config. shallow_clone ( ) ,
422421 beacon,
423422 // Using shared WASM engine here as creating new WASM engines is expensive
424423 // (takes seconds to minutes). It's only acceptable here because this situation is
0 commit comments