From 7b67611380af2810ca9de204f910a7472b428064 Mon Sep 17 00:00:00 2001 From: clemahieu Date: Sat, 17 Jan 2015 00:21:40 -0600 Subject: [PATCH] Correctly using cached work. --- rai/node.cpp | 24 ++++++++++++------------ rai/qt_test/qt.cpp | 9 ++++++--- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/rai/node.cpp b/rai/node.cpp index eb80daaa0b..ecc3ca8186 100644 --- a/rai/node.cpp +++ b/rai/node.cpp @@ -851,25 +851,25 @@ bool rai::wallet::receive (rai::send_block const & send_a, rai::private_key cons rai::frontier frontier; auto new_account (node.ledger.store.latest_get (send_a.hashables.destination, frontier)); std::unique_ptr block; - if (new_account) + if (!new_account) + { + auto receive (new rai::receive_block); + receive->hashables.previous = frontier.hash; + receive->hashables.source = hash; + receive->block_work_set (work_fetch (send_a.hashables.destination, receive->root ())); + rai::sign_message (prv_a, send_a.hashables.destination, receive->hash (), receive->signature); + block.reset (receive); + } + else { auto open (new rai::open_block); open->hashables.account = send_a.hashables.destination; open->hashables.source = hash; open->hashables.representative = representative_a; - node.work_create (*open); + open->block_work_set (work_fetch (send_a.hashables.destination, open->root ())); rai::sign_message (prv_a, send_a.hashables.destination, open->hash (), open->signature); block.reset (open); } - else - { - auto receive (new rai::receive_block); - receive->hashables.previous = frontier.hash; - receive->hashables.source = hash; - node.work_create (*receive); - rai::sign_message (prv_a, send_a.hashables.destination, receive->hash (), receive->signature); - block.reset (receive); - } node.processor.process_receive_republish (std::move (block)); result = false; } @@ -904,7 +904,7 @@ bool rai::wallet::send (rai::account const & account_a, rai::uint128_t const & a block->hashables.destination = account_a; block->hashables.previous = frontier.hash; block->hashables.balance = balance - amount; - node.work_create (*block); + block->block_work_set (work_fetch (account, block->root ())); rai::private_key prv; result = store.fetch (account, prv); assert (!result); diff --git a/rai/qt_test/qt.cpp b/rai/qt_test/qt.cpp index 8d49ee2ffc..8556e1eda6 100644 --- a/rai/qt_test/qt.cpp +++ b/rai/qt_test/qt.cpp @@ -127,10 +127,13 @@ TEST (wallet, send) QTest::keyClicks (wallet.send_account, key1.pub.to_base58check ().c_str ()); QTest::keyClicks (wallet.send_count, "2"); QTest::mouseClick (wallet.send_blocks_send, Qt::LeftButton); + auto iterations1 (0); while (wallet.node.ledger.account_balance (key1.pub).is_zero ()) { system.service->poll_one (); system.processor.poll_one (); + ++iterations1; + ASSERT_LT (iterations1, 200); } ASSERT_EQ (rai::scale_up (2), wallet.node.ledger.account_balance (key1.pub)); QTest::mouseClick (wallet.send_blocks_back, Qt::LeftButton); @@ -250,12 +253,12 @@ TEST (wallet, startup_work) ASSERT_TRUE (wallet.wallet_m->work.get (rai::test_genesis_key.pub, work1)); QTest::keyClicks (wallet.advanced.wallet_key_line, "34F0A37AAD20F4A260F0A5B3CB3D7FB50673212263E58A380BC10474BB039CE4"); QTest::mouseClick (wallet.advanced.wallet_add_key_button, Qt::LeftButton); - auto iterations2 (0); + auto iterations1 (0); while (wallet.wallet_m->work.get (rai::test_genesis_key.pub, work1)) { system.service->poll_one (); system.processor.poll_one (); - ++iterations2; - ASSERT_LT (iterations2, 200); + ++iterations1; + ASSERT_LT (iterations1, 200); } } \ No newline at end of file