2
This file is part of TON Blockchain Library.
4
TON Blockchain Library is free software: you can redistribute it and/or modify
5
it under the terms of the GNU Lesser General Public License as published by
6
the Free Software Foundation, either version 2 of the License, or
7
(at your option) any later version.
9
TON Blockchain Library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU Lesser General Public License for more details.
14
You should have received a copy of the GNU Lesser General Public License
15
along with TON Blockchain Library. If not, see <http://www.gnu.org/licenses/>.
17
Copyright 2017-2020 Telegram Systems LLP
19
#include "block-handle.hpp"
20
#include "adnl/utils.hpp"
21
#include "ton/ton-tl.hpp"
27
void BlockHandleImpl::flush(td::actor::ActorId<ValidatorManagerInterface> manager, BlockHandle self,
28
td::Promise<td::Unit> promise) {
29
td::actor::send_closure(manager, &ValidatorManager::write_handle, self, std::move(promise));
32
td::BufferSlice BlockHandleImpl::serialize() const {
35
auto flags = flags_.load(std::memory_order_consume) & ~(Flags::dbf_processed | Flags::dbf_moved_handle);
36
return create_serialize_tl_object<ton_api::db_block_info>(
37
create_tl_block_id(id_), flags, (flags & dbf_inited_prev_left) ? create_tl_block_id(prev_[0]) : nullptr,
38
(flags & dbf_inited_prev_right) ? create_tl_block_id(prev_[1]) : nullptr,
39
(flags & dbf_inited_next_left) ? create_tl_block_id(next_[0]) : nullptr,
40
(flags & dbf_inited_next_right) ? create_tl_block_id(next_[1]) : nullptr, (flags & dbf_inited_lt) ? lt_ : 0,
41
(flags & dbf_inited_ts) ? ts_ : 0, (flags & dbf_inited_state) ? state_ : RootHash::zero(),
42
(flags & dbf_inited_masterchain_ref_block) ? masterchain_ref_seqno_ : 0);
45
BlockHandleImpl::BlockHandleImpl(td::Slice data) {
46
auto obj = fetch_tl_object<ton_api::db_block_info>(data, true).move_as_ok();
47
flags_ = obj->flags_ & ~(Flags::dbf_processed | Flags::dbf_moved_handle);
48
id_ = create_block_id(obj->id_);
49
prev_[0] = (flags_ & dbf_inited_prev_left) ? create_block_id(obj->prev_left_) : BlockIdExt{};
50
prev_[1] = (flags_ & dbf_inited_prev_right) ? create_block_id(obj->prev_right_) : BlockIdExt{};
51
next_[0] = (flags_ & dbf_inited_next_left) ? create_block_id(obj->next_left_) : BlockIdExt{};
52
next_[1] = (flags_ & dbf_inited_next_right) ? create_block_id(obj->next_right_) : BlockIdExt{};
53
lt_ = (flags_ & dbf_inited_lt) ? obj->lt_ : 0;
54
ts_ = (flags_ & dbf_inited_ts) ? obj->ts_ : 0;
55
state_ = (flags_ & dbf_inited_state) ? obj->state_ : RootHash::zero();
56
masterchain_ref_seqno_ =
57
(flags_ & dbf_inited_masterchain_ref_block) ? static_cast<BlockSeqno>(obj->masterchain_ref_seqno_) : 0;
58
get_thread_safe_counter().add(1);
61
} // namespace validator