Skip to content

Commit

Permalink
Merge pull request #221 from VanGrx/develop
Browse files Browse the repository at this point in the history
Testnet 6.3 changes
  • Loading branch information
VanGrx authored Apr 22, 2020
2 parents 8561adf + 448eaa1 commit b9dbd21
Show file tree
Hide file tree
Showing 16 changed files with 797 additions and 121 deletions.
32 changes: 26 additions & 6 deletions src/blockchain_db/lmdb/db_lmdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3132,6 +3132,8 @@ output_data_t BlockchainLMDB::get_output_key(const uint64_t& amount, const uint6
if (result == MDB_SUCCESS)
{
output = parse_output_advanced_data_from_mdb(value_blob);
if(output.output_type != static_cast<uint64_t>(output_type))
throw0(DB_ERROR(lmdb_error("Attemting to get keys from output with ID " + std::to_string(output_id) + " for type "+ std::to_string(static_cast<uint64_t>(output_type)) + " but not found: ", result).c_str()));
}
else if (result == MDB_NOTFOUND)
throw0(DB_ERROR(lmdb_error("Attemting to get keys from output with ID " + std::to_string(output_id) + " but not found: ", result).c_str()));
Expand Down Expand Up @@ -5044,7 +5046,10 @@ bool BlockchainLMDB::is_valid_transaction_output_type(const txout_target_v &txou

current = parse_output_advanced_data_from_mdb(value_blob);

if(parse_and_validate_object_from_blob<safex::create_offer_data>(current.data, restored_sfx_offer_create)){
if(current.output_type == static_cast<uint64_t>(tx_out_type::out_safex_offer)){

parse_and_validate_object_from_blob<safex::create_offer_data>(current.data, restored_sfx_offer_create);

if(sfx_offer.offer_id == restored_sfx_offer_create.offer_id) {
sfx_offer.quantity = restored_sfx_offer_create.quantity;
sfx_offer.price = restored_sfx_offer_create.price;
Expand All @@ -5057,7 +5062,10 @@ bool BlockchainLMDB::is_valid_transaction_output_type(const txout_target_v &txou
return;
}
}
else if(parse_and_validate_object_from_blob<safex::edit_offer_data>(current.data, restored_sfx_offer_update)){
else if(current.output_type == static_cast<uint64_t>(tx_out_type::out_safex_offer_update)){

parse_and_validate_object_from_blob<safex::edit_offer_data>(current.data, restored_sfx_offer_update);

if(sfx_offer.offer_id == restored_sfx_offer_update.offer_id) {
sfx_offer.quantity = restored_sfx_offer_update.quantity;
sfx_offer.price = restored_sfx_offer_update.price;
Expand Down Expand Up @@ -5104,7 +5112,10 @@ bool BlockchainLMDB::is_valid_transaction_output_type(const txout_target_v &txou

current = parse_output_advanced_data_from_mdb(value_blob);

if(parse_and_validate_object_from_blob<safex::create_price_peg_data>(current.data, restored_sfx_price_peg_create)){
if(current.output_type == static_cast<uint64_t>(tx_out_type::out_safex_price_peg)){

parse_and_validate_object_from_blob<safex::create_price_peg_data>(current.data, restored_sfx_price_peg_create);

if(sfx_price_peg.price_peg_id == restored_sfx_price_peg_create.price_peg_id) {
sfx_price_peg.creator = restored_sfx_price_peg_create.creator;
sfx_price_peg.rate = restored_sfx_price_peg_create.rate;
Expand All @@ -5114,7 +5125,10 @@ bool BlockchainLMDB::is_valid_transaction_output_type(const txout_target_v &txou
return;
}
}
else if(parse_and_validate_object_from_blob<safex::update_price_peg_data>(current.data, restored_sfx_price_peg_update)){
else if(current.output_type == static_cast<uint64_t>(tx_out_type::out_safex_price_peg_update)){

parse_and_validate_object_from_blob<safex::update_price_peg_data>(current.data, restored_sfx_price_peg_update);

if(sfx_price_peg.price_peg_id == restored_sfx_price_peg_update.price_peg_id) {
sfx_price_peg.rate = restored_sfx_price_peg_update.rate;
return;
Expand Down Expand Up @@ -5355,13 +5369,19 @@ bool BlockchainLMDB::is_valid_transaction_output_type(const txout_target_v &txou

current = parse_output_advanced_data_from_mdb(value_blob);

if (parse_and_validate_object_from_blob<safex::create_account_data>(current.data, restored_sfx_account_create)) {
if(current.output_type == static_cast<uint64_t>(tx_out_type::out_safex_account)){

parse_and_validate_object_from_blob<safex::create_account_data>(current.data, restored_sfx_account_create);

if (sfx_account.username == restored_sfx_account_create.username) {
sfx_account.account_data = restored_sfx_account_create.account_data;
return;
}
}
else if (parse_and_validate_object_from_blob<safex::edit_account_data>(current.data, restored_sfx_account_update)){
else if(current.output_type == static_cast<uint64_t>(tx_out_type::out_safex_account_update)){

parse_and_validate_object_from_blob<safex::edit_account_data>(current.data, restored_sfx_account_update);

sfx_account.account_data = restored_sfx_account_update.account_data;
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/checkpoints/checkpoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ namespace cryptonote
if (nettype == TESTNET)
{
ADD_CHECKPOINT(1, "753e1454ebc44ffb18d7b390f7393a66ce7f3a8aaaf1e4e857af9df4e80d5784");
ADD_CHECKPOINT(185120,"e20c0cb90538e3fefb4e2ef4c7895dbe0747075c4900f476288ea8217a2309b6");
ADD_CHECKPOINT(100000,"f3b4a9e3c8fdc040cd78eb108910f1e24d5190cc4539b3cebd4f80aa686e6291");

return true;
}
Expand Down
13 changes: 13 additions & 0 deletions src/cryptonote_basic/cryptonote_basic.h
Original file line number Diff line number Diff line change
Expand Up @@ -552,11 +552,24 @@ namespace cryptonote
{
switch (txin.command_type) {
case safex::command_t::donate_network_fee:
case safex::command_t::simple_purchase:
return tx_out_type::out_cash;
case safex::command_t::token_stake:
return tx_out_type::out_token;
case safex::command_t::token_unstake:
return tx_out_type::out_staked_token;
case safex::command_t::create_account:
return tx_out_type::out_token;
case safex::command_t::edit_account:
case safex::command_t::create_offer:
case safex::command_t::create_price_peg:
return tx_out_type::out_safex_account;
case safex::command_t::edit_offer:
return tx_out_type::out_safex_offer;
case safex::command_t::update_price_peg:
return tx_out_type::out_safex_price_peg;
case safex::command_t::create_feedback:
return tx_out_type::out_safex_feedback_token;
case safex::command_t::nop:
default:
return tx_out_type::out_invalid;
Expand Down
2 changes: 1 addition & 1 deletion src/cryptonote_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ namespace config
std::string const GENESIS_TX = "013c01ff00018080a8ec85afd1b1010002d4372ec2272690ccd59880807d1fa00f7bd2fa67f7abb350cafbdc24a4ba372c8301011a1ca7d7e74037e4d000a0fc2cc61389ac7d8b0a6b600c62e77374477c4c414d1103a83b4a507df5b0dc5af701078828a1372d77761339a28a7ebb1ff450622f7456d1083f35430eba3353a9e42514480a0cbccbda5ee6abb2d856f8a9aae056a92a6ece1020496a36a4b68341e3b401653139683f8dc27d76ff9eb9c26c2528c26a";
uint32_t const GENESIS_NONCE = 10003;
uint64_t const HARDFORK_V4_INIT_DIFF = 6000;
uint64_t const HARDFORK_V4_START_HEIGHT = 185120;
uint64_t const HARDFORK_V4_START_HEIGHT = 100000;
}

namespace stagenet
Expand Down
61 changes: 41 additions & 20 deletions src/cryptonote_core/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ bool Blockchain::scan_outputkeys_for_indexes<Blockchain::outputs_generic_visitor
output_type = tx_out_type::out_safex_account;
break;
case safex::command_t::edit_offer:
output_type = tx_out_type::out_safex_account;
output_type = tx_out_type::out_safex_offer;
break;
case safex::command_t::simple_purchase:
//TODO: Check and set correct value
Expand All @@ -364,7 +364,7 @@ bool Blockchain::scan_outputkeys_for_indexes<Blockchain::outputs_generic_visitor
output_type = tx_out_type::out_safex_account;
break;
case safex::command_t::update_price_peg:
output_type = tx_out_type::out_safex_account;
output_type = tx_out_type::out_safex_price_peg;
break;
default:
MERROR_VER("Unknown command type");
Expand All @@ -383,6 +383,8 @@ bool Blockchain::scan_outputkeys_for_indexes<Blockchain::outputs_generic_visitor
case tx_out_type::out_staked_token:
case tx_out_type::out_safex_account:
case tx_out_type::out_safex_feedback_token:
case tx_out_type::out_safex_offer:
case tx_out_type::out_safex_price_peg:
{
absolute_offsets = txin.key_offsets;
break;
Expand Down Expand Up @@ -521,7 +523,9 @@ bool Blockchain::scan_outputkeys_for_indexes<Blockchain::outputs_generic_visitor
else if ((output_type == tx_out_type::out_staked_token)
|| (output_type == tx_out_type::out_network_fee)
|| (output_type == tx_out_type::out_safex_account)
|| (output_type == tx_out_type::out_safex_feedback_token)) {
|| (output_type == tx_out_type::out_safex_feedback_token)
|| (output_type == tx_out_type::out_safex_offer)
|| (output_type == tx_out_type::out_safex_price_peg)) {

std::vector<output_advanced_data_t> outputs;
bool found = false;
Expand Down Expand Up @@ -961,6 +965,7 @@ block Blockchain::pop_block_from_blockchain()

m_blocks_longhash_table.clear();
m_scan_table.clear();
m_scan_table_adv.clear();
m_blocks_txs_check.clear();
m_check_txin_table.clear();

Expand Down Expand Up @@ -3353,6 +3358,13 @@ bool Blockchain::check_safex_tx(const transaction &tx, tx_verification_context &
crypto::secret_key secret_seller_view_key;
crypto::public_key public_seller_spend_key;

if (tx.unlock_time > m_db->height())
{
MERROR("Purchase TX should not be locked");
tvc.m_safex_invalid_input = true;
return false;
}

for (const auto &vout: tx.vout) {
if (vout.target.type() == typeid(txout_to_script) && get_tx_out_type(vout.target) == cryptonote::tx_out_type::out_safex_purchase)
{
Expand Down Expand Up @@ -4216,14 +4228,7 @@ bool Blockchain::check_tx_input_generic(size_t tx_version, const T& txin, const
CHECK_AND_ASSERT_MES(sig.size() == output_keys.size(), false, "internal error: tx signatures count=" << sig.size() << " mismatch with outputs keys count for inputs=" << output_keys.size());
return true;
}
//TODO: GRKI Add this where needed
//
// std::vector<rct::ctkey >& m_output_keys;
// const Blockchain& m_bch;
// outputs_visitor(std::vector<rct::ctkey>& output_keys, const Blockchain& bch) :
// m_output_keys(output_keys), m_bch(bch)
// {
// }

//
// bool get_pwned(const public_key &key)
// {
Expand Down Expand Up @@ -4356,14 +4361,6 @@ bool Blockchain::check_tx_input_generic(size_t tx_version, const T& txin, const
// return false;
// }
//
// bool handle_output(uint64_t unlock_time, const crypto::public_key &pubkey, const rct::key &commitment)
// {
// //check tx unlock time
// if (!m_bch.is_tx_spendtime_unlocked(unlock_time))
// {
// MERROR_VER("One of outputs for one of inputs has wrong tx.unlock_time = " << unlock_time);
// return false;
// }
//
//
//
Expand Down Expand Up @@ -5131,6 +5128,7 @@ bool Blockchain::cleanup_handle_incoming_blocks(bool force_sync)
TIME_MEASURE_FINISH(t1);
m_blocks_longhash_table.clear();
m_scan_table.clear();
m_scan_table_adv.clear();
m_blocks_txs_check.clear();
m_check_txin_table.clear();

Expand Down Expand Up @@ -5444,6 +5442,7 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::list<block_complete_e
m_fake_pow_calc_time = 0;

m_scan_table.clear();
m_scan_table_adv.clear();
m_check_txin_table.clear();

TIME_MEASURE_FINISH(prepare);
Expand All @@ -5461,6 +5460,8 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::list<block_complete_e
// [output] stores all output_data_t for each absolute_offset
std::map<std::pair<tx_out_type, uint64_t>, std::vector<output_data_t>> tx_map;

std::set<tx_out_type> types;

// [input] store all found advanced output types and vector of their output ids
std::map<tx_out_type, std::vector<uint64_t>> advanced_output_ids_map;
// [output] stores all output_advanced_data_t for each tx_out_type
Expand All @@ -5470,6 +5471,7 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::list<block_complete_e
do { \
MERROR_VER(m) ;\
m_scan_table.clear(); \
m_scan_table_adv.clear(); \
return false; \
} while(0); \

Expand All @@ -5496,6 +5498,15 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::list<block_complete_e
its = m_scan_table.find(tx_prefix_hash);
assert(its != m_scan_table.end());

auto its_advanced = m_scan_table_adv.find(tx_prefix_hash);
if (its_advanced != m_scan_table_adv.end())
SCAN_TABLE_QUIT("Duplicate advanced tx found from incoming blocks.");

m_scan_table_adv.emplace(tx_prefix_hash, std::unordered_map<crypto::key_image, std::vector<output_advanced_data_t>>());
its_advanced = m_scan_table_adv.find(tx_prefix_hash);
assert(its_advanced != m_scan_table_adv.end());


// get all amounts from tx.vin(s)
for (const auto &txin : tx.vin)
{
Expand All @@ -5506,6 +5517,10 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::list<block_complete_e
if (it != its->second.end())
SCAN_TABLE_QUIT("Duplicate key_image found from incoming blocks.");

auto it_advanced = its_advanced->second.find(k_image);
if (it_advanced != its_advanced->second.end())
SCAN_TABLE_QUIT("Duplicate advanced key_image found from incoming blocks.");

const tx_out_type output_type = boost::apply_visitor(tx_output_type_visitor(), txin);
if (output_type == tx_out_type::out_cash || output_type == tx_out_type::out_token)
{
Expand All @@ -5514,7 +5529,7 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::list<block_complete_e
}
else
{
//nothing to do here for advanced outputs
types.insert(output_type);

}
}
Expand All @@ -5534,6 +5549,12 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::list<block_complete_e
tx_map.emplace(amount, std::vector<output_data_t>());
}

for(auto type: types)
{
if(tx_advanced_map.find(type)== tx_advanced_map.end())
tx_advanced_map.emplace(type, std::vector<output_advanced_data_t>());
}

// add new absolute_offsets to offset_map
for (const auto &txin : tx.vin)
{
Expand Down
Loading

0 comments on commit b9dbd21

Please sign in to comment.