Skip to content

Commit

Permalink
Rework validator-collator interaction
Browse files Browse the repository at this point in the history
1) Remove config 41, move "full collated data" to capabilities
2) Whitelist on collator nodes
3) "Ping" request for collator nodes
4) More customizable collators list for validators
5) CollationManager
  • Loading branch information
SpyCheese committed Nov 21, 2024
1 parent 7d2110c commit b3bea41
Show file tree
Hide file tree
Showing 34 changed files with 1,204 additions and 319 deletions.
5 changes: 0 additions & 5 deletions crypto/block/block.tlb
Original file line number Diff line number Diff line change
Expand Up @@ -801,11 +801,6 @@ misbehaviour_punishment_config_v1#01
= MisbehaviourPunishmentConfig;
_ MisbehaviourPunishmentConfig = ConfigParam 40;

// collator_nodes: each collator is (workchain:int32 shard:uint64 adnl_id:uint256)
collator_info#00 = CollatorInfo;
colator_config#a0 full_collated_data:Bool collator_nodes:(HashmapE 352 CollatorInfo) = CollatorConfig;
_ CollatorConfig = ConfigParam 41;

size_limits_config#01 max_msg_bits:uint32 max_msg_cells:uint32 max_library_cells:uint32 max_vm_data_depth:uint16
max_ext_msg_size:uint32 max_ext_msg_depth:uint16 = SizeLimitsConfig;
size_limits_config_v2#02 max_msg_bits:uint32 max_msg_cells:uint32 max_library_cells:uint32 max_vm_data_depth:uint16
Expand Down
24 changes: 0 additions & 24 deletions crypto/block/mc-config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2339,28 +2339,4 @@ td::optional<PrecompiledContractsConfig::Contract> PrecompiledContractsConfig::g
return c;
}

CollatorConfig Config::get_collator_config(bool need_collator_nodes) const {
CollatorConfig collator_config;
gen::CollatorConfig::Record rec;
auto cell = get_config_param(41, -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> value, 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
6 changes: 0 additions & 6 deletions crypto/block/mc-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -543,11 +543,6 @@ struct CollatorNodeDescr {
ton::NodeIdShort adnl_id;
};

struct CollatorConfig {
bool full_collated_data = false;
std::vector<CollatorNodeDescr> collator_nodes;
};

class Config {
enum {
default_mc_catchain_lifetime = 200,
Expand Down Expand Up @@ -664,7 +659,6 @@ 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;
td::Result<SizeLimitsConfig> get_size_limits_config() const;
static td::Result<SizeLimitsConfig> do_get_size_limits_config(td::Ref<vm::CellSlice> cs);
std::unique_ptr<vm::Dictionary> get_suspended_addresses(ton::UnixTime now) const;
Expand Down
28 changes: 20 additions & 8 deletions tl/generate/scheme/ton_api.tl
Original file line number Diff line number Diff line change
Expand Up @@ -646,8 +646,9 @@ engine.validator.fullNodeMaster port:int adnl:int256 = engine.validator.FullNode
engine.validator.fullNodeSlave ip:int port:int adnl:PublicKey = engine.validator.FullNodeSlave;
engine.validator.fullNodeConfig ext_messages_broadcast_disabled:Bool = engine.validator.FullNodeConfig;
engine.validator.fastSyncMemberCertificate adnl_id:int256 certificate:overlay.MemberCertificate = engine.validator.FastSyncMemberCertificate;
engine.validator.collatorNodeWhitelist enabled:Bool adnl_ids:(vector int256) = engine.validator.CollatorNodeWhitelist;
engine.validator.extraConfig state_serializer_enabled:Bool fast_sync_member_certificates:(vector engine.validator.fastSyncMemberCertificate)
= engine.validator.ExtraConfig;
collator_node_whitelist:engine.validator.collatorNodeWhitelist = engine.validator.ExtraConfig;
engine.validator.config out_port:int addrs:(vector engine.Addr) adnl:(vector engine.adnl)
dht:(vector engine.dht)
validators:(vector engine.validator) collators:(vector engine.collator)
Expand All @@ -670,11 +671,10 @@ engine.validator.collatorOptions
dispatch_phase_2_max_per_initiator:int dispatch_phase_3_max_per_initiator:int
whitelist:(vector string) prioritylist:(vector string) = engine.validator.CollatorOptions;

engine.validator.collatorsList.collator adnl_id:int256 trusted:Bool = engine.validator.collatorsList.Collator;
engine.validator.collatorsList.collator adnl_id:int256 = engine.validator.collatorsList.Collator;
engine.validator.collatorsList.shard shard_id:tonNode.shardId collators:(vector engine.validator.collatorsList.collator)
= engine.validator.collatorsList.Shard;
engine.validator.collatorsList self_collate:Bool use_config_41:Bool shards:(vector engine.validator.collatorsList.shard)
= engine.validator.CollatorsList;
self_collate:Bool select_mode:string = engine.validator.collatorsList.Shard;
engine.validator.collatorsList shards:(vector engine.validator.collatorsList.shard) = engine.validator.CollatorsList;

---functions---
---types---
Expand Down Expand Up @@ -740,6 +740,11 @@ engine.validator.perfTimerStats stats:(vector engine.validator.PerfTimerStatsByN

engine.validator.shardOutQueueSize size:long = engine.validator.ShardOutQueueSize;

engine.validator.collationManagerStats.shard shard_id:tonNode.shardId self_collate:Bool select_mode:string active:Bool collators:(vector int256) = engine.validator.collationManagerStats.Shard;
engine.validator.collationManagerStats.collator adnl_id:int256 active:Bool alive:Bool ping_in:double = engine.validator.collationManagerStats.Collator;
engine.validator.collationManagerStats.localId adnl_id:int256 shards:(vector engine.validator.collationManagerStats.shard)
collators:(vector engine.validator.collationManagerStats.collator) = engine.validator.collationManagerStats.LocalId;
engine.validator.collationManagerStats local_ids:(vector engine.validator.collationManagerStats.localId) = engine.validator.CollationManagerStats;

---functions---

Expand Down Expand Up @@ -811,8 +816,14 @@ engine.validator.addShard shard:tonNode.shardId = engine.validator.Success;
engine.validator.delCollator adnl_id:int256 shard:tonNode.shardId = engine.validator.Success;
engine.validator.delShard shard:tonNode.shardId = engine.validator.Success;

engine.validator.collatorNodeSetWhitelistedValidator adnl_id:int256 add:Bool = engine.validator.Success;
engine.validator.collatorNodeSetWhitelistEnabled enabled:Bool = engine.validator.Success;
engine.validator.showCollatorNodeWhitelist = engine.validator.CollatorNodeWhitelist;

engine.validator.setCollatorsList list:engine.validator.collatorsList = engine.validator.Success;
engine.validator.clearCollatorsList = engine.validator.Success;
engine.validator.showCollatorsList = engine.validator.CollatorsList;
engine.validator.getCollationManagerStats = engine.validator.CollationManagerStats;

engine.validator.signOverlayMemberCertificate sign_by:int256 adnl_id:int256 slot:int expire_at:int = overlay.MemberCertificate;
engine.validator.importFastSyncMemberCertificate adnl_id:int256 certificate:overlay.MemberCertificate = engine.validator.Success;
Expand Down Expand Up @@ -887,8 +898,8 @@ validatorSession.stats success:Bool id:tonNode.blockIdExt timestamp:double self:

collatorNode.candidate source:PublicKey id:tonNode.blockIdExt data:bytes collated_data:bytes = collatorNode.Candidate;
collatorNode.compressedCandidate flags:# source:PublicKey id:tonNode.blockIdExt decompressed_size:int data:bytes = collatorNode.Candidate;
collatorNode.generateBlockSuccess candidate:collatorNode.Candidate = collatorNode.GenerateBlockResult;
collatorNode.generateBlockError code:int message:string = collatorNode.GenerateBlockResult;
collatorNode.pong flags:# = collatorNode.Pong;
collatorNode.error code:int message:string = collatorNode.Error;

validatorSession.newValidatorGroupStats.node id:int256 weight:long = validatorSession.newValidatorGroupStats.Node;
validatorSession.newValidatorGroupStats session_id:int256 workchain:int shard:long cc_seqno:int
Expand All @@ -901,7 +912,8 @@ validatorSession.endValidatorGroupStats session_id:int256 timestamp:double

---functions---
collatorNode.generateBlock shard:tonNode.shardId cc_seqno:int prev_blocks:(vector tonNode.blockIdExt)
creator:int256 = collatorNode.GenerateBlockResult;
creator:int256 = collatorNode.Candidate;
collatorNode.ping flags:# = collatorNode.Pong;

---types---

Expand Down
Binary file modified tl/generate/scheme/ton_api.tlo
Binary file not shown.
3 changes: 2 additions & 1 deletion ton/ton-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ enum GlobalCapabilities {
capShortDequeue = 32,
capStoreOutMsgQueueSize = 64,
capMsgMetadata = 128,
capDeferMessages = 256
capDeferMessages = 256,
capFullCollatedData = 512
};

inline int shard_pfx_len(ShardId shard) {
Expand Down
144 changes: 134 additions & 10 deletions validator-engine-console/validator-engine-console-query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1582,6 +1582,92 @@ td::Status DelShardQuery::receive(td::BufferSlice data) {
return td::Status::OK();
}

td::Status CollatorNodeAddWhitelistedValidatorQuery::run() {
TRY_RESULT_ASSIGN(adnl_id_, tokenizer_.get_token<ton::PublicKeyHash>());
TRY_STATUS(tokenizer_.check_endl());
return td::Status::OK();
}

td::Status CollatorNodeAddWhitelistedValidatorQuery::send() {
auto b = ton::create_serialize_tl_object<ton::ton_api::engine_validator_collatorNodeSetWhitelistedValidator>(
adnl_id_.bits256_value(), true);
td::actor::send_closure(console_, &ValidatorEngineConsole::envelope_send_query, std::move(b), create_promise());
return td::Status::OK();
}

td::Status CollatorNodeAddWhitelistedValidatorQuery::receive(td::BufferSlice data) {
TRY_RESULT_PREFIX(f, ton::fetch_tl_object<ton::ton_api::engine_validator_success>(data.as_slice(), true),
"received incorrect answer: ");
td::TerminalIO::out() << "success\n";
return td::Status::OK();
}

td::Status CollatorNodeDelWhitelistedValidatorQuery::run() {
TRY_RESULT_ASSIGN(adnl_id_, tokenizer_.get_token<ton::PublicKeyHash>());
TRY_STATUS(tokenizer_.check_endl());
return td::Status::OK();
}

td::Status CollatorNodeDelWhitelistedValidatorQuery::send() {
auto b = ton::create_serialize_tl_object<ton::ton_api::engine_validator_collatorNodeSetWhitelistedValidator>(
adnl_id_.bits256_value(), false);
td::actor::send_closure(console_, &ValidatorEngineConsole::envelope_send_query, std::move(b), create_promise());
return td::Status::OK();
}

td::Status CollatorNodeDelWhitelistedValidatorQuery::receive(td::BufferSlice data) {
TRY_RESULT_PREFIX(f, ton::fetch_tl_object<ton::ton_api::engine_validator_success>(data.as_slice(), true),
"received incorrect answer: ");
td::TerminalIO::out() << "success\n";
return td::Status::OK();
}

td::Status CollatorNodeEnableWhitelistQuery::run() {
TRY_RESULT(value, tokenizer_.get_token<int>());
if (value != 0 && value != 1) {
return td::Status::Error("expected 0 or 1");
}
TRY_STATUS(tokenizer_.check_endl());
enabled_ = value;
return td::Status::OK();
}

td::Status CollatorNodeEnableWhitelistQuery::send() {
auto b = ton::create_serialize_tl_object<ton::ton_api::engine_validator_collatorNodeSetWhitelistEnabled>(enabled_);
td::actor::send_closure(console_, &ValidatorEngineConsole::envelope_send_query, std::move(b), create_promise());
return td::Status::OK();
}

td::Status CollatorNodeEnableWhitelistQuery::receive(td::BufferSlice data) {
TRY_RESULT_PREFIX(f, ton::fetch_tl_object<ton::ton_api::engine_validator_success>(data.as_slice(), true),
"received incorrect answer: ");
td::TerminalIO::out() << "success\n";
return td::Status::OK();
}

td::Status CollatorNodeShowWhitelistQuery::run() {
TRY_STATUS(tokenizer_.check_endl());
return td::Status::OK();
}

td::Status CollatorNodeShowWhitelistQuery::send() {
auto b = ton::create_serialize_tl_object<ton::ton_api::engine_validator_showCollatorNodeWhitelist>();
td::actor::send_closure(console_, &ValidatorEngineConsole::envelope_send_query, std::move(b), create_promise());
return td::Status::OK();
}

td::Status CollatorNodeShowWhitelistQuery::receive(td::BufferSlice data) {
TRY_RESULT_PREFIX(f,
ton::fetch_tl_object<ton::ton_api::engine_validator_collatorNodeWhitelist>(data.as_slice(), true),
"received incorrect answer: ");
td::TerminalIO::out() << "Collator node whitelist: " << (f->enabled_ ? "ENABLED" : "DISABLED") << "\n";
td::TerminalIO::out() << f->adnl_ids_.size() << " validator adnl ids\n";
for (const auto &id : f->adnl_ids_) {
td::TerminalIO::out() << id.to_hex() << "\n";
}
return td::Status::OK();
}

td::Status SetCollatorsListQuery::run() {
TRY_RESULT_ASSIGN(file_name_, tokenizer_.get_token<std::string>());
TRY_STATUS(tokenizer_.check_endl());
Expand Down Expand Up @@ -1611,9 +1697,7 @@ td::Status ClearCollatorsListQuery::run() {
}

td::Status ClearCollatorsListQuery::send() {
auto list = ton::create_tl_object<ton::ton_api::engine_validator_collatorsList>();
list->self_collate_ = true;
auto b = ton::create_serialize_tl_object<ton::ton_api::engine_validator_setCollatorsList>(std::move(list));
auto b = ton::create_serialize_tl_object<ton::ton_api::engine_validator_clearCollatorsList>();
td::actor::send_closure(console_, &ValidatorEngineConsole::envelope_send_query, std::move(b), create_promise());
return td::Status::OK();
}
Expand All @@ -1640,20 +1724,60 @@ td::Status ShowCollatorsListQuery::receive(td::BufferSlice data) {
TRY_RESULT_PREFIX(list, ton::fetch_tl_object<ton::ton_api::engine_validator_collatorsList>(data.as_slice(), true),
"received incorrect answer: ");
td::TerminalIO::out() << "Collators list:\n";
if (list->self_collate_) {
td::TerminalIO::out() << "self_collate = true\n";
}
if (list->use_config_41_) {
td::TerminalIO::out() << "use_config_41 = true\n";
}
if (list->shards_.empty()) {
td::TerminalIO::out() << "Shard list is empty\n";
return td::Status::OK();
}
for (const auto &shard : list->shards_) {
td::TerminalIO::out() << "Shard " << create_shard_id(shard->shard_id_).to_str() << "\n";
td::TerminalIO::out() << " Self collate = " << shard->self_collate_ << "\n";
td::TerminalIO::out() << " Select mode = " << shard->select_mode_ << "\n";
for (const auto &collator : shard->collators_) {
td::TerminalIO::out() << " Collator " << collator->adnl_id_ << (collator->trusted_ ? " (trusted)" : "") << "\n";
td::TerminalIO::out() << " Collator " << collator->adnl_id_ << "\n";
}
}
return td::Status::OK();
}

td::Status GetCollationManagerStatsQuery::run() {
TRY_STATUS(tokenizer_.check_endl());
return td::Status::OK();
}

td::Status GetCollationManagerStatsQuery::send() {
auto b = ton::create_serialize_tl_object<ton::ton_api::engine_validator_getCollationManagerStats>();
td::actor::send_closure(console_, &ValidatorEngineConsole::envelope_send_query, std::move(b), create_promise());
return td::Status::OK();
}

td::Status GetCollationManagerStatsQuery::receive(td::BufferSlice data) {
TRY_RESULT_PREFIX(list,
ton::fetch_tl_object<ton::ton_api::engine_validator_collationManagerStats>(data.as_slice(), true),
"received incorrect answer: ");
if (list->local_ids_.empty()) {
td::TerminalIO::out() << "No stats\n";
return td::Status::OK();;
}
for (auto &stats : list->local_ids_) {
td::TerminalIO::out() << "VALIDATOR ADNL ID = " << stats->adnl_id_ << "\n";
std::map<td::Bits256, ton::ton_api::engine_validator_collationManagerStats_collator*> collators;
for (auto &collator: stats->collators_) {
collators[collator->adnl_id_] = collator.get();
}
for (auto &shard : stats->shards_) {
td::TerminalIO::out() << " Shard " << create_shard_id(shard->shard_id_).to_str() << "\n";
td::TerminalIO::out() << " Self collate = " << shard->self_collate_ << "\n";
td::TerminalIO::out() << " Select mode = " << shard->select_mode_ << "\n";
td::TerminalIO::out() << " Active = " << shard->active_ << "\n";
td::TerminalIO::out() << " Collators: " << shard->collators_.size() << "\n";
for (auto &id : shard->collators_) {
auto collator = collators[id];
if (collator == nullptr) {
return td::Status::Error("collator not found");
}
td::TerminalIO::out() << " " << id << " alive=" << (int)collator->alive_
<< " ping_in=" << collator->ping_in_ << "\n";
}
}
}
return td::Status::OK();
Expand Down
Loading

0 comments on commit b3bea41

Please sign in to comment.