Stage verified suffix previews before new state hashing
This commit is contained in:
1 parent
5927196149
commit
f684872941
9 files changed
+350
-80
No files matched your search
@@ -703,8 +703,38 @@ pub struct Execution<F = u64> {
|
||||
|
||||
/// The exact final state is available for layout. Its fingerprint may still
|
||||
/// require the canonical hash before a completed execution can be published.
|
||||
#[derive(Debug)]
|
||||
pub struct DeferredStateFingerprint(Option<u64>);
|
||||
pub struct DeferredStateFingerprint(FingerprintState);
|
||||
|
||||
enum FingerprintState {
|
||||
Known(u64),
|
||||
NeedsHash(Option<state::CommandFingerprintBase>),
|
||||
}
|
||||
|
||||
impl fmt::Debug for DeferredStateFingerprint {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self.0 {
|
||||
FingerprintState::Known(value) => formatter.debug_tuple("Known").field(&value).finish(),
|
||||
FingerprintState::NeedsHash(_) => formatter.write_str("NeedsHash"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl DeferredStateFingerprint {
|
||||
fn known(value: u64) -> Self {
|
||||
Self(FingerprintState::Known(value))
|
||||
}
|
||||
|
||||
fn pending(prior: Option<&State>) -> Self {
|
||||
Self(FingerprintState::NeedsHash(prior.map(State::command_fingerprint_base)))
|
||||
}
|
||||
|
||||
fn calculate(&self, state: &State) -> u64 {
|
||||
match &self.0 {
|
||||
FingerprintState::Known(value) => *value,
|
||||
FingerprintState::NeedsHash(prior) => state.fingerprint_with_base(prior.as_ref()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<F> Execution<F> {
|
||||
fn with_outgoing_state<T>(self, outgoing_state: T) -> Execution<T> {
|
||||
@@ -739,13 +769,11 @@ impl<F> Execution<F> {
|
||||
|
||||
impl Execution<DeferredStateFingerprint> {
|
||||
fn needs_fingerprint(&self) -> bool {
|
||||
self.outgoing_state.0.is_none()
|
||||
matches!(self.outgoing_state.0, FingerprintState::NeedsHash(_))
|
||||
}
|
||||
|
||||
fn finish_fingerprint(self, previous: Option<&Execution>) -> Execution {
|
||||
let fingerprint = self.outgoing_state.0.unwrap_or_else(|| {
|
||||
self.state.fingerprint_with_prior(previous.map(|prior| &prior.state))
|
||||
});
|
||||
fn finish_fingerprint(self) -> Execution {
|
||||
let fingerprint = self.outgoing_state.calculate(&self.state);
|
||||
self.with_outgoing_state(fingerprint)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user