Skip to content

Commit

Permalink
feature-gate unchecked constructors in core
Browse files Browse the repository at this point in the history
  • Loading branch information
Fraser999 committed Sep 30, 2024
1 parent 132bddc commit d16b193
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions crates/astria-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ server = ["dep:tonic"]
test-utils = []
base64-serde = ["dep:base64-serde"]
brotli = ["dep:brotli"]
# When enabled, this adds constructors for some types that skip the normal constructor validity
# checks. It supports the case where the inputs are already deemed valid, e.g. having read them from
# local storage.
unchecked-constructors = []

[dev-dependencies]
astria-core = { path = ".", features = ["serde"] }
Expand Down
1 change: 1 addition & 0 deletions crates/astria-core/src/primitive/v1/asset/denom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ impl TracePrefixed {

/// This should only be used where the inputs have been provided by a trusted entity, e.g. read
/// from our own state store.
#[cfg(feature = "unchecked-constructors")]
#[doc(hidden)]
#[must_use]
pub fn unchecked_from_parts<I: IntoIterator<Item = (String, String)>>(
Expand Down
2 changes: 2 additions & 0 deletions crates/astria-core/src/primitive/v1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@ impl Address<Bech32m> {

/// This should only be used where the inputs have been provided by a trusted entity, e.g. read
/// from our own state store.
#[cfg(feature = "unchecked-constructors")]
#[doc(hidden)]
#[must_use]
pub fn unchecked_from_parts(bytes: [u8; ADDRESS_LEN], prefix: &str) -> Self {
Expand Down Expand Up @@ -889,6 +890,7 @@ mod tests {
let _ = address.into_raw();
}

#[cfg(feature = "unchecked-constructors")]
#[test]
fn address_to_unchecked_roundtrip() {
let bytes = [42u8; ADDRESS_LEN];
Expand Down
3 changes: 3 additions & 0 deletions crates/astria-core/src/sequencerblock/v1alpha1/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ impl RollupTransactions {

/// This should only be used where `parts` has been provided by a trusted entity, e.g. read from
/// our own state store.
#[cfg(feature = "unchecked-constructors")]
#[doc(hidden)]
#[must_use]
pub fn unchecked_from_parts(parts: RollupTransactionsParts) -> Self {
Expand Down Expand Up @@ -502,6 +503,7 @@ impl SequencerBlockHeader {

/// This should only be used where `parts` has been provided by a trusted entity, e.g. read from
/// our own state store.
#[cfg(feature = "unchecked-constructors")]
#[doc(hidden)]
#[must_use]
pub fn unchecked_from_parts(parts: SequencerBlockHeaderParts) -> Self {
Expand Down Expand Up @@ -969,6 +971,7 @@ impl SequencerBlock {

/// This should only be used where `parts` has been provided by a trusted entity, e.g. read from
/// our own state store.
#[cfg(feature = "unchecked-constructors")]
#[doc(hidden)]
#[must_use]
pub fn unchecked_from_parts(parts: SequencerBlockParts) -> Self {
Expand Down
6 changes: 5 additions & 1 deletion crates/astria-sequencer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ name = "astria-sequencer"
benchmark = ["divan"]

[dependencies]
astria-core = { path = "../astria-core", features = ["server", "serde"] }
astria-core = { path = "../astria-core", features = [
"server",
"serde",
"unchecked-constructors",
] }
astria-build-info = { path = "../astria-build-info", features = ["runtime"] }

# The "anyhow" feature is only included because it is necessary for the implementation of
Expand Down

0 comments on commit d16b193

Please sign in to comment.