8 #include <boost/assert.hpp> 9 #include <scale/scale.hpp> 19 std::shared_ptr<application::AppStateManager> app_state_manager,
20 std::shared_ptr<storage::BufferStorage> storage,
21 std::shared_ptr<blockchain::BlockTree> block_tree,
22 std::shared_ptr<blockchain::DigestTracker> digest_tracker)
23 : app_state_manager_(
std::move(app_state_manager)),
24 storage_(
std::move(storage)),
25 block_tree_(
std::move(block_tree)),
26 digest_tracker_(
std::move(digest_tracker)),
39 if (buf_opt_res.has_error()) {
41 "Can't check existence of partial applied block",
42 buf_opt_res.error().message());
47 auto buf_opt = buf_opt_res.value();
48 if (not buf_opt.has_value()) {
53 auto block_res = scale::decode<primitives::BlockInfo>(buf_opt.value());
54 if (block_res.has_value()) {
55 auto &block = block_res.value();
58 "Found partial applied block {}. Trying to rollback it",
66 "Can't check existence of partial applied block",
67 block_res.error().message());
74 BOOST_VERIFY_MSG(
in_progress_.compare_exchange_strong(val,
true),
75 "Allowed only one block applying in any time");
81 if (put_res.has_error()) {
83 "Can't store record of partial applied block",
84 put_res.error().message());
87 SL_DEBUG(
logger_,
"Start applying of block {}", block);
93 SL_DEBUG(
logger_,
"Applying of block {} finished successfully", block);
102 if (removal_res.has_error()) {
104 "Rolling back of block {} is failed: {}",
106 removal_res.error().message());
110 SL_DEBUG(
logger_,
"Applying of block {} was rolled back", block);
118 if (removal_res.has_error()) {
120 "Can't remove record of partial applied block",
121 removal_res.error().message());
Class represents arbitrary (including empty) byte buffer.
std::atomic_bool in_progress_
void rollback(primitives::BlockInfo block) override
std::shared_ptr< application::AppStateManager > app_state_manager_
ConsistencyKeeperImpl(std::shared_ptr< application::AppStateManager > app_state_manager, std::shared_ptr< storage::BufferStorage > storage, std::shared_ptr< blockchain::BlockTree > block_tree, std::shared_ptr< blockchain::DigestTracker > digest_tracker)
Guard start(primitives::BlockInfo block) override
std::shared_ptr< blockchain::BlockTree > block_tree_
void commit(primitives::BlockInfo block) override
std::shared_ptr< storage::BufferStorage > storage_
Logger createLogger(const std::string &tag)
std::shared_ptr< blockchain::DigestTracker > digest_tracker_
const common::Buffer kApplyingBlockInfoLookupKey