Skip to main content

Archive

Struct Archive 

Source
pub struct Archive { /* private fields */ }
Expand description

The store. One file, one process, any number of readers alongside the syncing writer.

Implementations§

Source§

impl Archive

Source

pub async fn backfill<S: BalSource + ?Sized>( &self, source: &S, addr: Address, opts: BackfillOpts, ) -> Result<BackfillReport>

Extend addr’s history backwards from its watch start. Takes the sync slot (a concurrent sync is refused and vice versa); reads stay available throughout. Every block is verified: header chained to the one above it, BAL hashed against the header.

The archive must have synced to at least the watch start, so that the block above the first one read is one the archive holds.

Source

pub async fn backfill_many<S: BalSource + ?Sized>( &self, source: &S, addrs: &[Address], opts: BackfillOpts, ) -> Result<Vec<BackfillReport>>

Archive::backfill for several addresses in one backward walk: every block is fetched and verified once and applied to each address whose history has not reached it yet, so a protocol of N contracts costs the same RPC traffic as one. Each address keeps its own start, target, creation and report; the reports come back in input order. max_blocks bounds the blocks read by the walk as a whole.

Source§

impl Archive

Source

pub fn storage_at( &self, addr: Address, slot: B256, block: u64, ) -> Result<StorageValue, NotAvailable>

Value of slot at the end of block. One ordered seek.

Source

pub fn history( &self, addr: Address, slot: B256, range: Range<u64>, ) -> Result<Vec<HistoryEntry>, NotAvailable>

All recorded changes of slot in range (half-open), ascending. Bootstrap records live at start - 1 and are therefore never inside a valid range; what comes back is BAL data only.

Source

pub fn changed_slots( &self, addr: Address, block: u64, ) -> Result<Vec<B256>, NotAvailable>

Slots of addr written in block, from the block index.

Source

pub fn boot_state(&self, addr: Address, slot: B256) -> Result<Option<BootState>>

Bootstrap state of a slot, if it has ever been seen or proven.

Source§

impl Archive

Source

pub async fn sync<S: BalSource + ?Sized>( &self, source: &S, state: Option<&dyn StateSource>, ) -> Result<SyncReport>

Sync from the archive head (or the earliest watch start) to the source head. state enables early bootstrap; without it, first-seen slots are left Pending and will be picked up by a later sync that has a state source — if the window has not passed by then.

A block the source reports as missing near its head ends the pass quietly (pooled gateways lag); the next pass picks it up.

Source

pub async fn sync_step<S: BalSource + ?Sized>( &self, source: &S, state: Option<&dyn StateSource>, max_blocks: Option<u64>, ) -> Result<SyncReport>

Archive::sync that applies at most max_blocks and returns, so a caller can show progress and keep reading between steps. The pass is complete when blocks_applied is 0 or to == source_head.

Source

pub async fn bootstrap_slot( &self, state: &dyn StateSource, addr: Address, slot: B256, ) -> Result<()>

Lazy bootstrap for a slot that never changed since watch start: prove its value at the archive head (which equals its value at start, by BAL completeness) and store it as the pre-value.

The head is read before the slot’s state is checked, and the write is skipped if a change at or before that head has been recorded, if the watch changed, or if the head block was replaced in the meantime — a sync running concurrently cannot turn a post-value into a stored pre-value.

Source§

impl Archive

Source

pub fn rollback_to(&self, block: u64) -> Result<()>

Delete everything above block and reset head to it. Walks the block index per watched address, so the cost is proportional to the records being removed, not to the size of the archive.

If the fork is below an address’s start - 1, every proven pre-value of that address is dropped too: those proofs were taken on a branch that may have written the slot before start, so they no longer describe the canonical chain. They are re-proven when needed.

Source§

impl Archive

Source

pub fn open(path: impl AsRef<Path>) -> Result<Self>

Open or create path with default configuration.

Source

pub fn open_with(path: impl AsRef<Path>, config: ArchiveConfig) -> Result<Self>

Open or create path. Refuses files written with another SCHEMA_VERSION.

Source

pub fn config(&self) -> &ArchiveConfig

Configuration this archive was opened with.

Source

pub fn watch(&self, addr: Address, from_block: u64) -> Result<()>

Start accumulating addr from from_block (inclusive). from_block must be above the current head and above any block the sync loop is currently applying: history before now is Archive::backfill, an explicit call. An address can be watched once; change its start with Archive::unwatch first (which drops its data).

Source

pub fn unwatch(&self, addr: Address) -> Result<()>

Stop watching and delete everything stored for addr. Taken under the watch gate; a block being applied concurrently re-checks the watchlist inside its transaction, so nothing is written for addr after this returns.

Source

pub fn compact_file(path: impl AsRef<Path>) -> Result<bool>

Rewrite the file without free pages. redb frees pages as records are overwritten and transactions retire, but never shrinks the file on its own; after a long backfill the difference is large. Needs the file to itself: call with no Archive open on it. Returns whether anything changed.

Source

pub fn created_at(&self, addr: Address) -> Result<Option<u64>>

Block in which addr was created, if a verified BAL showed it.

Source

pub fn watchlist(&self) -> Result<Vec<(Address, u64)>>

Watched addresses with their start blocks.

Source

pub fn stats(&self) -> Result<ArchiveStats>

Counts and sizes for status-style reporting. Scans the bootstrap table, so it is proportional to the number of distinct slots seen — fine for a command, not for a hot path.

Source

pub fn head(&self) -> Result<Option<(u64, B256)>>

Last applied block and its hash, if any block was applied.

Auto Trait Implementations§

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. 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 = !

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