1
0
Fork 0
forked from lthn/blockchain

Merge branch 'zarcanum' into multiassets

This commit is contained in:
cryptozoidberg 2022-11-24 21:50:58 +01:00
commit 8c1660e20f
No known key found for this signature in database
GPG key ID: 22DEB97A54C6FDEC
16 changed files with 229 additions and 59 deletions

View file

@ -1146,7 +1146,7 @@ wide_difficulty_type blockchain_storage::get_next_diff_conditional(bool pos) con
std::vector<uint64_t> timestamps;
std::vector<wide_difficulty_type> commulative_difficulties;
if (!m_db_blocks.size())
return DIFFICULTY_STARTER;
return DIFFICULTY_POW_STARTER;
//skip genesis timestamp
TIME_MEASURE_START_PD(target_calculating_enum_blocks);
CRITICAL_REGION_BEGIN(m_targetdata_cache_lock);
@ -1168,11 +1168,11 @@ wide_difficulty_type blockchain_storage::get_next_diff_conditional(bool pos) con
TIME_MEASURE_START_PD(target_calculating_calc);
if (m_core_runtime_config.is_hardfork_active_for_height(1, m_db_blocks.size()))
{
dif = next_difficulty_2(timestamps, commulative_difficulties, pos ? DIFFICULTY_POS_TARGET : DIFFICULTY_POW_TARGET);
dif = next_difficulty_2(timestamps, commulative_difficulties, pos ? global_difficulty_pos_target : global_difficulty_pow_target, pos ? global_difficulty_pos_starter : global_difficulty_pow_starter);
}
else
{
dif = next_difficulty_1(timestamps, commulative_difficulties, pos ? DIFFICULTY_POS_TARGET : DIFFICULTY_POW_TARGET);
dif = next_difficulty_1(timestamps, commulative_difficulties, pos ? global_difficulty_pos_target : global_difficulty_pow_target, pos ? global_difficulty_pos_starter : global_difficulty_pow_starter);
}
@ -1187,7 +1187,7 @@ wide_difficulty_type blockchain_storage::get_next_diff_conditional2(bool pos, co
std::vector<wide_difficulty_type> commulative_difficulties;
size_t count = 0;
if (!m_db_blocks.size())
return DIFFICULTY_STARTER;
return DIFFICULTY_POW_STARTER;
auto cb = [&](const block_extended_info& bei, bool is_main){
if (!bei.height)
@ -1206,9 +1206,9 @@ wide_difficulty_type blockchain_storage::get_next_diff_conditional2(bool pos, co
wide_difficulty_type diff = 0;
if(m_core_runtime_config.is_hardfork_active_for_height(1, abei.height))
diff = next_difficulty_2(timestamps, commulative_difficulties, pos ? DIFFICULTY_POS_TARGET : DIFFICULTY_POW_TARGET);
diff = next_difficulty_2(timestamps, commulative_difficulties, pos ? global_difficulty_pos_target : global_difficulty_pow_target, pos ? global_difficulty_pos_starter : global_difficulty_pow_starter);
else
diff = next_difficulty_1(timestamps, commulative_difficulties, pos ? DIFFICULTY_POS_TARGET : DIFFICULTY_POW_TARGET);
diff = next_difficulty_1(timestamps, commulative_difficulties, pos ? global_difficulty_pos_target : global_difficulty_pow_target, pos ? global_difficulty_pos_starter : global_difficulty_pow_starter);
return diff;
}
//------------------------------------------------------------------
@ -1268,7 +1268,7 @@ wide_difficulty_type blockchain_storage::get_next_difficulty_for_alternative_cha
commulative_difficulties.push_back(m_db_blocks[i]->cumulative_diff_precise);
}
return next_difficulty_1(timestamps, commulative_difficulties, pos ? DIFFICULTY_POS_TARGET:DIFFICULTY_POW_TARGET);
return next_difficulty_1(timestamps, commulative_difficulties, pos ? DIFFICULTY_POS_TARGET:DIFFICULTY_POW_TARGET, pos ? global_difficulty_pos_starter : global_difficulty_pow_starter);
}
//------------------------------------------------------------------
bool blockchain_storage::prevalidate_miner_transaction(const block& b, uint64_t height, bool pos) const
@ -2508,10 +2508,10 @@ bool blockchain_storage::add_out_to_get_random_outs(COMMAND_RPC_GET_RANDOM_OUTPU
CRITICAL_REGION_LOCAL(m_read_lock);
auto out_ptr = m_db_outputs.get_subitem(amount, g_index);
auto tx_ptr = m_db_transactions.find(out_ptr->tx_id);
CHECK_AND_ASSERT_MES(tx_ptr, false, "internal error: transaction with id " << out_ptr->tx_id << ENDL <<
", used in mounts global index for amount=" << amount << ": g_index=" << g_index << "not found in transactions index");
CHECK_AND_ASSERT_MES(tx_ptr, false, "internal error: transaction " << out_ptr->tx_id << " was not found in transaction DB, amount: " << print_money_brief(amount) <<
", g_index: " << g_index);
CHECK_AND_ASSERT_MES(tx_ptr->tx.vout.size() > out_ptr->out_no, false, "internal error: in global outs index, transaction out index="
<< out_ptr->out_no << " more than transaction outputs = " << tx_ptr->tx.vout.size() << ", for tx id = " << out_ptr->tx_id);
<< out_ptr->out_no << " is greater than transaction outputs = " << tx_ptr->tx.vout.size() << ", for tx id = " << out_ptr->tx_id);
CHECK_AND_ASSERT_MES(amount != 0 || height_upper_limit != 0, false, "height_upper_limit must be nonzero for hidden amounts (amount = 0)");
@ -2587,7 +2587,7 @@ size_t blockchain_storage::find_end_of_allowed_index(uint64_t amount) const
--i;
auto out_ptr = m_db_outputs.get_subitem(amount, i);
auto tx_ptr = m_db_transactions.find(out_ptr->tx_id);
CHECK_AND_ASSERT_MES(tx_ptr, 0, "internal error: failed to find transaction from outputs index with tx_id=" << out_ptr->tx_id);
CHECK_AND_ASSERT_MES(tx_ptr, 0, "internal error: failed to find transaction from outputs index with tx_id=" << out_ptr->tx_id << ", amount: " << print_money_brief(amount));
if (tx_ptr->m_keeper_block_height + CURRENCY_MINED_MONEY_UNLOCK_WINDOW <= get_current_blockchain_size())
return i+1;
} while (i != 0);
@ -2821,7 +2821,7 @@ bool blockchain_storage::forecast_difficulty(std::vector<std::pair<uint64_t, wid
out_height_2_diff_vector.push_back(std::make_pair(height, last_block_diff_for_this_type)); // the first element corresponds to the last block of this type
for (size_t i = 0; i < DIFFICULTY_CUT; ++i)
{
wide_difficulty_type diff = next_difficulty_1(timestamps, cumulative_difficulties, target_seconds);
wide_difficulty_type diff = next_difficulty_1(timestamps, cumulative_difficulties, target_seconds, pos ? global_difficulty_pos_starter : global_difficulty_pow_starter);
height += avg_interval;
out_height_2_diff_vector.push_back(std::make_pair(height, diff));
@ -3476,21 +3476,26 @@ bool blockchain_storage::get_outs(uint64_t amount, std::list<crypto::public_key>
bool blockchain_storage::pop_transaction_from_global_index(const transaction& tx, const crypto::hash& tx_id)
{
CRITICAL_REGION_LOCAL(m_read_lock);
size_t i = tx.vout.size()-1;
auto do_pop_output = [&](size_t i, uint64_t amount) -> bool {
uint64_t sz = m_db_outputs.get_item_size(amount);
CHECK_AND_ASSERT_MES(sz, false, "transactions outs global index: empty index for amount: " << amount);
auto back_item = m_db_outputs.get_subitem(amount, sz - 1);
CHECK_AND_ASSERT_MES(back_item->tx_id == tx_id, false, "transactions outs global index consistency broken: tx id missmatch");
CHECK_AND_ASSERT_MES(back_item->out_no == i, false, "transactions outs global index consistency broken: in transaction index missmatch");
m_db_outputs.pop_back_item(amount);
return true;
};
size_t i = tx.vout.size() - 1;
BOOST_REVERSE_FOREACH(const auto& otv, tx.vout)
{
VARIANT_SWITCH_BEGIN(otv);
VARIANT_CASE_CONST(tx_out_bare, ot)
if (ot.target.type() == typeid(txout_to_key) || ot.target.type() == typeid(txout_htlc))
{
uint64_t sz = m_db_outputs.get_item_size(ot.amount);
CHECK_AND_ASSERT_MES(sz, false, "transactions outs global index: empty index for amount: " << ot.amount);
auto back_item = m_db_outputs.get_subitem(ot.amount, sz - 1);
CHECK_AND_ASSERT_MES(back_item->tx_id == tx_id, false, "transactions outs global index consistency broken: tx id missmatch");
CHECK_AND_ASSERT_MES(back_item->out_no == i, false, "transactions outs global index consistency broken: in transaction index missmatch");
m_db_outputs.pop_back_item(ot.amount);
//if (!it->second.size())
// m_db_outputs.erase(it);
if (!do_pop_output(i, ot.amount))
return false;
}
else if (ot.target.type() == typeid(txout_multisig))
{
@ -3500,7 +3505,9 @@ bool blockchain_storage::pop_transaction_from_global_index(const transaction& tx
CHECK_AND_ASSERT_MES(res, false, "Internal error: multisig out not found, multisig_out_id " << multisig_out_id << "in multisig outs index");
}
VARIANT_CASE_CONST(tx_out_zarcanum, toz)
//@#@
// TODO: @#@# temporary comment this section and make a test for the corresponding bug
if (!do_pop_output(i, 0))
return false;
VARIANT_CASE_THROW_ON_OTHER();
VARIANT_SWITCH_END();
--i;

View file

@ -42,6 +42,7 @@
#include "misc_language.h"
#include "block_flags.h"
#include "etc_custom_serialization.h"
#include "difficulty.h"
namespace currency
{
@ -56,6 +57,10 @@ namespace currency
const static crypto::hash gdefault_genesis = epee::string_tools::hex_to_pod<crypto::hash>("CC608F59F8080E2FBFE3C8C80EB6E6A953D47CF2D6AEBD345BADA3A1CAB99852");
const static crypto::hash ffff_hash = epee::string_tools::hex_to_pod<crypto::hash>("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
const static wide_difficulty_type global_difficulty_pow_starter = DIFFICULTY_POW_STARTER;
const static wide_difficulty_type global_difficulty_pos_starter = DIFFICULTY_POS_STARTER;
const static uint64_t global_difficulty_pos_target = DIFFICULTY_POS_TARGET;
const static uint64_t global_difficulty_pow_target = DIFFICULTY_POW_TARGET;
typedef std::string payment_id_t;

View file

@ -65,7 +65,7 @@
#define CURRENCY_MINER_TX_MAX_OUTS CURRENCY_TX_MAX_ALLOWED_OUTS
#define CURRENCY_TX_OUTS_RND_SPLIT_DIGITS_TO_KEEP 3
#define DIFFICULTY_STARTER 1
#define DIFFICULTY_POW_STARTER 1
#define DIFFICULTY_POS_TARGET 120 // seconds
#define DIFFICULTY_POW_TARGET 120 // seconds
#define DIFFICULTY_TOTAL_TARGET ((DIFFICULTY_POS_TARGET + DIFFICULTY_POW_TARGET) / 4)
@ -110,6 +110,7 @@
#define STRATUM_DEFAULT_PORT 11777
#define P2P_NETWORK_ID_TESTNET_FLAG 0
#define P2P_MAINTAINERS_PUB_KEY "8f138bb73f6d663a3746a542770781a09579a7b84cb4125249e95530824ee607"
#define DIFFICULTY_POS_STARTER 1
#else
#define P2P_DEFAULT_PORT (11112 + CURRENCY_FORMATION_VERSION)
#define RPC_DEFAULT_PORT 12111
@ -117,6 +118,7 @@
#define STRARUM_DEFAULT_PORT 51113
#define P2P_NETWORK_ID_TESTNET_FLAG 1
#define P2P_MAINTAINERS_PUB_KEY "aaa2d7aabc8d383fd53a3ae898697b28f236ceade6bafc1eecff413a6a02272a"
#define DIFFICULTY_POS_STARTER 625000000000
#endif
#define P2P_NETWORK_ID_VER (CURRENCY_FORMATION_VERSION+0)
@ -250,10 +252,11 @@
#define ZANO_HARDFORK_03_AFTER_HEIGHT 1082577
#define ZANO_HARDFORK_04_AFTER_HEIGHT 999999999
#else
#define ZANO_HARDFORK_01_AFTER_HEIGHT 1440
#define ZANO_HARDFORK_02_AFTER_HEIGHT 1800
#define ZANO_HARDFORK_03_AFTER_HEIGHT 1801
#define ZANO_HARDFORK_04_AFTER_HEIGHT 999999999
/////// Zarcanum Testnet Pre-Alpha //////////////////////////////
#define ZANO_HARDFORK_01_AFTER_HEIGHT 1
#define ZANO_HARDFORK_02_AFTER_HEIGHT 2
#define ZANO_HARDFORK_03_AFTER_HEIGHT 3
#define ZANO_HARDFORK_04_AFTER_HEIGHT 4
#endif

View file

@ -4005,11 +4005,12 @@ namespace currency
const difficulties& a_diff,
const difficulties& b_diff )
{
static const wide_difficulty_type difficulty_starter = DIFFICULTY_STARTER;
const wide_difficulty_type& a_pos_cumulative_difficulty = a_diff.pos_diff > 0 ? a_diff.pos_diff : difficulty_starter;
const wide_difficulty_type& b_pos_cumulative_difficulty = b_diff.pos_diff > 0 ? b_diff.pos_diff : difficulty_starter;
const wide_difficulty_type& a_pow_cumulative_difficulty = a_diff.pow_diff > 0 ? a_diff.pow_diff : difficulty_starter;
const wide_difficulty_type& b_pow_cumulative_difficulty = b_diff.pow_diff > 0 ? b_diff.pow_diff : difficulty_starter;
static const wide_difficulty_type difficulty_pos_starter = DIFFICULTY_POS_STARTER;
static const wide_difficulty_type difficulty_pow_starter = DIFFICULTY_POW_STARTER;
const wide_difficulty_type& a_pos_cumulative_difficulty = a_diff.pos_diff > 0 ? a_diff.pos_diff : difficulty_pos_starter;
const wide_difficulty_type& b_pos_cumulative_difficulty = b_diff.pos_diff > 0 ? b_diff.pos_diff : difficulty_pos_starter;
const wide_difficulty_type& a_pow_cumulative_difficulty = a_diff.pow_diff > 0 ? a_diff.pow_diff : difficulty_pow_starter;
const wide_difficulty_type& b_pow_cumulative_difficulty = b_diff.pow_diff > 0 ? b_diff.pow_diff : difficulty_pow_starter;
boost::multiprecision::uint1024_t basic_sum = boost::multiprecision::uint1024_t(a_pow_cumulative_difficulty) + (boost::multiprecision::uint1024_t(a_pos_cumulative_difficulty)*difficulty_pow_at_split_point) / difficulty_pos_at_split_point;
boost::multiprecision::uint1024_t res =

View file

@ -815,9 +815,16 @@ namespace currency
uint64_t operator()(const txin_zc_input&) const { return 0; }
uint64_t operator()(const txin_gen& i) const { return 0; }
};
inline uint64_t get_amount_from_variant(const txin_v& v)
inline uint64_t get_amount_from_variant(const txin_v& v) noexcept
{
return boost::apply_visitor(input_amount_getter(), v);
try
{
return boost::apply_visitor(input_amount_getter(), v);
}
catch(...)
{
return 0;
}
}
//---------------------------------------------------------------
struct output_amount_getter : public boost::static_visitor<uint64_t>

View file

@ -179,7 +179,7 @@ namespace currency {
return res.convert_to<wide_difficulty_type>();
}
wide_difficulty_type next_difficulty_1(vector<uint64_t>& timestamps, vector<wide_difficulty_type>& cumulative_difficulties, size_t target_seconds)
wide_difficulty_type next_difficulty_1(vector<uint64_t>& timestamps, vector<wide_difficulty_type>& cumulative_difficulties, size_t target_seconds, const wide_difficulty_type& difficulty_starter)
{
// timestamps - first is latest, back - is oldest timestamps
@ -194,7 +194,7 @@ namespace currency {
CHECK_AND_ASSERT_MES(length == cumulative_difficulties.size(), 0, "Check \"length == cumulative_difficulties.size()\" failed");
if (length <= 1)
{
return DIFFICULTY_STARTER;
return difficulty_starter;
}
static_assert(DIFFICULTY_WINDOW >= 2, "Window is too small");
@ -221,7 +221,7 @@ namespace currency {
return summ / devider;
}
wide_difficulty_type next_difficulty_2(vector<uint64_t>& timestamps, vector<wide_difficulty_type>& cumulative_difficulties, size_t target_seconds)
wide_difficulty_type next_difficulty_2(vector<uint64_t>& timestamps, vector<wide_difficulty_type>& cumulative_difficulties, size_t target_seconds, const wide_difficulty_type& difficulty_starter)
{
// timestamps - first is latest, back - is oldest timestamps
@ -236,7 +236,7 @@ namespace currency {
CHECK_AND_ASSERT_MES(length == cumulative_difficulties.size(), 0, "Check \"length == cumulative_difficulties.size()\" failed");
if (length <= 1)
{
return DIFFICULTY_STARTER;
return difficulty_starter;
}
static_assert(DIFFICULTY_WINDOW >= 2, "Window is too small");

View file

@ -19,8 +19,8 @@ namespace currency
typedef boost::multiprecision::uint128_t wide_difficulty_type;
bool check_hash(const crypto::hash &hash, wide_difficulty_type difficulty);
wide_difficulty_type next_difficulty_1(std::vector<std::uint64_t>& timestamps, std::vector<wide_difficulty_type>& cumulative_difficulties, size_t target_seconds);
wide_difficulty_type next_difficulty_2(std::vector<std::uint64_t>& timestamps, std::vector<wide_difficulty_type>& cumulative_difficulties, size_t target_seconds);
wide_difficulty_type next_difficulty_1(std::vector<std::uint64_t>& timestamps, std::vector<wide_difficulty_type>& cumulative_difficulties, size_t target_seconds, const wide_difficulty_type& difficulty_starter);
wide_difficulty_type next_difficulty_2(std::vector<std::uint64_t>& timestamps, std::vector<wide_difficulty_type>& cumulative_difficulties, size_t target_seconds, const wide_difficulty_type& difficulty_starter);
uint64_t difficulty_to_boundary(wide_difficulty_type difficulty);
void difficulty_to_boundary_long(wide_difficulty_type difficulty, crypto::hash& result);
}

View file

@ -32,7 +32,7 @@ namespace nodetool
const command_line::arg_descriptor<bool> arg_p2p_allow_local_ip ("allow-local-ip", "Allow local ip add to peer list, mostly in debug purposes");
const command_line::arg_descriptor<std::vector<std::string> > arg_p2p_add_peer ("add-peer", "Manually add peer to local peerlist");
const command_line::arg_descriptor<std::vector<std::string> > arg_p2p_add_priority_node ("add-priority-node", "Specify list of peers to connect to and attempt to keep the connection open");
const command_line::arg_descriptor<bool> arg_p2p_use_only_priority_nodes ("use-only-priority-nodes", "Try to connect only to priority nodes");
const command_line::arg_descriptor<bool> arg_p2p_use_only_priority_nodes ("use-only-priority-nodes", "Connect only to priority nodes");
const command_line::arg_descriptor<std::vector<std::string> > arg_p2p_seed_node ("seed-node", "Connect to a node to retrieve peer addresses, and disconnect");
const command_line::arg_descriptor<bool> arg_p2p_hide_my_port ("hide-my-port", "Do not announce yourself as peerlist candidate");
const command_line::arg_descriptor<bool> arg_p2p_offline_mode ( "offline-mode", "Don't connect to any node and reject any connections");
@ -321,11 +321,15 @@ namespace nodetool
ADD_HARDCODED_SEED_NODE("159.69.76.144", P2P_DEFAULT_PORT);
ADD_HARDCODED_SEED_NODE("144.76.183.143", P2P_DEFAULT_PORT);
#else
//TODO:
ADD_HARDCODED_SEED_NODE("95.217.43.225", P2P_DEFAULT_PORT);
ADD_HARDCODED_SEED_NODE("94.130.137.230", P2P_DEFAULT_PORT);
ADD_HARDCODED_SEED_NODE("95.217.42.247", P2P_DEFAULT_PORT);
ADD_HARDCODED_SEED_NODE("94.130.160.115", P2P_DEFAULT_PORT);
// TESTNET
//ADD_HARDCODED_SEED_NODE("95.217.43.225", P2P_DEFAULT_PORT);
//ADD_HARDCODED_SEED_NODE("94.130.137.230", P2P_DEFAULT_PORT);
//ADD_HARDCODED_SEED_NODE("95.217.42.247", P2P_DEFAULT_PORT);
//ADD_HARDCODED_SEED_NODE("94.130.160.115", P2P_DEFAULT_PORT);
// TODO @#@# Here's the only Zarcanum Testnet Pre-Alpha node, update when ready
ADD_HARDCODED_SEED_NODE("95.217.42.247", 22070);
#endif
bool res = handle_command_line(vm);
@ -846,7 +850,7 @@ namespace nodetool
if (m_offline_mode)
return true;
if(!m_peerlist.get_white_peers_count() && m_seed_nodes.size() && !m_priority_peers.size())
if(!m_peerlist.get_white_peers_count() && m_seed_nodes.size() && !m_priority_peers.size() && !m_use_only_priority_peers)
{
size_t try_count = 0;
size_t current_index = crypto::rand<size_t>()%m_seed_nodes.size();

View file

@ -1890,6 +1890,21 @@ void wallet2::transfer(uint64_t amount, const currency::account_public_address&
this->transfer(dst, 0, 0, TX_DEFAULT_FEE, extra, attachments, get_current_split_strategy(), tools::tx_dust_policy(DEFAULT_DUST_THRESHOLD), result_tx);
}
//----------------------------------------------------------------------------------------------------
void wallet2::transfer(uint64_t amount, size_t fake_outs_count, const currency::account_public_address& acc, uint64_t fee /* = TX_DEFAULT_FEE*/,
const crypto::hash& asset_id /* = currency::null_hash */)
{
std::vector<currency::extra_v> extra;
std::vector<currency::attachment_v> attachments;
transaction result_tx = AUTO_VAL_INIT(result_tx);
std::vector<tx_destination_entry> dst;
dst.resize(1);
dst.back().addr.push_back(acc);
dst.back().amount = amount;
dst.back().asset_id = asset_id;
this->transfer(dst, fake_outs_count, 0, fee, extra, attachments, get_current_split_strategy(), tools::tx_dust_policy(DEFAULT_DUST_THRESHOLD), result_tx);
}
//----------------------------------------------------------------------------------------------------
void wallet2::transfer(uint64_t amount, const currency::account_public_address& acc, const crypto::hash& asset_id)
{
transaction result_tx = AUTO_VAL_INIT(result_tx);
@ -4892,15 +4907,16 @@ bool wallet2::prepare_tx_sources(size_t fake_outputs_count, std::vector<currency
if (fake_outputs_count)
{
COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::request req = AUTO_VAL_INIT(req);
req.use_forced_mix_outs = false; //add this feature to UI later
req.decoys_count = fake_outputs_count + 1;// add one to make possible (if need) to skip real output key
req.height_upper_limit = m_last_pow_block_h; // request decoys to be either older than, or the same age as stake output's height
req.use_forced_mix_outs = false; // TODO: add this feature to UI later
req.decoys_count = fake_outputs_count + 1; // one more to be able to skip a decoy in case it hits the real output
for (uint64_t i: selected_indicies)
{
auto it = m_transfers.begin() + i;
WLT_THROW_IF_FALSE_WALLET_INT_ERR_EX(it->m_ptx_wallet_info->m_tx.vout.size() > it->m_internal_output_index,
"m_internal_output_index = " << it->m_internal_output_index <<
" is greater or equal to outputs count = " << it->m_ptx_wallet_info->m_tx.vout.size());
req.amounts.push_back(it->amount());
req.amounts.push_back(it->is_zc() ? 0 : it->m_amount);
}
bool r = m_core_proxy->call_COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS(req, daemon_resp);

View file

@ -573,6 +573,7 @@ namespace tools
uint64_t unlocked_balance() const;
void transfer(uint64_t amount, const currency::account_public_address& acc, const crypto::hash& asset_id = currency::null_hash);
void transfer(uint64_t amount, size_t fake_outs_count, const currency::account_public_address& acc, uint64_t fee = TX_DEFAULT_FEE, const crypto::hash& asset_id = currency::null_hash);
void transfer(uint64_t amount, const currency::account_public_address& acc, currency::transaction& result_tx, const crypto::hash& asset_id = currency::null_hash);
void transfer(const std::vector<currency::tx_destination_entry>& dsts,

View file

@ -21,7 +21,7 @@ namespace
for (size_t i = 0; i < new_block_count; ++i)
{
block blk_next;
wide_difficulty_type diffic = next_difficulty_1(timestamps, cummulative_difficulties, DIFFICULTY_POW_TARGET);
wide_difficulty_type diffic = next_difficulty_1(timestamps, cummulative_difficulties, DIFFICULTY_POW_TARGET, DIFFICULTY_POW_STARTER);
if (!generator.construct_block_manually(blk_next, blk_prev, miner_account,
test_generator::bf_timestamp | test_generator::bf_diffic, 0, 0, blk_prev.timestamp, crypto::hash(), diffic))
return false;
@ -152,7 +152,7 @@ bool gen_block_invalid_nonce::generate(std::vector<test_event_entry>& events) co
return false;
// Create invalid nonce
wide_difficulty_type diffic = next_difficulty_1(timestamps, commulative_difficulties, DIFFICULTY_POW_TARGET);
wide_difficulty_type diffic = next_difficulty_1(timestamps, commulative_difficulties, DIFFICULTY_POW_TARGET, DIFFICULTY_POW_STARTER);
CHECK_AND_ASSERT_MES(diffic > 1, false, "diffic > 1 validation failed");
const block& blk_last = boost::get<block>(events.back());
uint64_t timestamp = blk_last.timestamp;

View file

@ -640,7 +640,14 @@ bool test_generator::find_kernel(const std::list<currency::account_base>& accs,
iterations_processed_total += context.iterations_processed;
}
LOG_PRINT_RED("PoS mining iteration failed, kernel was not found. Iterations processed across " << wallets.size() << " wallet(s): " << iterations_processed_total, LOG_LEVEL_0);
LOG_PRINT_RED("PoS mining iteration failed, kernel was not found. Iterations processed across " << wallets.size() << " wallet(s): " << iterations_processed_total << ENDL <<
"Stake wallet(s) transfers:", LOG_LEVEL_0);
for (size_t wallet_index = 0, size = wallets.size(); wallet_index < size; ++wallet_index)
{
std::shared_ptr<tools::wallet2> w = wallets[wallet_index].wallet;
LOG_PRINT_L0("wallet #" << wallet_index << " @ block " << w->get_top_block_height() << ENDL << wallets[wallet_index].wallet->dump_trunsfers());
}
return false;
}
@ -766,7 +773,7 @@ bool test_generator::get_params_for_next_pos_block(const crypto::hash& head_id,
std::vector<uint64_t> timestamps;
std::vector<wide_difficulty_type> commulative_difficulties;
if (!blocks.size())
return DIFFICULTY_STARTER;
return DIFFICULTY_POW_STARTER;
for (size_t i = blocks.size() - 1; i != 0; --i)
{
@ -775,7 +782,7 @@ bool test_generator::get_params_for_next_pos_block(const crypto::hash& head_id,
timestamps.push_back(blocks[i]->b.timestamp);
commulative_difficulties.push_back(blocks[i]->cumul_difficulty);
}
return next_difficulty_1(timestamps, commulative_difficulties, pow ? DIFFICULTY_POW_TARGET : DIFFICULTY_POS_TARGET);
return next_difficulty_1(timestamps, commulative_difficulties, pow ? global_difficulty_pow_target : global_difficulty_pos_target, pow ? global_difficulty_pow_starter : global_difficulty_pos_starter);
}
currency::wide_difficulty_type test_generator::get_cumul_difficulty_for_next_block(const crypto::hash& head_id, bool pow) const

View file

@ -1083,6 +1083,7 @@ int main(int argc, char* argv[])
GENERATE_AND_PLAY(zarcanum_gen_time_balance);
GENERATE_AND_PLAY(zarcanum_txs_with_big_shuffled_decoy_set_shuffled);
GENERATE_AND_PLAY(zarcanum_pos_block_math);
GENERATE_AND_PLAY(zarcanum_in_alt_chain);
// GENERATE_AND_PLAY(gen_block_reward);
// END OF TESTS */

View file

@ -2769,7 +2769,7 @@ bool premine_wallet_test::generate(std::vector<test_event_entry>& events) const
currency::generate_genesis_block(blk_0_info.b);
blk_0_info.already_generated_coins = get_outs_money_amount(blk_0_info.b.miner_tx);
blk_0_info.block_size = get_object_blobsize(blk_0_info.b.miner_tx);
blk_0_info.cumul_difficulty = DIFFICULTY_STARTER;
blk_0_info.cumul_difficulty = DIFFICULTY_POW_STARTER;
blk_0_info.ks_hash = currency::null_hash;
blk_0_info.m_transactions.clear();
events.push_back(blk_0_info.b);

View file

@ -131,9 +131,10 @@ bool zarcanum_basic_test::c1(currency::core& c, size_t ev_index, const std::vect
CHECK_AND_ASSERT_MES(check_balance_via_wallet(*alice_wlt, "Alice", transfer_amount * batches_to_Alice_count, UINT64_MAX, transfer_amount * batches_to_Alice_count), false, "");
//create transfer from post-zarcanum inputs to post-zarcanum inputs
//create transfer from post-zarcanum inputs to post-zarcanum inputs with mixins
uint64_t transfer_amount2 = AMOUNT_TO_TRANSFER_ZARCANUM_BASIC;
alice_wlt->transfer(transfer_amount2, m_accounts[BOB_ACC_IDX].get_public_address());
size_t nmix = 10;
alice_wlt->transfer(transfer_amount2, nmix, m_accounts[BOB_ACC_IDX].get_public_address());
LOG_PRINT_MAGENTA("Zarcanum-2-zarcanum transaction sent from Alice to Bob " << print_money_brief(transfer_amount2), LOG_LEVEL_0);
@ -432,6 +433,9 @@ bool zarcanum_pos_block_math::generate(std::vector<test_event_entry>& events) co
MAKE_NEXT_BLOCK(events, blk_1, blk_0, miner_acc);
REWIND_BLOCKS_N_WITH_TIME(events, blk_1r, blk_1, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 10);
//std::list<currency::account_base> miner_stake_sources( {miner_acc} );
//MAKE_NEXT_POS_BLOCK(events, blk_2, blk_1r, miner_acc, miner_stake_sources);
// blocks with an invalid zarcanum sig
for(size_t i = 1; ; ++i)
{
@ -467,7 +471,6 @@ bool zarcanum_pos_block_math::generate(std::vector<test_event_entry>& events) co
return true;
}
//------------------------------------------------------------------------------
zarcanum_txs_with_big_shuffled_decoy_set_shuffled::zarcanum_txs_with_big_shuffled_decoy_set_shuffled()
@ -592,3 +595,112 @@ bool zarcanum_txs_with_big_shuffled_decoy_set_shuffled::generate(std::vector<tes
return true;
}
//------------------------------------------------------------------------------
zarcanum_in_alt_chain::zarcanum_in_alt_chain()
{
REGISTER_CALLBACK_METHOD(zarcanum_in_alt_chain, c1);
m_hardforks.set_hardfork_height(ZANO_HARDFORK_04_ZARCANUM, 23);
}
bool zarcanum_in_alt_chain::generate(std::vector<test_event_entry>& events) const
{
bool r = false;
uint64_t ts = test_core_time::get_time();
m_accounts.resize(TOTAL_ACCS_COUNT);
account_base& miner_acc = m_accounts[MINER_ACC_IDX]; miner_acc.generate(); miner_acc.set_createtime(ts);
account_base& alice_acc = m_accounts[ALICE_ACC_IDX]; alice_acc.generate(); alice_acc.set_createtime(ts);
account_base& bob_acc = m_accounts[BOB_ACC_IDX]; bob_acc.generate(); bob_acc.set_createtime(ts);
MAKE_GENESIS_BLOCK(events, blk_0, miner_acc, ts);
DO_CALLBACK(events, "configure_core"); // necessary to set m_hardforks
REWIND_BLOCKS_N_WITH_TIME(events, blk_0r, blk_0, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW);
uint64_t alice_amount = COIN * 100;
MAKE_TX(events, tx_0, miner_acc, alice_acc, alice_amount, blk_0r);
MAKE_NEXT_BLOCK_TX1(events, blk_1, blk_0r, miner_acc, tx_0);
REWIND_BLOCKS_N_WITH_TIME(events, blk_1r, blk_1, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW);
std::list<currency::account_base> alice_stake_sources({ alice_acc });
MAKE_NEXT_POS_BLOCK(events, blk_2, blk_1r, alice_acc, alice_stake_sources);
DO_CALLBACK_PARAMS(events, "check_hardfork_inactive", static_cast<size_t>(ZANO_HARDFORK_04_ZARCANUM));
MAKE_NEXT_BLOCK(events, blk_3, blk_2, miner_acc);
DO_CALLBACK_PARAMS(events, "check_hardfork_active", static_cast<size_t>(ZANO_HARDFORK_04_ZARCANUM));
uint64_t bob_amount = COIN * 100;
MAKE_TX(events, tx_1, miner_acc, bob_acc, bob_amount, blk_3);
MAKE_NEXT_BLOCK_TX1(events, blk_4, blk_3, miner_acc, tx_1);
// HF4
// |
// 0 10 11 21 22 23 | 24 34 35 36 <- blockchain height
// (0 )..(0r)- (1 )..(1r)- !2 !- (3 )- (4 )..(4r)- (5 ) <- main chain
// tx_0 tx_1 \ tx_2
// -!5a!- (6a) <- alt chain
REWIND_BLOCKS_N_WITH_TIME(events, blk_4r, blk_4, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW);
// Bob: move all to miner
MAKE_TX(events, tx_2, bob_acc, miner_acc, bob_amount - TESTS_DEFAULT_FEE, blk_4r);
MAKE_NEXT_BLOCK_TX1(events, blk_5, blk_4r, miner_acc, tx_2);
// now in the main chain Bob has zero coins
// check it
CREATE_TEST_WALLET(bob_wlt, bob_acc, blk_0);
REFRESH_TEST_WALLET_AT_GEN_TIME(events, bob_wlt, blk_5, 3 * CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 5);
CHECK_TEST_WALLET_BALANCE_AT_GEN_TIME(bob_wlt, 0);
// TODO: check PoS mining against already spent key image
std::list<currency::account_base> bob_stake_sources({ bob_acc });
MAKE_NEXT_POS_BLOCK(events, blk_5a, blk_4r, bob_acc, bob_stake_sources);
MAKE_NEXT_BLOCK(events, blk_6a, blk_5a, miner_acc);
DO_CALLBACK_PARAMS(events, "check_top_block", params_top_block(get_block_height(blk_6a), get_block_hash(blk_6a)));
REWIND_BLOCKS_N_WITH_TIME(events, blk_6ar, blk_6a, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW);
DO_CALLBACK(events, "c1");
//MAKE_NEXT_POS_BLOCK(events, blk_7a, blk_5a, miner_acc, miner_stake_sources);
return true;
}
bool zarcanum_in_alt_chain::c1(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events)
{
bool r = false;
std::shared_ptr<tools::wallet2> alice_wlt = init_playtime_test_wallet(events, c, ALICE_ACC_IDX);
alice_wlt->refresh();
std::shared_ptr<tools::wallet2> bob_wlt = init_playtime_test_wallet(events, c, BOB_ACC_IDX);
bob_wlt->refresh();
CHECK_AND_FORCE_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool");
uint64_t stub = 0;
uint64_t alice_balance_before = alice_wlt->balance(stub);
uint64_t bob_balance_before = bob_wlt->balance(stub);
uint64_t transfer_amount = COIN;
uint64_t transfer_fee = TESTS_DEFAULT_FEE * 3;
size_t nmix = 38;
bob_wlt->transfer(transfer_amount, nmix, m_accounts[ALICE_ACC_IDX].get_public_address(), transfer_fee);
CHECK_AND_FORCE_ASSERT_MES(c.get_pool_transactions_count() == 2, false, "Incorrect txs count in the pool");
r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c);
CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed");
CHECK_AND_FORCE_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool");
alice_wlt->refresh();
CHECK_AND_ASSERT_MES(check_balance_via_wallet(*alice_wlt, "Alice", alice_balance_before + transfer_amount ), false, "");
bob_wlt->refresh();
CHECK_AND_ASSERT_MES(check_balance_via_wallet(*bob_wlt, "Bob", bob_balance_before - transfer_amount- transfer_fee), false, "");
return true;
}

View file

@ -38,4 +38,10 @@ struct zarcanum_txs_with_big_shuffled_decoy_set_shuffled : public wallet_test
bool generate(std::vector<test_event_entry>& events) const;
};
struct zarcanum_in_alt_chain : public wallet_test
{
zarcanum_in_alt_chain();
bool generate(std::vector<test_event_entry>& events) const;
bool c1(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
};