This repository has been archived by the owner on Mar 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
/
database_pbft_service.hpp
80 lines (59 loc) · 2.91 KB
/
database_pbft_service.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright (C) 2018 Bluzelle
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License, version 3,
// as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#pragma once
#include <include/boost_asio_beast.hpp>
#include <crud/crud_base.hpp>
#include <pbft/pbft_failure_detector_base.hpp>
#include <pbft/pbft_service_base.hpp>
#include <monitor/monitor_base.hpp>
#include <storage/storage_base.hpp>
#include <memory>
namespace bzn
{
class database_pbft_service final : public bzn::pbft_service_base, public std::enable_shared_from_this<database_pbft_service>
{
public:
database_pbft_service(std::shared_ptr<bzn::asio::io_context_base> io_context,
std::shared_ptr<bzn::storage_base> unstable_storage,
std::shared_ptr<bzn::crud_base> crud,
std::shared_ptr<bzn::monitor_base> monitor,
bzn::uuid_t uuid);
virtual ~database_pbft_service();
void apply_operation(const std::shared_ptr<bzn::pbft_operation>& op) override;
bool apply_operation_now(const bzn_envelope& msg, std::shared_ptr<bzn::session_base> session) override;
bzn::hash_t service_state_hash(uint64_t sequence_number) const override;
std::shared_ptr<bzn::service_state_t> get_service_state(uint64_t sequence_number) const override;
bool set_service_state(uint64_t sequence_number, const bzn::service_state_t& data) override;
void save_service_state_at(uint64_t sequence_number) override;
void consolidate_log(uint64_t sequence_number) override;
void register_execute_handler(bzn::execute_handler_t handler) override;
uint64_t applied_requests_count() const;
private:
void process_awaiting_operations();
void load_next_request_sequence();
void save_next_request_sequence();
std::shared_ptr<bzn::asio::io_context_base> io_context;
std::shared_ptr<bzn::storage_base> unstable_storage;
std::shared_ptr<bzn::crud_base> crud;
std::shared_ptr<bzn::monitor_base> monitor;
uint64_t next_request_sequence = 1;
const bzn::uuid_t uuid;
std::unordered_map<uint64_t, std::shared_ptr<bzn::pbft_operation>> operations_awaiting_result;
bzn::execute_handler_t execute_handler;
std::once_flag start_once;
std::mutex lock;
uint64_t next_checkpoint = 0;
uint64_t last_checkpoint = 0;
};
} // bzn