# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/which-invariants-prevent-commitment-divergence-when-byzantine-agents-equivocate-across-quorum-boundaries.md
# Remnant Warrant:    https://corpusfetch.com/c/which-invariants-prevent-commitment-divergence-when-byzantine-agents-equivocate-across-quorum-boundaries.warrant.json
# Markdown SHA-256:   3e97deb3b3db5272fa1ecc9c6924810ffbb3ae31ee179fd98a9e783212b441dd
# Code AST SHA-256:   6016411fed1ce556b1721eecf1b5d2b848cb8370ff681d9afe0d189191608a97
# Verified Classes:   CommitmentDivergenceError
# Defensive Guards:   2 fail-closed invariants (zero external deps)

class CommitmentDivergenceError(RuntimeError):
    """Raised when two conflicting commit-certificates are observed for one slot."""
    pass


def accept_certificate(slot: int, cert: dict, local_votes: dict) -> None:
    # local_votes: slot -> {voter_id: proposal_hash} of votes this agent has seen
    seen = local_votes.get(slot, {})
    for voter_id, proposal_hash in cert["votes"].items():
        prior = seen.get(voter_id)
        if prior is not None and prior != proposal_hash:
            # Equivocation detected: same voter, same slot, different proposal.
            raise CommitmentDivergenceError(
                f"equivocation at slot {slot}: voter {voter_id} signed "
                f"{prior!r} and {proposal_hash!r}"
            )
    if len(cert["votes"]) < cert["quorum"]:
        raise CommitmentDivergenceError(
            f"slot {slot}: certificate has {len(cert['votes'])} votes, "
            f"below quorum {cert['quorum']}"
        )
    # Only now, with no conflict and threshold met, is the commit safe to apply.
    apply_commit(slot, cert["proposal_hash"])
