mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
Merge branch 'testnet' into block-generation
This commit is contained in:
commit
a745f6f679
16 changed files with 453 additions and 126 deletions
|
@ -30,7 +30,8 @@ namespace ton {
|
|||
|
||||
namespace validator {
|
||||
|
||||
void ValidatorGroup::generate_block_candidate(td::uint32 round_id, td::Promise<BlockCandidate> promise) {
|
||||
void ValidatorGroup::generate_block_candidate(
|
||||
td::uint32 round_id, td::Promise<validatorsession::ValidatorSession::GeneratedCandidate> promise) {
|
||||
if (round_id > last_known_round_id_) {
|
||||
last_known_round_id_ = round_id;
|
||||
}
|
||||
|
@ -40,14 +41,18 @@ void ValidatorGroup::generate_block_candidate(td::uint32 round_id, td::Promise<B
|
|||
}
|
||||
if (cached_collated_block_) {
|
||||
if (cached_collated_block_->result) {
|
||||
promise.set_result(cached_collated_block_->result.value().clone());
|
||||
promise.set_value({cached_collated_block_->result.value().clone(), true});
|
||||
} else {
|
||||
cached_collated_block_->promises.push_back(std::move(promise));
|
||||
cached_collated_block_->promises.push_back(promise.wrap([](BlockCandidate &&res) {
|
||||
return validatorsession::ValidatorSession::GeneratedCandidate{std::move(res), true};
|
||||
}));
|
||||
}
|
||||
return;
|
||||
}
|
||||
cached_collated_block_ = std::make_shared<CachedCollatedBlock>();
|
||||
cached_collated_block_->promises.push_back(std::move(promise));
|
||||
cached_collated_block_->promises.push_back(promise.wrap([](BlockCandidate &&res) {
|
||||
return validatorsession::ValidatorSession::GeneratedCandidate{std::move(res), false};
|
||||
}));
|
||||
td::Promise<BlockCandidate> P = [SelfId = actor_id(this),
|
||||
cache = cached_collated_block_](td::Result<BlockCandidate> R) {
|
||||
td::actor::send_closure(SelfId, &ValidatorGroup::generated_block_candidate, std::move(cache), std::move(R));
|
||||
|
@ -83,7 +88,7 @@ void ValidatorGroup::generated_block_candidate(std::shared_ptr<CachedCollatedBlo
|
|||
}
|
||||
|
||||
void ValidatorGroup::validate_block_candidate(td::uint32 round_id, BlockCandidate block,
|
||||
td::Promise<UnixTime> promise) {
|
||||
td::Promise<std::pair<UnixTime, bool>> promise) {
|
||||
if (round_id > last_known_round_id_) {
|
||||
last_known_round_id_ = round_id;
|
||||
}
|
||||
|
@ -98,7 +103,7 @@ void ValidatorGroup::validate_block_candidate(td::uint32 round_id, BlockCandidat
|
|||
CacheKey cache_key = block_to_cache_key(block);
|
||||
auto it = approved_candidates_cache_.find(cache_key);
|
||||
if (it != approved_candidates_cache_.end()) {
|
||||
promise.set_result(it->second);
|
||||
promise.set_value({it->second, true});
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -123,7 +128,7 @@ void ValidatorGroup::validate_block_candidate(td::uint32 round_id, BlockCandidat
|
|||
ts);
|
||||
td::actor::send_closure(SelfId, &ValidatorGroup::add_available_block_candidate, block.pubkey.as_bits256(),
|
||||
block.id, block.collated_file_hash);
|
||||
promise.set_result(ts);
|
||||
promise.set_value({ts, false});
|
||||
},
|
||||
[&](CandidateReject reject) {
|
||||
promise.set_error(
|
||||
|
@ -241,15 +246,18 @@ std::unique_ptr<validatorsession::ValidatorSession::Callback> ValidatorGroup::ma
|
|||
void on_candidate(td::uint32 round, PublicKey source, validatorsession::ValidatorSessionRootHash root_hash,
|
||||
td::BufferSlice data, td::BufferSlice collated_data,
|
||||
td::Promise<validatorsession::ValidatorSession::CandidateDecision> promise) override {
|
||||
auto P = td::PromiseCreator::lambda([id = id_, promise = std::move(promise)](td::Result<td::uint32> R) mutable {
|
||||
if (R.is_ok()) {
|
||||
promise.set_value(validatorsession::ValidatorSession::CandidateDecision{R.move_as_ok()});
|
||||
} else {
|
||||
auto S = R.move_as_error();
|
||||
promise.set_value(
|
||||
validatorsession::ValidatorSession::CandidateDecision{S.message().c_str(), td::BufferSlice()});
|
||||
}
|
||||
});
|
||||
auto P =
|
||||
td::PromiseCreator::lambda([promise = std::move(promise)](td::Result<std::pair<td::uint32, bool>> R) mutable {
|
||||
if (R.is_ok()) {
|
||||
validatorsession::ValidatorSession::CandidateDecision decision(R.ok().first);
|
||||
decision.set_is_cached(R.ok().second);
|
||||
promise.set_value(std::move(decision));
|
||||
} else {
|
||||
auto S = R.move_as_error();
|
||||
promise.set_value(
|
||||
validatorsession::ValidatorSession::CandidateDecision{S.message().c_str(), td::BufferSlice()});
|
||||
}
|
||||
});
|
||||
|
||||
BlockCandidate candidate{Ed25519_PublicKey{source.ed25519_value().raw()},
|
||||
BlockIdExt{0, 0, 0, root_hash, sha256_bits256(data.as_slice())},
|
||||
|
@ -258,7 +266,8 @@ std::unique_ptr<validatorsession::ValidatorSession::Callback> ValidatorGroup::ma
|
|||
td::actor::send_closure(id_, &ValidatorGroup::validate_block_candidate, round, std::move(candidate),
|
||||
std::move(P));
|
||||
}
|
||||
void on_generate_slot(td::uint32 round, td::Promise<BlockCandidate> promise) override {
|
||||
void on_generate_slot(td::uint32 round,
|
||||
td::Promise<validatorsession::ValidatorSession::GeneratedCandidate> promise) override {
|
||||
td::actor::send_closure(id_, &ValidatorGroup::generate_block_candidate, round, std::move(promise));
|
||||
}
|
||||
void on_block_committed(td::uint32 round, PublicKey source, validatorsession::ValidatorSessionRootHash root_hash,
|
||||
|
@ -543,7 +552,7 @@ void ValidatorGroup::receive_collate_query_response(td::uint32 round_id, td::Buf
|
|||
}
|
||||
|
||||
auto P = td::PromiseCreator::lambda(
|
||||
[candidate = candidate.clone(), promise = std::move(promise)](td::Result<UnixTime> R) mutable {
|
||||
[candidate = candidate.clone(), promise = std::move(promise)](td::Result<std::pair<UnixTime, bool>> R) mutable {
|
||||
if (R.is_error()) {
|
||||
promise.set_error(R.move_as_error_prefix("validate received block error: "));
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue