New BLOB_TYPE for Arqma Service-Nodes version 16 Hard-Fork.

This commit is contained in:
m@lbit
2025-06-09 15:18:22 +02:00
parent 2a4f5cea7c
commit bd1af278a5
7 changed files with 174 additions and 52 deletions

View File

@@ -33,6 +33,7 @@
#include <deque> #include <deque>
#include <boost/mpl/vector.hpp> #include <boost/mpl/vector.hpp>
#include <boost/mpl/contains_fwd.hpp> #include <boost/mpl/contains_fwd.hpp>
#include <cstdint>
#undef MONERO_DEFAULT_LOG_CATEGORY #undef MONERO_DEFAULT_LOG_CATEGORY
#define MONERO_DEFAULT_LOG_CATEGORY "serialization" #define MONERO_DEFAULT_LOG_CATEGORY "serialization"

View File

@@ -29,6 +29,7 @@
#include "offshore/pricing_record.h" #include "offshore/pricing_record.h"
#include "zephyr_oracle/pricing_record.h" #include "zephyr_oracle/pricing_record.h"
#include "salvium_oracle/pricing_record.h" #include "salvium_oracle/pricing_record.h"
#include "txtypes.h"
namespace cryptonote namespace cryptonote
@@ -426,6 +427,8 @@ namespace cryptonote
size_t version; size_t version;
uint64_t unlock_time; //number of block (or time), used as a limitation like: spend this tx not early then block/time uint64_t unlock_time; //number of block (or time), used as a limitation like: spend this tx not early then block/time
txtype tx_type;
std::vector<txin_v> vin; std::vector<txin_v> vin;
std::vector<txin_zephyr_v> vin_zephyr; std::vector<txin_zephyr_v> vin_zephyr;
std::vector<txin_salvium_v> vin_salvium; std::vector<txin_salvium_v> vin_salvium;
@@ -752,9 +755,9 @@ namespace cryptonote
VARINT_FIELD(amount_slippage_limit) VARINT_FIELD(amount_slippage_limit)
} }
} }
} else { } else {
VARINT_FIELD(version) VARINT_FIELD(version)
if (version > loki_version_2 && (blob_type == BLOB_TYPE_CRYPTONOTE_LOKI || blob_type == BLOB_TYPE_CRYPTONOTE_XTNC)) if (version > loki_version_2 && (blob_type == BLOB_TYPE_CRYPTONOTE_LOKI || blob_type == BLOB_TYPE_CRYPTONOTE_XTNC))
{ {
@@ -762,22 +765,31 @@ namespace cryptonote
if (version == loki_version_3_per_output_unlock_times) if (version == loki_version_3_per_output_unlock_times)
FIELD(is_deregister) FIELD(is_deregister)
} }
if (version >= static_cast<size_t>(cryptonote::txversion::v3) && (blob_type == BLOB_TYPE_CRYPTONOTE_ARQMA))
{
VARINT_FIELD(tx_type)
if (static_cast<uint16_t>(tx_type) >= static_cast<uint16_t>(cryptonote::txtype::_count))
return false;
FIELD(output_unlock_times)
}
VARINT_FIELD(unlock_time) VARINT_FIELD(unlock_time)
if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR) if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR)
FIELD(vin_zephyr) FIELD(vin_zephyr)
else else
FIELD(vin) FIELD(vin)
if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR) if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR)
FIELD(vout_zephyr) FIELD(vout_zephyr)
else else
FIELD(vout) FIELD(vout)
if (blob_type == BLOB_TYPE_CRYPTONOTE_LOKI || blob_type == BLOB_TYPE_CRYPTONOTE_XTNC) if (blob_type == BLOB_TYPE_CRYPTONOTE_LOKI || blob_type == BLOB_TYPE_CRYPTONOTE_XTNC || blob_type == BLOB_TYPE_CRYPTONOTE_ARQMA)
{ {
if (version >= loki_version_3_per_output_unlock_times && vout.size() != output_unlock_times.size()) return false; if ((version >= loki_version_3_per_output_unlock_times || version >= static_cast<size_t>(cryptonote::txversion::v3)) && vout.size() != output_unlock_times.size())
return false;
} }
FIELD(extra) FIELD(extra)
if ((blob_type == BLOB_TYPE_CRYPTONOTE_LOKI || blob_type == BLOB_TYPE_CRYPTONOTE_XTNC) && version >= loki_version_4_tx_types) if ((blob_type == BLOB_TYPE_CRYPTONOTE_LOKI || blob_type == BLOB_TYPE_CRYPTONOTE_XTNC) && version >= loki_version_4_tx_types)

View File

@@ -30,30 +30,43 @@
#pragma once #pragma once
#define TX_EXTRA_PADDING_MAX_COUNT 255 #define TX_EXTRA_PADDING_MAX_COUNT 255
#define TX_EXTRA_NONCE_MAX_COUNT 255 #define TX_EXTRA_NONCE_MAX_COUNT 255
#define TX_EXTRA_OFFSHORE_MAX_COUNT 255 #define TX_EXTRA_OFFSHORE_MAX_COUNT 255
#define TX_EXTRA_MEMO_MAX_COUNT 255 #define TX_EXTRA_MEMO_MAX_COUNT 255
#define TX_EXTRA_TAG_PADDING 0x00 #define TX_EXTRA_TAG_PADDING 0x00
#define TX_EXTRA_TAG_PUBKEY 0x01 #define TX_EXTRA_TAG_PUBKEY 0x01
#define TX_EXTRA_NONCE 0x02 #define TX_EXTRA_NONCE 0x02
#define TX_EXTRA_MERGE_MINING_TAG 0x03 #define TX_EXTRA_MERGE_MINING_TAG 0x03
#define TX_EXTRA_TAG_ADDITIONAL_PUBKEYS 0x04 #define TX_EXTRA_TAG_ADDITIONAL_PUBKEYS 0x04
#define TX_EXTRA_TAG_OFFSHORE 0x17 #define TX_EXTRA_TAG_OFFSHORE 0x17
#define TX_EXTRA_TAG_MEMO 0x18 #define TX_EXTRA_TAG_MEMO 0x18
#define TX_EXTRA_TAG_SERVICE_NODE_REGISTER 0x70 #define TX_EXTRA_TAG_SERVICE_NODE_REGISTER 0x70
#define TX_EXTRA_TAG_SERVICE_NODE_DEREGISTER 0x71 #define TX_EXTRA_TAG_SERVICE_NODE_STATE_CHANGE 0x71
#define TX_EXTRA_TAG_SERVICE_NODE_WINNER 0x72 #define TX_EXTRA_TAG_SERVICE_NODE_WINNER 0x72
#define TX_EXTRA_TAG_SERVICE_NODE_CONTRIBUTOR 0x73 #define TX_EXTRA_TAG_SERVICE_NODE_CONTRIBUTOR 0x73
#define TX_EXTRA_TAG_SERVICE_NODE_PUBKEY 0x74 #define TX_EXTRA_TAG_SERVICE_NODE_PUBKEY 0x74
#define TX_EXTRA_TAG_TX_SECRET_KEY 0x75 #define TX_EXTRA_TAG_TX_SECRET_KEY 0x75
#define TX_EXTRA_TAG_TX_KEY_IMAGE_PROOFS 0x76 #define TX_EXTRA_TAG_TX_KEY_IMAGE_PROOFS 0x76
#define TX_EXTRA_TAG_TX_KEY_IMAGE_UNLOCK 0x77 #define TX_EXTRA_TAG_TX_KEY_IMAGE_UNLOCK 0x77
#define TX_EXTRA_MYSTERIOUS_MINERGATE_TAG 0xDE #define TX_EXTRA_TAG_SERVICE_NODE_DEREGISTER 0x78
#define TX_EXTRA_MYSTERIOUS_MINERGATE_TAG 0xDE
#define TX_EXTRA_NONCE_PAYMENT_ID 0x00 #define TX_EXTRA_NONCE_PAYMENT_ID 0x00
#define TX_EXTRA_NONCE_ENCRYPTED_PAYMENT_ID 0x01 #define TX_EXTRA_NONCE_ENCRYPTED_PAYMENT_ID 0x01
namespace service_nodes
{
enum class new_state : uint16_t
{
deregister = 0,
decommission,
recommission,
ip_change_penalty,
_count,
};
};
namespace cryptonote namespace cryptonote
{ {
@@ -277,6 +290,45 @@ namespace cryptonote
END_SERIALIZE() END_SERIALIZE()
}; };
struct tx_extra_service_node_state_change
{
struct vote
{
vote() = default;
vote(crypto::signature const &signature, uint32_t validator_index) : signature(signature), validator_index(validator_index) {}
crypto::signature signature;
uint32_t validator_index;
BEGIN_SERIALIZE()
VARINT_FIELD(validator_index)
FIELD(signature)
END_SERIALIZE()
};
service_nodes::new_state state;
uint64_t block_height;
uint32_t service_node_index;
std::vector<vote> votes;
tx_extra_service_node_state_change() = default;
template<typename... VotesArgs>
tx_extra_service_node_state_change(service_nodes::new_state state, uint64_t block_height, uint32_t service_node_index, VotesArgs &&...votes)
: state{state}, block_height{block_height}, service_node_index{service_node_index}, votes{std::forward<VotesArgs>(votes)...} {}
bool operator==(const tx_extra_service_node_state_change &sc) const
{
return state == sc.state && block_height == sc.block_height && service_node_index == sc.service_node_index;
}
BEGIN_SERIALIZE()
ENUM_FIELD(state, state < service_nodes::new_state::_count)
FIELD(block_height)
FIELD(service_node_index)
FIELD(votes)
END_SERIALIZE()
};
struct tx_extra_tx_secret_key struct tx_extra_tx_secret_key
{ {
crypto::secret_key key; crypto::secret_key key;
@@ -324,35 +376,37 @@ namespace cryptonote
tx_extra_merge_mining_tag, tx_extra_merge_mining_tag,
tx_extra_additional_pub_keys, tx_extra_additional_pub_keys,
tx_extra_mysterious_minergate, tx_extra_mysterious_minergate,
tx_extra_offshore, tx_extra_offshore,
tx_extra_memo, tx_extra_memo,
tx_extra_service_node_pubkey, tx_extra_service_node_pubkey,
tx_extra_service_node_register, tx_extra_service_node_register,
tx_extra_service_node_contributor, tx_extra_service_node_contributor,
tx_extra_service_node_winner, tx_extra_service_node_winner,
tx_extra_service_node_deregister, tx_extra_service_node_state_change,
tx_extra_tx_secret_key, tx_extra_tx_secret_key,
tx_extra_tx_key_image_proofs, tx_extra_tx_key_image_proofs,
tx_extra_tx_key_image_unlock tx_extra_tx_key_image_unlock,
tx_extra_service_node_deregister
> tx_extra_field; > tx_extra_field;
} }
BLOB_SERIALIZER(cryptonote::tx_extra_service_node_deregister::vote); BLOB_SERIALIZER(cryptonote::tx_extra_service_node_deregister::vote);
BLOB_SERIALIZER(cryptonote::tx_extra_tx_key_image_proofs::proof); BLOB_SERIALIZER(cryptonote::tx_extra_tx_key_image_proofs::proof);
VARIANT_TAG(binary_archive, cryptonote::tx_extra_padding, TX_EXTRA_TAG_PADDING); VARIANT_TAG(binary_archive, cryptonote::tx_extra_padding, TX_EXTRA_TAG_PADDING);
VARIANT_TAG(binary_archive, cryptonote::tx_extra_pub_key, TX_EXTRA_TAG_PUBKEY); VARIANT_TAG(binary_archive, cryptonote::tx_extra_pub_key, TX_EXTRA_TAG_PUBKEY);
VARIANT_TAG(binary_archive, cryptonote::tx_extra_nonce, TX_EXTRA_NONCE); VARIANT_TAG(binary_archive, cryptonote::tx_extra_nonce, TX_EXTRA_NONCE);
VARIANT_TAG(binary_archive, cryptonote::tx_extra_merge_mining_tag, TX_EXTRA_MERGE_MINING_TAG); VARIANT_TAG(binary_archive, cryptonote::tx_extra_merge_mining_tag, TX_EXTRA_MERGE_MINING_TAG);
VARIANT_TAG(binary_archive, cryptonote::tx_extra_additional_pub_keys, TX_EXTRA_TAG_ADDITIONAL_PUBKEYS); VARIANT_TAG(binary_archive, cryptonote::tx_extra_additional_pub_keys, TX_EXTRA_TAG_ADDITIONAL_PUBKEYS);
VARIANT_TAG(binary_archive, cryptonote::tx_extra_mysterious_minergate, TX_EXTRA_MYSTERIOUS_MINERGATE_TAG); VARIANT_TAG(binary_archive, cryptonote::tx_extra_mysterious_minergate, TX_EXTRA_MYSTERIOUS_MINERGATE_TAG);
VARIANT_TAG(binary_archive, cryptonote::tx_extra_offshore, TX_EXTRA_TAG_OFFSHORE); VARIANT_TAG(binary_archive, cryptonote::tx_extra_offshore, TX_EXTRA_TAG_OFFSHORE);
VARIANT_TAG(binary_archive, cryptonote::tx_extra_memo, TX_EXTRA_TAG_MEMO); VARIANT_TAG(binary_archive, cryptonote::tx_extra_memo, TX_EXTRA_TAG_MEMO);
VARIANT_TAG(binary_archive, cryptonote::tx_extra_service_node_register, TX_EXTRA_TAG_SERVICE_NODE_REGISTER); VARIANT_TAG(binary_archive, cryptonote::tx_extra_service_node_register, TX_EXTRA_TAG_SERVICE_NODE_REGISTER);
VARIANT_TAG(binary_archive, cryptonote::tx_extra_service_node_deregister, TX_EXTRA_TAG_SERVICE_NODE_DEREGISTER); VARIANT_TAG(binary_archive, cryptonote::tx_extra_service_node_state_change, TX_EXTRA_TAG_SERVICE_NODE_STATE_CHANGE);
VARIANT_TAG(binary_archive, cryptonote::tx_extra_service_node_contributor, TX_EXTRA_TAG_SERVICE_NODE_CONTRIBUTOR); VARIANT_TAG(binary_archive, cryptonote::tx_extra_service_node_contributor, TX_EXTRA_TAG_SERVICE_NODE_CONTRIBUTOR);
VARIANT_TAG(binary_archive, cryptonote::tx_extra_service_node_winner, TX_EXTRA_TAG_SERVICE_NODE_WINNER); VARIANT_TAG(binary_archive, cryptonote::tx_extra_service_node_winner, TX_EXTRA_TAG_SERVICE_NODE_WINNER);
VARIANT_TAG(binary_archive, cryptonote::tx_extra_service_node_pubkey, TX_EXTRA_TAG_SERVICE_NODE_PUBKEY); VARIANT_TAG(binary_archive, cryptonote::tx_extra_service_node_pubkey, TX_EXTRA_TAG_SERVICE_NODE_PUBKEY);
VARIANT_TAG(binary_archive, cryptonote::tx_extra_tx_secret_key, TX_EXTRA_TAG_TX_SECRET_KEY); VARIANT_TAG(binary_archive, cryptonote::tx_extra_tx_secret_key, TX_EXTRA_TAG_TX_SECRET_KEY);
VARIANT_TAG(binary_archive, cryptonote::tx_extra_tx_key_image_proofs, TX_EXTRA_TAG_TX_KEY_IMAGE_PROOFS); VARIANT_TAG(binary_archive, cryptonote::tx_extra_tx_key_image_proofs, TX_EXTRA_TAG_TX_KEY_IMAGE_PROOFS);
VARIANT_TAG(binary_archive, cryptonote::tx_extra_tx_key_image_unlock, TX_EXTRA_TAG_TX_KEY_IMAGE_UNLOCK); VARIANT_TAG(binary_archive, cryptonote::tx_extra_tx_key_image_unlock, TX_EXTRA_TAG_TX_KEY_IMAGE_UNLOCK);
VARIANT_TAG(binary_archive, cryptonote::tx_extra_service_node_deregister, TX_EXTRA_TAG_SERVICE_NODE_DEREGISTER);

View File

@@ -0,0 +1,26 @@
#pragma once
#include <cstdint>
namespace cryptonote
{
enum class txversion : uint16_t
{
v0 = 0,
v1,
v2,
v3,
_count
};
enum class txtype : uint16_t
{
standard = 0,
state_change,
key_image_unlock,
stake,
_count
};
}

View File

@@ -39,4 +39,5 @@ enum BLOB_TYPE {
BLOB_TYPE_CRYPTONOTE_ZEPHYR = 13, // ZEPHYR BLOB_TYPE_CRYPTONOTE_ZEPHYR = 13, // ZEPHYR
BLOB_TYPE_CRYPTONOTE_XLA = 14, // XLA BLOB_TYPE_CRYPTONOTE_XLA = 14, // XLA
BLOB_TYPE_CRYPTONOTE_SALVIUM= 15, // Salvium BLOB_TYPE_CRYPTONOTE_SALVIUM= 15, // Salvium
BLOB_TYPE_CRYPTONOTE_ARQMA = 16 // Arqma
}; };

View File

@@ -7,6 +7,7 @@
#include <algorithm> #include <algorithm>
#include "cryptonote_basic/cryptonote_basic.h" #include "cryptonote_basic/cryptonote_basic.h"
#include "cryptonote_basic/cryptonote_format_utils.h" #include "cryptonote_basic/cryptonote_format_utils.h"
#include "cryptonote_basic/tx_extra.h"
#include "common/base58.h" #include "common/base58.h"
#include "serialization/binary_utils.h" #include "serialization/binary_utils.h"
#include <nan.h> #include <nan.h>
@@ -330,7 +331,11 @@ NAN_METHOD(construct_mm_parent_block_blob) { // (parentBlockTemplate, blob_type,
b.set_blob_type(blob_type); b.set_blob_type(blob_type);
if (!parse_and_validate_block_from_blob(input, b)) return THROW_ERROR_EXCEPTION("construct_mm_parent_block_blob: Failed to parse prent block"); if (!parse_and_validate_block_from_blob(input, b)) return THROW_ERROR_EXCEPTION("construct_mm_parent_block_blob: Failed to parse prent block");
if (blob_type == BLOB_TYPE_CRYPTONOTE_LOKI || blob_type == BLOB_TYPE_CRYPTONOTE_XTNC) b.miner_tx.version = cryptonote::loki_version_2; if (blob_type == BLOB_TYPE_CRYPTONOTE_LOKI || blob_type == BLOB_TYPE_CRYPTONOTE_XTNC) b.miner_tx.version = cryptonote::loki_version_2;
if (blob_type == BLOB_TYPE_CRYPTONOTE_ARQMA) {
b.miner_tx.version = static_cast<size_t>(cryptonote::txversion::v3);
b.miner_tx.tx_type = cryptonote::txtype::standard;
}
block b2 = AUTO_VAL_INIT(b2); block b2 = AUTO_VAL_INIT(b2);
b2.set_blob_type(BLOB_TYPE_FORKNOTE2); b2.set_blob_type(BLOB_TYPE_FORKNOTE2);
if (!parse_and_validate_block_from_blob(child_input, b2)) return THROW_ERROR_EXCEPTION("construct_mm_parent_block_blob: Failed to parse child block"); if (!parse_and_validate_block_from_blob(child_input, b2)) return THROW_ERROR_EXCEPTION("construct_mm_parent_block_blob: Failed to parse child block");

View File

@@ -97,6 +97,29 @@ inline bool do_serialize(Archive &ar, bool &v)
bool r = ::do_serialize(ar, f); \ bool r = ::do_serialize(ar, f); \
if (!r || !ar.stream().good()) return false; \ if (!r || !ar.stream().good()) return false; \
} while(0); } while(0);
/*! \macro ENUM_FIELD(f, test)
* \brief tags and serializes (as a varint) the scoped enum \a f with a requirement that expression\
* \a test be true(typically for range testing).
*/
#define ENUM_FIELD(f, test) ENUM_FIELD_N(#f, f, test)
/*! \macro ENUM_FIELD_N(t, f, begin, end)
*
* \brief tags (as \a t) and serializes (as a varint) the scoped enum \a f with a requirement that
* expression \a test be true (typically for range testing).
*/
#define ENUM_FIELD_N(t, f, test) \
do { \
using enum_t = decltype(f); \
using int_t = typename std::underlying_type<enum_t>::type; \
int_t int_value = W ? static_cast<int_t>(f) : 0; \
ar.tag(t); \
ar.serialize_varint(int_value); \
if(!ar.stream().good()) return false; \
if(!W) { \
f = static_cast<enum_t>(int_value); \
if(!(test)) return false; \
} \
} while(0);
#define VARINT_FIELD(f) \ #define VARINT_FIELD(f) \
do { \ do { \
ar.tag(#f); \ ar.tag(#f); \