pub struct UtxoOverlay<'a> { /* private fields */ }Expand description
Zero-copy overlay for UTXO set modifications during block validation.
Provides a view over the base UTXO set that captures additions and deletions without copying the underlying data.
Implementations§
Source§impl<'a> UtxoOverlay<'a>
impl<'a> UtxoOverlay<'a>
Sourcepub fn new(
base: &'a HashMap<OutPoint, Arc<UTXO>, FxBuildHasher>,
) -> UtxoOverlay<'a>
pub fn new( base: &'a HashMap<OutPoint, Arc<UTXO>, FxBuildHasher>, ) -> UtxoOverlay<'a>
Create a new overlay over the given UTXO set.
This is O(1) - no copying of the base set.
Sourcepub fn with_capacity(
base: &'a HashMap<OutPoint, Arc<UTXO>, FxBuildHasher>,
additions_cap: usize,
deletions_cap: usize,
) -> UtxoOverlay<'a>
pub fn with_capacity( base: &'a HashMap<OutPoint, Arc<UTXO>, FxBuildHasher>, additions_cap: usize, deletions_cap: usize, ) -> UtxoOverlay<'a>
Create a new overlay with custom capacity hints.
Sourcepub fn get(&self, outpoint: &OutPoint) -> Option<&UTXO>
pub fn get(&self, outpoint: &OutPoint) -> Option<&UTXO>
Look up a UTXO by outpoint.
First checks deletions, then additions, then base set.
Sourcepub fn contains_key(&self, outpoint: &OutPoint) -> bool
pub fn contains_key(&self, outpoint: &OutPoint) -> bool
Check if a UTXO exists.
Sourcepub fn insert(&mut self, outpoint: OutPoint, utxo: UTXO)
pub fn insert(&mut self, outpoint: OutPoint, utxo: UTXO)
Add a new UTXO (created by a transaction in this block).
Sourcepub fn insert_arc(&mut self, outpoint: OutPoint, utxo: Arc<UTXO>)
pub fn insert_arc(&mut self, outpoint: OutPoint, utxo: Arc<UTXO>)
Add a new UTXO from Arc. Use when sharing with undo log.
Sourcepub fn mark_spent(&mut self, outpoint: &OutPoint)
pub fn mark_spent(&mut self, outpoint: &OutPoint)
Mark a UTXO as spent without returning it. Use when the return value is discarded (e.g. IBD path). Avoids cloning the UTXO (~50 bytes per input).
Sourcepub fn remove(&mut self, outpoint: &OutPoint) -> Option<Arc<UTXO>>
pub fn remove(&mut self, outpoint: &OutPoint) -> Option<Arc<UTXO>>
Mark a UTXO as spent (consumed by a transaction in this block).
Returns the UTXO for undo-log path. Use mark_spent when return value is discarded.
Sourcepub fn additions_len(&self) -> usize
pub fn additions_len(&self) -> usize
Get the number of additions in this overlay.
Sourcepub fn deletions_len(&self) -> usize
pub fn deletions_len(&self) -> usize
Get the number of deletions in this overlay.
Sourcepub fn apply_to_base(self) -> HashMap<OutPoint, Arc<UTXO>, FxBuildHasher>
pub fn apply_to_base(self) -> HashMap<OutPoint, Arc<UTXO>, FxBuildHasher>
Apply the overlay changes to produce a new UTXO set.
This is called at the end of successful block validation. Base clone is cheap (Arc refcount only); additions wrapped in Arc.
Sourcepub fn additions(&self) -> &HashMap<OutPoint, Arc<UTXO>, FxBuildHasher>
pub fn additions(&self) -> &HashMap<OutPoint, Arc<UTXO>, FxBuildHasher>
Get immutable access to additions (for undo log generation).
Sourcepub fn deletions(&self) -> &HashSet<[u8; 36], FxBuildHasher>
pub fn deletions(&self) -> &HashSet<[u8; 36], FxBuildHasher>
Get immutable access to deletion keys (for undo log generation).
Sourcepub fn into_changes(
self,
) -> (HashMap<OutPoint, Arc<UTXO>, FxBuildHasher>, HashSet<[u8; 36], FxBuildHasher>)
pub fn into_changes( self, ) -> (HashMap<OutPoint, Arc<UTXO>, FxBuildHasher>, HashSet<[u8; 36], FxBuildHasher>)
Consume the overlay and return its changes as owned data.
This releases the borrow on the base UTXO set, allowing the caller to apply the changes directly to the mutable utxo_set without re-iterating all transactions.
Returns (additions, deletions) — the net UTXO changes from this block.
Trait Implementations§
Source§impl<'a> Debug for UtxoOverlay<'a>
impl<'a> Debug for UtxoOverlay<'a>
Source§impl<'a> UtxoLookup for UtxoOverlay<'a>
Implementation of UtxoLookup for UtxoOverlay.
impl<'a> UtxoLookup for UtxoOverlay<'a>
Implementation of UtxoLookup for UtxoOverlay.
Auto Trait Implementations§
impl<'a> Freeze for UtxoOverlay<'a>
impl<'a> RefUnwindSafe for UtxoOverlay<'a>
impl<'a> Send for UtxoOverlay<'a>
impl<'a> Sync for UtxoOverlay<'a>
impl<'a> Unpin for UtxoOverlay<'a>
impl<'a> UnsafeUnpin for UtxoOverlay<'a>
impl<'a> UnwindSafe for UtxoOverlay<'a>
Blanket Implementations§
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> 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 more