Skip to content

Commit

Permalink
core tests: update priority for service nodes selected as winners (#506)
Browse files Browse the repository at this point in the history
  • Loading branch information
msgmaxim authored and Doy-lee committed Mar 19, 2019
1 parent 10f7bbd commit aaa3388
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/cryptonote_core/service_node_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1389,8 +1389,10 @@ namespace service_nodes
crypto::public_key winner = select_winner();

crypto::public_key check_winner_pubkey = cryptonote::get_service_node_winner_from_tx_extra(miner_tx.extra);
if (check_winner_pubkey != winner)
if (check_winner_pubkey != winner) {
MERROR("Service node reward winner is incorrect");
return false;
}

const std::vector<std::pair<cryptonote::account_public_address, uint64_t>> addresses_and_portions = get_winner_addresses_and_portions();

Expand Down
12 changes: 7 additions & 5 deletions tests/core_tests/chaingen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,18 +245,19 @@ cryptonote::transaction linear_chain_generator::create_registration_tx(const cry
const cryptonote::keypair& sn_keys)
{
const sn_contributor_t contr = { acc.get_keys().m_account_address, STAKING_PORTIONS };
uint32_t expires = height() + service_nodes::staking_num_lock_blocks(cryptonote::FAKECHAIN);
const uint32_t reg_height = height() + 1;
uint32_t expires = reg_height + service_nodes::staking_num_lock_blocks(cryptonote::FAKECHAIN);

/// Account for some inconsistency in service_nodes::staking_num_lock_blocks
/// on the boundary between hardforks 9 and 10
if (get_hf_version() == cryptonote::network_version_9_service_nodes &&
get_hf_version_at(expires) == cryptonote::network_version_10_bulletproofs)
if ((get_hf_version() == cryptonote::network_version_9_service_nodes && get_hf_version_at(expires) == cryptonote::network_version_10_bulletproofs)
|| get_hf_version() == cryptonote::network_version_10_bulletproofs)
{
expires += STAKING_REQUIREMENT_LOCK_BLOCKS_EXCESS;
}

const auto reg_idx = registration_buffer_.size();
registration_buffer_.push_back({ expires, sn_keys, contr, { height(), reg_idx } });
registration_buffer_.push_back({ expires, sn_keys, contr, { reg_height, reg_idx } });
return make_default_registration_tx(events_, acc, sn_keys, blocks_.back(), gen_.m_hf_version);
}

Expand Down Expand Up @@ -366,7 +367,7 @@ inline void sn_list::expire_old(uint64_t height)
{
/// remove_if is stable, no need for re-sorting
const auto new_end = std::remove_if(
sn_owners_.begin(), sn_owners_.end(), [height](const sn_registration& reg) { return height > reg.valid_until; });
sn_owners_.begin(), sn_owners_.end(), [height](const sn_registration& reg) { return height >= reg.valid_until; });

sn_owners_.erase(new_end, sn_owners_.end());
}
Expand All @@ -391,6 +392,7 @@ inline const boost::optional<crypto::public_key> sn_list::get_winner_pk(uint64_t
});

it->last_reward.height = height;
it->last_reward.priority = UINT32_MAX;

return it->keys.pub;
}
Expand Down
6 changes: 3 additions & 3 deletions tests/core_tests/service_nodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,8 +585,8 @@ bool deregister_too_old::generate(std::vector<test_event_entry>& events)
const auto pk = gen.get_test_pk(0);
const auto dereg_tx = gen.build_deregister(pk, false).build();

/// create enough block to make deregistrations invalid (60 - 1 blocks)
gen.rewind_blocks_n(service_nodes::deregister_vote::DEREGISTER_LIFETIME_BY_HEIGHT-1);
/// create enough blocks to make deregistrations invalid (60 blocks)
gen.rewind_blocks_n(service_nodes::deregister_vote::DEREGISTER_LIFETIME_BY_HEIGHT);

/// In the real world, this transaction should not make it into a block, but in this case we do try to add it (as in
/// tests we must add specify transactions manually), which should exercise the same validation code and reject the
Expand Down Expand Up @@ -771,7 +771,7 @@ bool test_swarms_basic::generate(std::vector<test_event_entry>& events)
for (auto i = init_sn_count; i < SN_KEYS_COUNT; ++i) {
const auto sn = get_static_keys(i);
const auto tx = gen.create_registration_tx(gen.first_miner(), sn);
gen.create_block({tx});
gen.create_block({tx});
}

/// test that another swarm has been created
Expand Down

0 comments on commit aaa3388

Please sign in to comment.