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

Flag "full collated data" in mc config; fix accept-block

This commit is contained in:
SpyCheese 2022-08-15 19:27:19 +03:00
parent 81d32ba5d6
commit 011e97f53c
17 changed files with 76 additions and 55 deletions

View file

@ -734,15 +734,15 @@ misbehaviour_punishment_config_v1#01
= MisbehaviourPunishmentConfig;
_ MisbehaviourPunishmentConfig = ConfigParam 40;
// collator_nodes: each collator is (workchain:int32 shard:uint64 adnl_id:uint256)
colator_config#a0 full_collated_data:Bool collator_nodes:(HashmapE 352 Unit) = CollatorConfig;
_ CollatorConfig = ConfigParam 41;
oracle_bridge_params#_ bridge_address:bits256 oracle_mutlisig_address:bits256 oracles:(HashmapE 256 uint256) external_chain_address:bits256 = OracleBridgeParams;
_ OracleBridgeParams = ConfigParam 71; // Ethereum bridge
_ OracleBridgeParams = ConfigParam 72; // Binance Smart Chain bridge
_ OracleBridgeParams = ConfigParam 73; // Polygon bridge
// Set of collators: each collator is (workchain:int32 shard:int64 adnl_id:int256)
colator_set#a0 collators:(HashmapE 352 Unit) = CollatorSet;
_ CollatorSet = ConfigParam 81;
//
// PROOFS
//

View file

@ -2132,4 +2132,28 @@ Ref<vm::Cell> ConfigInfo::lookup_library(td::ConstBitPtr root_hash) const {
return lib;
}
CollatorConfig Config::get_collator_config(bool need_collator_nodes) const {
CollatorConfig collator_config;
gen::CollatorConfig::Record rec;
auto cell = get_config_param(41);
if (cell.is_null() || !tlb::unpack_cell(std::move(cell), rec)) {
return collator_config;
}
collator_config.full_collated_data = rec.full_collated_data;
if (need_collator_nodes) {
vm::Dictionary dict{rec.collator_nodes->prefetch_ref(), 32 + 64 + 256};
dict.check_for_each([&](Ref<vm::CellSlice>, td::ConstBitPtr key, int n) {
CHECK(n == 32 + 64 + 256);
auto workchain = (td::int32)key.get_int(32);
key.advance(32);
td::uint64 shard = key.get_uint(64);
key.advance(64);
td::Bits256 adnl_id(key);
collator_config.collator_nodes.push_back({ton::ShardIdFull(workchain, shard), adnl_id});
return true;
});
}
return collator_config;
}
} // namespace block

View file

@ -482,6 +482,16 @@ class ShardConfig {
bool set_shard_info(ton::ShardIdFull shard, Ref<vm::Cell> value);
};
struct CollatorNodeDescr {
ton::ShardIdFull shard;
ton::NodeIdShort adnl_id;
};
struct CollatorConfig {
bool full_collated_data = false;
std::vector<CollatorNodeDescr> collator_nodes;
};
class Config {
enum {
default_mc_catchain_lifetime = 200,
@ -593,6 +603,7 @@ class Config {
std::vector<ton::ValidatorDescr> compute_validator_set(ton::ShardIdFull shard, ton::UnixTime time,
ton::CatchainSeqno cc_seqno) const;
std::vector<ton::ValidatorDescr> compute_total_validator_set(int next) const;
CollatorConfig get_collator_config(bool need_collator_nodes) const;
static std::vector<ton::ValidatorDescr> do_compute_validator_set(const block::CatchainValidatorsConfig& ccv_conf,
ton::ShardIdFull shard,
const block::ValidatorSet& vset, ton::UnixTime time,

View file

@ -484,9 +484,4 @@ struct ValidatorSessionConfig {
static const td::uint32 BLOCK_HASH_COVERS_DATA_FROM_VERSION = 2;
};
struct CollatorNodeDescr {
ShardIdFull shard;
NodeIdShort adnl_id;
};
} // namespace ton

View file

@ -25,7 +25,7 @@ namespace ton {
namespace validator {
enum ValidateMode { fake = 1, lite = 2 };
enum ValidateMode { fake = 1, full_collated_data = 2 };
td::actor::ActorOwn<Db> create_db_actor(td::actor::ActorId<ValidatorManager> manager, std::string db_root_);
td::actor::ActorOwn<LiteServerCache> create_liteserver_cache_actor(td::actor::ActorId<ValidatorManager> manager,

View file

@ -144,6 +144,7 @@ bool AcceptBlockQuery::precheck_header() {
if (is_fork_ && !info.key_block) {
return fatal_error("fork block is not a key block");
}
before_split_ = info.before_split;
return true;
}
@ -538,6 +539,7 @@ void AcceptBlockQuery::written_state(td::Ref<ShardState> upd_state) {
}
//handle_->set_masterchain_block(prev_[0]);
handle_->set_split(before_split_);
handle_->set_state_root_hash(state_hash_);
handle_->set_logical_time(lt_);
handle_->set_unix_time(created_at_);

View file

@ -115,6 +115,7 @@ class AcceptBlockQuery : public td::actor::Actor {
UnixTime created_at_;
RootHash state_keep_old_hash_, state_old_hash_, state_hash_;
BlockIdExt mc_blkid_, prev_mc_blkid_;
bool before_split_;
Ref<MasterchainStateQ> last_mc_state_;
BlockIdExt last_mc_id_;

View file

@ -128,6 +128,7 @@ class Collator final : public td::actor::Actor {
void alarm() override;
int verbosity{3 * 0};
int verify{1};
bool full_collated_data_ = false;
ton::LogicalTime start_lt, max_lt;
ton::UnixTime now_;
ton::UnixTime prev_now_;

View file

@ -572,6 +572,8 @@ bool Collator::unpack_last_mc_state() {
<< " have been enabled in global configuration, but we support only " << supported_version()
<< " (upgrade validator software?)";
}
full_collated_data_ = config_->get_collator_config(false).full_collated_data;
LOG(DEBUG) << "full_collated_data is " << full_collated_data_;
// TODO: extract start_lt and end_lt from prev_mc_block as well
// std::cerr << " block::gen::ShardState::print_ref(mc_state_root) = ";
// block::gen::t_ShardState.print_ref(std::cerr, mc_state_root, 2);
@ -3982,6 +3984,9 @@ bool Collator::create_collated_data() {
}
collated_roots_.push_back(std::move(cell));
}
if (!full_collated_data_) {
return true;
}
// 2. Proofs for hashes of states: previous states + neighbors
for (const auto& p : block_state_proofs_) {
collated_roots_.push_back(p.second);

View file

@ -511,27 +511,6 @@ bool MasterchainStateQ::check_old_mc_block_id(const ton::BlockIdExt& blkid, bool
return config_ && config_->check_old_mc_block_id(blkid, strict);
}
std::vector<CollatorNodeDescr> MasterchainStateQ::get_collator_set() const {
block::gen::CollatorSet::Record rec;
auto cell = config_->get_config_param(81);
if (cell.is_null() || !tlb::unpack_cell(std::move(cell), rec)) {
return {};
}
vm::Dictionary dict{rec.collators->prefetch_ref(), 32 + 64 + 256};
std::vector<CollatorNodeDescr> collators;
dict.check_for_each([&](Ref<vm::CellSlice>, td::ConstBitPtr key, int n) {
CHECK(n == 32 + 64 + 256);
auto workchain = (td::int32)key.get_int(32);
key.advance(32);
td::uint64 shard = key.get_uint(64);
key.advance(64);
td::Bits256 adnl_id(key);
collators.push_back({ShardIdFull(workchain, shard), adnl_id});
return true;
});
return collators;
}
td::uint32 MasterchainStateQ::min_split_depth(WorkchainId workchain_id) const {
if (!config_) {
return 0;

View file

@ -150,7 +150,9 @@ class MasterchainStateQ : public MasterchainState, public ShardStateQ {
block::WorkchainSet get_workchain_list() const override {
return config_ ? config_->get_workchain_list() : block::WorkchainSet();
}
std::vector<CollatorNodeDescr> get_collator_set() const override;
block::CollatorConfig get_collator_config(bool need_collator_nodes) const override {
return config_ ? config_->get_collator_config(need_collator_nodes) : block::CollatorConfig();
}
private:
ZeroStateIdExt zerostate_id_;

View file

@ -63,10 +63,9 @@ ValidateQuery::ValidateQuery(ShardIdFull shard, BlockIdExt min_masterchain_block
, timeout(timeout)
, main_promise(std::move(promise))
, is_fake_(mode & ValidateMode::fake)
, is_lite_(mode & ValidateMode::lite)
, full_collated_data_(mode & ValidateMode::full_collated_data)
, shard_pfx_(shard_.shard)
, shard_pfx_len_(ton::shard_prefix_length(shard_)) {
proc_hash_.zero();
}
void ValidateQuery::alarm() {
@ -158,6 +157,7 @@ void ValidateQuery::finish_query() {
void ValidateQuery::start_up() {
LOG(INFO) << "validate query for " << block_candidate.id.to_str() << " started";
LOG(DEBUG) << "full_collated_data is " << full_collated_data_;
alarm_timestamp() = timeout;
rand_seed_.set_zero();
created_by_ = block_candidate.pubkey;
@ -258,9 +258,9 @@ void ValidateQuery::start_up() {
td::actor::send_closure_later(
std::move(self), &ValidateQuery::after_get_latest_mc_state, std::move(res));
});
// 3. load state(s) corresponding to previous block(s) (non-lite mode or masterchain)
// 3. load state(s) corresponding to previous block(s) (not full-collaoted-data or masterchain)
prev_states.resize(prev_blocks.size());
if (is_masterchain() || !is_lite_) {
if (is_masterchain() || !full_collated_data_) {
for (int i = 0; (unsigned)i < prev_blocks.size(); i++) {
// 3.1. load state
LOG(DEBUG) << "sending wait_block_state() query #" << i << " for " << prev_blocks[i].to_str() << " to Manager";
@ -991,8 +991,8 @@ bool ValidateQuery::check_this_shard_mc_info() {
*/
bool ValidateQuery::compute_prev_state() {
if (!is_masterchain() && is_lite_) {
return compute_prev_state_lite_mode();
if (!is_masterchain() && full_collated_data_) {
return compute_prev_state_from_collated_data();
}
CHECK(prev_states.size() == 1u + after_merge_);
prev_state_root_ = prev_states[0]->root_cell();
@ -1012,7 +1012,7 @@ bool ValidateQuery::compute_prev_state() {
return true;
}
bool ValidateQuery::compute_prev_state_lite_mode() {
bool ValidateQuery::compute_prev_state_from_collated_data() {
td::Bits256 state_hash;
if (id_.seqno() == 1) {
if (prev_blocks.size() != 1) {
@ -1255,7 +1255,7 @@ bool ValidateQuery::request_neighbor_queues() {
neighbors_.emplace_back(*shard_ptr);
}
int i = 0;
if (is_lite_) {
if (full_collated_data_) {
for (block::McShardDescr& descr : neighbors_) {
LOG(DEBUG) << "getting outbound queue of neighbor #" << i << " from collated data : " << descr.blk_.to_str();
td::Bits256 state_root_hash;

View file

@ -141,7 +141,7 @@ class ValidateQuery : public td::actor::Actor {
bool is_key_block_{false};
bool update_shard_cc_{false};
bool is_fake_{false};
bool is_lite_{false};
bool full_collated_data_{false};
bool prev_key_block_exists_{false};
bool debug_checks_{false};
bool outq_cleanup_partial_{false};
@ -221,7 +221,7 @@ class ValidateQuery : public td::actor::Actor {
td::RefInt256 import_fees_;
ton::LogicalTime proc_lt_{0}, claimed_proc_lt_{0}, min_enq_lt_{~0ULL};
ton::Bits256 proc_hash_, claimed_proc_hash_, min_enq_hash_;
ton::Bits256 proc_hash_ = ton::Bits256::zero(), claimed_proc_hash_, min_enq_hash_;
bool inbound_queues_empty_{false};
std::vector<std::tuple<Bits256, LogicalTime, LogicalTime>> msg_proc_lt_;
@ -286,7 +286,7 @@ class ValidateQuery : public td::actor::Actor {
bool extract_collated_data();
bool try_validate();
bool compute_prev_state();
bool compute_prev_state_lite_mode();
bool compute_prev_state_from_collated_data();
bool compute_next_state();
bool unpack_merge_prev_state();
bool unpack_prev_state();

View file

@ -82,7 +82,7 @@ class MasterchainState : virtual public ShardState {
virtual bool check_old_mc_block_id(const ton::BlockIdExt& blkid, bool strict = false) const = 0;
virtual td::Result<td::Ref<ConfigHolder>> get_config_holder() const = 0;
virtual block::WorkchainSet get_workchain_list() const = 0;
virtual std::vector<CollatorNodeDescr> get_collator_set() const = 0;
virtual block::CollatorConfig get_collator_config(bool need_collator_nodes) const = 0;
virtual td::Status prepare() {
return td::Status::OK();
}

View file

@ -2117,10 +2117,10 @@ td::actor::ActorOwn<ValidatorGroup> ValidatorManagerImpl::create_validator_group
auto validator_id = get_validator(shard, validator_set);
CHECK(!validator_id.is_zero());
auto G = td::actor::create_actor<ValidatorGroup>(
"validatorgroup", shard, validator_id, session_id, validator_set, last_masterchain_state_->get_collator_set(),
opts, keyring_, adnl_, rldp_, overlays_,
db_root_, actor_id(this), init_session,
opts_->check_unsafe_resync_allowed(validator_set->get_catchain_seqno()), opts_->validator_lite_mode());
"validatorgroup", shard, validator_id, session_id, validator_set,
last_masterchain_state_->get_collator_config(true), opts, keyring_, adnl_, rldp_, overlays_, db_root_,
actor_id(this), init_session, opts_->check_unsafe_resync_allowed(validator_set->get_catchain_seqno()),
opts_->validator_lite_mode());
return G;
}
}

View file

@ -42,7 +42,7 @@ void ValidatorGroup::generate_block_candidate(td::uint32 round_id, td::Promise<B
}
run_collate_query(shard_, min_masterchain_block_id_, prev_block_ids_,
Ed25519_PublicKey{local_id_full_.ed25519_value().raw()}, validator_set_, manager_,
td::Timestamp::in(10.0), std::move(promise));
td::Timestamp::in(20.0), std::move(promise));
}
void ValidatorGroup::validate_block_candidate(td::uint32 round_id, BlockCandidate block,
@ -102,7 +102,8 @@ void ValidatorGroup::validate_block_candidate(td::uint32 round_id, BlockCandidat
}
VLOG(VALIDATOR_DEBUG) << "validating block candidate " << next_block_id;
run_validate_query(shard_, min_masterchain_block_id_, prev_block_ids_, std::move(block), validator_set_, manager_,
td::Timestamp::in(10.0), std::move(P), lite_mode_ ? ValidateMode::lite : 0);
td::Timestamp::in(10.0), std::move(P),
collator_config_.full_collated_data ? ValidateMode::full_collated_data : 0);
}
void ValidatorGroup::update_approve_cache(td::uint32 round_id, CacheKey key, UnixTime value) {
@ -360,9 +361,9 @@ void ValidatorGroup::send_collate_query(td::uint32 round_id, td::Timestamp timeo
return;
}
adnl::AdnlNodeIdShort collator = adnl::AdnlNodeIdShort::zero();
// TODO: some other way for storing and choosing collators for real network
// TODO: some way to choose node (similar to "unreliability" in full-node)
int cnt = 0;
for (const CollatorNodeDescr& c : collator_set_) {
for (const block::CollatorNodeDescr& c : collator_config_.collator_nodes) {
if (shard_is_ancestor(shard_, c.shard) && td::Random::fast(0, cnt) == 0) {
collator = adnl::AdnlNodeIdShort(c.adnl_id);
++cnt;

View file

@ -60,7 +60,7 @@ class ValidatorGroup : public td::actor::Actor {
void get_session_info(td::Promise<tl_object_ptr<ton_api::engine_validator_validatorSessionInfo>> promise);
ValidatorGroup(ShardIdFull shard, PublicKeyHash local_id, ValidatorSessionId session_id,
td::Ref<ValidatorSet> validator_set, std::vector<CollatorNodeDescr> collator_set,
td::Ref<ValidatorSet> validator_set, block::CollatorConfig collator_config,
validatorsession::ValidatorSessionOptions config,
td::actor::ActorId<keyring::Keyring> keyring, td::actor::ActorId<adnl::Adnl> adnl,
td::actor::ActorId<rldp::Rldp> rldp, td::actor::ActorId<overlay::Overlays> overlays,
@ -70,7 +70,7 @@ class ValidatorGroup : public td::actor::Actor {
, local_id_(std::move(local_id))
, session_id_(session_id)
, validator_set_(std::move(validator_set))
, collator_set_(std::move(collator_set))
, collator_config_(std::move(collator_config))
, config_(std::move(config))
, keyring_(keyring)
, adnl_(adnl)
@ -110,7 +110,7 @@ class ValidatorGroup : public td::actor::Actor {
BlockIdExt min_masterchain_block_id_;
td::Ref<ValidatorSet> validator_set_;
std::vector<CollatorNodeDescr> collator_set_;
block::CollatorConfig collator_config_;
validatorsession::ValidatorSessionOptions config_;
td::actor::ActorId<keyring::Keyring> keyring_;