Skip to main content

apply

Function apply 

Source
pub fn apply<M: DiffTarget>(
    state: M,
    delta: &ArchivedBeaconStateDelta,
) -> Result<M, Error>
Expand description

Applies an archived BeaconStateDelta to a mutable beacon state.

The destination state is modified in place and returned after all delta components have been applied.

Before mutation begins, the function validates that:

  • the destination state’s fork matches the delta’s fork;
  • fork-specific fields are valid for that fork; and
  • the fork value can be successfully decoded from the archived delta.

§Errors

Returns Error::ForkMismatch when the delta and destination state belong to different forks.

Returns Error::InvalidFieldForFork when a fork-specific field is present in a delta where that field is not valid.

Returns Error::MalformedDelta when the archived fork cannot be decoded.

§Mutation

Fork and field validation occurs before state components are modified. Component application itself operates in place.

The destination state must correspond to the base state from which the delta was created. Applying a valid delta to an unrelated state is not expected to reconstruct the original target state.

§Complexity

Linear in the amount of data represented by the delta, with the exact cost determined by the individual component encodings.