Skip to main content

UtxoOverlay

Struct UtxoOverlay 

Source
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>

Source

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.

Source

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.

Source

pub fn get(&self, outpoint: &OutPoint) -> Option<&UTXO>

Look up a UTXO by outpoint.

First checks deletions, then additions, then base set.

Source

pub fn contains_key(&self, outpoint: &OutPoint) -> bool

Check if a UTXO exists.

Source

pub fn insert(&mut self, outpoint: OutPoint, utxo: UTXO)

Add a new UTXO (created by a transaction in this block).

Source

pub fn insert_arc(&mut self, outpoint: OutPoint, utxo: Arc<UTXO>)

Add a new UTXO from Arc. Use when sharing with undo log.

Source

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).

Source

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.

Source

pub fn additions_len(&self) -> usize

Get the number of additions in this overlay.

Source

pub fn deletions_len(&self) -> usize

Get the number of deletions in this overlay.

Source

pub fn base_len(&self) -> usize

Get the size of the base UTXO set.

Source

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.

Source

pub fn additions(&self) -> &HashMap<OutPoint, Arc<UTXO>, FxBuildHasher>

Get immutable access to additions (for undo log generation).

Source

pub fn deletions(&self) -> &HashSet<[u8; 36], FxBuildHasher>

Get immutable access to deletion keys (for undo log generation).

Source

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>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'a> UtxoLookup for UtxoOverlay<'a>

Implementation of UtxoLookup for UtxoOverlay.

Source§

fn get(&self, outpoint: &OutPoint) -> Option<&UTXO>

Look up a UTXO by outpoint.
Source§

fn contains_key(&self, outpoint: &OutPoint) -> bool

Check if a UTXO exists.
Source§

fn len(&self) -> usize

Get the number of UTXOs (approximate for overlays).
Source§

fn is_empty(&self) -> bool

Check if empty.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more