First completed round trip test of sFUL/FUSD -> FULM

After all of the trials and tribulations, we finally have a viable prototype!

The code is working for conversions of all kinds. There are a number of
strange and annoying bugs still present, like the rings in the CLI wallet are
misbehaving at times. But we have a viable product.
This commit is contained in:
Some Random Crypto Guy
2023-12-22 21:43:07 +00:00
parent 6d08d5aabf
commit a06b121dde
14 changed files with 223 additions and 234 deletions
+1 -1
View File
@@ -127,7 +127,7 @@ struct output_data_t
crypto::public_key pubkey; //!< the output's public key (for spend verification)
uint64_t unlock_time; //!< the output's unlock time (or height)
uint64_t height; //!< the height of the block which created the output
char asset_type[8]; //!< the asset type of the output
uint32_t asset_type; //!< the asset type of the output
rct::key commitment; //!< the output's amount commitment (for spend verification)
};
#pragma pack(pop)
+27 -49
View File
@@ -71,7 +71,7 @@ struct pre_rct_output_data_t
crypto::public_key pubkey; //!< the output's public key (for spend verification)
uint64_t unlock_time; //!< the output's unlock time (or height)
uint64_t height; //!< the height of the block which created the output
char asset_type[8]; //!< the asset type of the output
uint32_t asset_type; //!< the asset type of the output
};
#pragma pack(pop)
@@ -1075,19 +1075,6 @@ uint64_t BlockchainLMDB::add_transaction_data(const crypto::hash& blk_hash, cons
if (tx.type == cryptonote::transaction_type::CONVERT || tx.type == cryptonote::transaction_type::BURN) {
/*
// Conversion TX - update our records
circ_supply cs;
cs.tx_hash = tx_hash;
cs.asset_type = cryptonote::asset_id_from_type(tx.source_asset_type);
cs.amount_burnt = tx.amount_burnt;
cs.amount_minted = 0;
MDB_val_set(val_circ_supply, cs);
result = mdb_cursor_put(m_cur_circ_supply, &val_tx_id, &val_circ_supply, MDB_APPEND);
if (result)
throw0(DB_ERROR( lmdb_error("Failed to add tx circulating supply to db transaction: ", result).c_str() ));
*/
// Get the current tally value for the source currency type
MDB_val_copy<uint64_t> source_idx(cryptonote::asset_id_from_type(tx.source_asset_type));
boost::multiprecision::int128_t source_tally = 0;
@@ -1116,20 +1103,7 @@ uint64_t BlockchainLMDB::add_transaction_data(const crypto::hash& blk_hash, cons
bool ok = cryptonote::get_output_asset_type(out, asset_type);
if (!ok)
throw0(DB_ERROR("failed to get output asset type (needed to update the circulating supply data for the PROTOCOL_TX)"));
/*
circ_supply cs;
cs.tx_hash = tx_hash;
cs.asset_type = cryptonote::asset_id_from_type(asset_type);
cs.amount_burnt = 0;
cs.amount_minted = out.amount;
*/
minted_amounts[cryptonote::asset_id_from_type(asset_type)] += out.amount;
/*
MDB_val_set(val_circ_supply, cs);
result = mdb_cursor_put(m_cur_circ_supply, &val_tx_id, &val_circ_supply, MDB_APPENDDUP);
if (result)
throw0(DB_ERROR( lmdb_error("Failed to add tx circulating supply to db transaction: ", result).c_str() ));
*/
}
// Now update the overall tally entries
@@ -1360,6 +1334,8 @@ std::pair<uint64_t, uint64_t> BlockchainLMDB::add_output(const crypto::hash& tx_
if (result)
throw0(DB_ERROR(lmdb_error("Failed to add output tx hash to db transaction: ", result).c_str()));
uint32_t asset_type = cryptonote::asset_id_from_type(output_asset_type);
outkey ok;
MDB_val data;
MDB_val_copy<uint64_t> val_amount(tx_output.amount);
@@ -1380,11 +1356,7 @@ std::pair<uint64_t, uint64_t> BlockchainLMDB::add_output(const crypto::hash& tx_
ok.data.pubkey = output_public_key;
ok.data.unlock_time = unlock_time;
ok.data.height = m_height;
if(output_asset_type.length() >= sizeof(ok.data.asset_type))
throw0(DB_ERROR(lmdb_error("Invalid asset_type " + output_asset_type, result).c_str()));
memset(ok.data.asset_type, 0, sizeof(ok.data.asset_type));
memcpy(ok.data.asset_type, output_asset_type.c_str(), output_asset_type.length());
ok.data.asset_type = asset_type;
if (tx_output.amount == 0)
{
@@ -1401,7 +1373,7 @@ std::pair<uint64_t, uint64_t> BlockchainLMDB::add_output(const crypto::hash& tx_
throw0(DB_ERROR(lmdb_error("Failed to add output pubkey to db transaction: ", result).c_str()));
MDB_val_copy<const char *> k(output_asset_type.c_str());
MDB_val_copy<uint32_t> k(asset_type);
MDB_val v;
mdb_size_t num_outputs_of_asset_type = 0;
@@ -1420,7 +1392,7 @@ std::pair<uint64_t, uint64_t> BlockchainLMDB::add_output(const crypto::hash& tx_
oat.output_id = ok.output_id;
MDB_val_set(voat, oat);
MDB_val_copy<const char *> koat(output_asset_type.c_str());
MDB_val_copy<uint32_t> koat(asset_type);
if ((result = mdb_cursor_put(m_cur_output_types, &koat, &voat, MDB_APPENDDUP)))
throw0(DB_ERROR(lmdb_error("Failed to add output type to db transaction: ", result).c_str()));
@@ -1469,14 +1441,14 @@ void BlockchainLMDB::remove_tx_outputs(const uint64_t tx_id, const transaction&
for (size_t i = tx.vout.size(); i-- > 0;)
{
uint64_t amount = is_pseudo_rct ? 0 : tx.vout[i].amount;
std::string output_asset_type;
if (!get_output_asset_type(tx.vout[i], output_asset_type))
std::string output_asset_type_str;
if (!get_output_asset_type(tx.vout[i], output_asset_type_str))
throw0(DB_ERROR("Could not get an output asset_type from a tx output (removing)."));
remove_output(amount, amount_output_indices[i].first, output_asset_type, amount_output_indices[i].second);
remove_output(amount, amount_output_indices[i].first, output_asset_type_str, amount_output_indices[i].second);
}
}
void BlockchainLMDB::remove_output(const uint64_t amount, const uint64_t& out_index, const std::string& output_asset_type, const uint64_t& asset_type_output_id)
void BlockchainLMDB::remove_output(const uint64_t amount, const uint64_t& out_index, const std::string& output_asset_type_str, const uint64_t& asset_type_output_id)
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open();
@@ -1506,8 +1478,8 @@ void BlockchainLMDB::remove_output(const uint64_t amount, const uint64_t& out_in
throw1(DB_ERROR(lmdb_error("Error adding removal of output tx to db transaction", result).c_str()));
}
MDB_val_copy<const char *> koat(output_asset_type.c_str());
uint32_t output_asset_type = cryptonote::asset_id_from_type(output_asset_type_str);
MDB_val_copy<uint32_t> koat(output_asset_type);
MDB_val_set(voat, asset_type_output_id);
result = mdb_cursor_get(m_cur_output_types, &koat, &voat, MDB_GET_BOTH);
@@ -2913,7 +2885,10 @@ std::pair<std::vector<uint64_t>, uint64_t> BlockchainLMDB::get_block_cumulative_
}
const mdb_block_info *bi = ((const mdb_block_info *)v.mv_data) + (height - range_begin);
res.push_back(bi->bi_cum_rct_by_asset_type[asset_type]);
// if no asset type is provided in the request, an old client is requesting the cumulative outputs,
// and is expecting the global output distribution that isn't bucketed by asset type in response
res.push_back(asset_type.empty() ? bi->bi_cum_rct : bi->bi_cum_rct_by_asset_type[asset_type]);
if (height == heights[heights.size() - CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE])
num_spendable_global_outs = bi->bi_cum_rct;
@@ -3822,7 +3797,7 @@ uint64_t BlockchainLMDB::get_num_outputs(const uint64_t& amount) const
return num_elems;
}
uint64_t BlockchainLMDB::get_num_outputs_of_asset_type(const std::string asset_type) const
uint64_t BlockchainLMDB::get_num_outputs_of_asset_type(const std::string asset_type_str) const
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open();
@@ -3830,7 +3805,8 @@ uint64_t BlockchainLMDB::get_num_outputs_of_asset_type(const std::string asset_t
TXN_PREFIX_RDONLY();
RCURSOR(output_types);
MDB_val_copy<const char *> k(asset_type.c_str());
uint32_t asset_type = cryptonote::asset_id_from_type(asset_type_str);
MDB_val_copy<uint32_t> k(asset_type);
MDB_val v;
mdb_size_t num_outputs_of_asset_type = 0;
auto result = mdb_cursor_get(m_cur_output_types, &k, &v, MDB_SET);
@@ -3882,7 +3858,7 @@ output_data_t BlockchainLMDB::get_output_key(const uint64_t& amount, const uint6
return ret;
}
void BlockchainLMDB::get_output_id_from_asset_type_output_index(const std::string asset_type, const std::vector<uint64_t> &asset_type_output_indices, std::vector<uint64_t> &output_indices) const
void BlockchainLMDB::get_output_id_from_asset_type_output_index(const std::string asset_type_str, const std::vector<uint64_t> &asset_type_output_indices, std::vector<uint64_t> &output_indices) const
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open();
@@ -3893,7 +3869,8 @@ void BlockchainLMDB::get_output_id_from_asset_type_output_index(const std::strin
RCURSOR(output_types);
MDB_val_copy<const char *> k_type(asset_type.c_str());
uint32_t asset_type = cryptonote::asset_id_from_type(asset_type_str);
MDB_val_copy<uint32_t> k_type(asset_type);
for (size_t i = 0; i < asset_type_output_indices.size(); ++i)
{
@@ -3902,7 +3879,7 @@ void BlockchainLMDB::get_output_id_from_asset_type_output_index(const std::strin
auto get_result = mdb_cursor_get(m_cur_output_types, &k_type, &v, MDB_GET_BOTH);
if (get_result == MDB_NOTFOUND)
{
throw1(OUTPUT_DNE((std::string("Attempting to get output id by asset type output id (asset type " + asset_type + " asset type ouput id " + boost::lexical_cast<std::string>(asset_type_output_indices[i]) + "), but key does not exist (current height " + boost::lexical_cast<std::string>(height()) + ")").c_str())));
throw1(OUTPUT_DNE((std::string("Attempting to get output id by asset type output id (asset type " + asset_type_str + " asset type ouput id " + boost::lexical_cast<std::string>(asset_type_output_indices[i]) + "), but key does not exist (current height " + boost::lexical_cast<std::string>(height()) + ")").c_str())));
}
else if (get_result)
throw0(DB_ERROR(lmdb_error("Error attempting to retrieve an output id by asset type output id from the db", get_result).c_str()));
@@ -3914,7 +3891,7 @@ void BlockchainLMDB::get_output_id_from_asset_type_output_index(const std::strin
TXN_POSTFIX_RDONLY();
}
uint64_t BlockchainLMDB::get_output_id_from_asset_type_output_index(const std::string asset_type, const uint64_t &asset_type_output_index) const
uint64_t BlockchainLMDB::get_output_id_from_asset_type_output_index(const std::string asset_type_str, const uint64_t &asset_type_output_index) const
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open();
@@ -3922,13 +3899,14 @@ uint64_t BlockchainLMDB::get_output_id_from_asset_type_output_index(const std::s
TXN_PREFIX_RDONLY();
RCURSOR(output_types);
MDB_val_copy<const char *> k_type(asset_type.c_str());
uint32_t asset_type = cryptonote::asset_id_from_type(asset_type_str);
MDB_val_copy<uint32_t> k_type(asset_type);
MDB_val_set(v, asset_type_output_index);
auto get_result = mdb_cursor_get(m_cur_output_types, &k_type, &v, MDB_GET_BOTH);
if (get_result == MDB_NOTFOUND)
{
throw1(OUTPUT_DNE((std::string("Attempting to get output id by asset type output id (asset type " + asset_type + " asset type output id " + boost::lexical_cast<std::string>(asset_type_output_index) + "), but key does not exist (current height " + boost::lexical_cast<std::string>(height()) + ")").c_str())));
throw1(OUTPUT_DNE((std::string("Attempting to get output id by asset type output id (asset type " + asset_type_str + " asset type output id " + boost::lexical_cast<std::string>(asset_type_output_index) + "), but key does not exist (current height " + boost::lexical_cast<std::string>(height()) + ")").c_str())));
}
else if (get_result)
throw0(DB_ERROR(lmdb_error("Error attempting to retrieve an output id by asset type output id from the db", get_result).c_str()));