Struct sc_client_api::leaves::LeafSet
source · pub struct LeafSet<H, N> { /* private fields */ }
Expand description
list of leaf hashes ordered by number (descending). stored in memory for fast access. this allows very fast checking and modification of active leaves.
Implementations§
source§impl<H, N> LeafSet<H, N>where
H: Clone + PartialEq + Decode + Encode,
N: Debug + Clone + AtLeast32Bit + Decode + Encode,
impl<H, N> LeafSet<H, N>where
H: Clone + PartialEq + Decode + Encode,
N: Debug + Clone + AtLeast32Bit + Decode + Encode,
sourcepub fn new() -> Self
pub fn new() -> Self
Construct a new, blank leaf set.
Examples found in repository?
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
pub fn new() -> Blockchain<Block> {
let storage = Arc::new(RwLock::new(BlockchainStorage {
blocks: HashMap::new(),
hashes: HashMap::new(),
best_hash: Default::default(),
best_number: Zero::zero(),
finalized_hash: Default::default(),
finalized_number: Zero::zero(),
genesis_hash: Default::default(),
header_cht_roots: HashMap::new(),
leaves: LeafSet::new(),
aux: HashMap::new(),
}));
Blockchain { storage }
}
sourcepub fn read_from_db(
db: &dyn Database<H256>,
column: u32,
prefix: &[u8]
) -> Result<Self>
pub fn read_from_db(
db: &dyn Database<H256>,
column: u32,
prefix: &[u8]
) -> Result<Self>
Read the leaf list from the DB, using given prefix for keys.
sourcepub fn import(&mut self, hash: H, number: N, parent_hash: H) -> ImportOutcome<H, N>
pub fn import(&mut self, hash: H, number: N, parent_hash: H) -> ImportOutcome<H, N>
Update the leaf list on import.
Examples found in repository?
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
pub fn insert(
&self,
hash: Block::Hash,
header: <Block as BlockT>::Header,
justifications: Option<Justifications>,
body: Option<Vec<<Block as BlockT>::Extrinsic>>,
new_state: NewBlockState,
) -> sp_blockchain::Result<()> {
let number = *header.number();
if new_state.is_best() {
self.apply_head(&header)?;
}
{
let mut storage = self.storage.write();
storage.leaves.import(hash, number, *header.parent_hash());
storage.blocks.insert(hash, StoredBlock::new(header, body, justifications));
if let NewBlockState::Final = new_state {
storage.finalized_hash = hash;
storage.finalized_number = number;
}
if number == Zero::zero() {
storage.genesis_hash = hash;
}
}
Ok(())
}
sourcepub fn remove(
&mut self,
hash: H,
number: N,
parent_hash: Option<H>
) -> Option<RemoveOutcome<H, N>>
pub fn remove(
&mut self,
hash: H,
number: N,
parent_hash: Option<H>
) -> Option<RemoveOutcome<H, N>>
Update the leaf list on removal.
Note that the leaves set structure doesn’t have the information to decide if the
leaf we’re removing is the last children of the parent. Follows that this method requires
the caller to check this condition and optionally pass the parent_hash
if hash
is
its last child.
Returns None
if no modifications are applied.
sourcepub fn finalize_height(&mut self, number: N) -> FinalizationOutcome<H, N>
pub fn finalize_height(&mut self, number: N) -> FinalizationOutcome<H, N>
Note a block height finalized, displacing all leaves with number less than the finalized block’s.
Although it would be more technically correct to also prune out leaves at the same number as the finalized block, but with different hashes, the current behavior is simpler and our assumptions about how finalization works means that those leaves will be pruned soon afterwards anyway.
sourcepub fn displaced_by_finalize_height(
&self,
number: N
) -> FinalizationOutcome<H, N>
pub fn displaced_by_finalize_height(
&self,
number: N
) -> FinalizationOutcome<H, N>
The same as Self::finalize_height
, but it only simulates the operation.
This means that no changes are done.
Returns the leaves that would be displaced by finalizing the given block.
Examples found in repository?
430 431 432 433 434 435 436 437 438 439 440 441 442
fn displaced_leaves_after_finalizing(
&self,
block_number: NumberFor<Block>,
) -> sp_blockchain::Result<Vec<Block::Hash>> {
Ok(self
.storage
.read()
.leaves
.displaced_by_finalize_height(block_number)
.leaves()
.cloned()
.collect::<Vec<_>>())
}
sourcepub fn undo(&mut self) -> Undo<'_, H, N>
pub fn undo(&mut self) -> Undo<'_, H, N>
Undo all pending operations.
This returns an Undo
struct, where any
Displaced
objects that have returned by previous method calls
should be passed to via the appropriate methods. Otherwise,
the on-disk state may get out of sync with in-memory state.
sourcepub fn revert(&mut self, best_hash: H, best_number: N)
pub fn revert(&mut self, best_hash: H, best_number: N)
Revert to the given block height by dropping all leaves in the leaf set with a block number higher than the target.
sourcepub fn hashes(&self) -> Vec<H> ⓘ
pub fn hashes(&self) -> Vec<H> ⓘ
returns an iterator over all hashes in the leaf set ordered by their block number descending.
sourcepub fn count(&self) -> usize
pub fn count(&self) -> usize
Number of known leaves.
Examples found in repository?
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
fn info(&self) -> blockchain::Info<Block> {
let storage = self.storage.read();
blockchain::Info {
best_hash: storage.best_hash,
best_number: storage.best_number,
genesis_hash: storage.genesis_hash,
finalized_hash: storage.finalized_hash,
finalized_number: storage.finalized_number,
finalized_state: if storage.finalized_hash != Default::default() {
Some((storage.finalized_hash, storage.finalized_number))
} else {
None
},
number_leaves: storage.leaves.count(),
block_gap: None,
}
}
sourcepub fn prepare_transaction(
&mut self,
tx: &mut Transaction<H256>,
column: u32,
prefix: &[u8]
)
pub fn prepare_transaction(
&mut self,
tx: &mut Transaction<H256>,
column: u32,
prefix: &[u8]
)
Write the leaf list to the database transaction.
sourcepub fn highest_leaf(&self) -> Option<(N, &[H])>
pub fn highest_leaf(&self) -> Option<(N, &[H])>
Returns the highest leaf and all hashes associated to it.
Trait Implementations§
source§impl<H: PartialEq, N: PartialEq> PartialEq<LeafSet<H, N>> for LeafSet<H, N>
impl<H: PartialEq, N: PartialEq> PartialEq<LeafSet<H, N>> for LeafSet<H, N>
impl<H: Eq, N: Eq> Eq for LeafSet<H, N>
impl<H, N> StructuralEq for LeafSet<H, N>
impl<H, N> StructuralPartialEq for LeafSet<H, N>
Auto Trait Implementations§
impl<H, N> RefUnwindSafe for LeafSet<H, N>where
H: RefUnwindSafe,
N: RefUnwindSafe,
impl<H, N> Send for LeafSet<H, N>where
H: Send,
N: Send,
impl<H, N> Sync for LeafSet<H, N>where
H: Sync,
N: Sync,
impl<H, N> Unpin for LeafSet<H, N>
impl<H, N> UnwindSafe for LeafSet<H, N>where
H: RefUnwindSafe,
N: RefUnwindSafe,
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>
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>
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)
&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)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.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
§impl<T> SaturatedConversion for T
impl<T> SaturatedConversion for T
§fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
§fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
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
unchecked_from
.§impl<T, S> UniqueSaturatedInto<T> for Swhere
T: Bounded,
S: TryInto<T>,
impl<T, S> UniqueSaturatedInto<T> for Swhere
T: Bounded,
S: TryInto<T>,
§fn unique_saturated_into(self) -> T
fn unique_saturated_into(self) -> T
T
.