Skip to content

Dual Contract Builds with Optional Logging #273

@liuchengxu

Description

@liuchengxu

Summary

To balance development experience and on-chain performance, I propose maintaining two variants of our CosmWasm contracts:

  • Development Version: Logging enabled for better debugging and observability.
  • Production Version: Logging stripped out to reduce on-chain WASM overhead.

WASM logging incurs non-negligible execution costs, which makes a logging-free build preferable for production deployments. This issue tracks the design and implementation of tooling and workflows to support this approach.

Tasks

  • Created cosmwasm-logging Crate

    • Standard Rust log crate integration with CosmWasm's api.debug()
    • Zero-cost production builds using conditional compilation
    • Custom logger that formats output as target: [LEVEL] message
  • Contract Integration

    • Feature-Based Build System

      • logging feature: Full logging with log crate dependency
      • No features (default): No-op macros, zero runtime cost, no log dependency
      • Organized code structure with enabled/disabled modules
    • Dual-Build Integration

      • Configured via [package.metadata.optimizer] in Cargo.toml
        • Production: babylon_contract.wasm (no logging)
        • Development: babylon_contract-dev.wasm (full logging)
    • Added logging to contracts with structured targets

    • Called init_cosmwasm_logger() in all entry points: instantiate(), execute(), query(), reply(), migrate(), ensuring logging works in all unit tests regardless of entry point

  • Update babylon-sdk to use the dev version of contracts so that we can have the proper logging in development. We should integrate the logging into the rollup-bsn-contracts once everything goes well.

Optionally, we can support automated size/gas/cost comparison between the two builds.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions