Skip to content

Commit

Permalink
Fixing issue with generating incorrect work.
Browse files Browse the repository at this point in the history
  • Loading branch information
clemahieu committed Jan 18, 2015
1 parent a60290a commit 0eaf75c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
12 changes: 11 additions & 1 deletion rai/core_test/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ TEST (wallet, work_generate)
ASSERT_LT (iterations1, 200);
}
auto iterations2 (0);
while (wallet->work.get (account1, work1))
while (wallet->work.get (account1, work1) || rai::work_validate (system.nodes [0]->ledger.latest_root (account1), work1))
{
system.service->poll_one ();
system.processor.poll_one ();
Expand All @@ -490,4 +490,14 @@ TEST (wallet, startup_work)
++iterations2;
ASSERT_LT (iterations2, 200);
}
}

TEST (wallet, unsynced_work)
{
rai::system system (24000, 1);
auto wallet (system.wallet (0));
wallet->work.put (0, 0);
std::lock_guard <std::mutex> lock (wallet->mutex);
auto work1 (wallet->work_fetch (0, 0));
ASSERT_FALSE (rai::work_validate (0, work1));
}
16 changes: 12 additions & 4 deletions rai/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,14 @@ uint64_t rai::wallet::work_fetch (rai::account const & account_a, rai::block_has
{
result = rai::work_generate (root_a);
}
else
{
if (rai::work_validate (root_a, result))
{
result = rai::work_generate (root_a);
BOOST_LOG (node.log) << "Cached work invalid, regenerating";
}
}
return result;
}

Expand Down Expand Up @@ -1412,7 +1420,7 @@ service (processor_a)
auto wallet (i->second);
if (wallet->store.exists (account_a))
{
auto root (block_a.root ());
auto root (ledger.latest_root (account_a));
service.add (std::chrono::system_clock::now (), [wallet, account_a, root] ()
{
wallet->work_generate (account_a, root);
Expand All @@ -1427,7 +1435,7 @@ service (processor_a)
auto wallet (i->second);
if (wallet->store.exists (account_a))
{
auto root (block_a.root ());
auto root (ledger.latest_root (account_a));
service.add (std::chrono::system_clock::now (), [wallet, account_a, root] ()
{
wallet->work_generate (account_a, root);
Expand All @@ -1442,7 +1450,7 @@ service (processor_a)
auto wallet (i->second);
if (wallet->store.exists (account_a))
{
auto root (block_a.root ());
auto root (ledger.latest_root (account_a));
service.add (std::chrono::system_clock::now (), [wallet, account_a, root] ()
{
wallet->work_generate (account_a, root);
Expand All @@ -1457,7 +1465,7 @@ service (processor_a)
auto wallet (i->second);
if (wallet->store.exists (account_a))
{
auto root (block_a.root ());
auto root (ledger.latest_root (account_a));
service.add (std::chrono::system_clock::now (), [wallet, account_a, root] ()
{
wallet->work_generate (account_a, root);
Expand Down
3 changes: 3 additions & 0 deletions rai/secure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,7 @@ uint64_t rai::receive_block::block_work () const

void rai::receive_block::block_work_set (uint64_t work_a)
{
assert (!rai::work_validate (root (), work_a));
work = work_a;
}

Expand Down Expand Up @@ -1261,6 +1262,7 @@ uint64_t rai::open_block::block_work () const

void rai::open_block::block_work_set (uint64_t work_a)
{
assert (!rai::work_validate (root (), work_a));
work = work_a;
}

Expand Down Expand Up @@ -1493,6 +1495,7 @@ uint64_t rai::change_block::block_work () const

void rai::change_block::block_work_set (uint64_t work_a)
{
assert (!rai::work_validate (root (), work_a));
work = work_a;
}

Expand Down

0 comments on commit 0eaf75c

Please sign in to comment.