From bd1af278a58812cbca9db184bd888d0f80e1e035 Mon Sep 17 00:00:00 2001 From: "m@lbit" Date: Mon, 9 Jun 2025 15:18:22 +0200 Subject: [PATCH] New BLOB_TYPE for Arqma Service-Nodes version 16 Hard-Fork. --- .../keyvalue_serialization_overloads.h | 1 + src/cryptonote_basic/cryptonote_basic.h | 30 ++-- src/cryptonote_basic/tx_extra.h | 138 ++++++++++++------ src/cryptonote_basic/txtypes.h | 26 ++++ src/cryptonote_config.h | 1 + src/main.cc | 7 +- src/serialization/serialization.h | 23 +++ 7 files changed, 174 insertions(+), 52 deletions(-) create mode 100644 src/cryptonote_basic/txtypes.h diff --git a/src/contrib/epee/include/serialization/keyvalue_serialization_overloads.h b/src/contrib/epee/include/serialization/keyvalue_serialization_overloads.h index 5757d60..4d66116 100644 --- a/src/contrib/epee/include/serialization/keyvalue_serialization_overloads.h +++ b/src/contrib/epee/include/serialization/keyvalue_serialization_overloads.h @@ -33,6 +33,7 @@ #include #include #include +#include #undef MONERO_DEFAULT_LOG_CATEGORY #define MONERO_DEFAULT_LOG_CATEGORY "serialization" diff --git a/src/cryptonote_basic/cryptonote_basic.h b/src/cryptonote_basic/cryptonote_basic.h index a428c0c..3dab537 100644 --- a/src/cryptonote_basic/cryptonote_basic.h +++ b/src/cryptonote_basic/cryptonote_basic.h @@ -29,6 +29,7 @@ #include "offshore/pricing_record.h" #include "zephyr_oracle/pricing_record.h" #include "salvium_oracle/pricing_record.h" +#include "txtypes.h" namespace cryptonote @@ -426,6 +427,8 @@ namespace cryptonote 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 + txtype tx_type; + std::vector vin; std::vector vin_zephyr; std::vector vin_salvium; @@ -752,9 +755,9 @@ namespace cryptonote VARINT_FIELD(amount_slippage_limit) } } - + } else { - + VARINT_FIELD(version) 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) FIELD(is_deregister) } - + + if (version >= static_cast(cryptonote::txversion::v3) && (blob_type == BLOB_TYPE_CRYPTONOTE_ARQMA)) + { + VARINT_FIELD(tx_type) + if (static_cast(tx_type) >= static_cast(cryptonote::txtype::_count)) + return false; + FIELD(output_unlock_times) + } + VARINT_FIELD(unlock_time) - + if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR) FIELD(vin_zephyr) - else + else FIELD(vin) - + if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR) FIELD(vout_zephyr) else 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(cryptonote::txversion::v3)) && vout.size() != output_unlock_times.size()) + return false; } FIELD(extra) if ((blob_type == BLOB_TYPE_CRYPTONOTE_LOKI || blob_type == BLOB_TYPE_CRYPTONOTE_XTNC) && version >= loki_version_4_tx_types) diff --git a/src/cryptonote_basic/tx_extra.h b/src/cryptonote_basic/tx_extra.h index 6c3843a..36a9d25 100644 --- a/src/cryptonote_basic/tx_extra.h +++ b/src/cryptonote_basic/tx_extra.h @@ -30,30 +30,43 @@ #pragma once -#define TX_EXTRA_PADDING_MAX_COUNT 255 -#define TX_EXTRA_NONCE_MAX_COUNT 255 -#define TX_EXTRA_OFFSHORE_MAX_COUNT 255 -#define TX_EXTRA_MEMO_MAX_COUNT 255 +#define TX_EXTRA_PADDING_MAX_COUNT 255 +#define TX_EXTRA_NONCE_MAX_COUNT 255 +#define TX_EXTRA_OFFSHORE_MAX_COUNT 255 +#define TX_EXTRA_MEMO_MAX_COUNT 255 -#define TX_EXTRA_TAG_PADDING 0x00 -#define TX_EXTRA_TAG_PUBKEY 0x01 -#define TX_EXTRA_NONCE 0x02 -#define TX_EXTRA_MERGE_MINING_TAG 0x03 -#define TX_EXTRA_TAG_ADDITIONAL_PUBKEYS 0x04 -#define TX_EXTRA_TAG_OFFSHORE 0x17 -#define TX_EXTRA_TAG_MEMO 0x18 -#define TX_EXTRA_TAG_SERVICE_NODE_REGISTER 0x70 -#define TX_EXTRA_TAG_SERVICE_NODE_DEREGISTER 0x71 -#define TX_EXTRA_TAG_SERVICE_NODE_WINNER 0x72 -#define TX_EXTRA_TAG_SERVICE_NODE_CONTRIBUTOR 0x73 -#define TX_EXTRA_TAG_SERVICE_NODE_PUBKEY 0x74 -#define TX_EXTRA_TAG_TX_SECRET_KEY 0x75 -#define TX_EXTRA_TAG_TX_KEY_IMAGE_PROOFS 0x76 -#define TX_EXTRA_TAG_TX_KEY_IMAGE_UNLOCK 0x77 -#define TX_EXTRA_MYSTERIOUS_MINERGATE_TAG 0xDE +#define TX_EXTRA_TAG_PADDING 0x00 +#define TX_EXTRA_TAG_PUBKEY 0x01 +#define TX_EXTRA_NONCE 0x02 +#define TX_EXTRA_MERGE_MINING_TAG 0x03 +#define TX_EXTRA_TAG_ADDITIONAL_PUBKEYS 0x04 +#define TX_EXTRA_TAG_OFFSHORE 0x17 +#define TX_EXTRA_TAG_MEMO 0x18 +#define TX_EXTRA_TAG_SERVICE_NODE_REGISTER 0x70 +#define TX_EXTRA_TAG_SERVICE_NODE_STATE_CHANGE 0x71 +#define TX_EXTRA_TAG_SERVICE_NODE_WINNER 0x72 +#define TX_EXTRA_TAG_SERVICE_NODE_CONTRIBUTOR 0x73 +#define TX_EXTRA_TAG_SERVICE_NODE_PUBKEY 0x74 +#define TX_EXTRA_TAG_TX_SECRET_KEY 0x75 +#define TX_EXTRA_TAG_TX_KEY_IMAGE_PROOFS 0x76 +#define TX_EXTRA_TAG_TX_KEY_IMAGE_UNLOCK 0x77 +#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_ENCRYPTED_PAYMENT_ID 0x01 +#define TX_EXTRA_NONCE_PAYMENT_ID 0x00 +#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 { @@ -277,6 +290,45 @@ namespace cryptonote 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 votes; + + tx_extra_service_node_state_change() = default; + + template + 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(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 { crypto::secret_key key; @@ -324,35 +376,37 @@ namespace cryptonote tx_extra_merge_mining_tag, tx_extra_additional_pub_keys, tx_extra_mysterious_minergate, - tx_extra_offshore, - tx_extra_memo, + tx_extra_offshore, + tx_extra_memo, tx_extra_service_node_pubkey, tx_extra_service_node_register, tx_extra_service_node_contributor, tx_extra_service_node_winner, - tx_extra_service_node_deregister, + tx_extra_service_node_state_change, tx_extra_tx_secret_key, 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; } BLOB_SERIALIZER(cryptonote::tx_extra_service_node_deregister::vote); 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_pub_key, TX_EXTRA_TAG_PUBKEY); -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_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_offshore, TX_EXTRA_TAG_OFFSHORE); -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_deregister, TX_EXTRA_TAG_SERVICE_NODE_DEREGISTER); -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_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_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_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_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_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_offshore, TX_EXTRA_TAG_OFFSHORE); +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_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_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_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_unlock, TX_EXTRA_TAG_TX_KEY_IMAGE_UNLOCK); +VARIANT_TAG(binary_archive, cryptonote::tx_extra_service_node_deregister, TX_EXTRA_TAG_SERVICE_NODE_DEREGISTER); diff --git a/src/cryptonote_basic/txtypes.h b/src/cryptonote_basic/txtypes.h new file mode 100644 index 0000000..6246783 --- /dev/null +++ b/src/cryptonote_basic/txtypes.h @@ -0,0 +1,26 @@ +#pragma once + +#include + +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 + }; +} diff --git a/src/cryptonote_config.h b/src/cryptonote_config.h index 8627430..702f167 100644 --- a/src/cryptonote_config.h +++ b/src/cryptonote_config.h @@ -39,4 +39,5 @@ enum BLOB_TYPE { BLOB_TYPE_CRYPTONOTE_ZEPHYR = 13, // ZEPHYR BLOB_TYPE_CRYPTONOTE_XLA = 14, // XLA BLOB_TYPE_CRYPTONOTE_SALVIUM= 15, // Salvium + BLOB_TYPE_CRYPTONOTE_ARQMA = 16 // Arqma }; diff --git a/src/main.cc b/src/main.cc index 24a621e..da701b3 100644 --- a/src/main.cc +++ b/src/main.cc @@ -7,6 +7,7 @@ #include #include "cryptonote_basic/cryptonote_basic.h" #include "cryptonote_basic/cryptonote_format_utils.h" +#include "cryptonote_basic/tx_extra.h" #include "common/base58.h" #include "serialization/binary_utils.h" #include @@ -330,7 +331,11 @@ NAN_METHOD(construct_mm_parent_block_blob) { // (parentBlockTemplate, 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 (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(cryptonote::txversion::v3); + b.miner_tx.tx_type = cryptonote::txtype::standard; + } + block b2 = AUTO_VAL_INIT(b2); 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"); diff --git a/src/serialization/serialization.h b/src/serialization/serialization.h index 8b94308..56e2c8d 100644 --- a/src/serialization/serialization.h +++ b/src/serialization/serialization.h @@ -97,6 +97,29 @@ inline bool do_serialize(Archive &ar, bool &v) bool r = ::do_serialize(ar, f); \ if (!r || !ar.stream().good()) return false; \ } 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::type; \ + int_t int_value = W ? static_cast(f) : 0; \ + ar.tag(t); \ + ar.serialize_varint(int_value); \ + if(!ar.stream().good()) return false; \ + if(!W) { \ + f = static_cast(int_value); \ + if(!(test)) return false; \ + } \ + } while(0); #define VARINT_FIELD(f) \ do { \ ar.tag(#f); \