Interim checkin

This code contains working "return address" semantics for CONVERT and YIELD.
This commit is contained in:
Some Random Crypto Guy
2024-02-16 11:02:11 +00:00
parent a3a7f686f3
commit 606580a173
24 changed files with 457 additions and 281 deletions
+10 -4
View File
@@ -232,17 +232,22 @@ void BlockchainDB::add_transaction(const crypto::hash& blk_hash, const std::pair
{
// miner v2 txes have their coinbase output in one single out to save space,
// and we store them as rct outputs with an identity mask
uint64_t unlock_time = 0;
if (!cryptonote::get_output_unlock_time(tx.vout[i], unlock_time)) {
LOG_PRINT_L1("Failed to get output unlock time, aborting transaction addition");
throw std::runtime_error("Unexpected error getting output unlock_time, aborting");
}
if (miner_tx && tx.version == 2)
{
cryptonote::tx_out vout = tx.vout[i];
rct::key commitment = rct::zeroCommit(vout.amount);
vout.amount = 0;
amount_output_indices[i] = add_output(tx_hash, vout, i, tx.unlock_time,
amount_output_indices[i] = add_output(tx_hash, vout, i, unlock_time,
&commitment);
}
else
{
amount_output_indices[i] = add_output(tx_hash, tx.vout[i], i, tx.unlock_time,
amount_output_indices[i] = add_output(tx_hash, tx.vout[i], i, unlock_time,
tx.version > 1 ? &tx.rct_signatures.outPk[i].mask : NULL);
}
}
@@ -263,6 +268,7 @@ uint64_t BlockchainDB::add_block( const std::pair<block, blobdata>& blck
, const uint64_t& coins_generated
, const std::vector<std::pair<transaction, blobdata>>& txs
, const cryptonote::network_type& nettype
, cryptonote::yield_block_info& ybi
)
{
const block &blk = blck.first;
@@ -378,7 +384,7 @@ uint64_t BlockchainDB::add_block( const std::pair<block, blobdata>& blck
// No price available - bail out, because block is invalid
throw std::runtime_error("Asset type '" + tally.first + "' is not present in available pricing record");
}
// Convert the amount into FULM
// Convert the FUSD amount into FULM
boost::multiprecision::int128_t tally_128 = tally.second;
tally_128 *= asset_price;
tally_128 /= fulm_price;
@@ -395,7 +401,7 @@ uint64_t BlockchainDB::add_block( const std::pair<block, blobdata>& blck
// call out to subclass implementation to add the block & metadata
time1 = epee::misc_utils::get_tick_count();
add_block(blk, block_weight, long_term_block_weight, cumulative_difficulty, coins_generated, num_rct_outs, num_rct_outs_by_asset_type, blk_hash, slippage_total, yield_total, nettype);
add_block(blk, block_weight, long_term_block_weight, cumulative_difficulty, coins_generated, num_rct_outs, num_rct_outs_by_asset_type, blk_hash, slippage_total, yield_total, nettype, ybi);
TIME_MEASURE_FINISH(time1);
time_add_block1 += time1;
+9 -5
View File
@@ -157,7 +157,7 @@ struct txpool_tx_meta_t
{
crypto::hash max_used_block_id;
crypto::hash last_failed_id;
crypto::key_image input_k_image;
crypto::public_key return_pubkey;
crypto::public_key return_address;
crypto::public_key one_time_public_key;
uint64_t weight;
@@ -199,8 +199,8 @@ struct txpool_tx_meta_t
typedef struct yield_block_info {
uint64_t block_height;
uint64_t slippage_total;
uint64_t locked_coins;
uint64_t slippage_total_this_block;
uint64_t locked_coins_this_block;
uint64_t locked_coins_tally;
uint8_t network_health_percentage;
} yield_block_info;
@@ -210,6 +210,8 @@ typedef struct yield_tx_info {
crypto::hash tx_hash;
uint64_t locked_coins;
crypto::public_key return_address;
crypto::public_key P_change;
crypto::public_key return_pubkey;
} yield_tx_info;
#define DBF_SAFE 1
@@ -435,7 +437,8 @@ private:
const crypto::hash& blk_hash,
uint64_t slippage_total,
uint64_t yield_total,
const cryptonote::network_type& nettype
const cryptonote::network_type& nettype,
cryptonote::yield_block_info& ybi
) = 0;
/**
@@ -889,7 +892,8 @@ public:
, const uint64_t& coins_generated
, const std::vector<std::pair<transaction, blobdata>>& txs
, const cryptonote::network_type& nettype
);
, cryptonote::yield_block_info& ybi
);
/**
* @brief checks if a block exists
+36 -16
View File
@@ -257,8 +257,8 @@ const char* const LMDB_CIRC_SUPPLY_TALLY = "circ_supply_tally";
/**
* We have the following information that will go into a "yield_txs" table in the blockchain:
*
* block_height (uint64_t) (this is the key field)
* ---------------------------------------------------------
* block_height (uint64_t) (this is the key field)
* ------------------------------------------------------------
* txn_hash (crypto:hash) (so we can verify)
* dest_address (crypto::key) (where to send the yield)
* amount_locked (uint64_t) (how much was locked)
@@ -266,7 +266,7 @@ const char* const LMDB_CIRC_SUPPLY_TALLY = "circ_supply_tally";
* We also have the following information that will go into a "yield_blocks" table:
*
* block_height (uint64_t) (this is the key field)
* --------------------------------------------------------
* ------------------------------------------------------------
* slippage_amount (uint64_t) (amount needed to determine yield payout for the block)
* locked_coins (uint64_t) (total number of coins locked at this height)
* locked_coins_total (uint64_t) (total number of coins locked at this height)
@@ -804,13 +804,14 @@ int BlockchainLMDB::get_yield_block_info(const uint64_t height, yield_block_info
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open();
mdb_txn_cursors *m_cursors = &m_wcursors;
// Clear the YBI, just in case
std::memset(&ybi, 0, sizeof(struct yield_block_info));
// Query for the matured YIELD_BLOCK_INFO information
CURSOR(yield_blocks)
TXN_PREFIX_RDONLY();
RCURSOR(yield_blocks);
MDB_val v;
MDB_val_set(k, height);
int ret = mdb_cursor_get(m_cur_yield_blocks, &k, &v, MDB_SET);
@@ -832,19 +833,21 @@ int BlockchainLMDB::get_yield_tx_info(const uint64_t height, std::vector<yield_t
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open();
mdb_txn_cursors *m_cursors = &m_wcursors;
// Clear the container
yti_container.clear();
CURSOR(yield_txs)
// Query for the (presumably matured) YIELD_TX_INFO information
TXN_PREFIX_RDONLY();
RCURSOR(yield_txs);
MDB_val v;
MDB_val_set(k, height);
MDB_cursor_op op = MDB_FIRST_DUP;
MDB_cursor_op op = MDB_SET;
while (1)
{
int ret = mdb_cursor_get(m_cur_yield_txs, &k, &v, op);
op = MDB_NEXT_DUP;
op = MDB_NEXT;
if (ret == MDB_NOTFOUND)
break;
if (ret)
@@ -859,7 +862,7 @@ int BlockchainLMDB::get_yield_tx_info(const uint64_t height, std::vector<yield_t
return 0;
}
void BlockchainLMDB::add_block(const block& blk, size_t block_weight, uint64_t long_term_block_weight, const difficulty_type& cumulative_difficulty, const uint64_t& coins_generated, uint64_t num_rct_outs, oracle::asset_type_counts& cum_rct_by_asset_type, const crypto::hash& blk_hash, uint64_t slippage_total, uint64_t yield_total, const cryptonote::network_type& nettype)
void BlockchainLMDB::add_block(const block& blk, size_t block_weight, uint64_t long_term_block_weight, const difficulty_type& cumulative_difficulty, const uint64_t& coins_generated, uint64_t num_rct_outs, oracle::asset_type_counts& cum_rct_by_asset_type, const crypto::hash& blk_hash, uint64_t slippage_total, uint64_t yield_total, const cryptonote::network_type& nettype, cryptonote::yield_block_info& ybi)
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open();
@@ -890,9 +893,9 @@ void BlockchainLMDB::add_block(const block& blk, size_t block_weight, uint64_t l
int result = 0;
CURSOR(yield_blocks)
yield_block_info ybi_matured, ybi_prev, ybi;
yield_block_info ybi_matured, ybi_prev;
uint64_t yield_lock_period = cryptonote::get_config(nettype).YIELD_LOCK_PERIOD;
if (m_height >= yield_lock_period) {
if (m_height > yield_lock_period) {
uint64_t height_matured = m_height - yield_lock_period - 1;
result = get_yield_block_info(height_matured, ybi_matured);
if (result)
@@ -919,8 +922,8 @@ void BlockchainLMDB::add_block(const block& blk, size_t block_weight, uint64_t l
// Create the YIELD_BLOCK_INFO instance for this block
ybi.block_height = m_height;
ybi.slippage_total = slippage_total;
ybi.locked_coins = yield_total;
ybi.slippage_total_this_block = slippage_total;
ybi.locked_coins_this_block = yield_total;
ybi.locked_coins_tally = ybi_prev.locked_coins_tally - ybi_matured.locked_coins_tally + yield_total;
ybi.network_health_percentage = 100;
@@ -996,6 +999,7 @@ void BlockchainLMDB::remove_block()
CURSOR(block_heights)
CURSOR(blocks)
CURSOR(circ_supply_tally)
CURSOR(yield_blocks)
MDB_val_copy<uint64_t> k(m_height - 1);
MDB_val h = k;
if ((result = mdb_cursor_get(m_cur_block_info, (MDB_val *)&zerokval, &h, MDB_GET_BOTH)))
@@ -1016,6 +1020,13 @@ void BlockchainLMDB::remove_block()
if ((result = mdb_cursor_del(m_cur_block_info, 0)))
throw1(DB_ERROR(lmdb_error("Failed to add removal of block info to db transaction: ", result).c_str()));
MDB_val_copy<uint64_t> k2(m_height - 1);
MDB_val v = k2;
if ((result = mdb_cursor_get(m_cur_yield_blocks, &k2, NULL, MDB_SET)))
throw1(BLOCK_DNE(lmdb_error("Attempting to remove yield block info that's not in the db: ", result).c_str()));
if ((result = mdb_cursor_del(m_cur_yield_blocks, 0)))
throw1(DB_ERROR(lmdb_error("Failed to add removal of yield block info to db transaction: ", result).c_str()));
}
boost::multiprecision::int128_t
@@ -1229,6 +1240,15 @@ uint64_t BlockchainLMDB::add_transaction_data(const crypto::hash& blk_hash, cons
yield_data.tx_hash = tx_hash;
yield_data.return_address = tx.return_address;
yield_data.locked_coins = tx.amount_burnt;
if (tx.vin.empty())
throw0(DB_ERROR("tx.vin is empty (needed to create yield data for the PROTOCOL_TX)"));
if (tx.vin[0].type() != typeid(cryptonote::txin_to_key))
throw0(DB_ERROR("tx.vin[0] is wrong type (needed to create yield data for the PROTOCOL_TX)"));
yield_data.return_pubkey = tx.return_pubkey;
if (tx.vout.size() != 1)
throw0(DB_ERROR("tx.vout is wrong size (needed to create yield data for the PROTOCOL_TX)"));
if (!cryptonote::get_output_public_key(tx.vout[0], yield_data.P_change))
throw0(DB_ERROR("failed to get P_change from tx.vout[0] (needed to create yield data for the PROTOCOL_TX)"));
MDB_val_set(val_height, m_height);
MDB_val_set(val_yield_tx_data, yield_data);
result = mdb_cursor_put(m_cur_yield_txs, &val_height, &val_yield_tx_data, MDB_APPEND);
@@ -4606,7 +4626,7 @@ void BlockchainLMDB::block_rtxn_abort() const
}
uint64_t BlockchainLMDB::add_block(const std::pair<block, blobdata>& blk, size_t block_weight, uint64_t long_term_block_weight, const difficulty_type& cumulative_difficulty, const uint64_t& coins_generated,
const std::vector<std::pair<transaction, blobdata>>& txs, const cryptonote::network_type& nettype)
const std::vector<std::pair<transaction, blobdata>>& txs, const cryptonote::network_type& nettype, cryptonote::yield_block_info& ybi)
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open();
@@ -4624,7 +4644,7 @@ uint64_t BlockchainLMDB::add_block(const std::pair<block, blobdata>& blk, size_t
try
{
BlockchainDB::add_block(blk, block_weight, long_term_block_weight, cumulative_difficulty, coins_generated, txs, nettype);
BlockchainDB::add_block(blk, block_weight, long_term_block_weight, cumulative_difficulty, coins_generated, txs, nettype, ybi);
}
catch (const DB_ERROR_TXN_START& e)
{
+3 -1
View File
@@ -342,6 +342,7 @@ public:
, const uint64_t& coins_generated
, const std::vector<std::pair<transaction, blobdata>>& txs
, const cryptonote::network_type& nettype
, cryptonote::yield_block_info& ybi
);
virtual void set_batch_transactions(bool batch_transactions);
@@ -399,7 +400,8 @@ private:
const crypto::hash& blk_hash,
uint64_t slippage_total,
uint64_t yield_total,
const cryptonote::network_type& nettype
const cryptonote::network_type& nettype,
cryptonote::yield_block_info& ybi
);
virtual void remove_block();