Deterministic state-machine replay, checkpoint validation and divergence diagnostics for MoonBit.
let report = @moonreplaykit.replay(
journal,
initial_state,
payload_fingerprint,
state_fingerprint,
reducer,
)
let tree = @moonreplaykit.build_replay_evidence(
journal,
report,
payload_fingerprint,
).unwrap()
let proof = @moonreplaykit.replay_inclusion_proof(
journal,
report,
tree,
sequence,
).unwrap()
assert_true(@moonreplaykit.verify_replay_inclusion(proof))pub(all) struct Checkpoint[S] {
sequence : Int
state : S
state_hash : Int
journal_hash : Int
}pub(all) struct Divergence {
sequence : Int
kind : DivergenceKind
left_hash : Int
right_hash : Int
message : String
} derive(Eq, Debug)pub(all) enum InvariantResult {
Holds(Int)
Violated(Int, Int, String)
ReplayFailed(ReplayStatus)
} derive(Eq, Debug)fn[P] Journal::append(self : Journal[P], kind : String, payload : P, correlation_id : String, payload_fingerprint : (P) -> String) -> JournalEvent[P]pub(all) struct JournalEvent[P] {
sequence : Int
kind : String
payload : P
correlation_id : String
previous_hash : Int
hash : Int
}pub(all) struct MigrationReport[S] {
compatible : Bool
old_report : ReplayReport[S]
new_report : ReplayReport[S]
first_divergence : Divergence?
}fn[P] ReplayBranch::append(self : ReplayBranch[P], kind : String, payload : P, correlation_id : String, payload_fingerprint : (P) -> String) -> JournalEvent[P]fn[P] ReplayBranch::fork(name : String, source : Journal[P], sequence : Int, payload_fingerprint : (P) -> String) -> ReplayBranch[P]?pub(all) struct ReplayReport[S] {
status : ReplayStatus
initial_sequence : Int
applied_events : Int
final_sequence : Int
final_state : S
final_state_hash : Int
journal_tail_hash : Int
state_hashes : Array[Int]
}pub(all) enum ReplayStatus {
Completed
Rejected(Int, String)
InvalidJournal(ChainIssue)
InvalidCheckpoint(String)
} derive(Eq, Debug)pub(all) enum Transition[S] {
Accepted(S)
Rejected(String)
}fn[P, S] build_replay_evidence(journal : Journal[P], report : ReplayReport[S], payload_fingerprint : (P) -> String) -> ReplayEvidenceTree?fn[P] compare_histories(left : Journal[P], right : Journal[P], payload_fingerprint : (P) -> String) -> Divergence?fn[P, S] compare_reducer_versions(journal : Journal[P], initial_state : S, payload_fingerprint : (P) -> String, state_fingerprint : (S) -> String, old_reducer : (S, JournalEvent[P]) -> Transition[S], new_reducer : (S, JournalEvent[P]) -> Transition[S]) -> MigrationReport[S]fn event_fingerprint(previous_hash : Int, sequence : Int, kind : String, correlation_id : String, payload_fingerprint : String) -> Intfn[P] events_by_correlation(journal : Journal[P], correlation_id : String) -> Array[JournalEvent[P]]fn[P] events_in_range(journal : Journal[P], first_sequence : Int, last_sequence : Int) -> Array[JournalEvent[P]]fn[P, S] find_first_invariant_failure(journal : Journal[P], initial_state : S, payload_fingerprint : (P) -> String, state_fingerprint : (S) -> String, reducer : (S, JournalEvent[P]) -> Transition[S], invariant : (S) -> String?) -> InvariantResultfn fingerprint_text(text : String) -> Intfn json_escape(value : String) -> Stringfn[P, S] minimal_failing_prefix(journal : Journal[P], initial_state : S, payload_fingerprint : (P) -> String, state_fingerprint : (S) -> String, reducer : (S, JournalEvent[P]) -> Transition[S], invariant : (S) -> String?) -> Journal[P]?fn[P, S] replay(journal : Journal[P], initial_state : S, payload_fingerprint : (P) -> String, state_fingerprint : (S) -> String, reducer : (S, JournalEvent[P]) -> Transition[S]) -> ReplayReport[S]fn[P, S] replay_from_checkpoint(journal : Journal[P], checkpoint : Checkpoint[S], payload_fingerprint : (P) -> String, state_fingerprint : (S) -> String, reducer : (S, JournalEvent[P]) -> Transition[S]) -> ReplayReport[S]fn[P, S] replay_inclusion_proof(journal : Journal[P], report : ReplayReport[S], tree : ReplayEvidenceTree, sequence : Int) -> ReplayInclusionProof?fn[P, S] verify_determinism(journal : Journal[P], initial_state : S, payload_fingerprint : (P) -> String, state_fingerprint : (S) -> String, reducer : (S, JournalEvent[P]) -> Transition[S]) -> BoolDeterministic state-machine replay, checkpoint validation and divergence diagnostics for MoonBit.