LNS: Allow multi-year registration for lokinet entries

This commit is contained in:
Doyle 2020-02-14 17:04:29 +11:00
parent 8aacc33fb1
commit cbc0740f43
11 changed files with 169 additions and 180 deletions

View File

@ -66,15 +66,20 @@ namespace lns
{
enum struct mapping_type : uint16_t
{
session = 0,
wallet = 1,
lokinet = 2,
session,
wallet,
lokinet_1year,
lokinet_2years,
lokinet_5years,
lokinet_10years,
_count,
update_record_internal,
};
enum struct tx_command_t : uint8_t
{
buy = 0,
update = 1,
buy,
update,
_count,
};
};

View File

@ -200,11 +200,10 @@ static bool sql_run_statement(cryptonote::network_type nettype, lns_sql_type typ
bool mapping_record::active(cryptonote::network_type nettype, uint64_t blockchain_height) const
{
if (!loaded) return false;
if (type != mapping_type::lokinet) return true;
uint64_t expiry_blocks = lns::lokinet_expiry_blocks(nettype);
uint64_t const last_active_height = register_height + expiry_blocks;
return last_active_height >= (blockchain_height - 1);
if (!loaded) return false;
uint64_t expiry_blocks = lns::expiry_blocks(nettype, static_cast<lns::mapping_type>(type));
uint64_t const last_active_height = expiry_blocks == NO_EXPIRY ? NO_EXPIRY : (register_height + expiry_blocks);
return last_active_height >= (blockchain_height - 1);
}
static bool sql_compile_statement(sqlite3 *db, char const *query, int query_len, sqlite3_stmt **statement, bool optimise_for_multiple_usage = true)
@ -220,34 +219,25 @@ static bool sql_compile_statement(sqlite3 *db, char const *query, int query_len,
return result;
}
burn_type mapping_type_to_burn_type(mapping_type in)
{
burn_type result = burn_type::custom;
switch (in)
{
case mapping_type::lokinet: result = burn_type::lokinet_1year; break;
case mapping_type::session: result = burn_type::session; break;
case mapping_type::wallet: result = burn_type::wallet; break;
default: break;
}
return result;
}
uint64_t burn_requirement_in_atomic_loki(uint8_t /*hf_version*/, burn_type type)
uint64_t burn_requirement_in_atomic_loki(uint8_t /*hf_version*/, mapping_type type)
{
uint64_t result = 0;
switch (type)
{
case burn_type::update_record:
case mapping_type::update_record_internal:
result = 0;
break;
case burn_type::lokinet_1year: /* FALLTHRU */
case burn_type::session: /* FALLTHRU */
case burn_type::wallet: /* FALLTHRU */
case burn_type::custom: /* FALLTHRU */
default: result = 30 * COIN;
case mapping_type::lokinet_1year: /* FALLTHRU */
case mapping_type::session: /* FALLTHRU */
case mapping_type::wallet: /* FALLTHRU */
default:
result = 20 * COIN;
break;
case mapping_type::lokinet_2years: result = 40 * COIN; break;
case mapping_type::lokinet_5years: result = 80 * COIN; break;
case mapping_type::lokinet_10years: result = 120 * COIN; break;
}
return result;
}
@ -272,19 +262,30 @@ sqlite3 *init_loki_name_system(char const *file_path)
return result;
}
uint64_t lokinet_expiry_blocks(cryptonote::network_type nettype, uint64_t *renew_window)
uint64_t expiry_blocks(cryptonote::network_type nettype, mapping_type type, uint64_t *renew_window)
{
uint64_t renew_window_ = BLOCKS_EXPECTED_IN_DAYS(31);
uint64_t result = BLOCKS_EXPECTED_IN_YEARS(1) + renew_window_;
if (nettype == cryptonote::FAKECHAIN)
uint64_t renew_window_ = 0;
uint64_t result = NO_EXPIRY;
if (is_lokinet_type(type))
{
renew_window_ = 10;
result = 10 + renew_window_;
}
else if (nettype == cryptonote::TESTNET)
{
renew_window_ = BLOCKS_EXPECTED_IN_DAYS(1);
result = BLOCKS_EXPECTED_IN_DAYS(1) + renew_window_;
renew_window_ = BLOCKS_EXPECTED_IN_DAYS(31);
if (type == mapping_type::lokinet_1year) result = BLOCKS_EXPECTED_IN_YEARS(1);
else if (type == mapping_type::lokinet_2years) result = BLOCKS_EXPECTED_IN_YEARS(2);
else if (type == mapping_type::lokinet_5years) result = BLOCKS_EXPECTED_IN_YEARS(5);
else if (type == mapping_type::lokinet_10years) result = BLOCKS_EXPECTED_IN_YEARS(10);
result += renew_window_;
if (nettype == cryptonote::FAKECHAIN)
{
renew_window_ = 10;
result = 10 + renew_window_;
}
else if (nettype == cryptonote::TESTNET)
{
renew_window_ = BLOCKS_EXPECTED_IN_DAYS(1);
result = BLOCKS_EXPECTED_IN_DAYS(1) + renew_window_;
}
}
if (renew_window) *renew_window = renew_window_;
@ -337,7 +338,7 @@ bool validate_lns_name(mapping_type type, std::string const &name, std::string *
size_t max_name_len = lns::GENERIC_NAME_MAX;
if (type == mapping_type::session) max_name_len = lns::SESSION_DISPLAY_NAME_MAX;
else if (type == mapping_type::wallet) max_name_len = lns::WALLET_NAME_MAX;
else if (type == mapping_type::lokinet) max_name_len = lns::LOKINET_DOMAIN_NAME_MAX;
else if (is_lokinet_type(type)) max_name_len = lns::LOKINET_DOMAIN_NAME_MAX;
// NOTE: Validate name length
if (name.empty() || name.size() > max_name_len)
@ -353,7 +354,7 @@ bool validate_lns_name(mapping_type type, std::string const &name, std::string *
if (type == mapping_type::session)
{
}
else if (type == mapping_type::lokinet)
else if (is_lokinet_type(type))
{
// Domain has to start with a letter or digit, and can have letters, digits, or hyphens in between and must end with a .loki
// ^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.loki$
@ -484,7 +485,7 @@ bool validate_lns_value(cryptonote::network_type nettype, mapping_type type, std
{
int max_value_len = lns::GENERIC_VALUE_MAX;
bool value_require_exact_len = true;
if (type == mapping_type::lokinet) max_value_len = (LOKINET_ADDRESS_BINARY_LENGTH * 2);
if (is_lokinet_type(type)) max_value_len = (LOKINET_ADDRESS_BINARY_LENGTH * 2);
else if (type == mapping_type::session) max_value_len = (SESSION_PUBLIC_KEY_BINARY_LENGTH * 2);
else value_require_exact_len = false;
@ -500,7 +501,7 @@ bool validate_lns_value(cryptonote::network_type nettype, mapping_type type, std
memcpy(blob->buffer.data(), &addr_info.address, blob->len);
}
}
else if (type == mapping_type::lokinet)
else if (is_lokinet_type(type))
{
if (value.size() != 52)
{
@ -582,7 +583,7 @@ bool validate_lns_value_binary(mapping_type type, std::string const &value, std:
{
int max_value_len = lns::GENERIC_VALUE_MAX;
bool value_require_exact_len = true;
if (type == mapping_type::lokinet) max_value_len = LOKINET_ADDRESS_BINARY_LENGTH;
if (is_lokinet_type(type)) max_value_len = LOKINET_ADDRESS_BINARY_LENGTH;
else if (type == mapping_type::session) max_value_len = SESSION_PUBLIC_KEY_BINARY_LENGTH;
else if (type == mapping_type::wallet) max_value_len = sizeof(cryptonote::account_public_address);
else value_require_exact_len = false;
@ -641,11 +642,10 @@ static bool validate_against_previous_mapping(lns::name_system_db const &lns_db,
if (mapping)
{
expected_prev_txid = mapping.txid;
if (updating)
if (updating) // We can always update unless the mapping has expired
{
if (data.type == lns::mapping_type::lokinet && !mapping.active(lns_db.network_type(), blockchain_height))
if (!mapping.active(lns_db.network_type(), blockchain_height))
{
// Updating, we can always update unless the mapping has expired
if (reason)
{
err_stream << tx << ", " << data << ", TX requested to update mapping that has already expired";
@ -682,7 +682,7 @@ static bool validate_against_previous_mapping(lns::name_system_db const &lns_db,
}
else
{
if (data.type != lns::mapping_type::lokinet)
if (!is_lokinet_type(data.type))
{
if (reason)
{
@ -694,7 +694,7 @@ static bool validate_against_previous_mapping(lns::name_system_db const &lns_db,
}
uint64_t renew_window = 0;
uint64_t expiry_blocks = lns::lokinet_expiry_blocks(lns_db.network_type(), &renew_window);
uint64_t expiry_blocks = lns::expiry_blocks(lns_db.network_type(), data.type, &renew_window);
uint64_t const renew_window_offset = expiry_blocks - renew_window;
uint64_t const min_renew_height = mapping.register_height + renew_window_offset;
@ -812,16 +812,16 @@ bool name_system_db::validate_lns_tx(uint8_t hf_version, uint64_t blockchain_hei
if (!validate_against_previous_mapping(*this, blockchain_height, tx, *entry, reason))
return false;
uint64_t burn = cryptonote::get_burned_amount_from_tx_extra(tx.extra);
uint64_t const burn_required = entry->command == lns::tx_command_t::buy
? burn_requirement_in_atomic_loki(hf_version, mapping_type_to_burn_type(entry->type))
: 0;
const bool updating = entry->command == lns::tx_command_t::update;
uint64_t burn = cryptonote::get_burned_amount_from_tx_extra(tx.extra);
uint64_t burn_required = updating ? 0 : burn_requirement_in_atomic_loki(hf_version, static_cast<lns::mapping_type>(entry->type));
if (burn != burn_required)
{
if (reason)
{
char const *over_or_under = burn > burn_required ? "too much " : "insufficient ";
err_stream << tx << ", " << *entry << ", burned " << over_or_under << "loki=" << burn << ", require=" << burn_required;
if (updating) err_stream << ", updating requires just the ordinary transaction fee";
*reason = err_stream.str();
}
return false;
@ -830,49 +830,30 @@ bool name_system_db::validate_lns_tx(uint8_t hf_version, uint64_t blockchain_hei
return true;
}
bool validate_mapping_type(std::string const &type, lns::mapping_type *mapping_type, std::string *reason)
static std::string lowercase_string(std::string const &src)
{
std::string type_lowered = type;
for (char &ch : type_lowered)
std::string result = src;
for (char &ch : result)
{
if (ch >= 'A' && ch <= 'Z')
ch = ch + ('a' - 'A');
}
return result;
}
lns::mapping_type mapping_type_ = lns::mapping_type::session;
if (type_lowered == "session") mapping_type_ = lns::mapping_type::session;
bool validate_mapping_type(std::string const &mapping_type_str, lns::mapping_type *mapping_type, std::string *reason)
{
std::string mapping = lowercase_string(mapping_type_str);
lns::mapping_type mapping_type_;
if (mapping == "session") mapping_type_ = lns::mapping_type::session;
else
{
try
{
size_t value = std::stoul(type_lowered);
if (value > tools::enum_count<lns::mapping_type>)
{
if (reason) *reason = "LNS type specifies value too large, must be from [0-" + std::to_string(tools::enum_count<lns::mapping_type>) + "): " + std::to_string(value);
return false;
}
mapping_type_ = static_cast<lns::mapping_type>(value);
}
catch (std::exception const &)
{
if (reason)
{
*reason = "Failed to convert lns mapping (was not proper integer, or not one of the recognised: \"session\"), string was";
if (type.empty())
{
*reason += " empty.";
}
else
{
*reason += "=";
*reason += type;
}
}
return false;
}
if (reason) *reason = "Failed to convert lns mapping (was not proper integer, or not one of the recognised: \"session\"), string was=" + mapping_type_str;
return false;
}
if (mapping_type) *mapping_type = mapping_type_;
if (mapping_type) *mapping_type = static_cast<lns::mapping_type>(mapping_type_);
return true;
}
@ -1275,6 +1256,8 @@ std::vector<mapping_record> name_system_db::get_mappings(std::vector<uint16_t> c
{
std::string sql_statement;
// Generate string statement
if (types.size())
{
char constexpr SQL_PREFIX[] = R"(SELECT * FROM "mappings" JOIN "owner" ON "mappings"."owner_id" = "owner"."id" WHERE "name" = ? AND "type" in ()";
char constexpr SQL_SUFFIX[] = R"())";
@ -1289,6 +1272,10 @@ std::vector<mapping_record> name_system_db::get_mappings(std::vector<uint16_t> c
stream << SQL_SUFFIX;
sql_statement = stream.str();
}
else
{
sql_statement = R"(SELECT * FROM "mappings" JOIN "owner" ON "mappings"."owner_id" = "owner"."id" WHERE "name" = ?)";
}
// Compile Statement
std::vector<mapping_record> result;

View File

@ -37,40 +37,37 @@ struct lns_value
size_t len;
};
enum struct burn_type
{
none,
update_record,
lokinet_1year,
session,
wallet,
custom,
};
inline std::ostream &operator<<(std::ostream &os, mapping_type type)
{
switch(type)
{
case mapping_type::lokinet: os << "lokinet"; break;
case mapping_type::session: os << "session"; break;
case mapping_type::wallet: os << "wallet"; break;
default: assert(false); os << "xx_unhandled_type"; break;
case mapping_type::lokinet_1year: os << "lokinet_1year"; break;
case mapping_type::lokinet_2years: os << "lokinet_2years"; break;
case mapping_type::lokinet_5years: os << "lokinet_5years"; break;
case mapping_type::lokinet_10years: os << "lokinet_10years"; break;
case mapping_type::session: os << "session"; break;
case mapping_type::wallet: os << "wallet"; break;
default: assert(false); os << "xx_unhandled_type"; break;
}
return os;
}
constexpr bool mapping_type_allowed(uint8_t hf_version, mapping_type type) { return type == mapping_type::session; }
burn_type mapping_type_to_burn_type(mapping_type in);
uint64_t burn_requirement_in_atomic_loki(uint8_t hf_version, burn_type type);
constexpr bool is_lokinet_type (lns::mapping_type type) { return type >= mapping_type::lokinet_1year && type <= mapping_type::lokinet_10years; }
uint64_t burn_requirement_in_atomic_loki(uint8_t hf_version, mapping_type type);
sqlite3 *init_loki_name_system(char const *file_path);
uint64_t lokinet_expiry_blocks(cryptonote::network_type nettype, uint64_t *renew_window = nullptr);
uint64_t constexpr NO_EXPIRY = static_cast<uint64_t>(-1);
// return: The number of blocks until expiry from the registration height, if there is no expiration NO_EXPIRY is returned.
uint64_t expiry_blocks(cryptonote::network_type nettype, mapping_type type, uint64_t *renew_window = nullptr);
crypto::hash tx_extra_signature_hash(epee::span<const uint8_t> blob, crypto::hash const &prev_txid);
bool validate_lns_name(mapping_type type, std::string const &name, std::string *reason = nullptr);
// blob: if set, validate_lns_value will convert the value into the binary format suitable for storing into the LNS DB.
bool validate_lns_value(cryptonote::network_type nettype, mapping_type type, std::string const &value, lns_value *blob = nullptr, std::string *reason = nullptr);
bool validate_lns_value_binary(mapping_type type, std::string const &value, std::string *reason = nullptr);
bool validate_mapping_type(std::string const &type, lns::mapping_type *mapping_type, std::string *reason);
bool validate_mapping_type(std::string const &mapping_type_str, lns::mapping_type *mapping_type, std::string *reason);
struct owner_record
{
@ -102,7 +99,7 @@ struct mapping_record
operator bool() const { return loaded; }
bool loaded;
mapping_type type; // alias to lns::mapping_type
mapping_type type;
std::string name;
std::string value;
uint64_t register_height;
@ -119,7 +116,7 @@ struct name_system_db
void block_detach(cryptonote::Blockchain const &blockchain, uint64_t height);
uint64_t height () { return last_processed_height; }
bool save_owner (crypto::ed25519_public_key const &key, int64_t *row_id);
bool save_owner (crypto::ed25519_public_key const &key, int64_t *row_id);
bool save_mapping (crypto::hash const &tx_hash, cryptonote::tx_extra_loki_name_system const &src, uint64_t height, int64_t owner_id);
bool save_settings (uint64_t top_height, crypto::hash const &top_hash, int version);

View File

@ -3346,7 +3346,7 @@ namespace cryptonote
static std::string extract_lns_mapping_value(lns::mapping_record const &record)
{
std::string result;
if (static_cast<lns::mapping_type>(record.type) == lns::mapping_type::lokinet)
if (lns::is_lokinet_type(record.type))
{
char buf[64] = {};
base32z::encode(record.value, buf);

View File

@ -3427,7 +3427,7 @@ constexpr char const CORE_RPC_STATUS_TX_LONG_POLL_MAX_CONNECTIONS[] = "Daemon ma
struct request_entry
{
std::string name; // The name to resolve to a public key via Loki Name Service
std::vector<uint16_t> types; // Set 0 for Session. In future updates more mapping types will be available.
std::vector<uint16_t> types; // If empty, query all types. Currently only Session(0). In future updates more mapping types will be available.
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(name)
KV_SERIALIZE(types)

View File

@ -6596,9 +6596,12 @@ bool simple_wallet::print_lns_name_to_owners(const std::vector<std::string>& arg
cryptonote::COMMAND_RPC_GET_LNS_NAMES_TO_OWNERS::request_entry &entry = request.entries.back();
if (entry.types.empty())
{
entry.types.push_back(static_cast<uint16_t>(lns::mapping_type::wallet));
entry.types.push_back(static_cast<uint16_t>(lns::mapping_type::lokinet));
entry.types.push_back(static_cast<uint16_t>(lns::mapping_type::session));
entry.types.push_back(static_cast<uint16_t>(lns::mapping_type::wallet));
entry.types.push_back(static_cast<uint16_t>(lns::mapping_type::lokinet_1year));
entry.types.push_back(static_cast<uint16_t>(lns::mapping_type::lokinet_2years));
entry.types.push_back(static_cast<uint16_t>(lns::mapping_type::lokinet_5years));
entry.types.push_back(static_cast<uint16_t>(lns::mapping_type::lokinet_10years));
}
boost::optional<std::string> failed;

View File

@ -7558,7 +7558,7 @@ uint64_t wallet2::get_fee_quantization_mask() const
return fee_quantization_mask;
}
loki_construct_tx_params wallet2::construct_params(uint8_t hf_version, txtype tx_type, uint32_t priority, lns::burn_type lns_burn_type)
loki_construct_tx_params wallet2::construct_params(uint8_t hf_version, txtype tx_type, uint32_t priority, lns::mapping_type type)
{
loki_construct_tx_params tx_params;
tx_params.hf_version = hf_version;
@ -7567,7 +7567,7 @@ loki_construct_tx_params wallet2::construct_params(uint8_t hf_version, txtype tx
if (tx_type == txtype::loki_name_system)
{
assert(priority != tools::tx_priority_blink);
tx_params.burn_fixed = lns::burn_requirement_in_atomic_loki(hf_version, lns_burn_type);
tx_params.burn_fixed = lns::burn_requirement_in_atomic_loki(hf_version, type);
}
else if (priority == tools::tx_priority_blink)
{
@ -8523,8 +8523,8 @@ std::vector<wallet2::pending_tx> wallet2::create_buy_lns_mapping_tx(lns::mapping
if (reason) *reason = ERR_MSG_NETWORK_VERSION_QUERY_FAILED;
return {};
}
loki_construct_tx_params tx_params = wallet2::construct_params(*hf_version, txtype::loki_name_system, priority, lns::mapping_type_to_burn_type(static_cast<lns::mapping_type>(type)));
loki_construct_tx_params tx_params = wallet2::construct_params(*hf_version, txtype::loki_name_system, priority, type);
auto result = create_transactions_2({} /*dests*/,
CRYPTONOTE_DEFAULT_TX_MIXIN,
0 /*unlock_at_block*/,
@ -8549,7 +8549,7 @@ std::vector<wallet2::pending_tx> wallet2::create_buy_lns_mapping_tx(std::string
if (!lns::validate_mapping_type(type, &mapping_type, reason))
return {};
std::vector<wallet2::pending_tx> result = create_buy_lns_mapping_tx(mapping_type, owner, name, value, reason, priority, account_index, subaddr_indices);
std::vector<wallet2::pending_tx> result = create_buy_lns_mapping_tx(type, owner, name, value, reason, priority, account_index, subaddr_indices);
return result;
}
@ -8596,7 +8596,7 @@ std::vector<wallet2::pending_tx> wallet2::create_update_lns_mapping_tx(lns::mapp
if (reason) *reason = ERR_MSG_NETWORK_VERSION_QUERY_FAILED;
return {};
}
loki_construct_tx_params tx_params = wallet2::construct_params(*hf_version, txtype::loki_name_system, priority, lns::burn_type::update_record);
loki_construct_tx_params tx_params = wallet2::construct_params(*hf_version, txtype::loki_name_system, priority, lns::mapping_type::update_record_internal);
auto result = create_transactions_2({} /*dests*/,
CRYPTONOTE_DEFAULT_TX_MIXIN,

View File

@ -1386,7 +1386,7 @@ private:
// params constructor, accumulates the burn amounts if the priority is
// a blink and, or a lns tx. If it is a blink TX, lns_burn_type is ignored.
static cryptonote::loki_construct_tx_params construct_params(uint8_t hf_version, cryptonote::txtype tx_type, uint32_t priority, lns::burn_type lns_burn_type = lns::burn_type::none);
static cryptonote::loki_construct_tx_params construct_params(uint8_t hf_version, cryptonote::txtype tx_type, uint32_t priority, lns::mapping_type lns_burn_type = static_cast<lns::mapping_type>(0));
bool is_unattended() const { return m_unattended; }

View File

@ -533,7 +533,7 @@ cryptonote::transaction loki_chain_generator::create_loki_name_system_tx(crypton
uint64_t new_height = get_block_height(top().block) + 1;
uint8_t new_hf_version = get_hf_version_at(new_height);
if (burn == LNS_AUTO_BURN)
burn = lns::burn_requirement_in_atomic_loki(new_hf_version, lns::mapping_type_to_burn_type(type));
burn = lns::burn_requirement_in_atomic_loki(new_hf_version, type);
crypto::hash prev_txid = crypto::null_hash;
if (lns::mapping_record mapping = lns_db_.get_mapping(type, name))

View File

@ -1055,14 +1055,15 @@ bool loki_name_system_expiration::generate(std::vector<test_event_entry> &events
gen.add_mined_money_unlock_blocks();
lns_keys_t miner_key = make_lns_keys(miner);
if (lns::mapping_type_allowed(gen.hardfork(), lns::mapping_type::lokinet))
if (lns::mapping_type_allowed(gen.hardfork(), lns::mapping_type::lokinet_1year))
{
std::string const name = "mydomain.loki";
cryptonote::transaction tx = gen.create_and_add_loki_name_system_tx(miner, lns::mapping_type::lokinet, miner_key.lokinet_value, name);
auto mapping_type = lns::mapping_type::lokinet_1year;
cryptonote::transaction tx = gen.create_and_add_loki_name_system_tx(miner, mapping_type, miner_key.lokinet_value, name);
gen.create_and_add_next_block({tx});
uint64_t height_of_lns_entry = gen.height();
uint64_t expected_expiry_block = height_of_lns_entry + lns::lokinet_expiry_blocks(cryptonote::FAKECHAIN, nullptr);
uint64_t expected_expiry_block = height_of_lns_entry + lns::expiry_blocks(cryptonote::FAKECHAIN, mapping_type, nullptr);
loki_register_callback(events, "check_lns_entries", [&events, height_of_lns_entry, miner_key, name](cryptonote::core &c, size_t ev_index)
{
@ -1074,9 +1075,9 @@ bool loki_name_system_expiration::generate(std::vector<test_event_entry> &events
CHECK_EQ(owner.id, 1);
CHECK_EQ(miner_key.ed_key, owner.key);
lns::mapping_record mappings = lns_db.get_mapping(lns::mapping_type::lokinet, name);
lns::mapping_record mappings = lns_db.get_mapping(lns::mapping_type::lokinet_1year, name);
CHECK_EQ(mappings.loaded, true);
CHECK_EQ(mappings.type, lns::mapping_type::lokinet);
CHECK_EQ(mappings.type, lns::mapping_type::lokinet_1year);
CHECK_EQ(mappings.name, name);
CHECK_EQ(mappings.value, miner_key.lokinet_value);
CHECK_EQ(mappings.register_height, height_of_lns_entry);
@ -1098,10 +1099,10 @@ bool loki_name_system_expiration::generate(std::vector<test_event_entry> &events
CHECK_EQ(owner.id, 1);
CHECK_EQ(miner_key.ed_key, owner.key);
lns::mapping_record mappings = lns_db.get_mapping(lns::mapping_type::lokinet, name);
lns::mapping_record mappings = lns_db.get_mapping(lns::mapping_type::lokinet_1year, name);
CHECK_EQ(mappings.loaded, true);
CHECK_EQ(mappings.active(cryptonote::FAKECHAIN, blockchain_height), false);
CHECK_EQ(mappings.type, lns::mapping_type::lokinet);
CHECK_EQ(mappings.type, lns::mapping_type::lokinet_1year);
CHECK_EQ(mappings.name, name);
CHECK_EQ(mappings.value, miner_key.lokinet_value);
CHECK_EQ(mappings.register_height, height_of_lns_entry);
@ -1144,11 +1145,11 @@ bool loki_name_system_get_mappings_by_owner::generate(std::vector<test_event_ent
// NOTE: Register some Lokinet names
std::string lokinet_name1 = "lorem.loki";
std::string lokinet_name2 = "ipsum.loki";
if (lns::mapping_type_allowed(gen.hardfork(), lns::mapping_type::lokinet))
if (lns::mapping_type_allowed(gen.hardfork(), lns::mapping_type::lokinet_1year))
{
{
cryptonote::transaction tx1 = gen.create_and_add_loki_name_system_tx(bob, lns::mapping_type::lokinet, bob_key.lokinet_value, lokinet_name1);
cryptonote::transaction tx2 = gen.create_and_add_loki_name_system_tx(miner, lns::mapping_type::lokinet, bob_key.lokinet_value, lokinet_name2, &bob_key.ed_key);
cryptonote::transaction tx1 = gen.create_and_add_loki_name_system_tx(bob, lns::mapping_type::lokinet_1year, bob_key.lokinet_value, lokinet_name1);
cryptonote::transaction tx2 = gen.create_and_add_loki_name_system_tx(miner, lns::mapping_type::lokinet_1year, bob_key.lokinet_value, lokinet_name2, &bob_key.ed_key);
gen.create_and_add_next_block({tx1, tx2});
}
}
@ -1181,7 +1182,7 @@ bool loki_name_system_get_mappings_by_owner::generate(std::vector<test_event_ent
size_t expected_size = 0;
if (lns::mapping_type_allowed(c.get_blockchain_storage().get_current_hard_fork_version(), lns::mapping_type::session)) expected_size += 2;
if (lns::mapping_type_allowed(c.get_blockchain_storage().get_current_hard_fork_version(), lns::mapping_type::wallet)) expected_size += 2;
if (lns::mapping_type_allowed(c.get_blockchain_storage().get_current_hard_fork_version(), lns::mapping_type::lokinet)) expected_size += 2;
if (lns::mapping_type_allowed(c.get_blockchain_storage().get_current_hard_fork_version(), lns::mapping_type::lokinet_1year)) expected_size += 2;
CHECK_EQ(records.size(), expected_size);
if (lns::mapping_type_allowed(c.get_blockchain_storage().get_current_hard_fork_version(), lns::mapping_type::session))
@ -1196,7 +1197,7 @@ bool loki_name_system_get_mappings_by_owner::generate(std::vector<test_event_ent
CHECK_EQ(records[1].type, lns::mapping_type::session);
}
if (lns::mapping_type_allowed(c.get_blockchain_storage().get_current_hard_fork_version(), lns::mapping_type::lokinet))
if (lns::mapping_type_allowed(c.get_blockchain_storage().get_current_hard_fork_version(), lns::mapping_type::lokinet_1year))
{
CHECK_EQ(records[2].name, lokinet_name1);
CHECK_EQ(records[3].name, lokinet_name2);
@ -1204,8 +1205,8 @@ bool loki_name_system_get_mappings_by_owner::generate(std::vector<test_event_ent
CHECK_EQ(records[3].register_height, lokinet_height);
CHECK_EQ(records[2].value, bob_key.lokinet_value);
CHECK_EQ(records[3].value, bob_key.lokinet_value);
CHECK_EQ(records[2].type, lns::mapping_type::lokinet);
CHECK_EQ(records[3].type, lns::mapping_type::lokinet);
CHECK_EQ(records[2].type, lns::mapping_type::lokinet_1year);
CHECK_EQ(records[3].type, lns::mapping_type::lokinet_1year);
}
if (lns::mapping_type_allowed(c.get_blockchain_storage().get_current_hard_fork_version(), lns::mapping_type::wallet))
@ -1396,9 +1397,9 @@ bool loki_name_system_handles_duplicate_in_lns_db::generate(std::vector<test_eve
txs.push_back(bar2);
}
if (lns::mapping_type_allowed(gen.hardfork(), lns::mapping_type::lokinet))
if (lns::mapping_type_allowed(gen.hardfork(), lns::mapping_type::lokinet_1year))
{
cryptonote::transaction bar3 = gen.create_and_add_loki_name_system_tx(miner, lns::mapping_type::lokinet, miner_key.lokinet_value, session_name);
cryptonote::transaction bar3 = gen.create_and_add_loki_name_system_tx(miner, lns::mapping_type::lokinet_1year, miner_key.lokinet_value, session_name);
txs.push_back(bar3);
}
@ -1429,11 +1430,11 @@ bool loki_name_system_handles_duplicate_in_lns_db::generate(std::vector<test_eve
CHECK_EQ(mappings.register_height, height_of_lns_entry);
CHECK_EQ(mappings.owner_id, owner.id);
if (lns::mapping_type_allowed(c.get_blockchain_storage().get_current_hard_fork_version(), lns::mapping_type::lokinet))
if (lns::mapping_type_allowed(c.get_blockchain_storage().get_current_hard_fork_version(), lns::mapping_type::lokinet_1year))
{
lns::mapping_record mappings2 = lns_db.get_mapping(lns::mapping_type::lokinet, session_name);
lns::mapping_record mappings2 = lns_db.get_mapping(lns::mapping_type::lokinet_1year, session_name);
CHECK_EQ(mappings2.loaded, true);
CHECK_EQ(mappings2.type, lns::mapping_type::lokinet);
CHECK_EQ(mappings2.type, lns::mapping_type::lokinet_1year);
CHECK_EQ(mappings2.name, session_name);
CHECK_EQ(mappings2.value, miner_key.lokinet_value);
CHECK_EQ(mappings2.register_height, height_of_lns_entry);
@ -1515,9 +1516,7 @@ bool loki_name_system_invalid_tx_extra_params::generate(std::vector<test_event_e
char const *reason) -> void {
uint64_t new_height = cryptonote::get_block_height(gen.top().block) + 1;
uint8_t new_hf_version = gen.get_hf_version_at(new_height);
lns::burn_type burn_type = lns::mapping_type_to_burn_type(static_cast<lns::mapping_type>(data.type));
uint64_t burn_requirement = lns::burn_requirement_in_atomic_loki(new_hf_version, burn_type);
uint64_t burn_requirement = lns::burn_requirement_in_atomic_loki(new_hf_version, static_cast<lns::mapping_type>(data.type));
std::vector<uint8_t> extra;
cryptonote::add_loki_name_system_to_tx_extra(extra, data);
@ -1563,9 +1562,9 @@ bool loki_name_system_invalid_tx_extra_params::generate(std::vector<test_event_e
}
}
if (lns::mapping_type_allowed(gen.hardfork(), lns::mapping_type::lokinet))
if (lns::mapping_type_allowed(gen.hardfork(), lns::mapping_type::lokinet_1year))
{
valid_data.type = lns::mapping_type::lokinet;
valid_data.type = lns::mapping_type::lokinet_1year;
// Lokinet domain name too long
{
cryptonote::tx_extra_loki_name_system data = valid_data;
@ -1729,9 +1728,9 @@ bool loki_name_system_large_reorg::generate(std::vector<test_event_entry> &event
txs.push_back(wallet_tx);
}
if (lns::mapping_type_allowed(gen.hardfork(), lns::mapping_type::lokinet))
if (lns::mapping_type_allowed(gen.hardfork(), lns::mapping_type::lokinet_1year))
{
cryptonote::transaction lokinet_tx = gen.create_and_add_loki_name_system_tx(miner, lns::mapping_type::lokinet, miner_key.lokinet_value, miner_lokinet_domain1);
cryptonote::transaction lokinet_tx = gen.create_and_add_loki_name_system_tx(miner, lns::mapping_type::lokinet_1year, miner_key.lokinet_value, miner_lokinet_domain1);
txs.push_back(lokinet_tx);
}
gen.create_and_add_next_block(txs);
@ -1742,7 +1741,7 @@ bool loki_name_system_large_reorg::generate(std::vector<test_event_entry> &event
{
uint64_t height_of_lns_entry = gen.height();
uint64_t renew_window = 0;
uint64_t expiry_blocks = lns::lokinet_expiry_blocks(cryptonote::FAKECHAIN, &renew_window);
uint64_t expiry_blocks = lns::expiry_blocks(cryptonote::FAKECHAIN, lns::mapping_type::lokinet_1year, &renew_window);
miner_earliest_renewable_height = first_lns_height + expiry_blocks - renew_window;
}
@ -1754,7 +1753,7 @@ bool loki_name_system_large_reorg::generate(std::vector<test_event_entry> &event
size_t expected_size = 1;
if (lns::mapping_type_allowed(c.get_blockchain_storage().get_current_hard_fork_version(), lns::mapping_type::wallet)) expected_size += 1;
if (lns::mapping_type_allowed(c.get_blockchain_storage().get_current_hard_fork_version(), lns::mapping_type::lokinet)) expected_size += 1;
if (lns::mapping_type_allowed(c.get_blockchain_storage().get_current_hard_fork_version(), lns::mapping_type::lokinet_1year)) expected_size += 1;
CHECK_EQ(records.size(), expected_size);
for (lns::mapping_record const &record : records)
@ -1765,7 +1764,7 @@ bool loki_name_system_large_reorg::generate(std::vector<test_event_entry> &event
CHECK_EQ(record.register_height, first_lns_height);
CHECK_EQ(record.value, miner_key.session_value);
}
else if (record.type == lns::mapping_type::lokinet)
else if (record.type == lns::mapping_type::lokinet_1year)
{
CHECK_EQ(record.name, miner_lokinet_domain1);
CHECK_EQ(record.register_height, first_lns_height);
@ -1797,9 +1796,9 @@ bool loki_name_system_large_reorg::generate(std::vector<test_event_entry> &event
std::vector<cryptonote::transaction> txs;
txs.push_back(gen.create_and_add_loki_name_system_tx(bob, lns::mapping_type::session, bob_key.session_value, bob_session_name1));
if (lns::mapping_type_allowed(gen.hardfork(), lns::mapping_type::lokinet))
if (lns::mapping_type_allowed(gen.hardfork(), lns::mapping_type::lokinet_1year))
{
txs.push_back(gen.create_and_add_loki_name_system_tx(miner, lns::mapping_type::lokinet, miner_key.lokinet_value, miner_lokinet_domain1));
txs.push_back(gen.create_and_add_loki_name_system_tx(miner, lns::mapping_type::lokinet_1year, miner_key.lokinet_value, miner_lokinet_domain1));
}
gen.create_and_add_next_block(txs);
}
@ -1812,7 +1811,7 @@ bool loki_name_system_large_reorg::generate(std::vector<test_event_entry> &event
lns::name_system_db const &lns_db = c.get_blockchain_storage().name_system_db();
// NOTE: Check miner's record
if (lns::mapping_type_allowed(c.get_blockchain_storage().get_current_hard_fork_version(), lns::mapping_type::lokinet))
if (lns::mapping_type_allowed(c.get_blockchain_storage().get_current_hard_fork_version(), lns::mapping_type::lokinet_1year))
{
std::vector<lns::mapping_record> records = lns_db.get_mappings_by_owner(miner_key.ed_key);
for (lns::mapping_record const &record : records)
@ -1823,7 +1822,7 @@ bool loki_name_system_large_reorg::generate(std::vector<test_event_entry> &event
CHECK_EQ(record.register_height, first_lns_height);
CHECK_EQ(record.value, miner_key.session_value);
}
else if (record.type == lns::mapping_type::lokinet)
else if (record.type == lns::mapping_type::lokinet_1year)
{
CHECK_EQ(record.name, miner_lokinet_domain1);
CHECK_EQ(record.register_height, second_lns_height);
@ -1881,7 +1880,7 @@ bool loki_name_system_large_reorg::generate(std::vector<test_event_entry> &event
std::vector<lns::mapping_record> records = lns_db.get_mappings_by_owner(miner_key.ed_key);
size_t expected_size = 1;
if (lns::mapping_type_allowed(c.get_blockchain_storage().get_current_hard_fork_version(), lns::mapping_type::wallet)) expected_size += 1;
if (lns::mapping_type_allowed(c.get_blockchain_storage().get_current_hard_fork_version(), lns::mapping_type::lokinet)) expected_size += 1;
if (lns::mapping_type_allowed(c.get_blockchain_storage().get_current_hard_fork_version(), lns::mapping_type::lokinet_1year)) expected_size += 1;
CHECK_EQ(records.size(), expected_size);
for (lns::mapping_record const &record : records)
@ -1892,7 +1891,7 @@ bool loki_name_system_large_reorg::generate(std::vector<test_event_entry> &event
CHECK_EQ(record.register_height, first_lns_height);
CHECK_EQ(record.value, miner_key.session_value);
}
else if (record.type == lns::mapping_type::lokinet)
else if (record.type == lns::mapping_type::lokinet_1year)
{
CHECK_EQ(record.name, miner_lokinet_domain1);
CHECK_EQ(record.register_height, first_lns_height);
@ -1944,7 +1943,7 @@ bool loki_name_system_name_renewal::generate(std::vector<test_event_entry> &even
loki_chain_generator gen(events, hard_forks);
cryptonote::account_base miner = gen.first_miner_;
if (!lns::mapping_type_allowed(gen.hardfork(), lns::mapping_type::lokinet))
if (!lns::mapping_type_allowed(gen.hardfork(), lns::mapping_type::lokinet_1year))
return true;
{
@ -1955,13 +1954,14 @@ bool loki_name_system_name_renewal::generate(std::vector<test_event_entry> &even
lns_keys_t miner_key = make_lns_keys(miner);
std::string const name = "mydomain.loki";
cryptonote::transaction tx = gen.create_and_add_loki_name_system_tx(miner, lns::mapping_type::lokinet, miner_key.lokinet_value, name);
lns::mapping_type mapping_type = lns::mapping_type::lokinet_1year;
cryptonote::transaction tx = gen.create_and_add_loki_name_system_tx(miner, mapping_type, miner_key.lokinet_value, name);
gen.create_and_add_next_block({tx});
crypto::hash prev_txid = get_transaction_hash(tx);
uint64_t height_of_lns_entry = gen.height();
uint64_t renew_window = 0;
uint64_t expiry_blocks = lns::lokinet_expiry_blocks(cryptonote::FAKECHAIN, &renew_window);
uint64_t expiry_blocks = lns::expiry_blocks(cryptonote::FAKECHAIN, mapping_type, &renew_window);
uint64_t renew_window_block = height_of_lns_entry + expiry_blocks - renew_window;
loki_register_callback(events, "check_lns_entries", [&events, height_of_lns_entry, miner_key, name](cryptonote::core &c, size_t ev_index)
@ -1974,9 +1974,9 @@ bool loki_name_system_name_renewal::generate(std::vector<test_event_entry> &even
CHECK_EQ(owner.id, 1);
CHECK_EQ(miner_key.ed_key, owner.key);
lns::mapping_record mappings = lns_db.get_mapping(lns::mapping_type::lokinet, name);
lns::mapping_record mappings = lns_db.get_mapping(lns::mapping_type::lokinet_1year, name);
CHECK_EQ(mappings.loaded, true);
CHECK_EQ(mappings.type, lns::mapping_type::lokinet);
CHECK_EQ(mappings.type, lns::mapping_type::lokinet_1year);
CHECK_EQ(mappings.name, name);
CHECK_EQ(mappings.value, miner_key.lokinet_value);
CHECK_EQ(mappings.register_height, height_of_lns_entry);
@ -1989,7 +1989,7 @@ bool loki_name_system_name_renewal::generate(std::vector<test_event_entry> &even
gen.create_and_add_next_block();
// In the renewal window, try and renew the lokinet entry
cryptonote::transaction renew_tx = gen.create_and_add_loki_name_system_tx(miner, lns::mapping_type::lokinet, miner_key.lokinet_value, name);
cryptonote::transaction renew_tx = gen.create_and_add_loki_name_system_tx(miner, lns::mapping_type::lokinet_1year, miner_key.lokinet_value, name);
gen.create_and_add_next_block({renew_tx});
uint64_t renewal_height = gen.height();
@ -2003,9 +2003,9 @@ bool loki_name_system_name_renewal::generate(std::vector<test_event_entry> &even
CHECK_EQ(owner.id, 1);
CHECK_EQ(miner_key.ed_key, owner.key);
lns::mapping_record mappings = lns_db.get_mapping(lns::mapping_type::lokinet, name);
lns::mapping_record mappings = lns_db.get_mapping(lns::mapping_type::lokinet_1year, name);
CHECK_EQ(mappings.loaded, true);
CHECK_EQ(mappings.type, lns::mapping_type::lokinet);
CHECK_EQ(mappings.type, lns::mapping_type::lokinet_1year);
CHECK_EQ(mappings.name, name);
CHECK_EQ(mappings.value, miner_key.lokinet_value);
CHECK_EQ(mappings.register_height, renewal_height);
@ -2034,9 +2034,7 @@ bool loki_name_system_name_value_max_lengths::generate(std::vector<test_event_en
uint64_t new_height = cryptonote::get_block_height(gen.top().block) + 1;
uint8_t new_hf_version = gen.get_hf_version_at(new_height);
lns::burn_type burn_type = lns::mapping_type_to_burn_type(static_cast<lns::mapping_type>(data.type));
uint64_t burn_requirement = lns::burn_requirement_in_atomic_loki(new_hf_version, burn_type);
uint64_t burn_requirement = lns::burn_requirement_in_atomic_loki(new_hf_version, static_cast<lns::mapping_type>(data.type));
std::vector<uint8_t> extra;
cryptonote::add_loki_name_system_to_tx_extra(extra, data);
cryptonote::add_burned_amount_to_tx_extra(extra, burn_requirement);
@ -2065,9 +2063,9 @@ bool loki_name_system_name_value_max_lengths::generate(std::vector<test_event_en
}
// Lokinet
if (lns::mapping_type_allowed(gen.hardfork(), lns::mapping_type::lokinet))
if (lns::mapping_type_allowed(gen.hardfork(), lns::mapping_type::lokinet_1year))
{
data.type = lns::mapping_type::lokinet;
data.type = lns::mapping_type::lokinet_1year;
data.name = "doyle.loki";
data.value = std::string(lns::LOKINET_ADDRESS_BINARY_LENGTH, 'a');
make_lns_tx_with_custom_extra(gen, events, miner, data);
@ -2084,7 +2082,7 @@ bool loki_name_system_name_value_max_lengths::generate(std::vector<test_event_en
}
// Generic
if (lns::mapping_type_allowed(gen.hardfork(), lns::mapping_type::lokinet))
if (lns::mapping_type_allowed(gen.hardfork(), lns::mapping_type::lokinet_1year))
{
data.type = static_cast<lns::mapping_type>(1111);
data.name = std::string(lns::GENERIC_NAME_MAX, 'A');
@ -2106,20 +2104,20 @@ bool loki_name_system_update_mapping_after_expiry_fails::generate(std::vector<te
gen.add_mined_money_unlock_blocks();
lns_keys_t miner_key = make_lns_keys(miner);
if (lns::mapping_type_allowed(gen.hardfork(), lns::mapping_type::lokinet))
if (lns::mapping_type_allowed(gen.hardfork(), lns::mapping_type::lokinet_1year))
{
std::string const name = "mydomain.loki";
cryptonote::transaction tx = gen.create_and_add_loki_name_system_tx(miner, lns::mapping_type::lokinet, miner_key.lokinet_value, name);
cryptonote::transaction tx = gen.create_and_add_loki_name_system_tx(miner, lns::mapping_type::lokinet_1year, miner_key.lokinet_value, name);
gen.create_and_add_next_block({tx});
uint64_t height_of_lns_entry = gen.height();
uint64_t expected_expiry_block = height_of_lns_entry + lns::lokinet_expiry_blocks(cryptonote::FAKECHAIN, nullptr);
uint64_t expected_expiry_block = height_of_lns_entry + lns::expiry_blocks(cryptonote::FAKECHAIN, lns::mapping_type::lokinet_1year, nullptr);
while (gen.height() <= expected_expiry_block)
gen.create_and_add_next_block();
lns_keys_t bob_key = make_lns_keys(gen.add_account());
cryptonote::transaction tx1 = gen.create_loki_name_system_tx_update(miner, lns::mapping_type::lokinet, bob_key.lokinet_value, name);
cryptonote::transaction tx1 = gen.create_loki_name_system_tx_update(miner, lns::mapping_type::lokinet_1year, bob_key.lokinet_value, name);
gen.add_tx(tx1, false /*can_be_added_to_blockchain*/, "Can not update a LNS record that is already expired");
loki_register_callback(events, "check_still_expired", [&events, height_of_lns_entry, miner_key, name](cryptonote::core &c, size_t ev_index)
@ -2132,9 +2130,9 @@ bool loki_name_system_update_mapping_after_expiry_fails::generate(std::vector<te
CHECK_EQ(owner.id, 1);
CHECK_EQ(miner_key.ed_key, owner.key);
lns::mapping_record mappings = lns_db.get_mapping(lns::mapping_type::lokinet, name);
lns::mapping_record mappings = lns_db.get_mapping(lns::mapping_type::lokinet_1year, name);
CHECK_EQ(mappings.loaded, true);
CHECK_EQ(mappings.type, lns::mapping_type::lokinet);
CHECK_EQ(mappings.type, lns::mapping_type::lokinet_1year);
CHECK_EQ(mappings.name, name);
CHECK_EQ(mappings.value, miner_key.lokinet_value);
CHECK_EQ(mappings.register_height, height_of_lns_entry);
@ -2300,7 +2298,7 @@ bool loki_name_system_wrong_burn::generate(std::vector<test_event_entry> &events
}
lns_keys_t lns_keys = make_lns_keys(miner);
lns::mapping_type const types[] = {lns::mapping_type::session, lns::mapping_type::wallet, lns::mapping_type::lokinet};
lns::mapping_type const types[] = {lns::mapping_type::session, lns::mapping_type::wallet, lns::mapping_type::lokinet_1year};
for (int i = 0; i < 2; i++)
{
bool under_burn = (i == 0);
@ -2321,7 +2319,7 @@ bool loki_name_system_wrong_burn::generate(std::vector<test_event_entry> &events
value = lns_keys.wallet_value;
name = "My Friendly Wallet Name";
}
else if (type == lns::mapping_type::lokinet)
else if (type == lns::mapping_type::lokinet_1year)
{
value = lns_keys.lokinet_value;
name = "MyFriendlyLokinetName.loki";
@ -2331,8 +2329,7 @@ bool loki_name_system_wrong_burn::generate(std::vector<test_event_entry> &events
uint64_t new_height = cryptonote::get_block_height(gen.top().block) + 1;
uint8_t new_hf_version = gen.get_hf_version_at(new_height);
lns::burn_type burn_type = lns::mapping_type_to_burn_type(type);
uint64_t burn = lns::burn_requirement_in_atomic_loki(new_hf_version, burn_type);
uint64_t burn = lns::burn_requirement_in_atomic_loki(new_hf_version, type);
if (under_burn) burn -= 1;
else burn += 1;
@ -2364,7 +2361,7 @@ bool loki_name_system_wrong_version::generate(std::vector<test_event_entry> &eve
uint64_t new_height = cryptonote::get_block_height(gen.top().block) + 1;
uint8_t new_hf_version = gen.get_hf_version_at(new_height);
uint64_t burn_requirement = lns::burn_requirement_in_atomic_loki(new_hf_version, lns::burn_type::session);
uint64_t burn_requirement = lns::burn_requirement_in_atomic_loki(new_hf_version, lns::mapping_type::session);
std::vector<uint8_t> extra;
cryptonote::add_loki_name_system_to_tx_extra(extra, data);

View File

@ -8,7 +8,7 @@ TEST(loki_name_system, lokinet_domain_names)
char domain_edkeys[lns::LOKINET_ADDRESS_BINARY_LENGTH * 2] = {};
memset(domain_edkeys, 'a', sizeof(domain_edkeys));
lns::mapping_type const lokinet = lns::mapping_type::lokinet;
lns::mapping_type const lokinet = lns::mapping_type::lokinet_1year;
// Should work
{