Require that the first block for an account receive something to match existing behavior.

This commit is contained in:
clemahieu 2018-03-12 23:26:15 -05:00
commit 9c8a3669d4
3 changed files with 23 additions and 2 deletions

View file

@ -1845,6 +1845,23 @@ TEST (ledger, utx_open_previous_fail)
ASSERT_EQ (rai::process_result::gap_previous, ledger.process (transaction, open1).code);
}
TEST (ledger, utx_open_source_fail)
{
bool init (false);
rai::block_store store (init, rai::unique_path ());
ASSERT_TRUE (!init);
rai::ledger ledger (store);
rai::genesis genesis;
ledger.utx_parse_canary = genesis.hash ();
rai::transaction transaction (store.environment, nullptr, true);
genesis.initialize (transaction, store);
rai::keypair destination;
rai::utx_block send1 (rai::genesis_account, genesis.hash (), rai::genesis_account, rai::genesis_amount - rai::Gxrb_ratio, destination.pub, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0);
ASSERT_EQ (rai::process_result::progress, ledger.process (transaction, send1).code);
rai::utx_block open1 (destination.pub, 0, rai::genesis_account, 0, 0, destination.prv, destination.pub, 0);
ASSERT_EQ (rai::process_result::gap_source, ledger.process (transaction, open1).code);
}
TEST (ledger, utx_send_change)
{
bool init (false);

View file

@ -3242,10 +3242,10 @@ TEST (rpc, block_create_utx_open)
ASSERT_NE (nullptr, utx_block);
ASSERT_EQ (rai::block_type::utx, utx_block->type ());
ASSERT_EQ (utx_hash, utx_block->hash ().to_string ());
ASSERT_TRUE (system.nodes [0]->latest (key.pub).is_zero ());
ASSERT_TRUE (system.nodes[0]->latest (key.pub).is_zero ());
auto process_result (system.nodes[0]->process (*utx_block));
ASSERT_EQ (rai::process_result::progress, process_result.code);
ASSERT_FALSE (system.nodes [0]->latest (key.pub).is_zero ());
ASSERT_FALSE (system.nodes[0]->latest (key.pub).is_zero ());
}
TEST (rpc, wallet_lock)

View file

@ -218,6 +218,10 @@ void ledger_processor::utx_block_impl (rai::utx_block const & block_a)
{
// Account does not yet exists
result.code = block_a.previous ().is_zero () ? rai::process_result::progress : rai::process_result::gap_previous; // Does the first block in an account yield 0 for previous() ? (Unambigious)
if (result.code == rai::process_result::progress)
{
result.code = !block_a.hashables.link.is_zero () ? rai::process_result::progress : rai::process_result::gap_source; // Is the first block receiving from a send ? (Unambigious)
}
}
if (result.code == rai::process_result::progress)
{