1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-03-09 15:40:10 +00:00

Download persistent states when syncing new shards

This commit is contained in:
SpyCheese 2022-08-17 16:29:50 +03:00
parent be2169e523
commit ea7a5776fe
18 changed files with 273 additions and 17 deletions

View file

@ -21,6 +21,7 @@
#include "ton/ton-io.hpp"
#include "common/checksum.h"
#include "common/delay.h"
#include "validator/downloaders/download-state.hpp"
namespace ton {
@ -106,6 +107,19 @@ void WaitBlockState::start() {
});
td::actor::send_closure(manager_, &ValidatorManager::send_get_zero_state_request, handle_->id(), priority_,
std::move(P));
} else if (check_persistent_state_desc()) {
auto P = td::PromiseCreator::lambda([SelfId = actor_id(this)](td::Result<td::Ref<ShardState>> R) {
if (R.is_error()) {
LOG(WARNING) << "failed to get persistent state: " << R.move_as_error();
td::actor::send_closure(SelfId, &WaitBlockState::start);
} else {
td::actor::send_closure(SelfId, &WaitBlockState::written_state, R.move_as_ok());
}
});
BlockIdExt masterchain_id = persistent_state_desc_->masterchain_id;
td::actor::create_actor<DownloadShardState>("downloadstate", handle_->id(), masterchain_id, priority_, manager_,
timeout_, std::move(P))
.release();
} else if (!handle_->inited_prev() || (!handle_->inited_proof() && !handle_->inited_proof_link())) {
auto P = td::PromiseCreator::lambda([SelfId = actor_id(this), handle = handle_](td::Result<td::BufferSlice> R) {
if (R.is_error()) {

View file

@ -27,12 +27,14 @@ namespace validator {
class WaitBlockState : public td::actor::Actor {
public:
WaitBlockState(BlockHandle handle, td::uint32 priority, td::actor::ActorId<ValidatorManager> manager,
td::Timestamp timeout, td::Promise<td::Ref<ShardState>> promise)
td::Timestamp timeout, td::Promise<td::Ref<ShardState>> promise,
td::Ref<PersistentStateDescription> persistent_state_desc = {})
: handle_(std::move(handle))
, priority_(priority)
, manager_(manager)
, timeout_(timeout)
, promise_(std::move(promise)) {
, promise_(std::move(promise))
, persistent_state_desc_(std::move(persistent_state_desc)) {
}
void abort_query(td::Status reason);
@ -73,6 +75,7 @@ class WaitBlockState : public td::actor::Actor {
td::actor::ActorId<ValidatorManager> manager_;
td::Timestamp timeout_;
td::Promise<td::Ref<ShardState>> promise_;
td::Ref<PersistentStateDescription> persistent_state_desc_;
td::Ref<ShardState> prev_state_;
td::Ref<BlockData> block_;
@ -81,6 +84,14 @@ class WaitBlockState : public td::actor::Actor {
td::Timestamp next_static_file_attempt_;
//td::PerfWarningTimer perf_timer_{"waitstate", 1.0};
bool check_persistent_state_desc() const {
if (persistent_state_desc_.is_null()) {
return false;
}
auto now = (UnixTime)td::Clocks::system();
return persistent_state_desc_->end_time > now + 3600 && persistent_state_desc_->start_time < now - 6 * 3600;
}
};
} // namespace validator