Skip to content

Commit

Permalink
feat(rpc): fix build, remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
MrWad3r committed Feb 3, 2025
1 parent 88370ce commit 4af22af
Show file tree
Hide file tree
Showing 6 changed files with 458 additions and 48 deletions.
3 changes: 2 additions & 1 deletion block-util/src/message/ext_msg_repr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ impl ExtMsgRepr {
pub const MAX_ALLOWED_MERKLE_DEPTH: u8 = 2;
pub const MAX_MSG_BITS: u64 = 1 << 21;
pub const MAX_MSG_CELLS: u64 = 1 << 13;
pub const BOUNDARY_BOC_SIZE: usize = 3500;

pub const ALLOWED_WORKCHAINS: std::ops::RangeInclusive<i8> = -1..=0;

// === General methods ===

pub(crate) fn validate<T: AsRef<[u8]>>(bytes: T) -> Result<(), InvalidExtMsg> {
pub fn validate<T: AsRef<[u8]>>(bytes: T) -> Result<(), InvalidExtMsg> {
if bytes.as_ref().len() > Self::MAX_BOC_SIZE {
return Err(InvalidExtMsg::BocSizeExceeded);
}
Expand Down
16 changes: 0 additions & 16 deletions block-util/src/message/external_message_decoder.rs

This file was deleted.

5 changes: 1 addition & 4 deletions block-util/src/message/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
mod ext_msg_repr;
mod external_message_decoder;

pub use ext_msg_repr::{create_big_message, create_deep_merkle, MsgStorageStat};
pub use external_message_decoder::{ExternalMessageValidator, RawMessageRepr};
pub use ext_msg_repr::{create_big_message, create_deep_merkle, ExtMsgRepr, MsgStorageStat};
40 changes: 27 additions & 13 deletions core/src/blockchain_rpc/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use bytes::{Buf, Bytes};
use everscale_types::models::BlockId;
use futures_util::Future;
use serde::{Deserialize, Serialize};
use tycho_block_util::message::{ExternalMessageValidator, RawMessageRepr};
use tycho_block_util::message::ExtMsgRepr;
use tycho_network::{try_handle_prefix, InboundRequestMeta, Response, Service, ServiceRequest};
use tycho_storage::{ArchiveId, BlockConnection, KeyBlocksDirection, PersistentStateKind, Storage};
use tycho_util::futures::BoxFutureOrNoop;
Expand Down Expand Up @@ -326,19 +326,33 @@ impl<B: BroadcastListener> Service<ServiceRequest> for BlockchainRpcService<B> {
metrics::counter!("tycho_rpc_broadcast_external_message_rx_bytes_total")
.increment(req.body.len() as u64);

if req.body.len() > RawMessageRepr::BOUNDARY_BOC_SIZE {
if let Err(e) = RawMessageRepr::validate(req.body.as_ref()) {
tracing::debug!("failed to validate external message: {e:?}");
return BoxFutureOrNoop::Noop;
}
if req.body.len() > ExtMsgRepr::BOUNDARY_BOC_SIZE {
let cloned = req.body.clone();
BoxFutureOrNoop::future(async move {
match tycho_util::sync::rayon_run_fifo(move || {
ExtMsgRepr::validate(&cloned)
})
.await
{
Ok(_) => {
inner
.broadcast_listener
.handle_message(req.metadata, req.body)
.await;
}
Err(e) => {
tracing::debug!("failed to validate external message: {e:?}");
}
}
})
} else {
BoxFutureOrNoop::future(async move {
inner
.broadcast_listener
.handle_message(req.metadata, req.body)
.await;
})
}

BoxFutureOrNoop::future(async move {
inner
.broadcast_listener
.handle_message(req.metadata, req.body)
.await;
})
}
constructor => {
tracing::debug!("unknown broadcast constructor: {constructor:08x}");
Expand Down
Loading

0 comments on commit 4af22af

Please sign in to comment.