Skip to content

Commit

Permalink
Enforce tm block size bounds during (de)serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
sug0 committed Nov 30, 2022
1 parent bd4ae94 commit 414b6e9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 15 deletions.
16 changes: 2 additions & 14 deletions apps/src/lib/config/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,7 @@ pub mod genesis_config {
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct ParametersConfig {
// Max Tendermint block size in bytes.
// XXX: we use i64 becauase that's what tower-abci
// and tendermint-rs expect
pub max_bytes_per_block: i64,
pub max_bytes_per_block: TendermintBytesPerBlock,
// Minimum number of blocks per epoch.
// XXX: u64 doesn't work with toml-rs!
pub min_num_of_blocks: u64,
Expand Down Expand Up @@ -537,9 +535,6 @@ pub mod genesis_config {
})
.collect();

const BLOCK_SIZE_EXPECT: &str =
"The acceptable size range for a Tendermint block is 1B - 100MB";

let parameters = Parameters {
epoch_duration: EpochDuration {
min_num_of_blocks: config.parameters.min_num_of_blocks,
Expand All @@ -553,14 +548,7 @@ pub mod genesis_config {
config.parameters.max_expected_time_per_block,
)
.into(),
max_bytes_per_block: TendermintBytesPerBlock::new(
config
.parameters
.max_bytes_per_block
.try_into()
.expect(BLOCK_SIZE_EXPECT),
)
.expect(BLOCK_SIZE_EXPECT),
max_bytes_per_block: config.parameters.max_bytes_per_block,
vp_whitelist: config.parameters.vp_whitelist.unwrap_or_default(),
tx_whitelist: config.parameters.tx_whitelist.unwrap_or_default(),
};
Expand Down
2 changes: 1 addition & 1 deletion tests/src/e2e/ledger_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2303,7 +2303,7 @@ fn proposal_submission() -> Result<()> {
let test = setup::network(
|genesis| {
let parameters = ParametersConfig {
max_bytes_per_block: 20 << 20,
max_bytes_per_block: Default::default(),
min_num_of_blocks: 1,
min_duration: 1,
max_expected_time_per_block: 1,
Expand Down

0 comments on commit 414b6e9

Please sign in to comment.