mirror of
https://git.wownero.com/wownero/wownero.git
synced 2024-08-15 01:03:23 +00:00
v8: per byte fee, pad bulletproofs, fixed 11 ring size
This commit is contained in:
parent
869b3bf824
commit
5ffb2ff9b7
55 changed files with 1241 additions and 878 deletions
|
@ -36,24 +36,24 @@ using namespace cryptonote;
|
|||
|
||||
namespace
|
||||
{
|
||||
bool construct_miner_tx_by_size(transaction& miner_tx, uint64_t height, uint64_t already_generated_coins,
|
||||
const account_public_address& miner_address, std::vector<size_t>& block_sizes, size_t target_tx_size,
|
||||
size_t target_block_size, uint64_t fee = 0)
|
||||
bool construct_miner_tx_by_weight(transaction& miner_tx, uint64_t height, uint64_t already_generated_coins,
|
||||
const account_public_address& miner_address, std::vector<size_t>& block_weights, size_t target_tx_weight,
|
||||
size_t target_block_weight, uint64_t fee = 0)
|
||||
{
|
||||
if (!construct_miner_tx(height, misc_utils::median(block_sizes), already_generated_coins, target_block_size, fee, miner_address, miner_tx))
|
||||
if (!construct_miner_tx(height, misc_utils::median(block_weights), already_generated_coins, target_block_weight, fee, miner_address, miner_tx))
|
||||
return false;
|
||||
|
||||
size_t current_size = get_object_blobsize(miner_tx);
|
||||
size_t current_weight = get_transaction_weight(miner_tx);
|
||||
size_t try_count = 0;
|
||||
while (target_tx_size != current_size)
|
||||
while (target_tx_weight != current_weight)
|
||||
{
|
||||
++try_count;
|
||||
if (10 < try_count)
|
||||
return false;
|
||||
|
||||
if (target_tx_size < current_size)
|
||||
if (target_tx_weight < current_weight)
|
||||
{
|
||||
size_t diff = current_size - target_tx_size;
|
||||
size_t diff = current_weight - target_tx_weight;
|
||||
if (diff <= miner_tx.extra.size())
|
||||
miner_tx.extra.resize(miner_tx.extra.size() - diff);
|
||||
else
|
||||
|
@ -61,28 +61,28 @@ namespace
|
|||
}
|
||||
else
|
||||
{
|
||||
size_t diff = target_tx_size - current_size;
|
||||
size_t diff = target_tx_weight - current_weight;
|
||||
miner_tx.extra.resize(miner_tx.extra.size() + diff);
|
||||
}
|
||||
|
||||
current_size = get_object_blobsize(miner_tx);
|
||||
current_weight = get_transaction_weight(miner_tx);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool construct_max_size_block(test_generator& generator, block& blk, const block& blk_prev, const account_base& miner_account,
|
||||
bool construct_max_weight_block(test_generator& generator, block& blk, const block& blk_prev, const account_base& miner_account,
|
||||
size_t median_block_count = CRYPTONOTE_REWARD_BLOCKS_WINDOW)
|
||||
{
|
||||
std::vector<size_t> block_sizes;
|
||||
generator.get_last_n_block_sizes(block_sizes, get_block_hash(blk_prev), median_block_count);
|
||||
std::vector<size_t> block_weights;
|
||||
generator.get_last_n_block_weights(block_weights, get_block_hash(blk_prev), median_block_count);
|
||||
|
||||
size_t median = misc_utils::median(block_sizes);
|
||||
size_t median = misc_utils::median(block_weights);
|
||||
median = std::max(median, static_cast<size_t>(CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1));
|
||||
|
||||
transaction miner_tx;
|
||||
bool r = construct_miner_tx_by_size(miner_tx, get_block_height(blk_prev) + 1, generator.get_already_generated_coins(blk_prev),
|
||||
miner_account.get_keys().m_account_address, block_sizes, 2 * median, 2 * median);
|
||||
bool r = construct_miner_tx_by_weight(miner_tx, get_block_height(blk_prev) + 1, generator.get_already_generated_coins(blk_prev),
|
||||
miner_account.get_keys().m_account_address, block_weights, 2 * median, 2 * median);
|
||||
if (!r)
|
||||
return false;
|
||||
|
||||
|
@ -97,7 +97,7 @@ namespace
|
|||
for (size_t i = 0; i < block_count; ++i)
|
||||
{
|
||||
block blk_i;
|
||||
if (!construct_max_size_block(generator, blk_i, blk, miner_account))
|
||||
if (!construct_max_weight_block(generator, blk_i, blk, miner_account))
|
||||
return false;
|
||||
|
||||
events.push_back(blk_i);
|
||||
|
@ -141,18 +141,18 @@ bool gen_block_reward::generate(std::vector<test_event_entry>& events) const
|
|||
// Test: block reward is calculated using median of the latest CRYPTONOTE_REWARD_BLOCKS_WINDOW blocks
|
||||
DO_CALLBACK(events, "mark_invalid_block");
|
||||
block blk_1_bad_1;
|
||||
if (!construct_max_size_block(generator, blk_1_bad_1, blk_0r, miner_account, CRYPTONOTE_REWARD_BLOCKS_WINDOW + 1))
|
||||
if (!construct_max_weight_block(generator, blk_1_bad_1, blk_0r, miner_account, CRYPTONOTE_REWARD_BLOCKS_WINDOW + 1))
|
||||
return false;
|
||||
events.push_back(blk_1_bad_1);
|
||||
|
||||
DO_CALLBACK(events, "mark_invalid_block");
|
||||
block blk_1_bad_2;
|
||||
if (!construct_max_size_block(generator, blk_1_bad_2, blk_0r, miner_account, CRYPTONOTE_REWARD_BLOCKS_WINDOW - 1))
|
||||
if (!construct_max_weight_block(generator, blk_1_bad_2, blk_0r, miner_account, CRYPTONOTE_REWARD_BLOCKS_WINDOW - 1))
|
||||
return false;
|
||||
events.push_back(blk_1_bad_2);
|
||||
|
||||
block blk_1;
|
||||
if (!construct_max_size_block(generator, blk_1, blk_0r, miner_account))
|
||||
if (!construct_max_weight_block(generator, blk_1, blk_0r, miner_account))
|
||||
return false;
|
||||
events.push_back(blk_1);
|
||||
|
||||
|
@ -187,16 +187,16 @@ bool gen_block_reward::generate(std::vector<test_event_entry>& events) const
|
|||
{
|
||||
transaction tx_1 = construct_tx_with_fee(events, blk_5, miner_account, bob_account, MK_COINS(1), 11 * TESTS_DEFAULT_FEE);
|
||||
transaction tx_2 = construct_tx_with_fee(events, blk_5, miner_account, bob_account, MK_COINS(1), 13 * TESTS_DEFAULT_FEE);
|
||||
size_t txs_1_size = get_object_blobsize(tx_1) + get_object_blobsize(tx_2);
|
||||
size_t txs_1_weight = get_transaction_weight(tx_1) + get_transaction_weight(tx_2);
|
||||
uint64_t txs_fee = get_tx_fee(tx_1) + get_tx_fee(tx_2);
|
||||
|
||||
std::vector<size_t> block_sizes;
|
||||
generator.get_last_n_block_sizes(block_sizes, get_block_hash(blk_7), CRYPTONOTE_REWARD_BLOCKS_WINDOW);
|
||||
size_t median = misc_utils::median(block_sizes);
|
||||
std::vector<size_t> block_weights;
|
||||
generator.get_last_n_block_weights(block_weights, get_block_hash(blk_7), CRYPTONOTE_REWARD_BLOCKS_WINDOW);
|
||||
size_t median = misc_utils::median(block_weights);
|
||||
|
||||
transaction miner_tx;
|
||||
bool r = construct_miner_tx_by_size(miner_tx, get_block_height(blk_7) + 1, generator.get_already_generated_coins(blk_7),
|
||||
miner_account.get_keys().m_account_address, block_sizes, 2 * median - txs_1_size, 2 * median, txs_fee);
|
||||
bool r = construct_miner_tx_by_weight(miner_tx, get_block_height(blk_7) + 1, generator.get_already_generated_coins(blk_7),
|
||||
miner_account.get_keys().m_account_address, block_weights, 2 * median - txs_1_weight, 2 * median, txs_fee);
|
||||
if (!r)
|
||||
return false;
|
||||
|
||||
|
@ -206,7 +206,7 @@ bool gen_block_reward::generate(std::vector<test_event_entry>& events) const
|
|||
|
||||
block blk_8;
|
||||
generator.construct_block_manually(blk_8, blk_7, miner_account, test_generator::bf_miner_tx | test_generator::bf_tx_hashes,
|
||||
0, 0, 0, crypto::hash(), 0, miner_tx, txs_1_hashes, txs_1_size);
|
||||
0, 0, 0, crypto::hash(), 0, miner_tx, txs_1_hashes, txs_1_weight);
|
||||
|
||||
events.push_back(blk_8);
|
||||
DO_CALLBACK(events, "mark_checked_block");
|
||||
|
|
|
@ -586,11 +586,11 @@ bool gen_block_invalid_binary_format::generate(std::vector<test_event_entry>& ev
|
|||
block blk_test;
|
||||
std::vector<crypto::hash> tx_hashes;
|
||||
tx_hashes.push_back(get_transaction_hash(tx_0));
|
||||
size_t txs_size = get_object_blobsize(tx_0);
|
||||
size_t txs_weight = get_transaction_weight(tx_0);
|
||||
diffic = next_difficulty(timestamps, cummulative_difficulties,DIFFICULTY_TARGET_V1);
|
||||
if (!generator.construct_block_manually(blk_test, blk_last, miner_account,
|
||||
test_generator::bf_diffic | test_generator::bf_timestamp | test_generator::bf_tx_hashes, 0, 0, blk_last.timestamp,
|
||||
crypto::hash(), diffic, transaction(), tx_hashes, txs_size))
|
||||
crypto::hash(), diffic, transaction(), tx_hashes, txs_weight))
|
||||
return false;
|
||||
|
||||
blobdata blob = t_serializable_object_to_blob(blk_test);
|
||||
|
|
|
@ -42,7 +42,7 @@ using namespace cryptonote;
|
|||
// Tests
|
||||
|
||||
bool gen_bp_tx_validation_base::generate_with(std::vector<test_event_entry>& events,
|
||||
const int *out_idx, int mixin, size_t n_txes, const uint64_t *amounts_paid, bool valid, const bool *multi_out,
|
||||
size_t mixin, size_t n_txes, const uint64_t *amounts_paid, bool valid, const rct::RangeProofType *range_proof_type,
|
||||
const std::function<bool(std::vector<tx_source_entry> &sources, std::vector<tx_destination_entry> &destinations, size_t tx_idx)> &pre_tx,
|
||||
const std::function<bool(transaction &tx, size_t tx_idx)> &post_tx) const
|
||||
{
|
||||
|
@ -51,11 +51,11 @@ bool gen_bp_tx_validation_base::generate_with(std::vector<test_event_entry>& eve
|
|||
GENERATE_ACCOUNT(miner_account);
|
||||
MAKE_GENESIS_BLOCK(events, blk_0, miner_account, ts_start);
|
||||
|
||||
// create 8 miner accounts, and have them mine the next 8 blocks
|
||||
cryptonote::account_base miner_accounts[8];
|
||||
// create 12 miner accounts, and have them mine the next 12 blocks
|
||||
cryptonote::account_base miner_accounts[12];
|
||||
const cryptonote::block *prev_block = &blk_0;
|
||||
cryptonote::block blocks[8 + CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW];
|
||||
for (size_t n = 0; n < 8; ++n) {
|
||||
cryptonote::block blocks[12 + CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW];
|
||||
for (size_t n = 0; n < 12; ++n) {
|
||||
miner_accounts[n].generate();
|
||||
CHECK_AND_ASSERT_MES(generator.construct_block_manually(blocks[n], *prev_block, miner_accounts[n],
|
||||
test_generator::bf_major_ver | test_generator::bf_minor_ver | test_generator::bf_timestamp | test_generator::bf_hf_version,
|
||||
|
@ -70,16 +70,16 @@ bool gen_bp_tx_validation_base::generate_with(std::vector<test_event_entry>& eve
|
|||
// rewind
|
||||
cryptonote::block blk_r, blk_last;
|
||||
{
|
||||
blk_last = blocks[7];
|
||||
blk_last = blocks[11];
|
||||
for (size_t i = 0; i < CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW; ++i)
|
||||
{
|
||||
CHECK_AND_ASSERT_MES(generator.construct_block_manually(blocks[8+i], blk_last, miner_account,
|
||||
CHECK_AND_ASSERT_MES(generator.construct_block_manually(blocks[12+i], blk_last, miner_account,
|
||||
test_generator::bf_major_ver | test_generator::bf_minor_ver | test_generator::bf_timestamp | test_generator::bf_hf_version,
|
||||
2, 2, blk_last.timestamp + DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN * 2, // v2 has blocks twice as long
|
||||
crypto::hash(), 0, transaction(), std::vector<crypto::hash>(), 0, 0, 2),
|
||||
false, "Failed to generate block");
|
||||
events.push_back(blocks[8+i]);
|
||||
blk_last = blocks[8+i];
|
||||
events.push_back(blocks[12+i]);
|
||||
blk_last = blocks[12+i];
|
||||
}
|
||||
blk_r = blk_last;
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ bool gen_bp_tx_validation_base::generate_with(std::vector<test_event_entry>& eve
|
|||
const uint64_t needed_amount = input_amounts_available[n];
|
||||
src.amount = input_amounts_available[n];
|
||||
size_t real_index_in_tx = 0;
|
||||
for (size_t m = 0; m < 7; ++m) {
|
||||
for (size_t m = 0; m <= mixin; ++m) {
|
||||
size_t index_in_tx = 0;
|
||||
for (size_t i = 0; i < blocks[m].miner_tx.vout.size(); ++i)
|
||||
if (blocks[m].miner_tx.vout[i].amount == needed_amount)
|
||||
|
@ -136,7 +136,7 @@ bool gen_bp_tx_validation_base::generate_with(std::vector<test_event_entry>& eve
|
|||
std::unordered_map<crypto::public_key, cryptonote::subaddress_index> subaddresses;
|
||||
subaddresses[miner_accounts[n].get_keys().m_account_address.m_spend_public_key] = {0,0};
|
||||
rct_txes.resize(rct_txes.size() + 1);
|
||||
bool r = construct_tx_and_get_tx_key(miner_accounts[n].get_keys(), subaddresses, sources, destinations, cryptonote::account_public_address{}, std::vector<uint8_t>(), rct_txes.back(), 0, tx_key, additional_tx_keys, true, multi_out[n] ? rct::RangeProofMultiOutputBulletproof : rct::RangeProofBulletproof);
|
||||
bool r = construct_tx_and_get_tx_key(miner_accounts[n].get_keys(), subaddresses, sources, destinations, cryptonote::account_public_address{}, std::vector<uint8_t>(), rct_txes.back(), 0, tx_key, additional_tx_keys, true, range_proof_type[n]);
|
||||
CHECK_AND_ASSERT_MES(r, false, "failed to construct transaction");
|
||||
|
||||
if (post_tx && !post_tx(rct_txes.back(), n))
|
||||
|
@ -199,93 +199,100 @@ bool gen_bp_tx_validation_base::check_bp(const cryptonote::transaction &tx, size
|
|||
while (sizes[n_sizes] != (size_t)-1)
|
||||
n_amounts += sizes[n_sizes++];
|
||||
CHECK_TEST_CONDITION(tx.rct_signatures.p.bulletproofs.size() == n_sizes);
|
||||
CHECK_TEST_CONDITION(rct::n_bulletproof_amounts(tx.rct_signatures.p.bulletproofs) == n_amounts);
|
||||
CHECK_TEST_CONDITION(rct::n_bulletproof_max_amounts(tx.rct_signatures.p.bulletproofs) == n_amounts);
|
||||
for (size_t n = 0; n < n_sizes; ++n)
|
||||
CHECK_TEST_CONDITION(rct::n_bulletproof_amounts(tx.rct_signatures.p.bulletproofs[n]) == sizes[n]);
|
||||
CHECK_TEST_CONDITION(rct::n_bulletproof_max_amounts(tx.rct_signatures.p.bulletproofs[n]) == sizes[n]);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool gen_bp_tx_valid_1::generate(std::vector<test_event_entry>& events) const
|
||||
{
|
||||
const int mixin = 6;
|
||||
const int out_idx[] = {1, -1};
|
||||
const size_t mixin = 10;
|
||||
const uint64_t amounts_paid[] = {10000, (uint64_t)-1};
|
||||
const size_t bp_sizes[] = {1, (size_t)-1};
|
||||
const bool multi_out[] = {false};
|
||||
return generate_with(events, out_idx, mixin, 1, amounts_paid, true, multi_out, NULL, [&](const cryptonote::transaction &tx, size_t tx_idx){ return check_bp(tx, tx_idx, bp_sizes, "gen_bp_tx_valid_1"); });
|
||||
const rct::RangeProofType range_proof_type[] = {rct::RangeProofPaddedBulletproof};
|
||||
return generate_with(events, mixin, 1, amounts_paid, true, range_proof_type, NULL, [&](const cryptonote::transaction &tx, size_t tx_idx){ return check_bp(tx, tx_idx, bp_sizes, "gen_bp_tx_valid_1"); });
|
||||
}
|
||||
|
||||
bool gen_bp_tx_invalid_1_1::generate(std::vector<test_event_entry>& events) const
|
||||
{
|
||||
const int mixin = 6;
|
||||
const int out_idx[] = {1, -1};
|
||||
const size_t mixin = 10;
|
||||
const uint64_t amounts_paid[] = {5000, 5000, (uint64_t)-1};
|
||||
const size_t bp_sizes[] = {1, 1, (size_t)-1};
|
||||
const bool multi_out[] = {false};
|
||||
return generate_with(events, out_idx, mixin, 1, amounts_paid, false, multi_out, NULL, [&](const cryptonote::transaction &tx, size_t tx_idx){ return check_bp(tx, tx_idx, bp_sizes, "gen_bp_tx_invalid_1_1"); });
|
||||
const rct::RangeProofType range_proof_type[] = { rct::RangeProofBulletproof };
|
||||
return generate_with(events, mixin, 1, amounts_paid, false, range_proof_type, NULL, NULL);
|
||||
}
|
||||
|
||||
bool gen_bp_tx_valid_2::generate(std::vector<test_event_entry>& events) const
|
||||
{
|
||||
const int mixin = 6;
|
||||
const int out_idx[] = {1, -1};
|
||||
const size_t mixin = 10;
|
||||
const uint64_t amounts_paid[] = {5000, 5000, (uint64_t)-1};
|
||||
const size_t bp_sizes[] = {2, (size_t)-1};
|
||||
const bool multi_out[] = {true};
|
||||
return generate_with(events, out_idx, mixin, 1, amounts_paid, true, multi_out, NULL, [&](const cryptonote::transaction &tx, size_t tx_idx){ return check_bp(tx, tx_idx, bp_sizes, "gen_bp_tx_valid_2"); });
|
||||
const rct::RangeProofType range_proof_type[] = {rct::RangeProofPaddedBulletproof};
|
||||
return generate_with(events, mixin, 1, amounts_paid, true, range_proof_type, NULL, [&](const cryptonote::transaction &tx, size_t tx_idx){ return check_bp(tx, tx_idx, bp_sizes, "gen_bp_tx_valid_2"); });
|
||||
}
|
||||
|
||||
bool gen_bp_tx_valid_4_2_1::generate(std::vector<test_event_entry>& events) const
|
||||
bool gen_bp_tx_valid_3::generate(std::vector<test_event_entry>& events) const
|
||||
{
|
||||
const int mixin = 6;
|
||||
const int out_idx[] = {1, -1};
|
||||
const size_t mixin = 10;
|
||||
const uint64_t amounts_paid[] = {5000, 5000, 5000, (uint64_t)-1};
|
||||
const size_t bp_sizes[] = {4, (size_t)-1};
|
||||
const rct::RangeProofType range_proof_type[] = { rct::RangeProofPaddedBulletproof };
|
||||
return generate_with(events, mixin, 1, amounts_paid, true, range_proof_type, NULL, [&](const cryptonote::transaction &tx, size_t tx_idx){ return check_bp(tx, tx_idx, bp_sizes, "gen_bp_tx_valid_3"); });
|
||||
}
|
||||
|
||||
bool gen_bp_tx_valid_16::generate(std::vector<test_event_entry>& events) const
|
||||
{
|
||||
const size_t mixin = 10;
|
||||
const uint64_t amounts_paid[] = {500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, (uint64_t)-1};
|
||||
const size_t bp_sizes[] = {16, (size_t)-1};
|
||||
const rct::RangeProofType range_proof_type[] = { rct::RangeProofPaddedBulletproof };
|
||||
return generate_with(events, mixin, 1, amounts_paid, true, range_proof_type, NULL, [&](const cryptonote::transaction &tx, size_t tx_idx){ return check_bp(tx, tx_idx, bp_sizes, "gen_bp_tx_valid_16"); });
|
||||
}
|
||||
|
||||
bool gen_bp_tx_invalid_4_2_1::generate(std::vector<test_event_entry>& events) const
|
||||
{
|
||||
const size_t mixin = 10;
|
||||
const uint64_t amounts_paid[] = {1000, 1000, 1000, 1000, 1000, 1000, 1000, (uint64_t)-1};
|
||||
const size_t bp_sizes[] = {4, 2, 1, (size_t)-1};
|
||||
const bool multi_out[] = {true};
|
||||
return generate_with(events, out_idx, mixin, 1, amounts_paid, true, multi_out, NULL, [&](const cryptonote::transaction &tx, size_t tx_idx){ return check_bp(tx, tx_idx, bp_sizes, "gen_bp_tx_valid_4_2_1"); });
|
||||
const rct::RangeProofType range_proof_type[] = { rct::RangeProofMultiOutputBulletproof };
|
||||
return generate_with(events, mixin, 1, amounts_paid, false, range_proof_type, NULL, NULL);
|
||||
}
|
||||
|
||||
bool gen_bp_tx_valid_16_16::generate(std::vector<test_event_entry>& events) const
|
||||
bool gen_bp_tx_invalid_16_16::generate(std::vector<test_event_entry>& events) const
|
||||
{
|
||||
const int mixin = 6;
|
||||
const int out_idx[] = {1, -1};
|
||||
const size_t mixin = 10;
|
||||
const uint64_t amounts_paid[] = {1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, (uint64_t)-1};
|
||||
const size_t bp_sizes[] = {16, 16, (size_t)-1};
|
||||
const bool multi_out[] = {true};
|
||||
return generate_with(events, out_idx, mixin, 1, amounts_paid, true, multi_out, NULL, [&](const cryptonote::transaction &tx, size_t tx_idx){ return check_bp(tx, tx_idx, bp_sizes, "gen_bp_tx_valid_16_16"); });
|
||||
const rct::RangeProofType range_proof_type[] = { rct::RangeProofMultiOutputBulletproof };
|
||||
return generate_with(events, mixin, 1, amounts_paid, false, range_proof_type, NULL, NULL);
|
||||
}
|
||||
|
||||
bool gen_bp_txs_valid_2_and_2::generate(std::vector<test_event_entry>& events) const
|
||||
{
|
||||
const int mixin = 6;
|
||||
const int out_idx[] = {1, -1};
|
||||
const size_t mixin = 10;
|
||||
const uint64_t amounts_paid[] = {1000, 1000, (size_t)-1, 1000, 1000, (uint64_t)-1};
|
||||
const size_t bp_sizes[] = {2, (size_t)-1, 2, (size_t)-1};
|
||||
const bool multi_out[] = {true};
|
||||
return generate_with(events, out_idx, mixin, 2, amounts_paid, true, multi_out, NULL, [&](const cryptonote::transaction &tx, size_t tx_idx){ return check_bp(tx, tx_idx, bp_sizes, "gen_bp_txs_valid_2_2"); });
|
||||
const rct::RangeProofType range_proof_type[] = { rct::RangeProofPaddedBulletproof, rct::RangeProofPaddedBulletproof};
|
||||
return generate_with(events, mixin, 2, amounts_paid, true, range_proof_type, NULL, [&](const cryptonote::transaction &tx, size_t tx_idx){ return check_bp(tx, tx_idx, bp_sizes, "gen_bp_txs_valid_2_and_2"); });
|
||||
}
|
||||
|
||||
bool gen_bp_txs_valid_2_and_8_2_and_16_16_1::generate(std::vector<test_event_entry>& events) const
|
||||
bool gen_bp_txs_invalid_2_and_8_2_and_16_16_1::generate(std::vector<test_event_entry>& events) const
|
||||
{
|
||||
const int mixin = 6;
|
||||
const int out_idx[] = {1, -1};
|
||||
const size_t mixin = 10;
|
||||
const uint64_t amounts_paid[] = {1000, 1000, (uint64_t)-1, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, (uint64_t)-1, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, (uint64_t)-1};
|
||||
const bool multi_out[] = {true, true, true};
|
||||
const size_t bp_sizes[] = {2, (size_t)-1, 8, 2, (size_t)-1, 16, 16, 1, (size_t)-1};
|
||||
return generate_with(events, out_idx, mixin, 3, amounts_paid, true, multi_out, NULL, [&](const cryptonote::transaction &tx, size_t tx_idx){ return check_bp(tx, tx_idx, bp_sizes, "gen_bp_txs_valid_1_1_and_8_2_and_16_16_1"); });
|
||||
const rct::RangeProofType range_proof_type[] = {rct::RangeProofMultiOutputBulletproof, rct::RangeProofMultiOutputBulletproof, rct::RangeProofMultiOutputBulletproof};
|
||||
return generate_with(events, mixin, 3, amounts_paid, false, range_proof_type, NULL, NULL);
|
||||
}
|
||||
|
||||
bool gen_bp_tx_invalid_not_enough_proofs::generate(std::vector<test_event_entry>& events) const
|
||||
{
|
||||
DEFINE_TESTS_ERROR_CONTEXT("gen_bp_tx_invalid_not_enough_proofs");
|
||||
const int mixin = 6;
|
||||
const int out_idx[] = {1, -1};
|
||||
const uint64_t amounts_paid[] = {10000, (uint64_t)-1};
|
||||
const bool multi_out[] = {false};
|
||||
return generate_with(events, out_idx, mixin, 1, amounts_paid, false, multi_out, NULL, [&](cryptonote::transaction &tx, size_t idx){
|
||||
const size_t mixin = 10;
|
||||
const uint64_t amounts_paid[] = {5000, 5000, (uint64_t)-1};
|
||||
const rct::RangeProofType range_proof_type[] = { rct::RangeProofBulletproof };
|
||||
return generate_with(events, mixin, 1, amounts_paid, false, range_proof_type, NULL, [&](cryptonote::transaction &tx, size_t idx){
|
||||
CHECK_TEST_CONDITION(tx.rct_signatures.type == rct::RCTTypeBulletproof);
|
||||
CHECK_TEST_CONDITION(!tx.rct_signatures.p.bulletproofs.empty());
|
||||
tx.rct_signatures.p.bulletproofs.pop_back();
|
||||
CHECK_TEST_CONDITION(!tx.rct_signatures.p.bulletproofs.empty());
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
@ -293,11 +300,10 @@ bool gen_bp_tx_invalid_not_enough_proofs::generate(std::vector<test_event_entry>
|
|||
bool gen_bp_tx_invalid_too_many_proofs::generate(std::vector<test_event_entry>& events) const
|
||||
{
|
||||
DEFINE_TESTS_ERROR_CONTEXT("gen_bp_tx_invalid_too_many_proofs");
|
||||
const int mixin = 6;
|
||||
const int out_idx[] = {1, -1};
|
||||
const size_t mixin = 10;
|
||||
const uint64_t amounts_paid[] = {10000, (uint64_t)-1};
|
||||
const bool multi_out[] = {false};
|
||||
return generate_with(events, out_idx, mixin, 1, amounts_paid, false, multi_out, NULL, [&](cryptonote::transaction &tx, size_t idx){
|
||||
const rct::RangeProofType range_proof_type[] = { rct::RangeProofBulletproof };
|
||||
return generate_with(events, mixin, 1, amounts_paid, false, range_proof_type, NULL, [&](cryptonote::transaction &tx, size_t idx){
|
||||
CHECK_TEST_CONDITION(tx.rct_signatures.type == rct::RCTTypeBulletproof);
|
||||
CHECK_TEST_CONDITION(!tx.rct_signatures.p.bulletproofs.empty());
|
||||
tx.rct_signatures.p.bulletproofs.push_back(tx.rct_signatures.p.bulletproofs.back());
|
||||
|
@ -308,11 +314,10 @@ bool gen_bp_tx_invalid_too_many_proofs::generate(std::vector<test_event_entry>&
|
|||
bool gen_bp_tx_invalid_wrong_amount::generate(std::vector<test_event_entry>& events) const
|
||||
{
|
||||
DEFINE_TESTS_ERROR_CONTEXT("gen_bp_tx_invalid_wrong_amount");
|
||||
const int mixin = 6;
|
||||
const int out_idx[] = {1, -1};
|
||||
const size_t mixin = 10;
|
||||
const uint64_t amounts_paid[] = {10000, (uint64_t)-1};
|
||||
const bool multi_out[] = {false};
|
||||
return generate_with(events, out_idx, mixin, 1, amounts_paid, false, multi_out, NULL, [&](cryptonote::transaction &tx, size_t idx){
|
||||
const rct::RangeProofType range_proof_type[] = { rct::RangeProofBulletproof };
|
||||
return generate_with(events, mixin, 1, amounts_paid, false, range_proof_type, NULL, [&](cryptonote::transaction &tx, size_t idx){
|
||||
CHECK_TEST_CONDITION(tx.rct_signatures.type == rct::RCTTypeBulletproof);
|
||||
CHECK_TEST_CONDITION(!tx.rct_signatures.p.bulletproofs.empty());
|
||||
tx.rct_signatures.p.bulletproofs.back() = rct::bulletproof_PROVE(1000, rct::skGen());
|
||||
|
@ -320,20 +325,15 @@ bool gen_bp_tx_invalid_wrong_amount::generate(std::vector<test_event_entry>& eve
|
|||
});
|
||||
}
|
||||
|
||||
bool gen_bp_tx_invalid_switched::generate(std::vector<test_event_entry>& events) const
|
||||
bool gen_bp_tx_invalid_borromean_type::generate(std::vector<test_event_entry>& events) const
|
||||
{
|
||||
DEFINE_TESTS_ERROR_CONTEXT("gen_bp_tx_invalid_switched");
|
||||
const int mixin = 6;
|
||||
const int out_idx[] = {1, -1};
|
||||
const uint64_t amounts_paid[] = {1001, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, (uint64_t)-1};
|
||||
const bool multi_out[] = {true};
|
||||
return generate_with(events, out_idx, mixin, 1, amounts_paid, false, multi_out, NULL, [&](cryptonote::transaction &tx, size_t tx_idx){
|
||||
DEFINE_TESTS_ERROR_CONTEXT("gen_bp_tx_invalid_borromean_type");
|
||||
const size_t mixin = 10;
|
||||
const uint64_t amounts_paid[] = {5000, 5000, (uint64_t)-1};
|
||||
const rct::RangeProofType range_proof_type[] = {rct::RangeProofPaddedBulletproof};
|
||||
return generate_with(events, mixin, 1, amounts_paid, false, range_proof_type, NULL, [&](cryptonote::transaction &tx, size_t tx_idx){
|
||||
CHECK_TEST_CONDITION(tx.rct_signatures.type == rct::RCTTypeBulletproof);
|
||||
CHECK_TEST_CONDITION(tx.rct_signatures.p.bulletproofs.size() == 2);
|
||||
rct::Bulletproof proof = tx.rct_signatures.p.bulletproofs[0];
|
||||
tx.rct_signatures.p.bulletproofs[0] = tx.rct_signatures.p.bulletproofs[1];
|
||||
tx.rct_signatures.p.bulletproofs[1] = proof;
|
||||
tx.rct_signatures.type = rct::RCTTypeSimple;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -81,8 +81,8 @@ struct gen_bp_tx_validation_base : public test_chain_unit_base
|
|||
return true;
|
||||
}
|
||||
|
||||
bool generate_with(std::vector<test_event_entry>& events, const int *out_idx, int mixin,
|
||||
size_t n_txes, const uint64_t *amounts_paid, bool valid, const bool *multi_out,
|
||||
bool generate_with(std::vector<test_event_entry>& events, size_t mixin,
|
||||
size_t n_txes, const uint64_t *amounts_paid, bool valid, const rct::RangeProofType *range_proof_type,
|
||||
const std::function<bool(std::vector<cryptonote::tx_source_entry> &sources, std::vector<cryptonote::tx_destination_entry> &destinations, size_t)> &pre_tx,
|
||||
const std::function<bool(cryptonote::transaction &tx, size_t)> &post_tx) const;
|
||||
|
||||
|
@ -95,7 +95,7 @@ private:
|
|||
|
||||
template<>
|
||||
struct get_test_options<gen_bp_tx_validation_base> {
|
||||
const std::pair<uint8_t, uint64_t> hard_forks[4] = {std::make_pair(1, 0), std::make_pair(2, 1), std::make_pair(8, 69), std::make_pair(0, 0)};
|
||||
const std::pair<uint8_t, uint64_t> hard_forks[4] = {std::make_pair(1, 0), std::make_pair(2, 1), std::make_pair(8, 73), std::make_pair(0, 0)};
|
||||
const cryptonote::test_options test_options = {
|
||||
hard_forks
|
||||
};
|
||||
|
@ -120,17 +120,29 @@ struct gen_bp_tx_valid_2 : public gen_bp_tx_validation_base
|
|||
};
|
||||
template<> struct get_test_options<gen_bp_tx_valid_2>: public get_test_options<gen_bp_tx_validation_base> {};
|
||||
|
||||
struct gen_bp_tx_valid_4_2_1 : public gen_bp_tx_validation_base
|
||||
struct gen_bp_tx_valid_3 : public gen_bp_tx_validation_base
|
||||
{
|
||||
bool generate(std::vector<test_event_entry>& events) const;
|
||||
};
|
||||
template<> struct get_test_options<gen_bp_tx_valid_4_2_1>: public get_test_options<gen_bp_tx_validation_base> {};
|
||||
template<> struct get_test_options<gen_bp_tx_valid_3>: public get_test_options<gen_bp_tx_validation_base> {};
|
||||
|
||||
struct gen_bp_tx_valid_16_16 : public gen_bp_tx_validation_base
|
||||
struct gen_bp_tx_valid_16 : public gen_bp_tx_validation_base
|
||||
{
|
||||
bool generate(std::vector<test_event_entry>& events) const;
|
||||
};
|
||||
template<> struct get_test_options<gen_bp_tx_valid_16_16>: public get_test_options<gen_bp_tx_validation_base> {};
|
||||
template<> struct get_test_options<gen_bp_tx_valid_16>: public get_test_options<gen_bp_tx_validation_base> {};
|
||||
|
||||
struct gen_bp_tx_invalid_4_2_1 : public gen_bp_tx_validation_base
|
||||
{
|
||||
bool generate(std::vector<test_event_entry>& events) const;
|
||||
};
|
||||
template<> struct get_test_options<gen_bp_tx_invalid_4_2_1>: public get_test_options<gen_bp_tx_validation_base> {};
|
||||
|
||||
struct gen_bp_tx_invalid_16_16 : public gen_bp_tx_validation_base
|
||||
{
|
||||
bool generate(std::vector<test_event_entry>& events) const;
|
||||
};
|
||||
template<> struct get_test_options<gen_bp_tx_invalid_16_16>: public get_test_options<gen_bp_tx_validation_base> {};
|
||||
|
||||
struct gen_bp_txs_valid_2_and_2 : public gen_bp_tx_validation_base
|
||||
{
|
||||
|
@ -138,11 +150,11 @@ struct gen_bp_txs_valid_2_and_2 : public gen_bp_tx_validation_base
|
|||
};
|
||||
template<> struct get_test_options<gen_bp_txs_valid_2_and_2>: public get_test_options<gen_bp_tx_validation_base> {};
|
||||
|
||||
struct gen_bp_txs_valid_2_and_8_2_and_16_16_1 : public gen_bp_tx_validation_base
|
||||
struct gen_bp_txs_invalid_2_and_8_2_and_16_16_1 : public gen_bp_tx_validation_base
|
||||
{
|
||||
bool generate(std::vector<test_event_entry>& events) const;
|
||||
};
|
||||
template<> struct get_test_options<gen_bp_txs_valid_2_and_8_2_and_16_16_1>: public get_test_options<gen_bp_tx_validation_base> {};
|
||||
template<> struct get_test_options<gen_bp_txs_invalid_2_and_8_2_and_16_16_1>: public get_test_options<gen_bp_tx_validation_base> {};
|
||||
|
||||
struct gen_bp_tx_invalid_not_enough_proofs : public gen_bp_tx_validation_base
|
||||
{
|
||||
|
@ -162,9 +174,8 @@ struct gen_bp_tx_invalid_wrong_amount : public gen_bp_tx_validation_base
|
|||
};
|
||||
template<> struct get_test_options<gen_bp_tx_invalid_wrong_amount>: public get_test_options<gen_bp_tx_validation_base> {};
|
||||
|
||||
struct gen_bp_tx_invalid_switched : public gen_bp_tx_validation_base
|
||||
struct gen_bp_tx_invalid_borromean_type : public gen_bp_tx_validation_base
|
||||
{
|
||||
bool generate(std::vector<test_event_entry>& events) const;
|
||||
};
|
||||
template<> struct get_test_options<gen_bp_tx_invalid_switched>: public get_test_options<gen_bp_tx_validation_base> {};
|
||||
|
||||
template<> struct get_test_options<gen_bp_tx_invalid_borromean_type>: public get_test_options<gen_bp_tx_validation_base> {};
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -159,20 +159,20 @@ public:
|
|||
block_info()
|
||||
: prev_id()
|
||||
, already_generated_coins(0)
|
||||
, block_size(0)
|
||||
, block_weight(0)
|
||||
{
|
||||
}
|
||||
|
||||
block_info(crypto::hash a_prev_id, uint64_t an_already_generated_coins, size_t a_block_size)
|
||||
block_info(crypto::hash a_prev_id, uint64_t an_already_generated_coins, size_t a_block_weight)
|
||||
: prev_id(a_prev_id)
|
||||
, already_generated_coins(an_already_generated_coins)
|
||||
, block_size(a_block_size)
|
||||
, block_weight(a_block_weight)
|
||||
{
|
||||
}
|
||||
|
||||
crypto::hash prev_id;
|
||||
uint64_t already_generated_coins;
|
||||
size_t block_size;
|
||||
size_t block_weight;
|
||||
};
|
||||
|
||||
enum block_fields
|
||||
|
@ -190,15 +190,15 @@ public:
|
|||
};
|
||||
|
||||
void get_block_chain(std::vector<block_info>& blockchain, const crypto::hash& head, size_t n) const;
|
||||
void get_last_n_block_sizes(std::vector<size_t>& block_sizes, const crypto::hash& head, size_t n) const;
|
||||
void get_last_n_block_weights(std::vector<size_t>& block_weights, const crypto::hash& head, size_t n) const;
|
||||
uint64_t get_already_generated_coins(const crypto::hash& blk_id) const;
|
||||
uint64_t get_already_generated_coins(const cryptonote::block& blk) const;
|
||||
|
||||
void add_block(const cryptonote::block& blk, size_t tsx_size, std::vector<size_t>& block_sizes, uint64_t already_generated_coins,
|
||||
void add_block(const cryptonote::block& blk, size_t tsx_size, std::vector<size_t>& block_weights, uint64_t already_generated_coins,
|
||||
uint8_t hf_version = 1);
|
||||
bool 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);
|
||||
bool construct_block(cryptonote::block& blk, const cryptonote::account_base& miner_acc, uint64_t timestamp);
|
||||
bool construct_block(cryptonote::block& blk, const cryptonote::block& blk_prev, const cryptonote::account_base& miner_acc,
|
||||
const std::list<cryptonote::transaction>& tx_list = std::list<cryptonote::transaction>());
|
||||
|
|
|
@ -227,14 +227,16 @@ int main(int argc, char* argv[])
|
|||
GENERATE_AND_PLAY(gen_bp_tx_valid_1);
|
||||
GENERATE_AND_PLAY(gen_bp_tx_invalid_1_1);
|
||||
GENERATE_AND_PLAY(gen_bp_tx_valid_2);
|
||||
GENERATE_AND_PLAY(gen_bp_tx_valid_4_2_1);
|
||||
GENERATE_AND_PLAY(gen_bp_tx_valid_16_16);
|
||||
GENERATE_AND_PLAY(gen_bp_tx_valid_3);
|
||||
GENERATE_AND_PLAY(gen_bp_tx_valid_16);
|
||||
GENERATE_AND_PLAY(gen_bp_tx_invalid_4_2_1);
|
||||
GENERATE_AND_PLAY(gen_bp_tx_invalid_16_16);
|
||||
GENERATE_AND_PLAY(gen_bp_txs_valid_2_and_2);
|
||||
GENERATE_AND_PLAY(gen_bp_txs_valid_2_and_8_2_and_16_16_1);
|
||||
GENERATE_AND_PLAY(gen_bp_txs_invalid_2_and_8_2_and_16_16_1);
|
||||
GENERATE_AND_PLAY(gen_bp_tx_invalid_not_enough_proofs);
|
||||
GENERATE_AND_PLAY(gen_bp_tx_invalid_too_many_proofs);
|
||||
GENERATE_AND_PLAY(gen_bp_tx_invalid_wrong_amount);
|
||||
GENERATE_AND_PLAY(gen_bp_tx_invalid_switched);
|
||||
GENERATE_AND_PLAY(gen_bp_tx_invalid_borromean_type);
|
||||
|
||||
el::Level level = (failed_tests.empty() ? el::Level::Info : el::Level::Error);
|
||||
MLOG(level, "\nREPORT:");
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
|
||||
#include "multi_tx_test_base.h"
|
||||
|
||||
template<size_t a_ring_size, size_t a_outputs, bool a_rct, bool a_bulletproof>
|
||||
template<size_t a_ring_size, size_t a_outputs, bool a_rct, rct::RangeProofType range_proof_type = rct::RangeProofBorromean>
|
||||
class test_check_tx_signature : private multi_tx_test_base<a_ring_size>
|
||||
{
|
||||
static_assert(0 < a_ring_size, "ring_size must be greater than 0");
|
||||
|
@ -50,7 +50,6 @@ public:
|
|||
static const size_t ring_size = a_ring_size;
|
||||
static const size_t outputs = a_outputs;
|
||||
static const bool rct = a_rct;
|
||||
static const bool bulletproof = a_bulletproof;
|
||||
|
||||
typedef multi_tx_test_base<a_ring_size> base_class;
|
||||
|
||||
|
@ -72,7 +71,7 @@ public:
|
|||
std::vector<crypto::secret_key> additional_tx_keys;
|
||||
std::unordered_map<crypto::public_key, cryptonote::subaddress_index> subaddresses;
|
||||
subaddresses[this->m_miners[this->real_source_idx].get_keys().m_account_address.m_spend_public_key] = {0,0};
|
||||
if (!construct_tx_and_get_tx_key(this->m_miners[this->real_source_idx].get_keys(), subaddresses, this->m_sources, destinations, cryptonote::account_public_address{}, std::vector<uint8_t>(), m_tx, 0, tx_key, additional_tx_keys, rct, bulletproof ? rct::RangeProofMultiOutputBulletproof : rct::RangeProofBorromean))
|
||||
if (!construct_tx_and_get_tx_key(this->m_miners[this->real_source_idx].get_keys(), subaddresses, this->m_sources, destinations, cryptonote::account_public_address{}, std::vector<uint8_t>(), m_tx, 0, tx_key, additional_tx_keys, rct, range_proof_type))
|
||||
return false;
|
||||
|
||||
get_transaction_prefix_hash(m_tx, m_tx_prefix_hash);
|
||||
|
@ -136,7 +135,7 @@ public:
|
|||
m_txes.resize(a_num_txes + (extra_outs > 0 ? 1 : 0));
|
||||
for (size_t n = 0; n < a_num_txes; ++n)
|
||||
{
|
||||
if (!construct_tx_and_get_tx_key(this->m_miners[this->real_source_idx].get_keys(), subaddresses, this->m_sources, destinations, cryptonote::account_public_address{}, std::vector<uint8_t>(), m_txes[n], 0, tx_key, additional_tx_keys, true, rct::RangeProofMultiOutputBulletproof))
|
||||
if (!construct_tx_and_get_tx_key(this->m_miners[this->real_source_idx].get_keys(), subaddresses, this->m_sources, destinations, cryptonote::account_public_address{}, std::vector<uint8_t>(), m_txes[n], 0, tx_key, additional_tx_keys, true, rct::RangeProofPaddedBulletproof))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -132,21 +132,25 @@ int main(int argc, char** argv)
|
|||
TEST_PERFORMANCE3(filter, p, test_construct_tx, 100, 2, true);
|
||||
TEST_PERFORMANCE3(filter, p, test_construct_tx, 100, 10, true);
|
||||
|
||||
TEST_PERFORMANCE4(filter, p, test_check_tx_signature, 1, 2, false, false);
|
||||
TEST_PERFORMANCE4(filter, p, test_check_tx_signature, 2, 2, false, false);
|
||||
TEST_PERFORMANCE4(filter, p, test_check_tx_signature, 10, 2, false, false);
|
||||
TEST_PERFORMANCE4(filter, p, test_check_tx_signature, 100, 2, false, false);
|
||||
TEST_PERFORMANCE4(filter, p, test_check_tx_signature, 2, 10, false, false);
|
||||
TEST_PERFORMANCE3(filter, p, test_check_tx_signature, 1, 2, false);
|
||||
TEST_PERFORMANCE3(filter, p, test_check_tx_signature, 2, 2, false);
|
||||
TEST_PERFORMANCE3(filter, p, test_check_tx_signature, 10, 2, false);
|
||||
TEST_PERFORMANCE3(filter, p, test_check_tx_signature, 100, 2, false);
|
||||
TEST_PERFORMANCE3(filter, p, test_check_tx_signature, 2, 10, false);
|
||||
|
||||
TEST_PERFORMANCE4(filter, p, test_check_tx_signature, 2, 2, true, false);
|
||||
TEST_PERFORMANCE4(filter, p, test_check_tx_signature, 10, 2, true, false);
|
||||
TEST_PERFORMANCE4(filter, p, test_check_tx_signature, 100, 2, true, false);
|
||||
TEST_PERFORMANCE4(filter, p, test_check_tx_signature, 2, 10, true, false);
|
||||
TEST_PERFORMANCE4(filter, p, test_check_tx_signature, 2, 2, true, rct::RangeProofBorromean);
|
||||
TEST_PERFORMANCE4(filter, p, test_check_tx_signature, 10, 2, true, rct::RangeProofBorromean);
|
||||
TEST_PERFORMANCE4(filter, p, test_check_tx_signature, 100, 2, true, rct::RangeProofBorromean);
|
||||
TEST_PERFORMANCE4(filter, p, test_check_tx_signature, 2, 10, true, rct::RangeProofBorromean);
|
||||
|
||||
TEST_PERFORMANCE4(filter, p, test_check_tx_signature, 2, 2, true, true);
|
||||
TEST_PERFORMANCE4(filter, p, test_check_tx_signature, 10, 2, true, true);
|
||||
TEST_PERFORMANCE4(filter, p, test_check_tx_signature, 100, 2, true, true);
|
||||
TEST_PERFORMANCE4(filter, p, test_check_tx_signature, 2, 10, true, true);
|
||||
TEST_PERFORMANCE4(filter, p, test_check_tx_signature, 2, 2, true, rct::RangeProofPaddedBulletproof);
|
||||
TEST_PERFORMANCE4(filter, p, test_check_tx_signature, 2, 2, true, rct::RangeProofMultiOutputBulletproof);
|
||||
TEST_PERFORMANCE4(filter, p, test_check_tx_signature, 10, 2, true, rct::RangeProofPaddedBulletproof);
|
||||
TEST_PERFORMANCE4(filter, p, test_check_tx_signature, 10, 2, true, rct::RangeProofMultiOutputBulletproof);
|
||||
TEST_PERFORMANCE4(filter, p, test_check_tx_signature, 100, 2, true, rct::RangeProofPaddedBulletproof);
|
||||
TEST_PERFORMANCE4(filter, p, test_check_tx_signature, 100, 2, true, rct::RangeProofMultiOutputBulletproof);
|
||||
TEST_PERFORMANCE4(filter, p, test_check_tx_signature, 2, 10, true, rct::RangeProofPaddedBulletproof);
|
||||
TEST_PERFORMANCE4(filter, p, test_check_tx_signature, 2, 10, true, rct::RangeProofMultiOutputBulletproof);
|
||||
|
||||
TEST_PERFORMANCE3(filter, p, test_check_tx_signature_aggregated_bulletproofs, 2, 2, 64);
|
||||
TEST_PERFORMANCE3(filter, p, test_check_tx_signature_aggregated_bulletproofs, 10, 2, 64);
|
||||
|
|
|
@ -40,14 +40,14 @@ namespace
|
|||
class block_reward_and_already_generated_coins : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
static const size_t current_block_size = CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1 / 2;
|
||||
static const size_t current_block_weight = CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1 / 2;
|
||||
|
||||
bool m_block_not_too_big;
|
||||
uint64_t m_block_reward;
|
||||
};
|
||||
|
||||
#define TEST_ALREADY_GENERATED_COINS(already_generated_coins, expected_reward) \
|
||||
m_block_not_too_big = get_block_reward(0, current_block_size, already_generated_coins, m_block_reward,1); \
|
||||
m_block_not_too_big = get_block_reward(0, current_block_weight, already_generated_coins, m_block_reward,1); \
|
||||
ASSERT_TRUE(m_block_not_too_big); \
|
||||
ASSERT_EQ(m_block_reward, expected_reward);
|
||||
|
||||
|
@ -74,7 +74,7 @@ namespace
|
|||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------
|
||||
class block_reward_and_current_block_size : public ::testing::Test
|
||||
class block_reward_and_current_block_weight : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
virtual void SetUp()
|
||||
|
@ -84,9 +84,9 @@ namespace
|
|||
ASSERT_LT(CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1, m_standard_block_reward);
|
||||
}
|
||||
|
||||
void do_test(size_t median_block_size, size_t current_block_size)
|
||||
void do_test(size_t median_block_weight, size_t current_block_weight)
|
||||
{
|
||||
m_block_not_too_big = get_block_reward(median_block_size, current_block_size, already_generated_coins, m_block_reward, 1);
|
||||
m_block_not_too_big = get_block_reward(median_block_weight, current_block_weight, already_generated_coins, m_block_reward, 1);
|
||||
}
|
||||
|
||||
static const uint64_t already_generated_coins = 0;
|
||||
|
@ -96,28 +96,28 @@ namespace
|
|||
uint64_t m_standard_block_reward;
|
||||
};
|
||||
|
||||
TEST_F(block_reward_and_current_block_size, handles_block_size_less_relevance_level)
|
||||
TEST_F(block_reward_and_current_block_weight, handles_block_weight_less_relevance_level)
|
||||
{
|
||||
do_test(0, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1 - 1);
|
||||
ASSERT_TRUE(m_block_not_too_big);
|
||||
ASSERT_EQ(m_block_reward, m_standard_block_reward);
|
||||
}
|
||||
|
||||
TEST_F(block_reward_and_current_block_size, handles_block_size_eq_relevance_level)
|
||||
TEST_F(block_reward_and_current_block_weight, handles_block_weight_eq_relevance_level)
|
||||
{
|
||||
do_test(0, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1);
|
||||
ASSERT_TRUE(m_block_not_too_big);
|
||||
ASSERT_EQ(m_block_reward, m_standard_block_reward);
|
||||
}
|
||||
|
||||
TEST_F(block_reward_and_current_block_size, handles_block_size_gt_relevance_level)
|
||||
TEST_F(block_reward_and_current_block_weight, handles_block_weight_gt_relevance_level)
|
||||
{
|
||||
do_test(0, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1 + 1);
|
||||
ASSERT_TRUE(m_block_not_too_big);
|
||||
ASSERT_LT(m_block_reward, m_standard_block_reward);
|
||||
}
|
||||
|
||||
TEST_F(block_reward_and_current_block_size, handles_block_size_less_2_relevance_level)
|
||||
TEST_F(block_reward_and_current_block_weight, handles_block_weight_less_2_relevance_level)
|
||||
{
|
||||
do_test(0, 2 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1 - 1);
|
||||
ASSERT_TRUE(m_block_not_too_big);
|
||||
|
@ -125,21 +125,21 @@ namespace
|
|||
ASSERT_LT(0, m_block_reward);
|
||||
}
|
||||
|
||||
TEST_F(block_reward_and_current_block_size, handles_block_size_eq_2_relevance_level)
|
||||
TEST_F(block_reward_and_current_block_weight, handles_block_weight_eq_2_relevance_level)
|
||||
{
|
||||
do_test(0, 2 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1);
|
||||
ASSERT_TRUE(m_block_not_too_big);
|
||||
ASSERT_EQ(0, m_block_reward);
|
||||
}
|
||||
|
||||
TEST_F(block_reward_and_current_block_size, handles_block_size_gt_2_relevance_level)
|
||||
TEST_F(block_reward_and_current_block_weight, handles_block_weight_gt_2_relevance_level)
|
||||
{
|
||||
do_test(0, 2 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1 + 1);
|
||||
ASSERT_FALSE(m_block_not_too_big);
|
||||
}
|
||||
|
||||
#ifdef __x86_64__ // For 64-bit systems only, because block size is limited to size_t.
|
||||
TEST_F(block_reward_and_current_block_size, fails_on_huge_median_size)
|
||||
TEST_F(block_reward_and_current_block_weight, fails_on_huge_median_size)
|
||||
{
|
||||
#if !defined(NDEBUG)
|
||||
size_t huge_size = std::numeric_limits<uint32_t>::max() + UINT64_C(2);
|
||||
|
@ -147,7 +147,7 @@ namespace
|
|||
#endif
|
||||
}
|
||||
|
||||
TEST_F(block_reward_and_current_block_size, fails_on_huge_block_size)
|
||||
TEST_F(block_reward_and_current_block_weight, fails_on_huge_block_weight)
|
||||
{
|
||||
#if !defined(NDEBUG)
|
||||
size_t huge_size = std::numeric_limits<uint32_t>::max() + UINT64_C(2);
|
||||
|
@ -157,94 +157,94 @@ namespace
|
|||
#endif // __x86_64__
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------
|
||||
class block_reward_and_last_block_sizes : public ::testing::Test
|
||||
class block_reward_and_last_block_weights : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
virtual void SetUp()
|
||||
{
|
||||
m_last_block_sizes.push_back(3 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1);
|
||||
m_last_block_sizes.push_back(5 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1);
|
||||
m_last_block_sizes.push_back(7 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1);
|
||||
m_last_block_sizes.push_back(11 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1);
|
||||
m_last_block_sizes.push_back(13 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1);
|
||||
m_last_block_weights.push_back(3 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1);
|
||||
m_last_block_weights.push_back(5 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1);
|
||||
m_last_block_weights.push_back(7 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1);
|
||||
m_last_block_weights.push_back(11 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1);
|
||||
m_last_block_weights.push_back(13 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1);
|
||||
|
||||
m_last_block_sizes_median = 7 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1;
|
||||
m_last_block_weights_median = 7 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1;
|
||||
|
||||
m_block_not_too_big = get_block_reward(epee::misc_utils::median(m_last_block_sizes), 0, already_generated_coins, m_standard_block_reward, 1);
|
||||
m_block_not_too_big = get_block_reward(epee::misc_utils::median(m_last_block_weights), 0, already_generated_coins, m_standard_block_reward, 1);
|
||||
ASSERT_TRUE(m_block_not_too_big);
|
||||
ASSERT_LT(CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1, m_standard_block_reward);
|
||||
}
|
||||
|
||||
void do_test(size_t current_block_size)
|
||||
void do_test(size_t current_block_weight)
|
||||
{
|
||||
m_block_not_too_big = get_block_reward(epee::misc_utils::median(m_last_block_sizes), current_block_size, already_generated_coins, m_block_reward, 1);
|
||||
m_block_not_too_big = get_block_reward(epee::misc_utils::median(m_last_block_weights), current_block_weight, already_generated_coins, m_block_reward, 1);
|
||||
}
|
||||
|
||||
static const uint64_t already_generated_coins = 0;
|
||||
|
||||
std::vector<size_t> m_last_block_sizes;
|
||||
uint64_t m_last_block_sizes_median;
|
||||
std::vector<size_t> m_last_block_weights;
|
||||
uint64_t m_last_block_weights_median;
|
||||
bool m_block_not_too_big;
|
||||
uint64_t m_block_reward;
|
||||
uint64_t m_standard_block_reward;
|
||||
};
|
||||
|
||||
TEST_F(block_reward_and_last_block_sizes, handles_block_size_less_median)
|
||||
TEST_F(block_reward_and_last_block_weights, handles_block_weight_less_median)
|
||||
{
|
||||
do_test(m_last_block_sizes_median - 1);
|
||||
do_test(m_last_block_weights_median - 1);
|
||||
ASSERT_TRUE(m_block_not_too_big);
|
||||
ASSERT_EQ(m_block_reward, m_standard_block_reward);
|
||||
}
|
||||
|
||||
TEST_F(block_reward_and_last_block_sizes, handles_block_size_eq_median)
|
||||
TEST_F(block_reward_and_last_block_weights, handles_block_weight_eq_median)
|
||||
{
|
||||
do_test(m_last_block_sizes_median);
|
||||
do_test(m_last_block_weights_median);
|
||||
ASSERT_TRUE(m_block_not_too_big);
|
||||
ASSERT_EQ(m_block_reward, m_standard_block_reward);
|
||||
}
|
||||
|
||||
TEST_F(block_reward_and_last_block_sizes, handles_block_size_gt_median)
|
||||
TEST_F(block_reward_and_last_block_weights, handles_block_weight_gt_median)
|
||||
{
|
||||
do_test(m_last_block_sizes_median + 1);
|
||||
do_test(m_last_block_weights_median + 1);
|
||||
ASSERT_TRUE(m_block_not_too_big);
|
||||
ASSERT_LT(m_block_reward, m_standard_block_reward);
|
||||
}
|
||||
|
||||
TEST_F(block_reward_and_last_block_sizes, handles_block_size_less_2_medians)
|
||||
TEST_F(block_reward_and_last_block_weights, handles_block_weight_less_2_medians)
|
||||
{
|
||||
do_test(2 * m_last_block_sizes_median - 1);
|
||||
do_test(2 * m_last_block_weights_median - 1);
|
||||
ASSERT_TRUE(m_block_not_too_big);
|
||||
ASSERT_LT(m_block_reward, m_standard_block_reward);
|
||||
ASSERT_LT(0, m_block_reward);
|
||||
}
|
||||
|
||||
TEST_F(block_reward_and_last_block_sizes, handles_block_size_eq_2_medians)
|
||||
TEST_F(block_reward_and_last_block_weights, handles_block_weight_eq_2_medians)
|
||||
{
|
||||
do_test(2 * m_last_block_sizes_median);
|
||||
do_test(2 * m_last_block_weights_median);
|
||||
ASSERT_TRUE(m_block_not_too_big);
|
||||
ASSERT_EQ(0, m_block_reward);
|
||||
}
|
||||
|
||||
TEST_F(block_reward_and_last_block_sizes, handles_block_size_gt_2_medians)
|
||||
TEST_F(block_reward_and_last_block_weights, handles_block_weight_gt_2_medians)
|
||||
{
|
||||
do_test(2 * m_last_block_sizes_median + 1);
|
||||
do_test(2 * m_last_block_weights_median + 1);
|
||||
ASSERT_FALSE(m_block_not_too_big);
|
||||
}
|
||||
|
||||
TEST_F(block_reward_and_last_block_sizes, calculates_correctly)
|
||||
TEST_F(block_reward_and_last_block_weights, calculates_correctly)
|
||||
{
|
||||
ASSERT_EQ(0, m_last_block_sizes_median % 8);
|
||||
ASSERT_EQ(0, m_last_block_weights_median % 8);
|
||||
|
||||
do_test(m_last_block_sizes_median * 9 / 8);
|
||||
do_test(m_last_block_weights_median * 9 / 8);
|
||||
ASSERT_TRUE(m_block_not_too_big);
|
||||
ASSERT_EQ(m_block_reward, m_standard_block_reward * 63 / 64);
|
||||
|
||||
// 3/2 = 12/8
|
||||
do_test(m_last_block_sizes_median * 3 / 2);
|
||||
do_test(m_last_block_weights_median * 3 / 2);
|
||||
ASSERT_TRUE(m_block_not_too_big);
|
||||
ASSERT_EQ(m_block_reward, m_standard_block_reward * 3 / 4);
|
||||
|
||||
do_test(m_last_block_sizes_median * 15 / 8);
|
||||
do_test(m_last_block_weights_median * 15 / 8);
|
||||
ASSERT_TRUE(m_block_not_too_big);
|
||||
ASSERT_EQ(m_block_reward, m_standard_block_reward * 15 / 64);
|
||||
}
|
||||
|
|
|
@ -319,7 +319,7 @@ TYPED_TEST(BlockchainDBTest, RetrieveBlockData)
|
|||
|
||||
ASSERT_NO_THROW(this->m_db->add_block(this->m_blocks[0], t_sizes[0], t_diffs[0], t_coins[0], this->m_txs[0]));
|
||||
|
||||
ASSERT_EQ(t_sizes[0], this->m_db->get_block_size(0));
|
||||
ASSERT_EQ(t_sizes[0], this->m_db->get_block_weight(0));
|
||||
ASSERT_EQ(t_diffs[0], this->m_db->get_block_cumulative_difficulty(0));
|
||||
ASSERT_EQ(t_diffs[0], this->m_db->get_block_difficulty(0));
|
||||
ASSERT_EQ(t_coins[0], this->m_db->get_block_already_generated_coins(0));
|
||||
|
|
|
@ -129,7 +129,7 @@ TEST(bulletproofs, multi_splitting)
|
|||
}
|
||||
|
||||
rct::ctkeyV outSk;
|
||||
rct::rctSig s = rct::genRctSimple(rct::zero(), sc, destinations, inamounts, outamounts, available, mixRing, amount_keys, NULL, NULL, index, outSk, rct::RangeProofMultiOutputBulletproof, hw::get_device("default"));
|
||||
rct::rctSig s = rct::genRctSimple(rct::zero(), sc, destinations, inamounts, outamounts, available, mixRing, amount_keys, NULL, NULL, index, outSk, rct::RangeProofPaddedBulletproof, hw::get_device("default"));
|
||||
ASSERT_TRUE(rct::verRctSimple(s));
|
||||
for (size_t i = 0; i < n_outputs; ++i)
|
||||
{
|
||||
|
|
|
@ -58,46 +58,46 @@ namespace
|
|||
TEST_F(fee, 10xmr)
|
||||
{
|
||||
// CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 and lower are clamped
|
||||
ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(10000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2, 3), clamp_fee(2000000000));
|
||||
ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(10000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 / 2, 3), clamp_fee(2000000000));
|
||||
ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(10000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 / 100, 3), clamp_fee(2000000000));
|
||||
ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(10000000000000, 1, 3), 2000000000);
|
||||
ASSERT_EQ(Blockchain::get_dynamic_base_fee(10000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2, 3), clamp_fee(2000000000));
|
||||
ASSERT_EQ(Blockchain::get_dynamic_base_fee(10000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 / 2, 3), clamp_fee(2000000000));
|
||||
ASSERT_EQ(Blockchain::get_dynamic_base_fee(10000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 / 100, 3), clamp_fee(2000000000));
|
||||
ASSERT_EQ(Blockchain::get_dynamic_base_fee(10000000000000, 1, 3), 2000000000);
|
||||
|
||||
// higher is inverse proportional
|
||||
ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(10000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 2, 3), clamp_fee(2000000000 / 2));
|
||||
ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(10000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 10, 3), clamp_fee(2000000000 / 10));
|
||||
ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(10000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 1000, 3), clamp_fee(2000000000 / 1000));
|
||||
ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(10000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 20000ull, 3), clamp_fee(2000000000 / 20000));
|
||||
ASSERT_EQ(Blockchain::get_dynamic_base_fee(10000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 2, 3), clamp_fee(2000000000 / 2));
|
||||
ASSERT_EQ(Blockchain::get_dynamic_base_fee(10000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 10, 3), clamp_fee(2000000000 / 10));
|
||||
ASSERT_EQ(Blockchain::get_dynamic_base_fee(10000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 1000, 3), clamp_fee(2000000000 / 1000));
|
||||
ASSERT_EQ(Blockchain::get_dynamic_base_fee(10000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 20000ull, 3), clamp_fee(2000000000 / 20000));
|
||||
}
|
||||
|
||||
TEST_F(fee, 1xmr)
|
||||
{
|
||||
// CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 and lower are clamped
|
||||
ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(1000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2, 3), clamp_fee(200000000));
|
||||
ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(1000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 / 2, 3), clamp_fee(200000000));
|
||||
ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(1000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 / 100, 3), clamp_fee(200000000));
|
||||
ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(1000000000000, 1, 3), 200000000);
|
||||
ASSERT_EQ(Blockchain::get_dynamic_base_fee(1000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2, 3), clamp_fee(200000000));
|
||||
ASSERT_EQ(Blockchain::get_dynamic_base_fee(1000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 / 2, 3), clamp_fee(200000000));
|
||||
ASSERT_EQ(Blockchain::get_dynamic_base_fee(1000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 / 100, 3), clamp_fee(200000000));
|
||||
ASSERT_EQ(Blockchain::get_dynamic_base_fee(1000000000000, 1, 3), 200000000);
|
||||
|
||||
// higher is inverse proportional
|
||||
ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(1000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 2, 3), clamp_fee(200000000 / 2));
|
||||
ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(1000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 10, 3), clamp_fee(200000000 / 10));
|
||||
ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(1000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 1000, 3), clamp_fee(200000000 / 1000));
|
||||
ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(1000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 20000ull, 3), clamp_fee(200000000 / 20000));
|
||||
ASSERT_EQ(Blockchain::get_dynamic_base_fee(1000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 2, 3), clamp_fee(200000000 / 2));
|
||||
ASSERT_EQ(Blockchain::get_dynamic_base_fee(1000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 10, 3), clamp_fee(200000000 / 10));
|
||||
ASSERT_EQ(Blockchain::get_dynamic_base_fee(1000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 1000, 3), clamp_fee(200000000 / 1000));
|
||||
ASSERT_EQ(Blockchain::get_dynamic_base_fee(1000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 20000ull, 3), clamp_fee(200000000 / 20000));
|
||||
}
|
||||
|
||||
TEST_F(fee, dot3xmr)
|
||||
{
|
||||
// CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 and lower are clamped
|
||||
ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(300000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2, 3), clamp_fee(60000000));
|
||||
ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(300000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 / 2, 3), clamp_fee(60000000));
|
||||
ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(300000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 / 100, 3), clamp_fee(60000000));
|
||||
ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(300000000000, 1, 3), 60000000);
|
||||
ASSERT_EQ(Blockchain::get_dynamic_base_fee(300000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2, 3), clamp_fee(60000000));
|
||||
ASSERT_EQ(Blockchain::get_dynamic_base_fee(300000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 / 2, 3), clamp_fee(60000000));
|
||||
ASSERT_EQ(Blockchain::get_dynamic_base_fee(300000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 / 100, 3), clamp_fee(60000000));
|
||||
ASSERT_EQ(Blockchain::get_dynamic_base_fee(300000000000, 1, 3), 60000000);
|
||||
|
||||
// higher is inverse proportional
|
||||
ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(300000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 2, 3), clamp_fee(60000000 / 2));
|
||||
ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(300000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 10, 3), clamp_fee(60000000 / 10));
|
||||
ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(300000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 1000, 3), clamp_fee(60000000 / 1000));
|
||||
ASSERT_EQ(Blockchain::get_dynamic_per_kb_fee(300000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 20000ull, 3), clamp_fee(60000000 / 20000));
|
||||
ASSERT_EQ(Blockchain::get_dynamic_base_fee(300000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 2, 3), clamp_fee(60000000 / 2));
|
||||
ASSERT_EQ(Blockchain::get_dynamic_base_fee(300000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 10, 3), clamp_fee(60000000 / 10));
|
||||
ASSERT_EQ(Blockchain::get_dynamic_base_fee(300000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 1000, 3), clamp_fee(60000000 / 1000));
|
||||
ASSERT_EQ(Blockchain::get_dynamic_base_fee(300000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 20000ull, 3), clamp_fee(60000000 / 20000));
|
||||
}
|
||||
|
||||
static bool is_more_or_less(double x, double y)
|
||||
|
@ -116,7 +116,7 @@ namespace
|
|||
600000000000ull, // .6 monero, minimum reward per block at 2min
|
||||
300000000000ull, // .3 monero, minimum reward per block at 1min
|
||||
};
|
||||
static const uint64_t median_block_sizes[] = {
|
||||
static const uint64_t median_block_weights[] = {
|
||||
CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2,
|
||||
CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 2,
|
||||
CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 10,
|
||||
|
@ -127,9 +127,9 @@ namespace
|
|||
|
||||
for (uint64_t block_reward: block_rewards)
|
||||
{
|
||||
for (uint64_t median_block_size: median_block_sizes)
|
||||
for (uint64_t median_block_weight: median_block_weights)
|
||||
{
|
||||
ASSERT_TRUE(is_more_or_less(Blockchain::get_dynamic_per_kb_fee(block_reward, median_block_size, 3) * (median_block_size / 1024.) * MAX_MULTIPLIER / (double)block_reward, 1.992 * 1000 / 1024));
|
||||
ASSERT_TRUE(is_more_or_less(Blockchain::get_dynamic_base_fee(block_reward, median_block_weight, 3) * (median_block_weight / 1024.) * MAX_MULTIPLIER / (double)block_reward, 1.992 * 1000 / 1024));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ public:
|
|||
virtual uint64_t get_block_timestamp(const uint64_t& height) const { return 0; }
|
||||
virtual std::vector<uint64_t> get_block_cumulative_rct_outputs(const std::vector<uint64_t> &heights) const { return {}; }
|
||||
virtual uint64_t get_top_block_timestamp() const { return 0; }
|
||||
virtual size_t get_block_size(const uint64_t& height) const { return 128; }
|
||||
virtual size_t get_block_weight(const uint64_t& height) const { return 128; }
|
||||
virtual difficulty_type get_block_cumulative_difficulty(const uint64_t& height) const { return 10; }
|
||||
virtual difficulty_type get_block_difficulty(const uint64_t& height) const { return 0; }
|
||||
virtual uint64_t get_block_already_generated_coins(const uint64_t& height) const { return 10000000000; }
|
||||
|
@ -130,7 +130,7 @@ public:
|
|||
virtual bool for_all_txpool_txes(std::function<bool(const crypto::hash&, const txpool_tx_meta_t&, const cryptonote::blobdata*)>, bool include_blob = false, bool include_unrelayed_txes = false) const { return false; }
|
||||
|
||||
virtual void add_block( const block& blk
|
||||
, const size_t& block_size
|
||||
, size_t block_weight
|
||||
, const difficulty_type& cumulative_difficulty
|
||||
, const uint64_t& coins_generated
|
||||
, uint64_t num_rct_outs
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue