1
0
Fork 0
forked from lthn/blockchain

attempt to fix issue with broken versioning in tx versioned structs

This commit is contained in:
cryptozoidberg 2023-09-01 11:59:23 +02:00
parent fb456bb2b9
commit 37e6a68509
No known key found for this signature in database
GPG key ID: 22DEB97A54C6FDEC
6 changed files with 54 additions and 13 deletions

View file

@ -748,8 +748,9 @@ namespace currency
std::string meta_info;
crypto::public_key owner = currency::null_pkey; // consider premultipling by 1/8
bool hidden_supply = false;
uint8_t version = 0;
BEGIN_VERSIONED_SERIALIZE(0)
BEGIN_VERSIONED_SERIALIZE(0, version)
FIELD(total_max_supply)
FIELD(current_supply)
FIELD(decimal_point)
@ -809,6 +810,7 @@ namespace currency
#define ASSET_DESCRIPTOR_OPERATION_UPDATE 3
#define ASSET_DESCRIPTOR_OPERATION_PUBLIC_BURN 4
#define ASSET_DESCRIPTOR_OPERATION_STRUCTURE_VER 1
struct asset_descriptor_operation
{
@ -817,8 +819,9 @@ namespace currency
boost::optional<crypto::public_key> opt_amount_commitment; // premultiplied by 1/8
boost::optional<crypto::signature> opt_proof; // operation proof - for update/emit
boost::optional<crypto::public_key> opt_asset_id; // target asset_id - for update/emit
uint8_t verion = ASSET_DESCRIPTOR_OPERATION_STRUCTURE_VER;
BEGIN_VERSIONED_SERIALIZE(1)
BEGIN_VERSIONED_SERIALIZE(ASSET_DESCRIPTOR_OPERATION_STRUCTURE_VER, verion)
FIELD(operation_type)
FIELD(descriptor)
FIELD(opt_amount_commitment)
@ -842,8 +845,9 @@ namespace currency
// linear composition proof for the fact amount_commitment = lin(asset_id, G)
boost::optional<crypto::linear_composition_proof_s> opt_amount_commitment_composition_proof; // for hidden supply
boost::optional<crypto::signature> opt_amount_commitment_g_proof; // for non-hidden supply, proofs that amount_commitment - supply * asset_id = lin(G)
uint8_t version = 0;
BEGIN_VERSIONED_SERIALIZE(0)
BEGIN_VERSIONED_SERIALIZE(0, version)
FIELD(opt_amount_commitment_composition_proof)
FIELD(opt_amount_commitment_g_proof)
END_SERIALIZE()
@ -851,6 +855,8 @@ namespace currency
BEGIN_BOOST_SERIALIZATION()
BOOST_SERIALIZE(opt_amount_commitment_composition_proof)
BOOST_SERIALIZE(opt_amount_commitment_g_proof)
BOOST_END_VERSION_UNDER(1)
BOOST_SERIALIZE(version)
END_BOOST_SERIALIZATION()
};
@ -1160,6 +1166,9 @@ BLOB_SERIALIZER(currency::txout_to_key);
VARIANT_TAG(json_archive, type_name, json_tag)
BOOST_CLASS_VERSION(currency::asset_descriptor_operation, 1);
BOOST_CLASS_VERSION(currency::asset_operation_proof, 1);
// txin_v variant currency
SET_VARIANT_TAGS(currency::txin_gen, 0, "gen");

View file

@ -561,6 +561,8 @@ namespace currency
}
context.m_priv.m_requested_objects.erase(req_it);
LOG_PRINT_L4("[NOTIFY_RESPONSE_GET_OBJECTS] BLOCK " << get_block_hash(b) << "[" << get_block_height(b) << "/" << count << "], txs: " << b.tx_hashes.size());
}
LOG_PRINT_CYAN("Block parsing time avr: " << (count > 0 ? total_blocks_parsing_time / count : 0) << " mcs, total for " << count << " blocks: " << total_blocks_parsing_time / 1000 << " ms", LOG_LEVEL_2);
@ -581,12 +583,13 @@ namespace currency
for (const block_complete_entry& block_entry : arg.blocks)
{
CHECK_STOP_FLAG__DROP_AND_RETURN_IF_SET(1, "Blocks processing interrupted, connection dropped");
block_verification_context bvc = boost::value_initialized<block_verification_context>();
//process transactions
size_t count_txs = 0;
TIME_MEASURE_START(transactions_process_time);
for (const auto& tx_blob : block_entry.txs)
{
LOG_PRINT_L4("[NOTIFY_RESPONSE_GET_OBJECTS] BL/TX ["<< count << "/" << count_txs << "]: " << epst::buff_to_hex_nodelimer(tx_blob));
CHECK_STOP_FLAG__DROP_AND_RETURN_IF_SET(1, "Block txs processing interrupted, connection dropped");
crypto::hash tx_id = null_hash;
transaction tx = AUTO_VAL_INIT(tx);
@ -598,6 +601,7 @@ namespace currency
return 1;
}
bvc.m_onboard_transactions[tx_id] = tx;
count_txs++;
// tx_verification_context tvc = AUTO_VAL_INIT(tvc);
// m_core.handle_incoming_tx(tx_blob, tvc, true);
// if(tvc.m_verification_failed)

View file

@ -102,12 +102,22 @@ do { \
do { \
_ser_ar.tag("VERSION"); \
if (!_ser_ar.stream().good()){break;} \
s_version = s_current_version = ver; \
_ser_ar.serialize_varint(s_version); \
_ser_ar.serialize_varint(s_version); \
if (!_ser_ar.stream().good()) return false; \
if(s_version > s_current_version) return false; \
} while (0);
#define VERSION_TO_MEMBER(last_ver, this_version_member) \
do { \
_ser_ar.tag("VERSION"); \
if (!_ser_ar.stream().good()){break;} \
_ser_ar.serialize_varint(this_version_member); \
if (!_ser_ar.stream().good()) return false; \
if(this_version_member > last_ver) return false; \
s_version = this_version_member; \
} while (0);
/*
#define CURRENT_VERSION(v) \
do { \
@ -120,9 +130,9 @@ do { \
if(s_version < x ) {return true;}
#define BEGIN_VERSIONED_SERIALIZE(ver) \
#define BEGIN_VERSIONED_SERIALIZE(last_ver, this_version_member) \
BEGIN_SERIALIZE() \
VERSION(ver)
VERSION_TO_MEMBER(last_ver, this_version_member)
#define DEFINE_SERIALIZATION_VERSION(v) inline static uint32_t get_serialization_version() { return v; }

View file

@ -1347,7 +1347,7 @@ namespace wallet_public
crypto::secret_key one_time_skey;
BEGIN_SERIALIZE_OBJECT()
VERSION(0)
VERSION(0) //use VERSION_TO_MEMBER if it's more then 0
FIELD(gen_context)
FIELD(one_time_skey)
END_SERIALIZE()
@ -1358,9 +1358,8 @@ namespace wallet_public
currency::transaction tx_template;
std::string encrypted_context; //ionic_swap_proposal_context encrypted with derivation
BEGIN_SERIALIZE_OBJECT()
VERSION(0)
VERSION(0) //use VERSION_TO_MEMBER if it's more then 0
FIELD(tx_template)
FIELD(encrypted_context)
END_SERIALIZE()

View file

@ -50,3 +50,22 @@ private:
std::vector<currency::tx_destination_entry> m_destinations;
currency::transaction m_tx;
};
void parse_weird_tx()
{
const std::string expected_hash = "62ee9fb89293f042cbcebb02d05fa15036ffca2bdeb4c48162f2d93a420e5974";
std::string tx_hex_buff;
epee::file_io_utils::load_file_to_string("E:\\tmp\\tx_as_hex.txt", tx_hex_buff);
std::string tx_blob;
epee::string_tools::parse_hexstr_to_binbuff(tx_hex_buff, tx_blob);
currency::transaction tx;
bool r = currency::parse_and_validate_tx_from_blob(tx_blob, tx);
std::string res_hash = epee::string_tools::pod_to_hex(currency::get_transaction_hash(tx));
if (res_hash != expected_hash)
{
std::cout << "this is sad";
}
}

View file

@ -35,8 +35,8 @@ int main(int argc, char** argv)
epee::log_space::log_singletone::get_default_log_file().c_str(),
epee::log_space::log_singletone::get_default_log_folder().c_str());
thread_pool_tests();
parse_weird_tx();
//thread_pool_tests();
// std::string buf1 = tools::get_varint_data<uint64_t>(CURRENCY_PUBLIC_ADDRESS_BASE58_PREFIX);
// std::string buf2 = tools::get_varint_data<uint64_t>(CURRENCY_PUBLIC_INTEG_ADDRESS_BASE58_PREFIX);