Skip to content

Commit

Permalink
Merge pull request #145 from AdminXeq/coinbase
Browse files Browse the repository at this point in the history
Coinbase amounts clarification and display fixes
  • Loading branch information
AdminXeq committed Apr 17, 2023
2 parents 30bb7ce + 4aab79f commit cb7fc00
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 16 deletions.
22 changes: 14 additions & 8 deletions src/cryptonote_core/cryptonote_core.cpp
Expand Up @@ -1240,41 +1240,47 @@ namespace cryptonote
return m_mempool.check_for_key_images(key_im, spent);
}
//-----------------------------------------------------------------------------------------------
std::tuple<uint64_t, uint64_t, uint64_t> core::get_coinbase_tx_sum(const uint64_t start_offset, const size_t count)
std::tuple<uint64_t, uint64_t, uint64_t, uint64_t> core::get_coinbase_tx_sum(const uint64_t start_offset, const size_t count)
{
uint64_t emission_amount = 0;
uint64_t total_fee_amount = 0;
uint64_t burnt_xeq = 0;
uint64_t token_swap = 0;
if (count)
{
const uint64_t end = start_offset + count - 1;
m_blockchain_storage.for_blocks_range(start_offset, end,
[this, &emission_amount, &total_fee_amount, &burnt_xeq](uint64_t, const crypto::hash& hash, const block& b){
[this, &emission_amount, &total_fee_amount, &burnt_xeq, &token_swap](uint64_t, const crypto::hash& hash, const block& b){
std::vector <transaction> txs;
std::vector<crypto::hash> missed_txs;
uint64_t coinbase_amount = get_outs_money_amount(b.miner_tx);
this->get_transactions(b.tx_hashes, txs, missed_txs);
uint64_t tx_fee_amount = 0;
uint64_t b_xeq = 0;
for(const auto& tx: txs)
{
tx_fee_amount += get_tx_miner_fee(tx, b.major_version >= HF_VERSION_FEE_BURNING);
if(b.major_version >= HF_VERSION_FEE_BURNING)
{
burnt_xeq += get_burned_amount_from_tx_extra(tx.extra);
b_xeq += get_burned_amount_from_tx_extra(tx.extra);
}
}

emission_amount += coinbase_amount - tx_fee_amount;
emission_amount += coinbase_amount - (tx_fee_amount + b_xeq);
total_fee_amount += tx_fee_amount;
if(b.major_version >= 17)
burnt_xeq += b_xeq;
return true;
});

const uint8_t hf_ver = m_blockchain_storage.get_current_hard_fork_version();
if (hf_ver > 16)
{
emission_amount -= (uint64_t)0x1176592e000;
token_swap += (uint64_t)0x2e90edd000;
}
return true;
});
}

return std::tuple<uint64_t, uint64_t, uint64_t>(burnt_xeq, emission_amount, total_fee_amount);
return std::tuple<uint64_t, uint64_t, uint64_t, uint64_t>(burnt_xeq, emission_amount, total_fee_amount, token_swap);
}
//-----------------------------------------------------------------------------------------------
bool core::check_tx_inputs_keyimages_diff(const transaction& tx) const
Expand Down
4 changes: 2 additions & 2 deletions src/cryptonote_core/cryptonote_core.h
Expand Up @@ -786,8 +786,8 @@ namespace cryptonote
*
* @return the number of blocks to sync in one go
*/
std::tuple<uint64_t, uint64_t, uint64_t> get_coinbase_tx_sum(const uint64_t start_offset, const size_t count);
std::tuple<uint64_t, uint64_t, uint64_t, uint64_t> get_coinbase_tx_sum(const uint64_t start_offset, const size_t count);

/**
* @brief get the network type we're on
*
Expand Down
10 changes: 6 additions & 4 deletions src/daemon/rpc_command_executor.cpp
Expand Up @@ -1954,12 +1954,14 @@ bool t_rpc_command_executor::print_coinbase_tx_sum(uint64_t height, uint64_t cou
}
}

tools::msg_writer() << "Sum of coinbase transactions between block heights ["
tools::msg_writer() << "Sum of coinbase transactions between block heights ("
<< height << ", " << (height + count) << ") is "
<< cryptonote::print_money(res.emission_amount + res.fee_amount) << " "
<< cryptonote::print_money(res.emission_amount + res.fee_amount) << " \n"
<< "consisting of " << cryptonote::print_money(res.emission_amount)
<< " in emissions, and " << cryptonote::print_money(res.fee_amount)
<< " in fees, and " << cryptonote::print_money(res.burn_amount) << " was burnt.";
<< " in emissions,\nand " << cryptonote::print_money(res.fee_amount)
<< " in fees,\nand " << cryptonote::print_money(res.burn_amount)
<< " was burnt,\nand " << cryptonote::print_money(res.token_amount)
<< " was locked at cross-chain bridge.";
return true;
}

Expand Down
3 changes: 2 additions & 1 deletion src/rpc/core_rpc_server.cpp
Expand Up @@ -2777,10 +2777,11 @@ namespace cryptonote
return true;
}
CHECK_PAYMENT_MIN1(req, res, COST_PER_COINBASE_TX_SUM_BLOCK * req.count, false);
std::tuple<uint64_t, uint64_t, uint64_t> amounts = m_core.get_coinbase_tx_sum(req.height, req.count);
std::tuple<uint64_t, uint64_t, uint64_t, uint64_t> amounts = m_core.get_coinbase_tx_sum(req.height, req.count);
res.emission_amount = std::get<1>(amounts);
res.fee_amount = std::get<2>(amounts);
res.burn_amount = std::get<0>(amounts);
res.token_amount = std::get<3>(amounts);
res.status = CORE_RPC_STATUS_OK;
return true;
}
Expand Down
2 changes: 2 additions & 0 deletions src/rpc/core_rpc_server_commands_defs.h
Expand Up @@ -2528,12 +2528,14 @@ namespace cryptonote
uint64_t emission_amount;
uint64_t fee_amount;
uint64_t burn_amount;
uint64_t token_amount;

BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE_PARENT(rpc_access_response_base)
KV_SERIALIZE(emission_amount)
KV_SERIALIZE(fee_amount)
KV_SERIALIZE(burn_amount)
KV_SERIALIZE(token_amount)
END_KV_SERIALIZE_MAP()
};
typedef epee::misc_utils::struct_init<response_t> response;
Expand Down
2 changes: 1 addition & 1 deletion src/version.cpp.in
@@ -1,6 +1,6 @@
#define DEF_XEQ_VERSION_MAJOR 17
#define DEF_XEQ_VERSION_MINOR 2
#define DEF_XEQ_VERSION_PATCH 0
#define DEF_XEQ_VERSION_PATCH 1
#define DEF_XEQ_VERSION_IS_RELEASE @VERSION_IS_RELEASE@


Expand Down

0 comments on commit cb7fc00

Please sign in to comment.