1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-02-15 04:32:21 +00:00

fixed possible CE

This commit is contained in:
ton 2020-03-24 11:00:14 +04:00
parent 9f351fc29f
commit 606e970ed5
4 changed files with 106 additions and 97 deletions

View file

@ -39,9 +39,12 @@ namespace validator {
using td::Ref; using td::Ref;
class Collator final : public td::actor::Actor { class Collator final : public td::actor::Actor {
static constexpr int supported_version = 1; static constexpr int supported_version() {
static constexpr long long supported_capabilities = return 1;
ton::capCreateStatsEnabled | ton::capBounceMsgBody | ton::capReportVersion; }
static constexpr long long supported_capabilities() {
return ton::capCreateStatsEnabled | ton::capBounceMsgBody | ton::capReportVersion;
}
using LtCellRef = block::LtCellRef; using LtCellRef = block::LtCellRef;
using NewOutMsg = block::NewOutMsg; using NewOutMsg = block::NewOutMsg;
const ShardIdFull shard; const ShardIdFull shard;

View file

@ -197,8 +197,8 @@ void Collator::start_up() {
// 4. load external messages // 4. load external messages
LOG(DEBUG) << "sending get_external_messages() query to Manager"; LOG(DEBUG) << "sending get_external_messages() query to Manager";
++pending; ++pending;
td::actor::send_closure_later(manager, &ValidatorManager::get_external_messages, td::actor::send_closure_later(manager, &ValidatorManager::get_external_messages, shard,
shard, [self = get_self()](td::Result<std::vector<Ref<ExtMessage>>> res)->void { [self = get_self()](td::Result<std::vector<Ref<ExtMessage>>> res) -> void {
LOG(DEBUG) << "got answer to get_external_messages() query"; LOG(DEBUG) << "got answer to get_external_messages() query";
td::actor::send_closure_later(std::move(self), &Collator::after_get_external_messages, td::actor::send_closure_later(std::move(self), &Collator::after_get_external_messages,
std::move(res)); std::move(res));
@ -208,8 +208,8 @@ void Collator::start_up() {
LOG(DEBUG) << "sending get_shard_blocks() query to Manager"; LOG(DEBUG) << "sending get_shard_blocks() query to Manager";
++pending; ++pending;
td::actor::send_closure_later( td::actor::send_closure_later(
manager, &ValidatorManager::get_shard_blocks, manager, &ValidatorManager::get_shard_blocks, prev_blocks[0],
prev_blocks[0], [self = get_self()](td::Result<std::vector<Ref<ShardTopBlockDescription>>> res)->void { [self = get_self()](td::Result<std::vector<Ref<ShardTopBlockDescription>>> res) -> void {
LOG(DEBUG) << "got answer to get_shard_blocks() query"; LOG(DEBUG) << "got answer to get_shard_blocks() query";
td::actor::send_closure_later(std::move(self), &Collator::after_get_shard_blocks, std::move(res)); td::actor::send_closure_later(std::move(self), &Collator::after_get_shard_blocks, std::move(res));
}); });
@ -414,8 +414,8 @@ void Collator::after_get_mc_state(td::Result<std::pair<Ref<MasterchainState>, Bl
// NB. it is needed only for creating a correct ExtBlkRef reference to it, which requires start_lt and end_lt // NB. it is needed only for creating a correct ExtBlkRef reference to it, which requires start_lt and end_lt
LOG(DEBUG) << "sending wait_block_data() query #-1 for " << mc_block_id_.to_str() << " to Manager"; LOG(DEBUG) << "sending wait_block_data() query #-1 for " << mc_block_id_.to_str() << " to Manager";
++pending; ++pending;
td::actor::send_closure_later(manager, &ValidatorManager::wait_block_data_short, mc_block_id_, priority(), td::actor::send_closure_later(manager, &ValidatorManager::wait_block_data_short, mc_block_id_, priority(), timeout,
timeout, [self = get_self()](td::Result<Ref<BlockData>> res) { [self = get_self()](td::Result<Ref<BlockData>> res) {
LOG(DEBUG) << "got answer to wait_block_data query #-1"; LOG(DEBUG) << "got answer to wait_block_data query #-1";
td::actor::send_closure_later(std::move(self), &Collator::after_get_block_data, -1, td::actor::send_closure_later(std::move(self), &Collator::after_get_block_data, -1,
std::move(res)); std::move(res));
@ -530,14 +530,14 @@ bool Collator::unpack_last_mc_state() {
<< ", " << block_limits_->bytes.hard() << "]"; << ", " << block_limits_->bytes.hard() << "]";
LOG(DEBUG) << "block limits: gas [" << block_limits_->gas.underload() << ", " << block_limits_->gas.soft() << ", " LOG(DEBUG) << "block limits: gas [" << block_limits_->gas.underload() << ", " << block_limits_->gas.soft() << ", "
<< block_limits_->gas.hard() << "]"; << block_limits_->gas.hard() << "]";
if (config_->has_capabilities() && (config_->get_capabilities() & ~supported_capabilities)) { if (config_->has_capabilities() && (config_->get_capabilities() & ~supported_capabilities())) {
LOG(ERROR) << "block generation capabilities " << config_->get_capabilities() LOG(ERROR) << "block generation capabilities " << config_->get_capabilities()
<< " have been enabled in global configuration, but we support only " << supported_capabilities << " have been enabled in global configuration, but we support only " << supported_capabilities()
<< " (upgrade validator software?)"; << " (upgrade validator software?)";
} }
if (config_->get_global_version() > supported_version) { if (config_->get_global_version() > supported_version()) {
LOG(ERROR) << "block version " << config_->get_global_version() LOG(ERROR) << "block version " << config_->get_global_version()
<< " have been enabled in global configuration, but we support only " << supported_version << " have been enabled in global configuration, but we support only " << supported_version()
<< " (upgrade validator software?)"; << " (upgrade validator software?)";
} }
// TODO: extract start_lt and end_lt from prev_mc_block as well // TODO: extract start_lt and end_lt from prev_mc_block as well
@ -2938,9 +2938,9 @@ bool Collator::update_shard_config(const block::WorkchainSet& wc_set, const bloc
WorkchainId wc_id{ton::workchainInvalid}; WorkchainId wc_id{ton::workchainInvalid};
Ref<block::WorkchainInfo> wc_info; Ref<block::WorkchainInfo> wc_info;
ton::BlockSeqno& min_seqno = min_ref_mc_seqno_; ton::BlockSeqno& min_seqno = min_ref_mc_seqno_;
return shard_conf_->process_sibling_shard_hashes([ return shard_conf_->process_sibling_shard_hashes(
&wc_set, &wc_id, &wc_info, &ccvc, &min_seqno, now = now_, update_cc [&wc_set, &wc_id, &wc_info, &ccvc, &min_seqno, now = now_, update_cc](block::McShardHash& cur,
](block::McShardHash & cur, const block::McShardHash* sibling) { const block::McShardHash* sibling) {
if (!cur.is_valid()) { if (!cur.is_valid()) {
return -2; return -2;
} }
@ -3603,7 +3603,7 @@ bool Collator::create_block_info(Ref<vm::Cell>& block_info) {
} }
bool Collator::store_version(vm::CellBuilder& cb) const { bool Collator::store_version(vm::CellBuilder& cb) const {
return block::gen::t_GlobalVersion.pack_capabilities(cb, supported_version, supported_capabilities); return block::gen::t_GlobalVersion.pack_capabilities(cb, supported_version(), supported_capabilities());
} }
bool Collator::store_zero_state_ref(vm::CellBuilder& cb) { bool Collator::store_zero_state_ref(vm::CellBuilder& cb) {

View file

@ -270,16 +270,16 @@ void ValidateQuery::start_up() {
// 5. request masterchain state referred to in the block // 5. request masterchain state referred to in the block
if (!is_masterchain()) { if (!is_masterchain()) {
++pending; ++pending;
td::actor::send_closure_later(manager, &ValidatorManager::wait_block_state_short, mc_blkid_, priority(), td::actor::send_closure_later(manager, &ValidatorManager::wait_block_state_short, mc_blkid_, priority(), timeout,
timeout, [self = get_self()](td::Result<Ref<ShardState>> res) { [self = get_self()](td::Result<Ref<ShardState>> res) {
LOG(DEBUG) << "got answer to wait_block_state() query for masterchain block"; LOG(DEBUG) << "got answer to wait_block_state() query for masterchain block";
td::actor::send_closure_later(std::move(self), &ValidateQuery::after_get_mc_state, td::actor::send_closure_later(std::move(self), &ValidateQuery::after_get_mc_state,
std::move(res)); std::move(res));
}); });
// 5.1. request corresponding block handle // 5.1. request corresponding block handle
++pending; ++pending;
td::actor::send_closure_later(manager, &ValidatorManager::get_block_handle, mc_blkid_, td::actor::send_closure_later(manager, &ValidatorManager::get_block_handle, mc_blkid_, true,
true, [self = get_self()](td::Result<BlockHandle> res) { [self = get_self()](td::Result<BlockHandle> res) {
LOG(DEBUG) << "got answer to get_block_handle() query for masterchain block"; LOG(DEBUG) << "got answer to get_block_handle() query for masterchain block";
td::actor::send_closure_later(std::move(self), &ValidateQuery::got_mc_handle, td::actor::send_closure_later(std::move(self), &ValidateQuery::got_mc_handle,
std::move(res)); std::move(res));
@ -679,14 +679,14 @@ bool ValidateQuery::try_unpack_mc_state() {
config_->set_block_id_ext(mc_blkid_); config_->set_block_id_ext(mc_blkid_);
ihr_enabled_ = config_->ihr_enabled(); ihr_enabled_ = config_->ihr_enabled();
create_stats_enabled_ = config_->create_stats_enabled(); create_stats_enabled_ = config_->create_stats_enabled();
if (config_->has_capabilities() && (config_->get_capabilities() & ~supported_capabilities)) { if (config_->has_capabilities() && (config_->get_capabilities() & ~supported_capabilities())) {
LOG(ERROR) << "block generation capabilities " << config_->get_capabilities() LOG(ERROR) << "block generation capabilities " << config_->get_capabilities()
<< " have been enabled in global configuration, but we support only " << supported_capabilities << " have been enabled in global configuration, but we support only " << supported_capabilities()
<< " (upgrade validator software?)"; << " (upgrade validator software?)";
} }
if (config_->get_global_version() > supported_version) { if (config_->get_global_version() > supported_version()) {
LOG(ERROR) << "block version " << config_->get_global_version() LOG(ERROR) << "block version " << config_->get_global_version()
<< " have been enabled in global configuration, but we support only " << supported_version << " have been enabled in global configuration, but we support only " << supported_version()
<< " (upgrade validator software?)"; << " (upgrade validator software?)";
} }
@ -1323,11 +1323,12 @@ bool ValidateQuery::request_aux_mc_state(BlockSeqno seqno, Ref<MasterchainStateQ
CHECK(blkid.is_valid_ext() && blkid.is_masterchain()); CHECK(blkid.is_valid_ext() && blkid.is_masterchain());
LOG(DEBUG) << "sending auxiliary wait_block_state() query for " << blkid.to_str() << " to Manager"; LOG(DEBUG) << "sending auxiliary wait_block_state() query for " << blkid.to_str() << " to Manager";
++pending; ++pending;
td::actor::send_closure_later(manager, &ValidatorManager::wait_block_state_short, blkid, priority(), timeout, [ td::actor::send_closure_later(manager, &ValidatorManager::wait_block_state_short, blkid, priority(), timeout,
self = get_self(), blkid [self = get_self(), blkid](td::Result<Ref<ShardState>> res) {
](td::Result<Ref<ShardState>> res) {
LOG(DEBUG) << "got answer to wait_block_state query for " << blkid.to_str(); LOG(DEBUG) << "got answer to wait_block_state query for " << blkid.to_str();
td::actor::send_closure_later(std::move(self), &ValidateQuery::after_get_aux_shard_state, blkid, std::move(res)); td::actor::send_closure_later(std::move(self),
&ValidateQuery::after_get_aux_shard_state, blkid,
std::move(res));
}); });
state.clear(); state.clear();
return true; return true;
@ -2326,12 +2327,12 @@ bool ValidateQuery::precheck_account_updates() {
LOG(INFO) << "pre-checking all Account updates between the old and the new state"; LOG(INFO) << "pre-checking all Account updates between the old and the new state";
try { try {
CHECK(ps_.account_dict_ && ns_.account_dict_); CHECK(ps_.account_dict_ && ns_.account_dict_);
if (!ps_.account_dict_->scan_diff(*ns_.account_dict_, if (!ps_.account_dict_->scan_diff(
*ns_.account_dict_,
[this](td::ConstBitPtr key, int key_len, Ref<vm::CellSlice> old_val_extra, [this](td::ConstBitPtr key, int key_len, Ref<vm::CellSlice> old_val_extra,
Ref<vm::CellSlice> new_val_extra) { Ref<vm::CellSlice> new_val_extra) {
CHECK(key_len == 256); CHECK(key_len == 256);
return precheck_one_account_update(key, std::move(old_val_extra), return precheck_one_account_update(key, std::move(old_val_extra), std::move(new_val_extra));
std::move(new_val_extra));
}, },
3 /* check augmentation of changed nodes */)) { 3 /* check augmentation of changed nodes */)) {
return reject_query("invalid ShardAccounts dictionary in the new state"); return reject_query("invalid ShardAccounts dictionary in the new state");
@ -2687,12 +2688,12 @@ bool ValidateQuery::precheck_message_queue_update() {
try { try {
CHECK(ps_.out_msg_queue_ && ns_.out_msg_queue_); CHECK(ps_.out_msg_queue_ && ns_.out_msg_queue_);
CHECK(out_msg_dict_); CHECK(out_msg_dict_);
if (!ps_.out_msg_queue_->scan_diff(*ns_.out_msg_queue_, if (!ps_.out_msg_queue_->scan_diff(
*ns_.out_msg_queue_,
[this](td::ConstBitPtr key, int key_len, Ref<vm::CellSlice> old_val_extra, [this](td::ConstBitPtr key, int key_len, Ref<vm::CellSlice> old_val_extra,
Ref<vm::CellSlice> new_val_extra) { Ref<vm::CellSlice> new_val_extra) {
CHECK(key_len == 352); CHECK(key_len == 352);
return precheck_one_message_queue_update(key, std::move(old_val_extra), return precheck_one_message_queue_update(key, std::move(old_val_extra), std::move(new_val_extra));
std::move(new_val_extra));
}, },
3 /* check augmentation of changed nodes */)) { 3 /* check augmentation of changed nodes */)) {
return reject_query("invalid OutMsgQueue dictionary in the new state"); return reject_query("invalid OutMsgQueue dictionary in the new state");
@ -4673,7 +4674,8 @@ bool ValidateQuery::check_one_library_update(td::ConstBitPtr key, Ref<vm::CellSl
} else { } else {
old_publishers = std::make_unique<vm::Dictionary>(256); old_publishers = std::make_unique<vm::Dictionary>(256);
} }
if (!old_publishers->scan_diff(*new_publishers, if (!old_publishers->scan_diff(
*new_publishers,
[this, lib_key = key](td::ConstBitPtr key, int key_len, Ref<vm::CellSlice> old_val, [this, lib_key = key](td::ConstBitPtr key, int key_len, Ref<vm::CellSlice> old_val,
Ref<vm::CellSlice> new_val) { Ref<vm::CellSlice> new_val) {
CHECK(key_len == 256); CHECK(key_len == 256);
@ -5009,12 +5011,13 @@ bool ValidateQuery::check_mc_state_extra() {
try { try {
vm::AugmentedDictionary old_prev_dict{old_extra.r1.prev_blocks, 32, block::tlb::aug_OldMcBlocksInfo}; vm::AugmentedDictionary old_prev_dict{old_extra.r1.prev_blocks, 32, block::tlb::aug_OldMcBlocksInfo};
vm::AugmentedDictionary new_prev_dict{new_extra.r1.prev_blocks, 32, block::tlb::aug_OldMcBlocksInfo}; vm::AugmentedDictionary new_prev_dict{new_extra.r1.prev_blocks, 32, block::tlb::aug_OldMcBlocksInfo};
if (!old_prev_dict.scan_diff(new_prev_dict, if (!old_prev_dict.scan_diff(
new_prev_dict,
[this](td::ConstBitPtr key, int key_len, Ref<vm::CellSlice> old_val_extra, [this](td::ConstBitPtr key, int key_len, Ref<vm::CellSlice> old_val_extra,
Ref<vm::CellSlice> new_val_extra) { Ref<vm::CellSlice> new_val_extra) {
CHECK(key_len == 32); CHECK(key_len == 32);
return check_one_prev_dict_update( return check_one_prev_dict_update((unsigned)key.get_uint(32), std::move(old_val_extra),
(unsigned)key.get_uint(32), std::move(old_val_extra), std::move(new_val_extra)); std::move(new_val_extra));
}, },
3 /* check augmentation of changed nodes */)) { 3 /* check augmentation of changed nodes */)) {
return reject_query("invalid previous block dictionary in the new state"); return reject_query("invalid previous block dictionary in the new state");

View file

@ -107,9 +107,12 @@ inline ErrorCtxSet ErrorCtx::set_guard(std::vector<std::string> str_list) {
*/ */
class ValidateQuery : public td::actor::Actor { class ValidateQuery : public td::actor::Actor {
static constexpr int supported_version = 1; static constexpr int supported_version() {
static constexpr long long supported_capabilities = return 1;
ton::capCreateStatsEnabled | ton::capBounceMsgBody | ton::capReportVersion; }
static constexpr long long supported_capabilities() {
return ton::capCreateStatsEnabled | ton::capBounceMsgBody | ton::capReportVersion;
}
public: public:
ValidateQuery(ShardIdFull shard, UnixTime min_ts, BlockIdExt min_masterchain_block_id, std::vector<BlockIdExt> prev, ValidateQuery(ShardIdFull shard, UnixTime min_ts, BlockIdExt min_masterchain_block_id, std::vector<BlockIdExt> prev,