Correctly using cached work.
This commit is contained in:
parent
fe48fa01ce
commit
7b67611380
2 changed files with 18 additions and 15 deletions
24
rai/node.cpp
24
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 <rai::block> 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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue