mirror of
https://github.com/oxen-io/oxen-core.git
synced 2023-12-14 02:22:56 +01:00
Add versioning to uptime proofs to enforce behaviour
This commit is contained in:
parent
fabd1bf84b
commit
9abf99a819
|
@ -1265,9 +1265,9 @@ namespace cryptonote
|
|||
return result;
|
||||
}
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
bool core::handle_uptime_proof(uint64_t timestamp, const crypto::public_key& pubkey, const crypto::signature& sig)
|
||||
bool core::handle_uptime_proof(const NOTIFY_UPTIME_PROOF::request &proof)
|
||||
{
|
||||
return m_quorum_cop.handle_uptime_proof(timestamp, pubkey, sig);
|
||||
return m_quorum_cop.handle_uptime_proof(proof);
|
||||
}
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
void core::on_transaction_relayed(const cryptonote::blobdata& tx_blob)
|
||||
|
|
|
@ -115,7 +115,7 @@ namespace cryptonote
|
|||
*
|
||||
* @return true if we haven't seen it before and thus need to relay.
|
||||
*/
|
||||
bool handle_uptime_proof(uint64_t timestamp, const crypto::public_key& pubkey, const crypto::signature& sig);
|
||||
bool handle_uptime_proof(const NOTIFY_UPTIME_PROOF::request &proof);
|
||||
|
||||
/**
|
||||
* @brief handles an incoming transaction
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include "service_node_list.h"
|
||||
#include "cryptonote_config.h"
|
||||
#include "cryptonote_core.h"
|
||||
#include "version.h"
|
||||
#include "quorum_cop.h"
|
||||
|
||||
#undef LOKI_DEFAULT_LOG_CATEGORY
|
||||
|
@ -146,16 +147,27 @@ namespace service_nodes
|
|||
return result;
|
||||
}
|
||||
|
||||
bool quorum_cop::handle_uptime_proof(uint64_t timestamp, const crypto::public_key& pubkey, const crypto::signature& sig)
|
||||
bool quorum_cop::handle_uptime_proof(const cryptonote::NOTIFY_UPTIME_PROOF::request &proof)
|
||||
{
|
||||
uint64_t now = time(nullptr);
|
||||
|
||||
uint64_t timestamp = proof.timestamp;
|
||||
const crypto::public_key& pubkey = proof.pubkey;
|
||||
const crypto::signature& sig = proof.sig;
|
||||
|
||||
if ((timestamp < now - UPTIME_PROOF_BUFFER_IN_SECONDS) || (timestamp > now + UPTIME_PROOF_BUFFER_IN_SECONDS))
|
||||
return false;
|
||||
|
||||
if (!m_core.is_service_node(pubkey))
|
||||
return false;
|
||||
|
||||
if (!(proof.snode_version_major == 2 &&
|
||||
proof.snode_version_minor == 0 &&
|
||||
proof.snode_version_patch == 0))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
CRITICAL_REGION_LOCAL(m_lock);
|
||||
if (m_uptime_proof_seen[pubkey] >= now - (UPTIME_PROOF_FREQUENCY_IN_SECONDS / 2))
|
||||
return false; // already received one uptime proof for this node recently.
|
||||
|
@ -170,8 +182,11 @@ namespace service_nodes
|
|||
|
||||
void generate_uptime_proof_request(const crypto::public_key& pubkey, const crypto::secret_key& seckey, cryptonote::NOTIFY_UPTIME_PROOF::request& req)
|
||||
{
|
||||
req.timestamp = time(nullptr);
|
||||
req.pubkey = pubkey;
|
||||
req.snode_version_major = static_cast<uint16_t>(LOKI_VERSION_MAJOR);
|
||||
req.snode_version_minor = static_cast<uint16_t>(LOKI_VERSION_MINOR);
|
||||
req.snode_version_patch = static_cast<uint16_t>(LOKI_VERSION_PATCH);
|
||||
req.timestamp = time(nullptr);
|
||||
req.pubkey = pubkey;
|
||||
|
||||
crypto::hash hash = make_hash(req.pubkey, req.timestamp);
|
||||
crypto::generate_signature(hash, pubkey, seckey, req.sig);
|
||||
|
|
|
@ -55,7 +55,7 @@ namespace service_nodes
|
|||
void block_added(const cryptonote::block& block, const std::vector<cryptonote::transaction>& txs) override;
|
||||
void blockchain_detached(uint64_t height) override;
|
||||
|
||||
bool handle_uptime_proof(uint64_t timestamp, const crypto::public_key& pubkey, const crypto::signature& sig);
|
||||
bool handle_uptime_proof(const cryptonote::NOTIFY_UPTIME_PROOF::request &proof);
|
||||
|
||||
static const uint64_t REORG_SAFETY_BUFFER_IN_BLOCKS = 20;
|
||||
static_assert(REORG_SAFETY_BUFFER_IN_BLOCKS < loki::service_node_deregister::VOTE_LIFETIME_BY_HEIGHT,
|
||||
|
|
|
@ -308,11 +308,18 @@ namespace cryptonote
|
|||
|
||||
struct request
|
||||
{
|
||||
uint16_t snode_version_major;
|
||||
uint16_t snode_version_minor;
|
||||
uint16_t snode_version_patch;
|
||||
|
||||
uint64_t timestamp;
|
||||
crypto::public_key pubkey;
|
||||
crypto::signature sig;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(snode_version_major)
|
||||
KV_SERIALIZE(snode_version_minor)
|
||||
KV_SERIALIZE(snode_version_patch)
|
||||
KV_SERIALIZE(timestamp)
|
||||
KV_SERIALIZE_VAL_POD_AS_BLOB(pubkey)
|
||||
KV_SERIALIZE_VAL_POD_AS_BLOB(sig)
|
||||
|
|
|
@ -92,7 +92,7 @@ namespace cryptonote
|
|||
HANDLE_NOTIFY_T2(NOTIFY_NEW_FLUFFY_BLOCK, &cryptonote_protocol_handler::handle_notify_new_fluffy_block)
|
||||
HANDLE_NOTIFY_T2(NOTIFY_REQUEST_FLUFFY_MISSING_TX, &cryptonote_protocol_handler::handle_request_fluffy_missing_tx)
|
||||
HANDLE_NOTIFY_T2(NOTIFY_NEW_DEREGISTER_VOTE, &cryptonote_protocol_handler::handle_notify_new_deregister_vote)
|
||||
HANDLE_NOTIFY_T2(NOTIFY_UPTIME_PROOF, &cryptonote_protocol_handler::handle_uptime_proof);
|
||||
HANDLE_NOTIFY_T2(NOTIFY_UPTIME_PROOF, &cryptonote_protocol_handler::handle_uptime_proof)
|
||||
END_INVOKE_MAP2()
|
||||
|
||||
bool on_idle();
|
||||
|
|
|
@ -687,7 +687,7 @@ namespace cryptonote
|
|||
MLOG_P2P_MESSAGE("Received NOTIFY_UPTIME_PROOF");
|
||||
if(context.m_state != cryptonote_connection_context::state_normal)
|
||||
return 1;
|
||||
if (m_core.handle_uptime_proof(arg.timestamp, arg.pubkey, arg.sig))
|
||||
if (m_core.handle_uptime_proof(arg))
|
||||
relay_uptime_proof(arg, context);
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -1,10 +1,21 @@
|
|||
#define DEF_LOKI_VERSION_MAJOR 1
|
||||
#define DEF_LOKI_VERSION_MINOR 0
|
||||
#define DEF_LOKI_VERSION_PATCH 4
|
||||
|
||||
#define STRINGIFY_2(val) #val
|
||||
#define STRINGIFY(val) STRINGIFY_2(val)
|
||||
#define DEF_LOKI_VERSION STRINGIFY(DEF_LOKI_VERSION_MAJOR) "." STRINGIFY(DEF_LOKI_VERSION_MINOR) "." STRINGIFY(DEF_LOKI_VERSION_PATCH)
|
||||
|
||||
#define DEF_LOKI_VERSION_TAG "@VERSIONTAG@"
|
||||
#define DEF_LOKI_VERSION "1.0.4"
|
||||
#define DEF_LOKI_RELEASE_NAME "Magic Mani"
|
||||
#define DEF_LOKI_VERSION_FULL DEF_LOKI_VERSION "-" DEF_LOKI_VERSION_TAG
|
||||
|
||||
#include "version.h"
|
||||
|
||||
const int LOKI_VERSION_MAJOR = DEF_LOKI_VERSION_MAJOR;
|
||||
const int LOKI_VERSION_MINOR = DEF_LOKI_VERSION_MINOR;
|
||||
const int LOKI_VERSION_PATCH = DEF_LOKI_VERSION_PATCH;
|
||||
|
||||
const char* const LOKI_VERSION_TAG = DEF_LOKI_VERSION_TAG;
|
||||
const char* const LOKI_VERSION = DEF_LOKI_VERSION;
|
||||
const char* const LOKI_RELEASE_NAME = DEF_LOKI_RELEASE_NAME;
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
extern const int LOKI_VERSION_MAJOR;
|
||||
extern const int LOKI_VERSION_MINOR;
|
||||
extern const int LOKI_VERSION_PATCH;
|
||||
|
||||
extern const char* const LOKI_VERSION_TAG;
|
||||
extern const char* const LOKI_VERSION;
|
||||
extern const char* const LOKI_RELEASE_NAME;
|
||||
|
|
|
@ -223,7 +223,7 @@ bool tests::proxy_core::handle_incoming_block(const cryptonote::blobdata& block_
|
|||
return true;
|
||||
}
|
||||
|
||||
bool tests::proxy_core::handle_uptime_proof(uint64_t timestamp, const crypto::public_key& pubkey, const crypto::signature& sig)
|
||||
bool tests::proxy_core::handle_uptime_proof(const cryptonote::NOTIFY_UPTIME_PROOF::request &proof)
|
||||
{
|
||||
// TODO: add tests for core uptime proof checking.
|
||||
return false; // never relay these for tests.
|
||||
|
|
|
@ -79,7 +79,7 @@ namespace tests
|
|||
bool handle_incoming_tx(const cryptonote::blobdata& tx_blob, cryptonote::tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay);
|
||||
bool handle_incoming_txs(const std::vector<cryptonote::blobdata>& tx_blobs, std::vector<cryptonote::tx_verification_context>& tvc, bool keeped_by_block, bool relayed, bool do_not_relay);
|
||||
bool handle_incoming_block(const cryptonote::blobdata& block_blob, cryptonote::block_verification_context& bvc, bool update_miner_blocktemplate = true);
|
||||
bool handle_uptime_proof(uint64_t timestamp, const crypto::public_key& pubkey, const crypto::signature& sig);
|
||||
bool handle_uptime_proof(const cryptonote::NOTIFY_UPTIME_PROOF::request &proof);
|
||||
void pause_mine(){}
|
||||
void resume_mine(){}
|
||||
bool on_idle(){return true;}
|
||||
|
|
|
@ -57,7 +57,7 @@ public:
|
|||
bool handle_incoming_tx(const cryptonote::blobdata& tx_blob, cryptonote::tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay) { return true; }
|
||||
bool handle_incoming_txs(const std::vector<cryptonote::blobdata>& tx_blob, std::vector<cryptonote::tx_verification_context>& tvc, bool keeped_by_block, bool relayed, bool do_not_relay) { return true; }
|
||||
bool handle_incoming_block(const cryptonote::blobdata& block_blob, cryptonote::block_verification_context& bvc, bool update_miner_blocktemplate = true) { return true; }
|
||||
bool handle_uptime_proof(uint64_t timestamp, const crypto::public_key& pubkey, const crypto::signature& sig) { return false; }
|
||||
bool handle_uptime_proof(const cryptonote::NOTIFY_UPTIME_PROOF::request &proof) { return false; }
|
||||
void pause_mine(){}
|
||||
void resume_mine(){}
|
||||
bool on_idle(){return true;}
|
||||
|
|
Loading…
Reference in a new issue