Code review

This commit is contained in:
Doyle 2019-09-09 11:14:19 +10:00
parent 8cf7e0f5ca
commit 0b92e9ba89
8 changed files with 18 additions and 33 deletions

View File

@ -223,12 +223,6 @@ namespace cryptonote
return reward;
}
loki_miner_tx_context::loki_miner_tx_context(network_type type, service_nodes::block_winner block_winner)
: nettype(type)
, block_winner(block_winner)
{
}
bool construct_miner_tx(
size_t height,
size_t median_weight,

View File

@ -52,7 +52,7 @@ namespace cryptonote
struct loki_miner_tx_context // NOTE(loki): All the custom fields required by Loki to use construct_miner_tx
{
loki_miner_tx_context(network_type type = MAINNET, service_nodes::block_winner block_winner = service_nodes::null_block_winner);
loki_miner_tx_context(network_type type = MAINNET, service_nodes::block_winner const &block_winner = service_nodes::null_block_winner) : nettype(type), block_winner(std::move(block_winner)) { }
network_type nettype;
service_nodes::block_winner block_winner;
uint64_t batched_governance = 0; // NOTE: 0 until hardfork v10, then use blockchain::calc_batched_governance_reward

View File

@ -1266,7 +1266,7 @@ namespace service_nodes
//
// Remove expired blacklisted key images
//
if (hf_version > cryptonote::network_version_11_infinite_staking)
if (hf_version >= cryptonote::network_version_11_infinite_staking)
{
for (auto entry = key_image_blacklist.begin(); entry != key_image_blacklist.end();)
{

View File

@ -349,8 +349,6 @@ namespace service_nodes
block_height height{0};
mutable quorum_manager quorums; // Mutable because we are allowed to (and need to) change it via std::set iterator
constexpr bool operator()(const state_t &lhs, const state_t &rhs) const { return lhs.height < rhs.height; }
state_t() = default;
state_t(block_height height) : height{height} {}
state_t(cryptonote::Blockchain const &blockchain, state_serialized &&state);

View File

@ -548,7 +548,7 @@ namespace service_nodes
pool_vote.vote.index_in_group != it->voter_index)
{
update_checkpoint = true;
checkpoint.signatures.insert(it, vote_to_voter_to_signature(pool_vote.vote));
checkpoint.signatures.insert(it, voter_to_signature(pool_vote.vote));
}
}
}
@ -558,7 +558,7 @@ namespace service_nodes
checkpoint = make_empty_service_node_checkpoint(vote.checkpoint.block_hash, vote.block_height);
checkpoint.signatures.reserve(votes.size());
for (pool_vote_entry const &pool_vote : votes)
checkpoint.signatures.push_back(vote_to_voter_to_signature(pool_vote.vote));
checkpoint.signatures.push_back(voter_to_signature(pool_vote.vote));
}
if (update_checkpoint)

View File

@ -338,14 +338,6 @@ namespace service_nodes
return result;
}
voter_to_signature vote_to_voter_to_signature(quorum_vote_t const &vote)
{
voter_to_signature result = {};
result.voter_index = vote.index_in_group;
result.signature = vote.signature;
return result;
}
bool verify_vote_age(const quorum_vote_t& vote, uint64_t latest_height, cryptonote::vote_verification_context &vvc)
{
bool result = true;

View File

@ -54,17 +54,6 @@ namespace service_nodes
{
struct testing_quorum;
struct voter_to_signature
{
uint16_t voter_index;
crypto::signature signature;
BEGIN_SERIALIZE()
FIELD(voter_index)
FIELD(signature)
END_SERIALIZE()
};
struct checkpoint_vote { crypto::hash block_hash; };
struct state_change_vote { uint16_t worker_index; new_state state; };
@ -109,10 +98,22 @@ namespace service_nodes
void serialize(Archive &ar, const unsigned int /*version*/) { }
};
struct voter_to_signature
{
voter_to_signature() = default;
voter_to_signature(quorum_vote_t const &vote) : voter_index(vote.index_in_group), signature(vote.signature) { }
uint16_t voter_index;
crypto::signature signature;
BEGIN_SERIALIZE()
FIELD(voter_index)
FIELD(signature)
END_SERIALIZE()
};
quorum_vote_t make_state_change_vote(uint64_t block_height, uint16_t index_in_group, uint16_t worker_index, new_state state, crypto::public_key const &pub_key, crypto::secret_key const &secret_key);
quorum_vote_t make_checkpointing_vote(crypto::hash const &block_hash, uint64_t block_height, uint16_t index_in_quorum, crypto::public_key const &pub_key, crypto::secret_key const &sec_key);
cryptonote::checkpoint_t make_empty_service_node_checkpoint(crypto::hash const &block_hash, uint64_t height);
voter_to_signature vote_to_voter_to_signature(quorum_vote_t const &vote);
bool verify_checkpoint (uint8_t hf_version, cryptonote::checkpoint_t const &checkpoint, service_nodes::testing_quorum const &quorum);
bool verify_tx_state_change (const cryptonote::tx_extra_service_node_state_change& state_change, uint64_t latest_height, cryptonote::tx_verification_context& vvc, const service_nodes::testing_quorum &quorum, uint8_t hf_version);

View File

@ -344,7 +344,7 @@ cryptonote::checkpoint_t loki_chain_generator::create_service_node_checkpoint(ui
crypto::secret_key const &sec_key = service_node_keys_[pub_key];
service_nodes::quorum_vote_t vote = service_nodes::make_checkpointing_vote(result.block_hash, block_height, i, pub_key, sec_key);
result.signatures.push_back(service_nodes::vote_to_voter_to_signature(vote));
result.signatures.push_back(service_nodes::voter_to_signature(vote));
}
return result;