Struct snapps_txn_reference_impl::sequence_event::SequenceState [−][src]
pub struct SequenceState {
pub most_recent_states: [SequenceStateHash; 5],
pub last_sequence_slot: u32,
}
Expand description
Information about all historical sequence events emmitted by snapp transactions.
This data is stored in last-in-first-out stack, stored as a cryptographic hash. The order that transactions are stored in this stack is determined by the order in which they are applied within blocks, as determined by block producers.
This structure stores the updates from the 5 most-recent slots, so that previous updates can be ‘rolled-up’ into an update of the main snapp state, while still allowing the snapp to accept new updates within the same block.
Fields
most_recent_states: [SequenceStateHash; 5]
History of sequenced event updates for the most recent 5 slots with updates.
last_sequence_slot: u32
The slot number (since genesis) of the most recent sequenced event update.
Implementations
The initial value of SequenceState
in accounts.
empty() =
SequenceState {
most_recent_states: [SequenceStateHash::empty(); 5],
last_sequence_slot: 0,
}
Update SequenceState
for the current block’s slot, shifting the most_recent_states
along by 1 position if the slot
is greater than last_sequence_slot
, and copying the
original first state into the first position.
if state.last_sequence_slot < slot {
let [state0, state1, state2, state3, _] = state.most_recent_states;
SequenceState {
most_recent_states: [state0, state0, state1, state2, state3],
last_sequence_slot: slot,
}
} else {
state
}
pub fn push_sequence_events_unconditional(
state: SequenceState,
sequence_events: &SequenceEvents<'_>
) -> SequenceState
pub fn push_sequence_events_unconditional(
state: SequenceState,
sequence_events: &SequenceEvents<'_>
) -> SequenceState
Update the most recent sequence state with the new hash after pushing the sequence event,
using SequenceStateHash::push_sequence_events
.
state.most_recent_states[0] =
SequenceStateHash::push_sequence_events(
sequence_events,
state.most_recent_states[0],
);
pub fn push_sequence_events(
state: SequenceState,
sequence_events: &SequenceEvents<'_>,
slot: u32
) -> SequenceState
pub fn push_sequence_events(
state: SequenceState,
sequence_events: &SequenceEvents<'_>,
slot: u32
) -> SequenceState
Push a sequence event at a given slot.
If the sequence event is empty, the SequenceState
must be returned unmodified.
Otherwise, this must call SequenceState::update_for_slot
and then
SequenceState::push_sequence_events_unconditional
.
if sequence_events.len() == 0 {
state
} else {
let state = SequenceState::update_for_slot(state, slot);
SequenceState::push_sequence_events_unconditional(state, sequence_events)
}