mirror of
https://github.com/oxen-io/oxen-core.git
synced 2023-12-14 02:22:56 +01:00
De-inline cryptonote_basic
Moves a bunch of inline methods out into a new cryptonote_basic.cpp compilation unit. (Given how widely cryptonote_basic.h gets included it seems desirable to have as little code needing compilation as possible).
This commit is contained in:
parent
38fc9fbcd6
commit
0450f3dad6
|
@ -29,6 +29,7 @@
|
|||
|
||||
add_library(cryptonote_basic
|
||||
account.cpp
|
||||
cryptonote_basic.cpp
|
||||
cryptonote_basic_impl.cpp
|
||||
cryptonote_format_utils.cpp
|
||||
difficulty.cpp
|
||||
|
|
140
src/cryptonote_basic/cryptonote_basic.cpp
Normal file
140
src/cryptonote_basic/cryptonote_basic.cpp
Normal file
|
@ -0,0 +1,140 @@
|
|||
#include "cryptonote_basic.h"
|
||||
|
||||
namespace cryptonote {
|
||||
|
||||
void transaction_prefix::set_null() {
|
||||
version = txversion::v1;
|
||||
unlock_time = 0;
|
||||
vin.clear();
|
||||
vout.clear();
|
||||
extra.clear();
|
||||
output_unlock_times.clear();
|
||||
type = txtype::standard;
|
||||
}
|
||||
|
||||
uint64_t transaction_prefix::get_unlock_time(size_t out_index) const {
|
||||
if (version >= txversion::v3_per_output_unlock_times)
|
||||
{
|
||||
if (out_index >= output_unlock_times.size())
|
||||
{
|
||||
LOG_ERROR("Tried to get unlock time of a v3 transaction with missing output unlock time");
|
||||
return unlock_time;
|
||||
}
|
||||
return output_unlock_times[out_index];
|
||||
}
|
||||
return unlock_time;
|
||||
}
|
||||
|
||||
transaction::transaction(const transaction &t) :
|
||||
transaction_prefix(t),
|
||||
hash_valid(false),
|
||||
blob_size_valid(false),
|
||||
signatures(t.signatures),
|
||||
rct_signatures(t.rct_signatures),
|
||||
pruned(t.pruned),
|
||||
unprunable_size(t.unprunable_size.load()),
|
||||
prefix_size(t.prefix_size.load())
|
||||
{
|
||||
if (t.is_hash_valid()) {
|
||||
hash = t.hash;
|
||||
set_hash_valid(true);
|
||||
}
|
||||
if (t.is_blob_size_valid()) {
|
||||
blob_size = t.blob_size;
|
||||
set_blob_size_valid(true);
|
||||
}
|
||||
}
|
||||
|
||||
transaction& transaction::operator=(const transaction& t) {
|
||||
transaction_prefix::operator=(t);
|
||||
set_hash_valid(false);
|
||||
set_blob_size_valid(false);
|
||||
signatures = t.signatures;
|
||||
rct_signatures = t.rct_signatures;
|
||||
if (t.is_hash_valid()) {
|
||||
hash = t.hash;
|
||||
set_hash_valid(true);
|
||||
}
|
||||
if (t.is_blob_size_valid()) {
|
||||
blob_size = t.blob_size;
|
||||
set_blob_size_valid(true);
|
||||
}
|
||||
pruned = t.pruned;
|
||||
unprunable_size = t.unprunable_size.load();
|
||||
prefix_size = t.prefix_size.load();
|
||||
return *this;
|
||||
}
|
||||
|
||||
void transaction::set_null()
|
||||
{
|
||||
transaction_prefix::set_null();
|
||||
signatures.clear();
|
||||
rct_signatures = {};
|
||||
rct_signatures.type = rct::RCTType::Null;
|
||||
set_hash_valid(false);
|
||||
set_blob_size_valid(false);
|
||||
pruned = false;
|
||||
unprunable_size = 0;
|
||||
prefix_size = 0;
|
||||
}
|
||||
|
||||
void transaction::invalidate_hashes()
|
||||
{
|
||||
set_hash_valid(false);
|
||||
set_blob_size_valid(false);
|
||||
}
|
||||
|
||||
size_t transaction::get_signature_size(const txin_v& tx_in)
|
||||
{
|
||||
if (std::holds_alternative<txin_to_key>(tx_in))
|
||||
return var::get<txin_to_key>(tx_in).key_offsets.size();
|
||||
return 0;
|
||||
}
|
||||
|
||||
block::block(const block& b) :
|
||||
block_header(b),
|
||||
miner_tx{b.miner_tx},
|
||||
tx_hashes{b.tx_hashes},
|
||||
signatures{b.signatures}
|
||||
{
|
||||
copy_hash(b);
|
||||
}
|
||||
|
||||
block::block(block&& b) :
|
||||
block_header(std::move(b)),
|
||||
miner_tx{std::move(b.miner_tx)},
|
||||
tx_hashes{std::move(b.tx_hashes)},
|
||||
signatures{std::move(b.signatures)}
|
||||
{
|
||||
copy_hash(b);
|
||||
}
|
||||
|
||||
block& block::operator=(const block& b)
|
||||
{
|
||||
block_header::operator=(b);
|
||||
miner_tx = b.miner_tx;
|
||||
tx_hashes = b.tx_hashes;
|
||||
signatures = b.signatures;
|
||||
copy_hash(b);
|
||||
return *this;
|
||||
}
|
||||
block& block::operator=(block&& b)
|
||||
{
|
||||
block_header::operator=(std::move(b));
|
||||
miner_tx = std::move(b.miner_tx);
|
||||
tx_hashes = std::move(b.tx_hashes);
|
||||
signatures = std::move(b.signatures);
|
||||
copy_hash(b);
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool block::is_hash_valid() const
|
||||
{
|
||||
return hash_valid.load(std::memory_order_acquire);
|
||||
}
|
||||
void block::set_hash_valid(bool v) const
|
||||
{
|
||||
hash_valid.store(v,std::memory_order_release);
|
||||
}
|
||||
|
||||
}
|
|
@ -51,16 +51,14 @@ namespace service_nodes
|
|||
struct quorum_signature
|
||||
{
|
||||
uint16_t voter_index;
|
||||
char padding[6];
|
||||
char padding[6] = {0};
|
||||
crypto::signature signature;
|
||||
|
||||
quorum_signature() = default;
|
||||
quorum_signature(uint16_t voter_index, crypto::signature const &signature)
|
||||
: voter_index(voter_index)
|
||||
, signature(signature)
|
||||
{
|
||||
std::memset(padding, 0, sizeof(padding));
|
||||
}
|
||||
quorum_signature(uint16_t voter_index, crypto::signature const &signature) :
|
||||
voter_index(voter_index),
|
||||
signature(signature)
|
||||
{}
|
||||
|
||||
BEGIN_SERIALIZE_OBJECT()
|
||||
FIELD(voter_index)
|
||||
|
@ -90,7 +88,7 @@ namespace cryptonote
|
|||
|
||||
struct txout_to_key
|
||||
{
|
||||
txout_to_key() { }
|
||||
txout_to_key() = default;
|
||||
txout_to_key(const crypto::public_key &_key) : key(_key) { }
|
||||
crypto::public_key key;
|
||||
};
|
||||
|
@ -175,12 +173,12 @@ namespace cryptonote
|
|||
{
|
||||
|
||||
public:
|
||||
static char const *version_to_string(txversion v);
|
||||
static char const *type_to_string(txtype type);
|
||||
static char const* version_to_string(txversion v);
|
||||
static char const* type_to_string(txtype type);
|
||||
|
||||
static txversion get_min_version_for_hf(uint8_t hf_version);
|
||||
static txversion get_max_version_for_hf(uint8_t hf_version);
|
||||
static txtype get_max_type_for_hf (uint8_t hf_version);
|
||||
static constexpr txversion get_min_version_for_hf(uint8_t hf_version);
|
||||
static constexpr txversion get_max_version_for_hf(uint8_t hf_version);
|
||||
static constexpr txtype get_max_type_for_hf (uint8_t hf_version);
|
||||
|
||||
// tx information
|
||||
txversion version;
|
||||
|
@ -216,34 +214,13 @@ namespace cryptonote
|
|||
ENUM_FIELD_N("type", type, type < txtype::_count);
|
||||
END_SERIALIZE()
|
||||
|
||||
transaction_prefix(){ set_null(); }
|
||||
void set_null()
|
||||
{
|
||||
version = txversion::v1;
|
||||
unlock_time = 0;
|
||||
vin.clear();
|
||||
vout.clear();
|
||||
extra.clear();
|
||||
output_unlock_times.clear();
|
||||
type = txtype::standard;
|
||||
}
|
||||
transaction_prefix() { set_null(); }
|
||||
void set_null();
|
||||
|
||||
uint64_t get_unlock_time(size_t out_index) const
|
||||
{
|
||||
if (version >= txversion::v3_per_output_unlock_times)
|
||||
{
|
||||
if (out_index >= output_unlock_times.size())
|
||||
{
|
||||
LOG_ERROR("Tried to get unlock time of a v3 transaction with missing output unlock time");
|
||||
return unlock_time;
|
||||
}
|
||||
return output_unlock_times[out_index];
|
||||
}
|
||||
return unlock_time;
|
||||
}
|
||||
uint64_t get_unlock_time(size_t out_index) const;
|
||||
};
|
||||
|
||||
class transaction: public transaction_prefix
|
||||
class transaction final : public transaction_prefix
|
||||
{
|
||||
private:
|
||||
// hash cache
|
||||
|
@ -251,7 +228,7 @@ namespace cryptonote
|
|||
mutable std::atomic<bool> blob_size_valid;
|
||||
|
||||
public:
|
||||
std::vector<std::vector<crypto::signature> > signatures; //count signatures always the same as inputs count
|
||||
std::vector<std::vector<crypto::signature>> signatures; //count signatures always the same as inputs count
|
||||
rct::rctSig rct_signatures;
|
||||
|
||||
// hash cache
|
||||
|
@ -263,10 +240,9 @@ namespace cryptonote
|
|||
std::atomic<unsigned int> unprunable_size;
|
||||
std::atomic<unsigned int> prefix_size;
|
||||
|
||||
transaction();
|
||||
transaction(const transaction &t): transaction_prefix(t), hash_valid(false), blob_size_valid(false), signatures(t.signatures), rct_signatures(t.rct_signatures), pruned(t.pruned), unprunable_size(t.unprunable_size.load()), prefix_size(t.prefix_size.load()) { if (t.is_hash_valid()) { hash = t.hash; set_hash_valid(true); } if (t.is_blob_size_valid()) { blob_size = t.blob_size; set_blob_size_valid(true); } }
|
||||
transaction &operator=(const transaction &t) { transaction_prefix::operator=(t); set_hash_valid(false); set_blob_size_valid(false); signatures = t.signatures; rct_signatures = t.rct_signatures; if (t.is_hash_valid()) { hash = t.hash; set_hash_valid(true); } if (t.is_blob_size_valid()) { blob_size = t.blob_size; set_blob_size_valid(true); } pruned = t.pruned; unprunable_size = t.unprunable_size.load(); prefix_size = t.prefix_size.load(); return *this; }
|
||||
virtual ~transaction();
|
||||
transaction() { set_null(); }
|
||||
transaction(const transaction &t);
|
||||
transaction& operator=(const transaction& t);
|
||||
void set_null();
|
||||
void invalidate_hashes();
|
||||
bool is_hash_valid() const { return hash_valid.load(std::memory_order_acquire); }
|
||||
|
@ -373,46 +349,6 @@ namespace cryptonote
|
|||
};
|
||||
|
||||
|
||||
inline
|
||||
transaction::transaction()
|
||||
{
|
||||
set_null();
|
||||
}
|
||||
|
||||
inline
|
||||
transaction::~transaction()
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
void transaction::set_null()
|
||||
{
|
||||
transaction_prefix::set_null();
|
||||
signatures.clear();
|
||||
rct_signatures = {};
|
||||
rct_signatures.type = rct::RCTType::Null;
|
||||
set_hash_valid(false);
|
||||
set_blob_size_valid(false);
|
||||
pruned = false;
|
||||
unprunable_size = 0;
|
||||
prefix_size = 0;
|
||||
}
|
||||
|
||||
inline
|
||||
void transaction::invalidate_hashes()
|
||||
{
|
||||
set_hash_valid(false);
|
||||
set_blob_size_valid(false);
|
||||
}
|
||||
|
||||
inline
|
||||
size_t transaction::get_signature_size(const txin_v& tx_in)
|
||||
{
|
||||
if (std::holds_alternative<txin_to_key>(tx_in))
|
||||
return var::get<txin_to_key>(tx_in).key_offsets.size();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
/* */
|
||||
/************************************************************************/
|
||||
|
@ -469,13 +405,13 @@ namespace cryptonote
|
|||
|
||||
public:
|
||||
block() = default;
|
||||
block(const block &b): block_header(b), miner_tx{b.miner_tx}, tx_hashes{b.tx_hashes}, signatures{b.signatures} { copy_hash(b); }
|
||||
block &operator=(const block &b) { block_header::operator=(b); miner_tx = b.miner_tx; tx_hashes = b.tx_hashes; signatures = b.signatures; copy_hash(b); return *this; }
|
||||
block(block &&b) : block_header(std::move(b)), miner_tx{std::move(b.miner_tx)}, tx_hashes{std::move(b.tx_hashes)}, signatures{std::move(b.signatures)} { copy_hash(b); }
|
||||
block &operator=(block &&b) { block_header::operator=(std::move(b)); miner_tx = std::move(b.miner_tx); tx_hashes = std::move(b.tx_hashes); signatures = std::move(b.signatures); copy_hash(b); return *this; }
|
||||
block(const block& b);
|
||||
block(block&& b);
|
||||
block& operator=(const block& b);
|
||||
block& operator=(block&& b);
|
||||
void invalidate_hashes() { set_hash_valid(false); }
|
||||
bool is_hash_valid() const { return hash_valid.load(std::memory_order_acquire); }
|
||||
void set_hash_valid(bool v) const { hash_valid.store(v,std::memory_order_release); }
|
||||
bool is_hash_valid() const;
|
||||
void set_hash_valid(bool v) const;
|
||||
|
||||
transaction miner_tx;
|
||||
std::vector<crypto::hash> tx_hashes;
|
||||
|
@ -528,7 +464,7 @@ namespace cryptonote
|
|||
return !(*this == rhs);
|
||||
}
|
||||
};
|
||||
constexpr account_public_address const null_address{};
|
||||
inline constexpr account_public_address null_address{};
|
||||
|
||||
struct keypair
|
||||
{
|
||||
|
@ -546,14 +482,14 @@ namespace cryptonote
|
|||
using byte_and_output_fees = std::pair<uint64_t, uint64_t>;
|
||||
|
||||
//---------------------------------------------------------------
|
||||
inline txversion transaction_prefix::get_min_version_for_hf(uint8_t hf_version)
|
||||
constexpr txversion transaction_prefix::get_min_version_for_hf(uint8_t hf_version)
|
||||
{
|
||||
if (hf_version >= cryptonote::network_version_7 && hf_version <= cryptonote::network_version_10_bulletproofs)
|
||||
return txversion::v2_ringct;
|
||||
return txversion::v4_tx_types;
|
||||
}
|
||||
|
||||
inline txversion transaction_prefix::get_max_version_for_hf(uint8_t hf_version)
|
||||
constexpr txversion transaction_prefix::get_max_version_for_hf(uint8_t hf_version)
|
||||
{
|
||||
if (hf_version >= cryptonote::network_version_7 && hf_version <= cryptonote::network_version_8)
|
||||
return txversion::v2_ringct;
|
||||
|
@ -564,7 +500,7 @@ namespace cryptonote
|
|||
return txversion::v4_tx_types;
|
||||
}
|
||||
|
||||
inline txtype transaction_prefix::get_max_type_for_hf(uint8_t hf_version)
|
||||
constexpr txtype transaction_prefix::get_max_type_for_hf(uint8_t hf_version)
|
||||
{
|
||||
txtype result = txtype::standard;
|
||||
if (hf_version >= network_version_15_lns) result = txtype::loki_name_system;
|
||||
|
@ -575,7 +511,7 @@ namespace cryptonote
|
|||
return result;
|
||||
}
|
||||
|
||||
inline char const *transaction_prefix::version_to_string(txversion v)
|
||||
inline const char* transaction_prefix::version_to_string(txversion v)
|
||||
{
|
||||
switch(v)
|
||||
{
|
||||
|
@ -587,7 +523,7 @@ namespace cryptonote
|
|||
}
|
||||
}
|
||||
|
||||
inline char const *transaction_prefix::type_to_string(txtype type)
|
||||
inline const char* transaction_prefix::type_to_string(txtype type)
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
|
|
|
@ -106,7 +106,7 @@
|
|||
*
|
||||
* public:
|
||||
* template <class Archive>
|
||||
* void serialize_value(Archive& a) {
|
||||
* void serialize_value(Archive& ar) {
|
||||
* serialization::value(ar, v1);
|
||||
* serialization::value(ar, v2);
|
||||
* }
|
||||
|
|
Loading…
Reference in a new issue