aboutsummaryrefslogtreecommitdiff
path: root/tests/core_tests/chaingen.cpp
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2018-07-18 22:24:53 +0100
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2018-09-11 13:38:07 +0000
commit5ffb2ff9b7c301eda5811a939c705f26627c4735 (patch)
treeac1ed0c55f69db9e65ebca9567bf3013e55c3bb6 /tests/core_tests/chaingen.cpp
parentbulletproofs: a few fixes from the Kudelski review (diff)
downloadmonero-5ffb2ff9b7c301eda5811a939c705f26627c4735.tar.xz
v8: per byte fee, pad bulletproofs, fixed 11 ring size
Diffstat (limited to 'tests/core_tests/chaingen.cpp')
-rw-r--r--tests/core_tests/chaingen.cpp76
1 files changed, 38 insertions, 38 deletions
diff --git a/tests/core_tests/chaingen.cpp b/tests/core_tests/chaingen.cpp
index 41256a4f1..d3cb52246 100644
--- a/tests/core_tests/chaingen.cpp
+++ b/tests/core_tests/chaingen.cpp
@@ -69,13 +69,13 @@ void test_generator::get_block_chain(std::vector<block_info>& blockchain, const
std::reverse(blockchain.begin(), blockchain.end());
}
-void test_generator::get_last_n_block_sizes(std::vector<size_t>& block_sizes, const crypto::hash& head, size_t n) const
+void test_generator::get_last_n_block_weights(std::vector<size_t>& block_weights, const crypto::hash& head, size_t n) const
{
std::vector<block_info> blockchain;
get_block_chain(blockchain, head, n);
BOOST_FOREACH(auto& bi, blockchain)
{
- block_sizes.push_back(bi.block_size);
+ block_weights.push_back(bi.block_weight);
}
}
@@ -95,17 +95,17 @@ uint64_t test_generator::get_already_generated_coins(const cryptonote::block& bl
return get_already_generated_coins(blk_hash);
}
-void test_generator::add_block(const cryptonote::block& blk, size_t tsx_size, std::vector<size_t>& block_sizes, uint64_t already_generated_coins, uint8_t hf_version)
+void test_generator::add_block(const cryptonote::block& blk, size_t txs_weight, std::vector<size_t>& block_weights, uint64_t already_generated_coins, uint8_t hf_version)
{
- const size_t block_size = tsx_size + get_object_blobsize(blk.miner_tx);
+ const size_t block_weight = txs_weight + get_transaction_weight(blk.miner_tx);
uint64_t block_reward;
- get_block_reward(misc_utils::median(block_sizes), block_size, already_generated_coins, block_reward, hf_version);
- m_blocks_info[get_block_hash(blk)] = block_info(blk.prev_id, already_generated_coins + block_reward, block_size);
+ get_block_reward(misc_utils::median(block_weights), block_weight, already_generated_coins, block_reward, hf_version);
+ m_blocks_info[get_block_hash(blk)] = block_info(blk.prev_id, already_generated_coins + block_reward, block_weight);
}
bool test_generator::construct_block(cryptonote::block& blk, uint64_t height, const crypto::hash& prev_id,
const cryptonote::account_base& miner_acc, uint64_t timestamp, uint64_t already_generated_coins,
- std::vector<size_t>& block_sizes, const std::list<cryptonote::transaction>& tx_list)
+ std::vector<size_t>& block_weights, const std::list<cryptonote::transaction>& tx_list)
{
blk.major_version = CURRENT_BLOCK_MAJOR_VERSION;
blk.minor_version = CURRENT_BLOCK_MINOR_VERSION;
@@ -121,52 +121,52 @@ bool test_generator::construct_block(cryptonote::block& blk, uint64_t height, co
}
uint64_t total_fee = 0;
- size_t txs_size = 0;
+ size_t txs_weight = 0;
BOOST_FOREACH(auto& tx, tx_list)
{
uint64_t fee = 0;
bool r = get_tx_fee(tx, fee);
CHECK_AND_ASSERT_MES(r, false, "wrong transaction passed to construct_block");
total_fee += fee;
- txs_size += get_object_blobsize(tx);
+ txs_weight += get_transaction_weight(tx);
}
blk.miner_tx = AUTO_VAL_INIT(blk.miner_tx);
- size_t target_block_size = txs_size + get_object_blobsize(blk.miner_tx);
+ size_t target_block_weight = txs_weight + get_transaction_weight(blk.miner_tx);
while (true)
{
- if (!construct_miner_tx(height, misc_utils::median(block_sizes), already_generated_coins, target_block_size, total_fee, miner_acc.get_keys().m_account_address, blk.miner_tx, blobdata(), 10))
+ if (!construct_miner_tx(height, misc_utils::median(block_weights), already_generated_coins, target_block_weight, total_fee, miner_acc.get_keys().m_account_address, blk.miner_tx, blobdata(), 10))
return false;
- size_t actual_block_size = txs_size + get_object_blobsize(blk.miner_tx);
- if (target_block_size < actual_block_size)
+ size_t actual_block_weight = txs_weight + get_transaction_weight(blk.miner_tx);
+ if (target_block_weight < actual_block_weight)
{
- target_block_size = actual_block_size;
+ target_block_weight = actual_block_weight;
}
- else if (actual_block_size < target_block_size)
+ else if (actual_block_weight < target_block_weight)
{
- size_t delta = target_block_size - actual_block_size;
+ size_t delta = target_block_weight - actual_block_weight;
blk.miner_tx.extra.resize(blk.miner_tx.extra.size() + delta, 0);
- actual_block_size = txs_size + get_object_blobsize(blk.miner_tx);
- if (actual_block_size == target_block_size)
+ actual_block_weight = txs_weight + get_transaction_weight(blk.miner_tx);
+ if (actual_block_weight == target_block_weight)
{
break;
}
else
{
- CHECK_AND_ASSERT_MES(target_block_size < actual_block_size, false, "Unexpected block size");
- delta = actual_block_size - target_block_size;
+ CHECK_AND_ASSERT_MES(target_block_weight < actual_block_weight, false, "Unexpected block size");
+ delta = actual_block_weight - target_block_weight;
blk.miner_tx.extra.resize(blk.miner_tx.extra.size() - delta);
- actual_block_size = txs_size + get_object_blobsize(blk.miner_tx);
- if (actual_block_size == target_block_size)
+ actual_block_weight = txs_weight + get_transaction_weight(blk.miner_tx);
+ if (actual_block_weight == target_block_weight)
{
break;
}
else
{
- CHECK_AND_ASSERT_MES(actual_block_size < target_block_size, false, "Unexpected block size");
+ CHECK_AND_ASSERT_MES(actual_block_weight < target_block_weight, false, "Unexpected block size");
blk.miner_tx.extra.resize(blk.miner_tx.extra.size() + delta, 0);
- target_block_size = txs_size + get_object_blobsize(blk.miner_tx);
+ target_block_weight = txs_weight + get_transaction_weight(blk.miner_tx);
}
}
}
@@ -183,16 +183,16 @@ bool test_generator::construct_block(cryptonote::block& blk, uint64_t height, co
while (!miner::find_nonce_for_given_block(blk, get_test_difficulty(), height))
blk.timestamp++;
- add_block(blk, txs_size, block_sizes, already_generated_coins);
+ add_block(blk, txs_weight, block_weights, already_generated_coins);
return true;
}
bool test_generator::construct_block(cryptonote::block& blk, const cryptonote::account_base& miner_acc, uint64_t timestamp)
{
- std::vector<size_t> block_sizes;
+ std::vector<size_t> block_weights;
std::list<cryptonote::transaction> tx_list;
- return construct_block(blk, 0, null_hash, miner_acc, timestamp, 0, block_sizes, tx_list);
+ return construct_block(blk, 0, null_hash, miner_acc, timestamp, 0, block_weights, tx_list);
}
bool test_generator::construct_block(cryptonote::block& blk, const cryptonote::block& blk_prev,
@@ -204,10 +204,10 @@ bool test_generator::construct_block(cryptonote::block& blk, const cryptonote::b
// Keep difficulty unchanged
uint64_t timestamp = blk_prev.timestamp + DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN;
uint64_t already_generated_coins = get_already_generated_coins(prev_id);
- std::vector<size_t> block_sizes;
- get_last_n_block_sizes(block_sizes, prev_id, CRYPTONOTE_REWARD_BLOCKS_WINDOW);
+ std::vector<size_t> block_weights;
+ get_last_n_block_weights(block_weights, prev_id, CRYPTONOTE_REWARD_BLOCKS_WINDOW);
- return construct_block(blk, height, prev_id, miner_acc, timestamp, already_generated_coins, block_sizes, tx_list);
+ return construct_block(blk, height, prev_id, miner_acc, timestamp, already_generated_coins, block_weights, tx_list);
}
bool test_generator::construct_block_manually(block& blk, const block& prev_block, const account_base& miner_acc,
@@ -216,7 +216,7 @@ bool test_generator::construct_block_manually(block& blk, const block& prev_bloc
const crypto::hash& prev_id/* = crypto::hash()*/, const difficulty_type& diffic/* = 1*/,
const transaction& miner_tx/* = transaction()*/,
const std::vector<crypto::hash>& tx_hashes/* = std::vector<crypto::hash>()*/,
- size_t txs_sizes/* = 0*/, size_t max_outs/* = 0*/, uint8_t hf_version/* = 1*/)
+ size_t txs_weight/* = 0*/, size_t max_outs/* = 0*/, uint8_t hf_version/* = 1*/)
{
blk.major_version = actual_params & bf_major_ver ? major_ver : CURRENT_BLOCK_MAJOR_VERSION;
blk.minor_version = actual_params & bf_minor_ver ? minor_ver : CURRENT_BLOCK_MINOR_VERSION;
@@ -228,17 +228,17 @@ bool test_generator::construct_block_manually(block& blk, const block& prev_bloc
size_t height = get_block_height(prev_block) + 1;
uint64_t already_generated_coins = get_already_generated_coins(prev_block);
- std::vector<size_t> block_sizes;
- get_last_n_block_sizes(block_sizes, get_block_hash(prev_block), CRYPTONOTE_REWARD_BLOCKS_WINDOW);
+ std::vector<size_t> block_weights;
+ get_last_n_block_weights(block_weights, get_block_hash(prev_block), CRYPTONOTE_REWARD_BLOCKS_WINDOW);
if (actual_params & bf_miner_tx)
{
blk.miner_tx = miner_tx;
}
else
{
- size_t current_block_size = txs_sizes + get_object_blobsize(blk.miner_tx);
+ size_t current_block_weight = txs_weight + get_transaction_weight(blk.miner_tx);
// TODO: This will work, until size of constructed block is less then CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE
- if (!construct_miner_tx(height, misc_utils::median(block_sizes), already_generated_coins, current_block_size, 0, miner_acc.get_keys().m_account_address, blk.miner_tx, blobdata(), max_outs, hf_version))
+ if (!construct_miner_tx(height, misc_utils::median(block_weights), already_generated_coins, current_block_weight, 0, miner_acc.get_keys().m_account_address, blk.miner_tx, blobdata(), max_outs, hf_version))
return false;
}
@@ -247,16 +247,16 @@ bool test_generator::construct_block_manually(block& blk, const block& prev_bloc
difficulty_type a_diffic = actual_params & bf_diffic ? diffic : get_test_difficulty();
fill_nonce(blk, a_diffic, height);
- add_block(blk, txs_sizes, block_sizes, already_generated_coins, hf_version);
+ add_block(blk, txs_weight, block_weights, already_generated_coins, hf_version);
return true;
}
bool test_generator::construct_block_manually_tx(cryptonote::block& blk, const cryptonote::block& prev_block,
const cryptonote::account_base& miner_acc,
- const std::vector<crypto::hash>& tx_hashes, size_t txs_size)
+ const std::vector<crypto::hash>& tx_hashes, size_t txs_weight)
{
- return construct_block_manually(blk, prev_block, miner_acc, bf_tx_hashes, 0, 0, 0, crypto::hash(), 0, transaction(), tx_hashes, txs_size);
+ return construct_block_manually(blk, prev_block, miner_acc, bf_tx_hashes, 0, 0, 0, crypto::hash(), 0, transaction(), tx_hashes, txs_weight);
}