Struct forest_filecoin::chain::store::chain_store::ChainStore
source · pub struct ChainStore<DB> {
publisher: Sender<HeadChange>,
pub db: Arc<DB>,
settings: Arc<dyn SettingsStore + Sync + Send>,
pub chain_index: Arc<ChainIndex<Arc<DB>>>,
tipset_tracker: TipsetTracker<DB>,
genesis_block_header: CachingBlockHeader,
validated_blocks: Mutex<HashSet<Cid>>,
eth_mappings: Arc<dyn EthMappingsStore + Sync + Send>,
pub chain_config: Arc<ChainConfig>,
}
Expand description
Stores chain data such as heaviest tipset and cached tipset info at each
epoch. This structure is thread-safe, and all caches are wrapped in a mutex
to allow a consistent ChainStore
to be shared across tasks.
Fields§
§publisher: Sender<HeadChange>
Publisher for head change events
db: Arc<DB>
key-value datastore
.
settings: Arc<dyn SettingsStore + Sync + Send>
Settings store
chain_index: Arc<ChainIndex<Arc<DB>>>
Used as a cache for tipset lookbacks
.
tipset_tracker: TipsetTracker<DB>
Tracks blocks for the purpose of forming tipsets.
genesis_block_header: CachingBlockHeader
§validated_blocks: Mutex<HashSet<Cid>>
validated blocks
eth_mappings: Arc<dyn EthMappingsStore + Sync + Send>
Ethereum mappings store
chain_config: Arc<ChainConfig>
Needed by the Ethereum mapping.
Implementations§
source§impl<DB> ChainStore<DB>where
DB: Blockstore,
impl<DB> ChainStore<DB>where
DB: Blockstore,
pub fn new( db: Arc<DB>, settings: Arc<dyn SettingsStore + Sync + Send>, eth_mappings: Arc<dyn EthMappingsStore + Sync + Send>, chain_config: Arc<ChainConfig>, genesis_block_header: CachingBlockHeader, ) -> Result<Self>
sourcepub fn set_heaviest_tipset(&self, ts: Arc<Tipset>) -> Result<(), Error>
pub fn set_heaviest_tipset(&self, ts: Arc<Tipset>) -> Result<(), Error>
Sets heaviest tipset within ChainStore
and store its tipset keys in
the settings store under the crate::db::setting_keys::HEAD_KEY
key.
sourcepub fn add_to_tipset_tracker(&self, header: &CachingBlockHeader)
pub fn add_to_tipset_tracker(&self, header: &CachingBlockHeader)
Adds a block header to the tipset tracker, which tracks valid headers.
sourcepub fn put_tipset(&self, ts: &Tipset) -> Result<(), Error>
pub fn put_tipset(&self, ts: &Tipset) -> Result<(), Error>
Writes tipset block headers to data store and updates heaviest tipset with other compatible tracked headers.
sourcepub fn put_tipset_key(&self, tsk: &TipsetKey) -> Result<(), Error>
pub fn put_tipset_key(&self, tsk: &TipsetKey) -> Result<(), Error>
Writes the TipsetKey
to the blockstore for EthAPI
queries.
sourcepub fn put_delegated_message_hashes<'a>(
&self,
headers: impl Iterator<Item = &'a CachingBlockHeader>,
) -> Result<(), Error>
pub fn put_delegated_message_hashes<'a>( &self, headers: impl Iterator<Item = &'a CachingBlockHeader>, ) -> Result<(), Error>
Writes the delegated message Cid
s to the blockstore for EthAPI
queries.
sourcepub fn get_required_tipset_key(
&self,
hash: &EthHash,
) -> Result<TipsetKey, Error>
pub fn get_required_tipset_key( &self, hash: &EthHash, ) -> Result<TipsetKey, Error>
Reads the TipsetKey
from the blockstore for EthAPI
queries.
sourcepub fn put_mapping(
&self,
k: EthHash,
v: Cid,
timestamp: u64,
) -> Result<(), Error>
pub fn put_mapping( &self, k: EthHash, v: Cid, timestamp: u64, ) -> Result<(), Error>
Writes with timestamp the Hash
to Cid
mapping to the blockstore for EthAPI
queries.
sourcepub fn get_mapping(&self, hash: &EthHash) -> Result<Option<Cid>, Error>
pub fn get_mapping(&self, hash: &EthHash) -> Result<Option<Cid>, Error>
Reads the Cid
from the blockstore for EthAPI
queries.
sourcefn expand_tipset(&self, header: CachingBlockHeader) -> Result<Tipset, Error>
fn expand_tipset(&self, header: CachingBlockHeader) -> Result<Tipset, Error>
Expands tipset to tipset with all other headers in the same epoch using the tipset tracker.
pub fn genesis_block_header(&self) -> &CachingBlockHeader
sourcepub fn heaviest_tipset(&self) -> Arc<Tipset>
pub fn heaviest_tipset(&self) -> Arc<Tipset>
Returns the currently tracked heaviest tipset.
sourcepub fn publisher(&self) -> &Publisher<HeadChange>
pub fn publisher(&self) -> &Publisher<HeadChange>
Returns a reference to the publisher of head changes.
sourcepub fn blockstore(&self) -> &DB
pub fn blockstore(&self) -> &DB
Returns key-value store instance.
sourcepub fn load_required_tipset_or_heaviest<'a>(
&self,
maybe_key: impl Into<Option<&'a TipsetKey>>,
) -> Result<Arc<Tipset>, Error>
pub fn load_required_tipset_or_heaviest<'a>( &self, maybe_key: impl Into<Option<&'a TipsetKey>>, ) -> Result<Arc<Tipset>, Error>
sourcefn update_heaviest(&self, ts: Arc<Tipset>) -> Result<(), Error>
fn update_heaviest(&self, ts: Arc<Tipset>) -> Result<(), Error>
Determines if provided tipset is heavier than existing known heaviest tipset
sourcepub fn is_block_validated(&self, cid: &Cid) -> bool
pub fn is_block_validated(&self, cid: &Cid) -> bool
Checks metadata file if block has already been validated.
sourcepub fn mark_block_as_validated(&self, cid: &Cid)
pub fn mark_block_as_validated(&self, cid: &Cid)
Marks block as validated in the metadata file.
pub fn unmark_block_as_validated(&self, cid: &Cid)
sourcepub fn messages_for_tipset(
&self,
ts: &Tipset,
) -> Result<Vec<ChainMessage>, Error>
pub fn messages_for_tipset( &self, ts: &Tipset, ) -> Result<Vec<ChainMessage>, Error>
Retrieves ordered valid messages from a Tipset
. This will only include
messages that will be passed through the VM.
sourcepub fn get_lookback_tipset_for_round(
chain_index: Arc<ChainIndex<Arc<DB>>>,
chain_config: Arc<ChainConfig>,
heaviest_tipset: Arc<Tipset>,
round: i64,
) -> Result<(Arc<Tipset>, Cid), Error>
pub fn get_lookback_tipset_for_round( chain_index: Arc<ChainIndex<Arc<DB>>>, chain_config: Arc<ChainConfig>, heaviest_tipset: Arc<Tipset>, round: i64, ) -> Result<(Arc<Tipset>, Cid), Error>
Gets look-back tipset (and state-root of that tipset) for block validations.
The look-back tipset for a round is the tipset with epoch round - chain_finality
. Chain
finality
is usually 900. The heaviest_tipset
is a reference point in the
blockchain. It must be a child of the look-back tipset.
pub fn settings(&self) -> Arc<dyn SettingsStore + Sync + Send>
sourcepub fn process_signed_messages(
&self,
messages: &[(SignedMessage, u64)],
) -> Result<()>where
DB: Blockstore,
pub fn process_signed_messages(
&self,
messages: &[(SignedMessage, u64)],
) -> Result<()>where
DB: Blockstore,
Filter SignedMessage
’s to keep only the most recent ones, then write corresponding entries to the Ethereum mapping.
pub fn headers_delegated_messages<'a>(
&self,
headers: impl Iterator<Item = &'a CachingBlockHeader>,
) -> Result<Vec<(SignedMessage, u64)>>where
DB: Blockstore,
Trait Implementations§
source§impl<DB> BitswapStoreRead for ChainStore<DB>where
DB: BitswapStoreRead,
impl<DB> BitswapStoreRead for ChainStore<DB>where
DB: BitswapStoreRead,
source§impl<DB> BitswapStoreReadWrite for ChainStore<DB>where
DB: BitswapStoreReadWrite,
impl<DB> BitswapStoreReadWrite for ChainStore<DB>where
DB: BitswapStoreReadWrite,
Auto Trait Implementations§
impl<DB> !Freeze for ChainStore<DB>
impl<DB> !RefUnwindSafe for ChainStore<DB>
impl<DB> Send for ChainStore<DB>
impl<DB> Sync for ChainStore<DB>
impl<DB> Unpin for ChainStore<DB>
impl<DB> !UnwindSafe for ChainStore<DB>
Blanket Implementations§
source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> FmtForward for T
impl<T> FmtForward for T
source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.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> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request
source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moresource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moresource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.source§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<T> References<RawCodec> for T
impl<T> References<RawCodec> for T
source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read moresource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.source§impl<T> Tap for T
impl<T> Tap for T
source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read moresource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read moresource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read moresource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read moresource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read moresource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read moresource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.