Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blockchain service message limits #577

Merged
merged 1 commit into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ bytesize = { version = "1.3.0", features = ["serde"] }
castaway = "0.2"
clap = { version = "4.5.3", features = ["derive"] }
crc32c = "0.6"
criterion = "0.5.1"
dashmap = "5.5.3"
dirs = "5.0.1"
ed25519 = "2.0"
Expand Down
10 changes: 10 additions & 0 deletions block-util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ rust-version.workspace = true
repository.workspace = true
license.workspace = true

[[bench]]
name = "big_message"
harness = false

[[bench]]
name = "decode_message"
harness = false

[dependencies]
# crates.io deps
anyhow = { workspace = true }
Expand All @@ -24,6 +32,8 @@ tl-proto = { workspace = true }
tycho-util = { workspace = true }

[dev-dependencies]
base64 = { workspace = true }
criterion = { workspace = true }

[features]
test = []
Expand Down
25 changes: 25 additions & 0 deletions block-util/benches/big_message.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use bytes::Bytes;
use criterion::{criterion_group, criterion_main, Criterion};
use everscale_types::prelude::Boc;
use tycho_block_util::message::ExtMsgRepr;

use self::common::create_big_message;

mod common;

fn big_message_benchmark(c: &mut Criterion) {
let boc = {
let cell = create_big_message().unwrap();
Boc::encode(&cell)
};

let bytes = Bytes::from(boc);
c.bench_function("big-message", |b| {
b.iter(|| {
let _ = ExtMsgRepr::validate(bytes.clone());
});
});
}

criterion_group!(benches, big_message_benchmark);
criterion_main!(benches);
36 changes: 36 additions & 0 deletions block-util/benches/common.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use everscale_types::cell::{Cell, CellBuilder, CellSliceRange};
use everscale_types::models::{MsgInfo, OwnedMessage};
use tycho_block_util::message::ExtMsgRepr;

pub fn create_big_message() -> anyhow::Result<Cell> {
let mut count = 0;
let body = make_big_tree(8, &mut count, ExtMsgRepr::MAX_MSG_CELLS as u16 - 100);

let body_range = CellSliceRange::full(body.as_ref());

let cell = CellBuilder::build_from(OwnedMessage {
info: MsgInfo::ExtIn(Default::default()),
init: None,
body: (body, body_range),
layout: None,
})?;

Ok(cell)
}

fn make_big_tree(depth: u8, count: &mut u16, target: u16) -> Cell {
*count += 1;

if depth == 0 {
CellBuilder::build_from(*count).unwrap()
} else {
let mut b = CellBuilder::new();
for _ in 0..4 {
if *count < target {
b.store_reference(make_big_tree(depth - 1, count, target))
.unwrap();
}
}
b.build().unwrap()
}
}
52 changes: 52 additions & 0 deletions block-util/benches/decode_message.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use base64::prelude::Engine as _;
use criterion::{criterion_group, criterion_main, Criterion};
use everscale_types::boc::Boc;
use everscale_types::cell::{Cell, CellTreeStats};
use everscale_types::models::MsgInfo;
use everscale_types::prelude::{CellFamily, Load};
use tycho_block_util::message::MsgStorageStat;

use self::common::create_big_message;

mod common;

fn decode_benchmark(c: &mut Criterion) {
let boc = {
let cell = create_big_message().unwrap();
Boc::encode_base64(&cell)
};

fn decode_base64_impl(data: &[u8]) -> Result<Vec<u8>, base64::DecodeError> {
base64::engine::general_purpose::STANDARD.decode(data)
}

c.bench_function("decode-base64", |b| {
b.iter(|| decode_base64_impl(boc.as_ref()).unwrap());
});

let x = decode_base64_impl(boc.as_ref()).unwrap();

c.bench_function("boc-decode-ext-base64", |b| {
b.iter(|| Boc::decode_ext(x.as_ref(), Cell::empty_context()));
});

let result = Boc::decode_ext(x.as_ref(), Cell::empty_context()).unwrap();

c.bench_function("owned-message-load", |b| {
b.iter(|| MsgInfo::load_from(&mut result.as_slice().unwrap()).unwrap());
});
let cs = &mut result.as_slice().unwrap();
let _ = MsgInfo::load_from(cs).unwrap();

c.bench_function("traverse", |b| {
b.iter(|| {
MsgStorageStat::check_slice(cs, 2, CellTreeStats {
bit_count: 1 << 21,
cell_count: 1 << 13,
})
});
});
}

criterion_group!(benches, decode_benchmark);
criterion_main!(benches);
21 changes: 10 additions & 11 deletions block-util/src/block/block_proof_stuff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,6 @@ pub struct BlockProofStuff {
impl BlockProofStuff {
#[cfg(any(test, feature = "test"))]
pub fn new_empty(block_id: &BlockId) -> Self {
use everscale_types::merkle::MerkleUpdate;

struct AlwaysInclude;

impl MerkleFilter for AlwaysInclude {
fn check(&self, _: &HashBytes) -> FilterAction {
FilterAction::Include
}
}

let block_info = BlockInfo {
shard: block_id.shard,
seqno: block_id.seqno,
Expand Down Expand Up @@ -240,7 +230,7 @@ impl BlockProofStuff {

anyhow::ensure!(
&signatures.consensus_info == mc_consensus_info,
"block consensus info does not match master state consensus info (found: {:?}, expected: {:?}",
"block consensus info does not match master state consensus info (found: {:?}, expected: {:?}",
signatures.consensus_info, mc_consensus_info,
);

Expand Down Expand Up @@ -549,3 +539,12 @@ impl ValidatorSubsetInfo {
})
}
}

// TODO: Move into `types`.
pub struct AlwaysInclude;

impl MerkleFilter for AlwaysInclude {
fn check(&self, _: &HashBytes) -> FilterAction {
FilterAction::Include
}
}
4 changes: 2 additions & 2 deletions block-util/src/block/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub use self::block_id_ext::{calc_next_block_id_short, BlockIdExt, BlockIdRelation};
pub use self::block_proof_stuff::{
check_with_master_state, check_with_prev_key_block_proof, BlockProofStuff, BlockProofStuffAug,
ValidatorSubsetInfo,
check_with_master_state, check_with_prev_key_block_proof, AlwaysInclude, BlockProofStuff,
BlockProofStuffAug, ValidatorSubsetInfo,
};
pub use self::block_stuff::{BlockStuff, BlockStuffAug};
pub use self::top_blocks::{ShardHeights, TopBlocks, TopBlocksShortIdsIter};
Expand Down
1 change: 1 addition & 0 deletions block-util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pub mod archive;
pub mod block;
pub mod config;
pub mod dict;
pub mod message;
pub mod queue;
pub mod state;
pub mod tl;
Loading