Skip to content

Commit 4e02ba6

Browse files
committed
Check limits from config in BuildOutMsgQueueProof
1 parent c12aff6 commit 4e02ba6

File tree

3 files changed

+33
-13
lines changed

3 files changed

+33
-13
lines changed

validator/full-node-shard.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -706,14 +706,6 @@ void FullNodeShardImpl::process_query(adnl::AdnlNodeIdShort src, ton_api::tonNod
706706
return;
707707
}
708708
block::ImportedMsgQueueLimits limits{(td::uint32)query.limits_->max_bytes_, (td::uint32)query.limits_->max_msgs_};
709-
if (limits.max_msgs > 512) {
710-
promise.set_error(td::Status::Error("max_msgs is too big"));
711-
return;
712-
}
713-
if (limits.max_bytes > (1 << 21)) {
714-
promise.set_error(td::Status::Error("max_bytes is too big"));
715-
return;
716-
}
717709
FLOG(DEBUG) {
718710
sb << "Got query getOutMsgQueueProof to shard " << dst_shard.to_str() << " from blocks";
719711
for (const BlockIdExt &id : blocks) {

validator/impl/out-msg-queue-proof.cpp

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -528,11 +528,11 @@ void OutMsgQueueImporter::alarm() {
528528
td::remove_if(it->second.pending_entries,
529529
[](const std::shared_ptr<CacheEntry>& entry) { return entry->done || entry->promises.empty(); });
530530
if (it->second.timeout.is_in_past()) {
531-
if (it->second.pending_entries.empty()) {
532-
it = small_cache_.erase(it);
533-
} else {
534-
++it;
535-
}
531+
if (it->second.pending_entries.empty()) {
532+
it = small_cache_.erase(it);
533+
} else {
534+
++it;
535+
}
536536
} else {
537537
alarm_timestamp().relax(it->second.timeout);
538538
++it;
@@ -571,6 +571,33 @@ void BuildOutMsgQueueProof::abort_query(td::Status reason) {
571571
}
572572

573573
void BuildOutMsgQueueProof::start_up() {
574+
if (blocks_.size() > 16) {
575+
abort_query(td::Status::Error("too many blocks"));
576+
return;
577+
}
578+
td::actor::send_closure(manager_, &ValidatorManagerInterface::get_top_masterchain_state,
579+
[SelfId = actor_id(this)](td::Result<Ref<MasterchainState>> R) {
580+
if (R.is_error()) {
581+
td::actor::send_closure(SelfId, &BuildOutMsgQueueProof::abort_query,
582+
R.move_as_error_prefix("failed to get masterchain state: "));
583+
} else {
584+
td::actor::send_closure(SelfId, &BuildOutMsgQueueProof::got_masterchain_state,
585+
R.move_as_ok());
586+
}
587+
});
588+
}
589+
590+
void BuildOutMsgQueueProof::got_masterchain_state(Ref<MasterchainState> mc_state) {
591+
auto config_limits = mc_state->get_imported_msg_queue_limits(dst_shard_.is_masterchain());
592+
if ((td::uint64)config_limits.max_msgs * blocks_.size() < limits_.max_msgs) {
593+
abort_query(td::Status::Error("too big max_msgs"));
594+
return;
595+
}
596+
if ((td::uint64)config_limits.max_bytes * blocks_.size() < limits_.max_bytes) {
597+
abort_query(td::Status::Error("too big max_bytes"));
598+
return;
599+
}
600+
574601
for (size_t i = 0; i < blocks_.size(); ++i) {
575602
BlockIdExt id = blocks_[i].id;
576603
++pending;

validator/impl/out-msg-queue-proof.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ class BuildOutMsgQueueProof : public td::actor::Actor {
105105

106106
void abort_query(td::Status reason);
107107
void start_up() override;
108+
void got_masterchain_state(Ref<MasterchainState> mc_state);
108109
void got_state_root(size_t i, Ref<vm::Cell> root);
109110
void got_block_root(size_t i, Ref<vm::Cell> root);
110111
void build_proof();

0 commit comments

Comments
 (0)