Skip to content

Emit structured events from shadow mode dry-run in governance contract #797

Description

@Mathews-25

Summary

shadow_mode.rs in contracts/governance/ simulates governance proposal execution without committing state, which is a valuable safety feature. However, the simulation results are only available as return values from a direct contract call. Off-chain monitoring tools and indexers cannot observe shadow-mode execution paths because no events are emitted during a dry run.

Motivation

  • Indexers and governance dashboards need a durable record of shadow-mode simulation outcomes to build "what-if" analytics for DAO proposals.
  • Emitting events during dry-run (even if the ledger state is not modified) allows event subscribers to detect proposals that would fail on execution before the vote closes.
  • This is consistent with the audit trail philosophy in audit_log.rs.

Proposed Implementation

  1. Add a ShadowModeResult event type:
    #[contracttype]
    pub struct ShadowModeResult {
        pub proposal_id: u32,
        pub success: bool,
        pub simulated_state_changes: Vec<String>, // human-readable summary
        pub failure_reason: Option<String>,
    }
  2. At the end of simulate_proposal in shadow_mode.rs, emit this event regardless of success/failure outcome.
  3. Ensure the simulation does not actually write any state (use a read-only check pattern — read storage, compute result, emit event, return result without writing).

Acceptance Criteria / Definition of Done

  • ShadowModeResult event is defined in events.rs (or equivalent).
  • simulate_proposal emits the event with correct success flag and failure_reason when applicable.
  • No persistent storage is written during a shadow-mode invocation.
  • Unit tests verify: (a) successful simulation emits event with success = true, (b) failing simulation emits event with success = false and non-null failure_reason.
  • cargo test passes with no regressions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions