Skip to content

Commit

Permalink
Voting winner patch (by Lee Bousfield) (#916)
Browse files Browse the repository at this point in the history
* Voting winner patch (by Lee Bousfield)

* Missed from patch
  • Loading branch information
SergiySW authored and argakiig committed Jun 12, 2018
1 parent 2900590 commit 5aabce5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
4 changes: 2 additions & 2 deletions rai/core_test/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ TEST (node, fork_publish)
ASSERT_NE (node1.active.roots.end (), existing);
auto election (existing->election);
rai::transaction transaction (node1.store.environment, nullptr, false);
election->compute_rep_votes (transaction);
election->compute_rep_votes (transaction, election->status.winner);
ASSERT_EQ (2, election->votes.rep_votes.size ());
node1.process_active (send2);
node1.block_processor.flush ();
Expand Down Expand Up @@ -1186,7 +1186,7 @@ TEST (node, rep_self_vote)
auto existing (active.roots.find (block0->root ()));
ASSERT_NE (active.roots.end (), existing);
rai::transaction transaction (node0->store.environment, nullptr, false);
existing->election->compute_rep_votes (transaction);
existing->election->compute_rep_votes (transaction, existing->election->status.winner);
auto & rep_votes (existing->election->votes.rep_votes);
ASSERT_EQ (3, rep_votes.size ());
ASSERT_NE (rep_votes.end (), rep_votes.find (rai::test_genesis_key.pub));
Expand Down
2 changes: 1 addition & 1 deletion rai/ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ size_t rai::shared_ptr_block_hash::operator() (std::shared_ptr<rai::block> const

bool rai::shared_ptr_block_hash::operator() (std::shared_ptr<rai::block> const & lhs, std::shared_ptr<rai::block> const & rhs) const
{
return *lhs == *rhs;
return lhs->hash () == rhs->hash ();
}

rai::ledger::ledger (rai::block_store & store_a, rai::stat & stat_a) :
Expand Down
17 changes: 12 additions & 5 deletions rai/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3112,12 +3112,12 @@ confirmed (false)
{
}

void rai::election::compute_rep_votes (MDB_txn * transaction_a)
void rai::election::compute_rep_votes (MDB_txn * transaction_a, std::shared_ptr<rai::block> block_a)
{
if (node.config.enable_voting)
{
node.wallets.foreach_representative (transaction_a, [this, transaction_a](rai::public_key const & pub_a, rai::raw_key const & prv_a) {
auto vote (this->node.store.vote_generate (transaction_a, pub_a, prv_a, status.winner));
node.wallets.foreach_representative (transaction_a, [this, transaction_a, block_a](rai::public_key const & pub_a, rai::raw_key const & prv_a) {
auto vote (this->node.store.vote_generate (transaction_a, pub_a, prv_a, block_a));
this->node.vote_processor.vote (vote, this->node.network.endpoint ());
});
}
Expand All @@ -3126,8 +3126,15 @@ void rai::election::compute_rep_votes (MDB_txn * transaction_a)
void rai::election::broadcast_winner ()
{
rai::transaction transaction (node.store.environment, nullptr, false);
compute_rep_votes (transaction);
node.network.republish_block (transaction, status.winner);
auto tally_l (node.ledger.tally (transaction, votes));
auto winner_l (tally_l.begin ());
auto block_l (status.winner);
if (winner_l != tally_l.end ())
{
block_l = winner_l->second;
}
compute_rep_votes (transaction, block_l);
node.network.republish_block (transaction, block_l);
}

void rai::election::confirm_once (MDB_txn * transaction_a)
Expand Down
2 changes: 1 addition & 1 deletion rai/node/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class election : public std::enable_shared_from_this<rai::election>
// Tell the network our view of the winner
void broadcast_winner ();
// Change our winner to agree with the network
void compute_rep_votes (MDB_txn *);
void compute_rep_votes (MDB_txn *, std::shared_ptr<rai::block>);
// Confirm this block if quorum is met
void confirm_if_quorum (MDB_txn *);
rai::votes votes;
Expand Down

0 comments on commit 5aabce5

Please sign in to comment.