mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
Add mempool messages cap
This commit is contained in:
parent
678a8a6a13
commit
69d0472510
7 changed files with 31 additions and 2 deletions
|
@ -1309,6 +1309,9 @@ td::Status ValidatorEngine::load_global_config() {
|
||||||
if (state_ttl_ != 0) {
|
if (state_ttl_ != 0) {
|
||||||
validator_options_.write().set_state_ttl(state_ttl_);
|
validator_options_.write().set_state_ttl(state_ttl_);
|
||||||
}
|
}
|
||||||
|
if (max_mempool_num_ != 0) {
|
||||||
|
validator_options_.write().set_max_mempool_num(max_mempool_num_);
|
||||||
|
}
|
||||||
if (block_ttl_ != 0) {
|
if (block_ttl_ != 0) {
|
||||||
validator_options_.write().set_block_ttl(block_ttl_);
|
validator_options_.write().set_block_ttl(block_ttl_);
|
||||||
}
|
}
|
||||||
|
@ -3336,6 +3339,10 @@ int main(int argc, char *argv[]) {
|
||||||
auto v = td::to_double(fname);
|
auto v = td::to_double(fname);
|
||||||
acts.push_back([&x, v]() { td::actor::send_closure(x, &ValidatorEngine::set_state_ttl, v); });
|
acts.push_back([&x, v]() { td::actor::send_closure(x, &ValidatorEngine::set_state_ttl, v); });
|
||||||
});
|
});
|
||||||
|
p.add_option('m', "mempool-num", "Maximal number of mempool external message", [&](td::Slice fname) {
|
||||||
|
auto v = td::to_double(fname);
|
||||||
|
acts.push_back([&x, v]() { td::actor::send_closure(x, &ValidatorEngine::set_max_mempool_num, v); });
|
||||||
|
});
|
||||||
p.add_option('b', "block-ttl", "blocks will be gc'd after this time (in seconds) default=7*86400",
|
p.add_option('b', "block-ttl", "blocks will be gc'd after this time (in seconds) default=7*86400",
|
||||||
[&](td::Slice fname) {
|
[&](td::Slice fname) {
|
||||||
auto v = td::to_double(fname);
|
auto v = td::to_double(fname);
|
||||||
|
|
|
@ -191,6 +191,7 @@ class ValidatorEngine : public td::actor::Actor {
|
||||||
std::map<CI_key, td::uint32> control_permissions_;
|
std::map<CI_key, td::uint32> control_permissions_;
|
||||||
|
|
||||||
double state_ttl_ = 0;
|
double state_ttl_ = 0;
|
||||||
|
double max_mempool_num_ = 0;
|
||||||
double block_ttl_ = 0;
|
double block_ttl_ = 0;
|
||||||
double sync_ttl_ = 0;
|
double sync_ttl_ = 0;
|
||||||
double archive_ttl_ = 0;
|
double archive_ttl_ = 0;
|
||||||
|
@ -223,6 +224,9 @@ class ValidatorEngine : public td::actor::Actor {
|
||||||
void set_state_ttl(double t) {
|
void set_state_ttl(double t) {
|
||||||
state_ttl_ = t;
|
state_ttl_ = t;
|
||||||
}
|
}
|
||||||
|
void set_max_mempool_num(double t) {
|
||||||
|
max_mempool_num_ = t;
|
||||||
|
}
|
||||||
void set_block_ttl(double t) {
|
void set_block_ttl(double t) {
|
||||||
block_ttl_ = t;
|
block_ttl_ = t;
|
||||||
}
|
}
|
||||||
|
|
|
@ -366,6 +366,9 @@ void ValidatorManagerImpl::new_external_message(td::BufferSlice data) {
|
||||||
if (!is_validator()) {
|
if (!is_validator()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if( ext_messages_.size() > max_mempool_num() ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
auto R = create_ext_message(std::move(data));
|
auto R = create_ext_message(std::move(data));
|
||||||
if (R.is_error()) {
|
if (R.is_error()) {
|
||||||
VLOG(VALIDATOR_NOTICE) << "dropping bad ihr message: " << R.move_as_error();
|
VLOG(VALIDATOR_NOTICE) << "dropping bad ihr message: " << R.move_as_error();
|
||||||
|
|
|
@ -580,6 +580,9 @@ class ValidatorManagerImpl : public ValidatorManager {
|
||||||
double block_ttl() const {
|
double block_ttl() const {
|
||||||
return opts_->block_ttl();
|
return opts_->block_ttl();
|
||||||
}
|
}
|
||||||
|
double max_mempool_num() const {
|
||||||
|
return opts_->max_mempool_num();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<BlockSeqno, WaitList<td::actor::Actor, td::Unit>> shard_client_waiters_;
|
std::map<BlockSeqno, WaitList<td::actor::Actor, td::Unit>> shard_client_waiters_;
|
||||||
|
|
|
@ -27,10 +27,11 @@ namespace validator {
|
||||||
td::Ref<ValidatorManagerOptions> ValidatorManagerOptions::create(
|
td::Ref<ValidatorManagerOptions> ValidatorManagerOptions::create(
|
||||||
BlockIdExt zero_block_id, BlockIdExt init_block_id,
|
BlockIdExt zero_block_id, BlockIdExt init_block_id,
|
||||||
std::function<bool(ShardIdFull, CatchainSeqno, ShardCheckMode)> check_shard, bool allow_blockchain_init,
|
std::function<bool(ShardIdFull, CatchainSeqno, ShardCheckMode)> check_shard, bool allow_blockchain_init,
|
||||||
double sync_blocks_before, double block_ttl, double state_ttl,
|
double sync_blocks_before, double block_ttl, double state_ttl, double max_mempool_num,
|
||||||
double archive_ttl, double key_proof_ttl, bool initial_sync_disabled) {
|
double archive_ttl, double key_proof_ttl, bool initial_sync_disabled) {
|
||||||
return td::make_ref<ValidatorManagerOptionsImpl>(zero_block_id, init_block_id, std::move(check_shard),
|
return td::make_ref<ValidatorManagerOptionsImpl>(zero_block_id, init_block_id, std::move(check_shard),
|
||||||
allow_blockchain_init, sync_blocks_before, block_ttl, state_ttl,
|
allow_blockchain_init, sync_blocks_before, block_ttl, state_ttl,
|
||||||
|
max_mempool_num,
|
||||||
archive_ttl, key_proof_ttl, initial_sync_disabled);
|
archive_ttl, key_proof_ttl, initial_sync_disabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,9 @@ struct ValidatorManagerOptionsImpl : public ValidatorManagerOptions {
|
||||||
double state_ttl() const override {
|
double state_ttl() const override {
|
||||||
return state_ttl_;
|
return state_ttl_;
|
||||||
}
|
}
|
||||||
|
double max_mempool_num() const override {
|
||||||
|
return max_mempool_num_;
|
||||||
|
}
|
||||||
double archive_ttl() const override {
|
double archive_ttl() const override {
|
||||||
return archive_ttl_;
|
return archive_ttl_;
|
||||||
}
|
}
|
||||||
|
@ -130,6 +133,9 @@ struct ValidatorManagerOptionsImpl : public ValidatorManagerOptions {
|
||||||
void set_state_ttl(double value) override {
|
void set_state_ttl(double value) override {
|
||||||
state_ttl_ = value;
|
state_ttl_ = value;
|
||||||
}
|
}
|
||||||
|
void set_max_mempool_num(double value) override {
|
||||||
|
max_mempool_num_ = value;
|
||||||
|
}
|
||||||
void set_archive_ttl(double value) override {
|
void set_archive_ttl(double value) override {
|
||||||
archive_ttl_ = value;
|
archive_ttl_ = value;
|
||||||
}
|
}
|
||||||
|
@ -163,7 +169,7 @@ struct ValidatorManagerOptionsImpl : public ValidatorManagerOptions {
|
||||||
ValidatorManagerOptionsImpl(BlockIdExt zero_block_id, BlockIdExt init_block_id,
|
ValidatorManagerOptionsImpl(BlockIdExt zero_block_id, BlockIdExt init_block_id,
|
||||||
std::function<bool(ShardIdFull, CatchainSeqno, ShardCheckMode)> check_shard,
|
std::function<bool(ShardIdFull, CatchainSeqno, ShardCheckMode)> check_shard,
|
||||||
bool allow_blockchain_init, double sync_blocks_before,
|
bool allow_blockchain_init, double sync_blocks_before,
|
||||||
double block_ttl, double state_ttl,
|
double block_ttl, double state_ttl, double max_mempool_num,
|
||||||
double archive_ttl, double key_proof_ttl,
|
double archive_ttl, double key_proof_ttl,
|
||||||
bool initial_sync_disabled)
|
bool initial_sync_disabled)
|
||||||
: zero_block_id_(zero_block_id)
|
: zero_block_id_(zero_block_id)
|
||||||
|
@ -173,6 +179,7 @@ struct ValidatorManagerOptionsImpl : public ValidatorManagerOptions {
|
||||||
, sync_blocks_before_(sync_blocks_before)
|
, sync_blocks_before_(sync_blocks_before)
|
||||||
, block_ttl_(block_ttl)
|
, block_ttl_(block_ttl)
|
||||||
, state_ttl_(state_ttl)
|
, state_ttl_(state_ttl)
|
||||||
|
, max_mempool_num_(max_mempool_num)
|
||||||
, archive_ttl_(archive_ttl)
|
, archive_ttl_(archive_ttl)
|
||||||
, key_proof_ttl_(key_proof_ttl)
|
, key_proof_ttl_(key_proof_ttl)
|
||||||
, initial_sync_disabled_(initial_sync_disabled) {
|
, initial_sync_disabled_(initial_sync_disabled) {
|
||||||
|
@ -186,6 +193,7 @@ struct ValidatorManagerOptionsImpl : public ValidatorManagerOptions {
|
||||||
double sync_blocks_before_;
|
double sync_blocks_before_;
|
||||||
double block_ttl_;
|
double block_ttl_;
|
||||||
double state_ttl_;
|
double state_ttl_;
|
||||||
|
double max_mempool_num_;
|
||||||
double archive_ttl_;
|
double archive_ttl_;
|
||||||
double key_proof_ttl_;
|
double key_proof_ttl_;
|
||||||
bool initial_sync_disabled_;
|
bool initial_sync_disabled_;
|
||||||
|
|
|
@ -56,6 +56,7 @@ struct ValidatorManagerOptions : public td::CntObject {
|
||||||
virtual double sync_blocks_before() const = 0;
|
virtual double sync_blocks_before() const = 0;
|
||||||
virtual double block_ttl() const = 0;
|
virtual double block_ttl() const = 0;
|
||||||
virtual double state_ttl() const = 0;
|
virtual double state_ttl() const = 0;
|
||||||
|
virtual double max_mempool_num() const = 0;
|
||||||
virtual double archive_ttl() const = 0;
|
virtual double archive_ttl() const = 0;
|
||||||
virtual double key_proof_ttl() const = 0;
|
virtual double key_proof_ttl() const = 0;
|
||||||
virtual bool initial_sync_disabled() const = 0;
|
virtual bool initial_sync_disabled() const = 0;
|
||||||
|
@ -81,6 +82,7 @@ struct ValidatorManagerOptions : public td::CntObject {
|
||||||
virtual void set_sync_blocks_before(double value) = 0;
|
virtual void set_sync_blocks_before(double value) = 0;
|
||||||
virtual void set_block_ttl(double value) = 0;
|
virtual void set_block_ttl(double value) = 0;
|
||||||
virtual void set_state_ttl(double value) = 0;
|
virtual void set_state_ttl(double value) = 0;
|
||||||
|
virtual void set_max_mempool_num(double value) = 0;
|
||||||
virtual void set_archive_ttl(double value) = 0;
|
virtual void set_archive_ttl(double value) = 0;
|
||||||
virtual void set_key_proof_ttl(double value) = 0;
|
virtual void set_key_proof_ttl(double value) = 0;
|
||||||
virtual void set_initial_sync_disabled(bool value) = 0;
|
virtual void set_initial_sync_disabled(bool value) = 0;
|
||||||
|
@ -96,6 +98,7 @@ struct ValidatorManagerOptions : public td::CntObject {
|
||||||
ShardCheckMode) { return true; },
|
ShardCheckMode) { return true; },
|
||||||
bool allow_blockchain_init = false, double sync_blocks_before = 300, double block_ttl = 86400 * 7,
|
bool allow_blockchain_init = false, double sync_blocks_before = 300, double block_ttl = 86400 * 7,
|
||||||
double state_ttl = 3600, double archive_ttl = 86400 * 365, double key_proof_ttl = 86400 * 3650,
|
double state_ttl = 3600, double archive_ttl = 86400 * 365, double key_proof_ttl = 86400 * 3650,
|
||||||
|
double max_mempool_num = 999999,
|
||||||
bool initial_sync_disabled = false);
|
bool initial_sync_disabled = false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue