Generate ublocks if we control an account that already has one as its head block even if the generate canary hasn't been deployed.

This commit is contained in:
clemahieu 2018-03-13 16:34:46 -05:00
commit 7c215ed41d
3 changed files with 36 additions and 4 deletions

View file

@ -978,3 +978,26 @@ TEST (wallet, password_race_corrupt_seed)
}
}
}
TEST (wallet, utx_implicit_generate)
{
rai::system system (24000, 1);
system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv);
rai::genesis genesis;
system.nodes [0]->ledger.utx_parse_canary = genesis.hash ();
{
rai::transaction transaction (system.nodes [0]->store.environment, nullptr, true);
ASSERT_FALSE (system.wallet (0)->should_generate_utx (transaction, genesis.hash ()));
rai::utx_block block (rai::test_genesis_key.pub, genesis.hash (), rai::test_genesis_key.pub, rai::genesis_amount - rai::Gxrb_ratio, rai::test_genesis_key.pub, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0);
ASSERT_EQ (rai::process_result::progress, system.nodes [0]->ledger.process (transaction, block).code);
ASSERT_TRUE (system.wallet (0)->should_generate_utx (transaction, block.hash ()));
}
ASSERT_FALSE (system.wallet (0)->search_pending ());
auto iterations (0);
while (system.nodes [0]->balance (rai::test_genesis_key.pub) != rai::genesis_amount)
{
system.poll ();
++iterations;
ASSERT_LT (iterations, 200);
}
}

View file

@ -865,7 +865,7 @@ std::shared_ptr<rai::block> rai::wallet::receive_action (rai::block const & send
{
std::shared_ptr<rai::block> rep_block = node.ledger.store.block_get (transaction, info.rep_block);
assert (rep_block != nullptr);
if (node.ledger.utx_generation_enabled (transaction))
if (should_generate_utx (transaction, info.head))
{
block.reset (new rai::utx_block (account, info.head, rep_block->representative (), info.balance.number () + pending_info.amount.number (), hash, prv, account, generate_work_a ? work_fetch (transaction, account, info.head) : 0));
}
@ -878,7 +878,7 @@ std::shared_ptr<rai::block> rai::wallet::receive_action (rai::block const & send
{
if (node.ledger.utx_generation_enabled (transaction))
{
block.reset (new rai::utx_block (account, info.head, representative_a, pending_info.amount, hash, prv, account, generate_work_a ? work_fetch (transaction, account, account) : 0));
block.reset (new rai::utx_block (account, 0, representative_a, pending_info.amount, hash, prv, account, generate_work_a ? work_fetch (transaction, account, account) : 0));
}
else
{
@ -940,7 +940,7 @@ std::shared_ptr<rai::block> rai::wallet::change_action (rai::account const & sou
rai::raw_key prv;
auto error2 (store.fetch (transaction, source_a, prv));
assert (!error2);
if (node.ledger.utx_generation_enabled (transaction))
if (should_generate_utx (transaction, info.head))
{
block.reset (new rai::utx_block (source_a, info.head, representative_a, info.balance, 0, prv, source_a, generate_work_a ? work_fetch (transaction, source_a, info.head) : 0));
}
@ -1017,7 +1017,7 @@ std::shared_ptr<rai::block> rai::wallet::send_action (rai::account const & sourc
assert (!error2);
std::shared_ptr<rai::block> rep_block = node.ledger.store.block_get (transaction, info.rep_block);
assert (rep_block != nullptr);
if (node.ledger.utx_generation_enabled (transaction))
if (should_generate_utx (transaction, info.head))
{
block.reset (new rai::utx_block (source_a, info.head, rep_block->representative (), balance - amount_a, account_a, prv, source_a, generate_work_a ? work_fetch (transaction, source_a, info.head) : 0));
}
@ -1052,6 +1052,14 @@ std::shared_ptr<rai::block> rai::wallet::send_action (rai::account const & sourc
return block;
}
bool rai::wallet::should_generate_utx (MDB_txn * transaction_a, rai::block_hash const & hash_a)
{
auto head (node.store.block_get(transaction_a, hash_a));
assert (head != nullptr);
auto is_utx (dynamic_cast<rai::utx_block *> (head.get ()) != nullptr);
return is_utx || node.ledger.utx_generation_enabled (transaction_a);
}
bool rai::wallet::change_sync (rai::account const & source_a, rai::account const & representative_a)
{
std::promise<bool> result;

View file

@ -151,6 +151,7 @@ public:
void work_ensure (MDB_txn *, rai::account const &);
bool search_pending ();
void init_free_accounts (MDB_txn *);
bool should_generate_utx (MDB_txn *, rai::block_hash const &);
/** Changes the wallet seed and returns the first account */
rai::public_key change_seed (MDB_txn * transaction_a, rai::raw_key const & prv_a);
std::unordered_set<rai::account> free_accounts;