-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Domain type & semantic validation of
max_tx_size
and max_num_msg
…
…config options (#1246) * Fix for #1245 * Split out params semantic validation from health check * Fixup changelog entry * Add .changelog entry * Extract max fraction of genesis block max size into a consant * Doc comments for constants * Harmonize error messages * Improve error message layout * Comments & output consistent with parameters * Final aestetic change Co-authored-by: Romain Ruetschi <[email protected]>
- Loading branch information
Showing
7 changed files
with
205 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
Use the [`flex-error`](https://docs.rs/flex-error/) crate to define and | ||
handle errors. | ||
- Use the [`flex-error`](https://docs.rs/flex-error/) crate to define and | ||
handle errors ([#1158]) | ||
|
||
[#1158]: https://github.com/informalsystems/ibc-rs/issues/1158 |
3 changes: 3 additions & 0 deletions
3
.changelog/unreleased/improvements/1245-max-params-validation.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
- Add semantic validation of of `max_tx_size` and `max_num_msg` config options ([#1245]) | ||
|
||
[#1245]: https://github.com/informalsystems/ibc-rs/issues/1245 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
//! Configuration-related types. | ||
//! | ||
//! Implements defaults, as well as serializing and | ||
//! deserializing with upper-bound verification. | ||
use serde::de::Unexpected; | ||
use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer}; | ||
|
||
#[derive(Debug, Clone, Copy)] | ||
pub struct MaxMsgNum(usize); | ||
|
||
impl MaxMsgNum { | ||
const DEFAULT: usize = 30; | ||
const MAX_BOUND: usize = 100; | ||
} | ||
|
||
impl Default for MaxMsgNum { | ||
fn default() -> Self { | ||
Self(Self::DEFAULT) | ||
} | ||
} | ||
|
||
impl<'de> Deserialize<'de> for MaxMsgNum { | ||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> | ||
where | ||
D: Deserializer<'de>, | ||
{ | ||
let u = usize::deserialize(deserializer)?; | ||
|
||
if u > Self::MAX_BOUND { | ||
return Err(D::Error::invalid_value( | ||
Unexpected::Unsigned(u as u64), | ||
&format!("a usize less than {}", Self::MAX_BOUND).as_str(), | ||
)); | ||
} | ||
|
||
Ok(MaxMsgNum(u)) | ||
} | ||
} | ||
|
||
impl Serialize for MaxMsgNum { | ||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: Serializer, | ||
{ | ||
self.0.serialize(serializer) | ||
} | ||
} | ||
|
||
impl From<MaxMsgNum> for usize { | ||
fn from(m: MaxMsgNum) -> Self { | ||
m.0 | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone, Copy)] | ||
pub struct MaxTxSize(usize); | ||
|
||
impl MaxTxSize { | ||
const DEFAULT: usize = 2 * 1048576; // 2 MBytes | ||
const MAX_BOUND: usize = 8 * 1048576; // 8 MBytes | ||
} | ||
|
||
impl Default for MaxTxSize { | ||
fn default() -> Self { | ||
Self(Self::DEFAULT) | ||
} | ||
} | ||
|
||
impl<'de> Deserialize<'de> for MaxTxSize { | ||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> | ||
where | ||
D: Deserializer<'de>, | ||
{ | ||
let u = usize::deserialize(deserializer)?; | ||
|
||
if u > Self::MAX_BOUND { | ||
return Err(D::Error::invalid_value( | ||
Unexpected::Unsigned(u as u64), | ||
&format!("a usize less than {}", Self::MAX_BOUND).as_str(), | ||
)); | ||
} | ||
|
||
Ok(MaxTxSize(u)) | ||
} | ||
} | ||
|
||
impl Serialize for MaxTxSize { | ||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: Serializer, | ||
{ | ||
self.0.serialize(serializer) | ||
} | ||
} | ||
|
||
impl From<MaxTxSize> for usize { | ||
fn from(m: MaxTxSize) -> Self { | ||
m.0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters