iroha icon indicating copy to clipboard operation
iroha copied to clipboard

[suggestion] disallow conditional compilation of structures

Open mversic opened this issue 2 years ago • 2 comments

Feature request

This structure in telemetry/src/config.rs:

pub struct Configuration {
    /// The node's name to be seen on the telemetry
    #[config(serde_as_str)]
    pub name: Option<String>,
    /// The url of the telemetry, e.g., ws://127.0.0.1:8001/submit
    #[config(serde_as_str)]
    pub url: Option<Url>,
    /// The minimum period of time in seconds to wait before reconnecting
    #[serde(default = "default_min_retry_period")]
    pub min_retry_period: u64,
    /// The maximum exponent of 2 that is used for increasing delay between reconnections
    #[serde(default = "default_max_retry_delay_exponent")]
    pub max_retry_delay_exponent: u8,
    /// The filepath that to write dev-telemetry to
    #[cfg(feature = "dev-telemetry")]
    #[config(serde_as_str)]
    pub file: Option<PathBuf>,
}

contains feature flag dev-telemetry on one of it's fields. Are we going to allow this? related to #2111

Motivation

Conditionally compiled structs are a problem for users of Iroha. This structure isn't encoded/signed, so it may not be such a big problem.

Who can help?

No response

mversic avatar Jul 14 '22 19:07 mversic

Sadly we can't check for this in IntoSchema because cfg directives are expanded before proc macros. What we can do is write a custom lint, and use clippy.

https://blog.trailofbits.com/2021/11/09/write-rust-lints-without-forking-clippy/

appetrosyan avatar Jul 25 '22 11:07 appetrosyan

We can implement a lint that checks for #[derive(IntoSchema) and lints on #[cfg(feature)` inside fields.

appetrosyan avatar Aug 11 '22 12:08 appetrosyan

Closing it as we decided that dynamic lints would introduce another level of complexity into an already unwieldy workflow.

ilchu avatar Dec 19 '22 07:12 ilchu