Fixes an issue where we were using a non-overwriting insert which wasn't updating the sequence number which was causing all vote traffic to be reflected.

This commit is contained in:
clemahieu 2018-03-21 15:40:25 -05:00
commit 8caed829b4
3 changed files with 5 additions and 2 deletions

View file

@ -341,7 +341,7 @@ TEST (state_block, serialization)
rai::vectorstream stream (bytes);
block1.serialize (stream);
}
ASSERT_EQ (0x5, bytes [215]); // Ensure work is serialized big-endian
ASSERT_EQ (0x5, bytes[215]); // Ensure work is serialized big-endian
ASSERT_EQ (rai::state_block::size, bytes.size ());
bool error1;
rai::bufferstream stream (bytes.data (), bytes.size ());

View file

@ -842,15 +842,18 @@ TEST (votes, add_existing)
auto votes1 (node1.active.roots.find (send1->root ())->election);
auto vote1 (std::make_shared<rai::vote> (rai::test_genesis_key.pub, rai::test_genesis_key.prv, 1, send1));
votes1->vote (vote1);
ASSERT_EQ (1, votes1->last_votes[rai::test_genesis_key.pub].second);
rai::keypair key2;
auto send2 (std::make_shared<rai::send_block> (genesis.hash (), key2.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0));
auto vote2 (std::make_shared<rai::vote> (rai::test_genesis_key.pub, rai::test_genesis_key.prv, 2, send2));
// Pretend we've waited the timeout
votes1->last_votes[rai::test_genesis_key.pub].first = std::chrono::steady_clock::now () - std::chrono::seconds (20);
votes1->vote (vote2);
ASSERT_EQ (2, votes1->last_votes[rai::test_genesis_key.pub].second);
// Also resend the old vote, and see if we respect the sequence number
votes1->last_votes[rai::test_genesis_key.pub].first = std::chrono::steady_clock::now () - std::chrono::seconds (20);
votes1->vote (vote1);
ASSERT_EQ (2, votes1->last_votes[rai::test_genesis_key.pub].second);
ASSERT_EQ (2, votes1->votes.rep_votes.size ());
ASSERT_NE (votes1->votes.rep_votes.end (), votes1->votes.rep_votes.find (rai::test_genesis_key.pub));
ASSERT_EQ (*send2, *votes1->votes.rep_votes[rai::test_genesis_key.pub]);

View file

@ -2946,7 +2946,7 @@ bool rai::election::vote (std::shared_ptr<rai::vote> vote_a)
}
if (should_process)
{
last_votes.insert (std::make_pair (vote_a->account, std::make_pair (std::chrono::steady_clock::now (), vote_a->sequence)));
last_votes[vote_a->account] = std::make_pair (std::chrono::steady_clock::now (), vote_a->sequence);
node.network.republish_vote (vote_a);
votes.vote (vote_a);
confirm_if_quorum (transaction);