2018-07-12 03:58:17 +02:00
|
|
|
// Copyright (c) 2018, The Loki Project
|
|
|
|
//
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without modification, are
|
|
|
|
// permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
|
|
|
// conditions and the following disclaimer.
|
|
|
|
//
|
|
|
|
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
|
|
|
// of conditions and the following disclaimer in the documentation and/or other
|
|
|
|
// materials provided with the distribution.
|
|
|
|
//
|
|
|
|
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
|
|
|
// used to endorse or promote products derived from this software without specific
|
|
|
|
// prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
|
|
|
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
|
|
|
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
|
|
|
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "blockchain.h"
|
2019-05-01 08:01:17 +02:00
|
|
|
#include "serialization/serialization.h"
|
2018-07-12 03:58:17 +02:00
|
|
|
#include "cryptonote_protocol/cryptonote_protocol_handler_common.h"
|
2019-04-11 07:08:26 +02:00
|
|
|
#include "cryptonote_basic/blobdatatype.h"
|
2018-07-12 03:58:17 +02:00
|
|
|
|
|
|
|
namespace cryptonote
|
|
|
|
{
|
|
|
|
class core;
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace service_nodes
|
|
|
|
{
|
2019-04-01 09:39:27 +02:00
|
|
|
struct proof_info
|
|
|
|
{
|
|
|
|
uint64_t timestamp;
|
|
|
|
uint16_t version_major, version_minor, version_patch;
|
|
|
|
};
|
|
|
|
|
2019-05-01 08:01:17 +02:00
|
|
|
struct quorum_checkpointing
|
|
|
|
{
|
|
|
|
std::vector<crypto::public_key> quorum_nodes;
|
|
|
|
BEGIN_SERIALIZE()
|
|
|
|
FIELD(quorum_nodes)
|
|
|
|
END_SERIALIZE()
|
|
|
|
};
|
|
|
|
|
|
|
|
struct quorum_uptime_proof
|
|
|
|
{
|
|
|
|
std::vector<crypto::public_key> quorum_nodes;
|
|
|
|
std::vector<crypto::public_key> nodes_to_test;
|
|
|
|
|
|
|
|
BEGIN_SERIALIZE()
|
|
|
|
FIELD(quorum_nodes)
|
|
|
|
FIELD(nodes_to_test)
|
|
|
|
END_SERIALIZE()
|
|
|
|
};
|
|
|
|
|
|
|
|
struct quorum_manager
|
|
|
|
{
|
|
|
|
std::shared_ptr<const quorum_uptime_proof> uptime_proof;
|
|
|
|
std::shared_ptr<const quorum_checkpointing> checkpointing;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum struct quorum_type
|
|
|
|
{
|
|
|
|
uptime_proof = 0,
|
|
|
|
checkpointing,
|
|
|
|
count,
|
|
|
|
};
|
|
|
|
|
2018-07-12 03:58:17 +02:00
|
|
|
class quorum_cop
|
|
|
|
: public cryptonote::Blockchain::BlockAddedHook,
|
2018-08-10 06:15:47 +02:00
|
|
|
public cryptonote::Blockchain::BlockchainDetachedHook,
|
|
|
|
public cryptonote::Blockchain::InitHook
|
2018-07-12 03:58:17 +02:00
|
|
|
{
|
|
|
|
public:
|
2018-10-10 07:24:01 +02:00
|
|
|
explicit quorum_cop(cryptonote::core& core);
|
2018-08-10 06:15:47 +02:00
|
|
|
|
2018-10-10 07:24:01 +02:00
|
|
|
void init() override;
|
|
|
|
void block_added(const cryptonote::block& block, const std::vector<cryptonote::transaction>& txs) override;
|
|
|
|
void blockchain_detached(uint64_t height) override;
|
2018-08-10 06:15:47 +02:00
|
|
|
|
2019-05-01 08:01:17 +02:00
|
|
|
void process_uptime_quorum (cryptonote::block const &block);
|
|
|
|
void process_checkpoint_quorum(cryptonote::block const &block);
|
|
|
|
|
2018-11-05 05:38:24 +01:00
|
|
|
bool handle_uptime_proof(const cryptonote::NOTIFY_UPTIME_PROOF::request &proof);
|
2018-07-12 03:58:17 +02:00
|
|
|
|
|
|
|
static const uint64_t REORG_SAFETY_BUFFER_IN_BLOCKS = 20;
|
2018-12-21 01:33:05 +01:00
|
|
|
static_assert(REORG_SAFETY_BUFFER_IN_BLOCKS < deregister_vote::VOTE_LIFETIME_BY_HEIGHT,
|
2018-07-12 03:58:17 +02:00
|
|
|
"Safety buffer should always be less than the vote lifetime");
|
|
|
|
bool prune_uptime_proof();
|
|
|
|
|
2019-04-01 09:39:27 +02:00
|
|
|
proof_info get_uptime_proof(const crypto::public_key &pubkey) const;
|
2018-08-15 04:59:05 +02:00
|
|
|
|
2019-03-18 00:47:23 +01:00
|
|
|
void generate_uptime_proof_request(cryptonote::NOTIFY_UPTIME_PROOF::request& req) const;
|
|
|
|
|
2018-07-12 03:58:17 +02:00
|
|
|
private:
|
|
|
|
|
|
|
|
cryptonote::core& m_core;
|
2019-05-01 08:01:17 +02:00
|
|
|
uint64_t m_uptime_proof_height;
|
2018-07-12 03:58:17 +02:00
|
|
|
|
2019-04-01 09:39:27 +02:00
|
|
|
std::unordered_map<crypto::public_key, proof_info> m_uptime_proof_seen;
|
2018-10-10 07:24:01 +02:00
|
|
|
mutable epee::critical_section m_lock;
|
2018-07-12 03:58:17 +02:00
|
|
|
};
|
|
|
|
}
|