Add work check for ledger::process () in Debug mode (#1939)

* Add work check for ledger::process () in Debug mode

* Update tests
This commit is contained in:
Sergey Kroshnin 2019-05-07 01:28:28 +03:00 committed by GitHub
commit 30539f82b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 312 additions and 223 deletions

View file

@ -804,7 +804,8 @@ TEST (block_store, upgrade_v2_v3)
store.initialize (transaction, genesis);
nano::stat stats;
nano::ledger ledger (store, stats);
nano::change_block change (hash, key1.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0);
nano::work_pool pool (std::numeric_limits<unsigned>::max ());
nano::change_block change (hash, key1.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, pool.generate (hash));
change_hash = change.hash ();
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, change).code);
ASSERT_EQ (0, ledger.weight (transaction, nano::test_genesis_key.pub));
@ -890,7 +891,8 @@ TEST (block_store, upgrade_v4_v5)
nano::account_info info;
ASSERT_FALSE (store.account_get (transaction, nano::test_genesis_key.pub, info));
nano::keypair key0;
nano::send_block block0 (info.head, key0.pub, nano::genesis_amount - nano::Gxrb_ratio, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0);
nano::work_pool pool (std::numeric_limits<unsigned>::max ());
nano::send_block block0 (info.head, key0.pub, nano::genesis_amount - nano::Gxrb_ratio, nano::test_genesis_key.prv, nano::test_genesis_key.pub, pool.generate (info.head));
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, block0).code);
hash = block0.hash ();
auto original (store.block_get (transaction, info.head));
@ -1211,7 +1213,8 @@ TEST (block_store, upgrade_sideband_two_blocks)
auto transaction (store.tx_begin_write ());
store.version_put (transaction, 11);
store.initialize (transaction, genesis);
nano::state_block block (nano::test_genesis_key.pub, genesis.hash (), nano::test_genesis_key.pub, nano::genesis_amount - nano::Gxrb_ratio, nano::test_genesis_key.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0);
nano::work_pool pool (std::numeric_limits<unsigned>::max ());
nano::state_block block (nano::test_genesis_key.pub, genesis.hash (), nano::test_genesis_key.pub, nano::genesis_amount - nano::Gxrb_ratio, nano::test_genesis_key.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, pool.generate (genesis.hash ()));
hash2 = block.hash ();
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, block).code);
write_legacy_sideband (store, transaction, *genesis.open, hash2, store.open_blocks);
@ -1250,10 +1253,11 @@ TEST (block_store, upgrade_sideband_two_accounts)
auto transaction (store.tx_begin_write ());
store.version_put (transaction, 11);
store.initialize (transaction, genesis);
nano::state_block block1 (nano::test_genesis_key.pub, genesis.hash (), nano::test_genesis_key.pub, nano::genesis_amount - nano::Gxrb_ratio, key.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0);
nano::work_pool pool (std::numeric_limits<unsigned>::max ());
nano::state_block block1 (nano::test_genesis_key.pub, genesis.hash (), nano::test_genesis_key.pub, nano::genesis_amount - nano::Gxrb_ratio, key.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, pool.generate (genesis.hash ()));
hash2 = block1.hash ();
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, block1).code);
nano::state_block block2 (key.pub, 0, nano::test_genesis_key.pub, nano::Gxrb_ratio, hash2, key.prv, key.pub, 0);
nano::state_block block2 (key.pub, 0, nano::test_genesis_key.pub, nano::Gxrb_ratio, hash2, key.prv, key.pub, pool.generate (key.pub));
hash3 = block2.hash ();
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, block2).code);
write_legacy_sideband (store, transaction, *genesis.open, hash2, store.open_blocks);
@ -1294,7 +1298,8 @@ TEST (block_store, insert_after_legacy)
store.version_put (transaction, 11);
store.initialize (transaction, genesis);
write_legacy_sideband (store, transaction, *genesis.open, 0, store.open_blocks);
nano::state_block block (nano::test_genesis_key.pub, genesis.hash (), nano::test_genesis_key.pub, nano::genesis_amount - nano::Gxrb_ratio, nano::test_genesis_key.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0);
nano::work_pool pool (std::numeric_limits<unsigned>::max ());
nano::state_block block (nano::test_genesis_key.pub, genesis.hash (), nano::test_genesis_key.pub, nano::genesis_amount - nano::Gxrb_ratio, nano::test_genesis_key.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, pool.generate (genesis.hash ()));
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, block).code);
}
@ -1321,6 +1326,7 @@ TEST (block_store, upgrade_sideband_epoch)
nano::genesis genesis;
nano::block_hash hash2;
auto path (nano::unique_path ());
nano::work_pool pool (std::numeric_limits<unsigned>::max ());
{
nano::logger_mt logger;
nano::mdb_store store (error, logger, path);
@ -1330,7 +1336,7 @@ TEST (block_store, upgrade_sideband_epoch)
auto transaction (store.tx_begin_write ());
store.version_put (transaction, 11);
store.initialize (transaction, genesis);
nano::state_block block1 (nano::test_genesis_key.pub, genesis.hash (), nano::test_genesis_key.pub, nano::genesis_amount, 42, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0);
nano::state_block block1 (nano::test_genesis_key.pub, genesis.hash (), nano::test_genesis_key.pub, nano::genesis_amount, 42, nano::test_genesis_key.prv, nano::test_genesis_key.pub, pool.generate (genesis.hash ()));
hash2 = block1.hash ();
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, block1).code);
ASSERT_EQ (nano::epoch::epoch_1, store.block_version (transaction, hash2));
@ -1349,7 +1355,7 @@ TEST (block_store, upgrade_sideband_epoch)
nano::block_sideband sideband;
auto block1 (store.block_get (transaction, hash2, &sideband));
ASSERT_NE (0, sideband.height);
nano::state_block block2 (nano::test_genesis_key.pub, hash2, nano::test_genesis_key.pub, nano::genesis_amount - nano::Gxrb_ratio, nano::test_genesis_key.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0);
nano::state_block block2 (nano::test_genesis_key.pub, hash2, nano::test_genesis_key.pub, nano::genesis_amount - nano::Gxrb_ratio, nano::test_genesis_key.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, pool.generate (hash2));
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, block2).code);
ASSERT_EQ (nano::epoch::epoch_1, store.block_version (transaction, block2.hash ()));
}
@ -1370,29 +1376,30 @@ TEST (block_store, sideband_height)
ledger.epoch_signer = epoch_key.pub;
auto transaction (store.tx_begin_write ());
store.initialize (transaction, genesis);
nano::send_block send (genesis.hash (), nano::test_genesis_key.pub, nano::genesis_amount - nano::Gxrb_ratio, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0);
nano::work_pool pool (std::numeric_limits<unsigned>::max ());
nano::send_block send (genesis.hash (), nano::test_genesis_key.pub, nano::genesis_amount - nano::Gxrb_ratio, nano::test_genesis_key.prv, nano::test_genesis_key.pub, pool.generate (genesis.hash ()));
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, send).code);
nano::receive_block receive (send.hash (), send.hash (), nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0);
nano::receive_block receive (send.hash (), send.hash (), nano::test_genesis_key.prv, nano::test_genesis_key.pub, pool.generate (send.hash ()));
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, receive).code);
nano::change_block change (receive.hash (), 0, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0);
nano::change_block change (receive.hash (), 0, nano::test_genesis_key.prv, nano::test_genesis_key.pub, pool.generate (receive.hash ()));
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, change).code);
nano::state_block state_send1 (nano::test_genesis_key.pub, change.hash (), 0, nano::genesis_amount - nano::Gxrb_ratio, key1.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0);
nano::state_block state_send1 (nano::test_genesis_key.pub, change.hash (), 0, nano::genesis_amount - nano::Gxrb_ratio, key1.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, pool.generate (change.hash ()));
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, state_send1).code);
nano::state_block state_send2 (nano::test_genesis_key.pub, state_send1.hash (), 0, nano::genesis_amount - 2 * nano::Gxrb_ratio, key2.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0);
nano::state_block state_send2 (nano::test_genesis_key.pub, state_send1.hash (), 0, nano::genesis_amount - 2 * nano::Gxrb_ratio, key2.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, pool.generate (state_send1.hash ()));
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, state_send2).code);
nano::state_block state_send3 (nano::test_genesis_key.pub, state_send2.hash (), 0, nano::genesis_amount - 3 * nano::Gxrb_ratio, key3.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0);
nano::state_block state_send3 (nano::test_genesis_key.pub, state_send2.hash (), 0, nano::genesis_amount - 3 * nano::Gxrb_ratio, key3.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, pool.generate (state_send2.hash ()));
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, state_send3).code);
nano::state_block state_open (key1.pub, 0, 0, nano::Gxrb_ratio, state_send1.hash (), key1.prv, key1.pub, 0);
nano::state_block state_open (key1.pub, 0, 0, nano::Gxrb_ratio, state_send1.hash (), key1.prv, key1.pub, pool.generate (key1.pub));
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, state_open).code);
nano::state_block epoch (key1.pub, state_open.hash (), 0, nano::Gxrb_ratio, ledger.epoch_link, epoch_key.prv, epoch_key.pub, 0);
nano::state_block epoch (key1.pub, state_open.hash (), 0, nano::Gxrb_ratio, ledger.epoch_link, epoch_key.prv, epoch_key.pub, pool.generate (state_open.hash ()));
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, epoch).code);
ASSERT_EQ (nano::epoch::epoch_1, store.block_version (transaction, epoch.hash ()));
nano::state_block epoch_open (key2.pub, 0, 0, 0, ledger.epoch_link, epoch_key.prv, epoch_key.pub, 0);
nano::state_block epoch_open (key2.pub, 0, 0, 0, ledger.epoch_link, epoch_key.prv, epoch_key.pub, pool.generate (key2.pub));
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, epoch_open).code);
ASSERT_EQ (nano::epoch::epoch_1, store.block_version (transaction, epoch_open.hash ()));
nano::state_block state_receive (key2.pub, epoch_open.hash (), 0, nano::Gxrb_ratio, state_send2.hash (), key2.prv, key2.pub, 0);
nano::state_block state_receive (key2.pub, epoch_open.hash (), 0, nano::Gxrb_ratio, state_send2.hash (), key2.prv, key2.pub, pool.generate (epoch_open.hash ()));
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, state_receive).code);
nano::open_block open (state_send3.hash (), nano::test_genesis_key.pub, key3.pub, key3.prv, key3.pub, 0);
nano::open_block open (state_send3.hash (), nano::test_genesis_key.pub, key3.pub, key3.prv, key3.pub, pool.generate (key3.pub));
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, open).code);
nano::block_sideband sideband1;
auto block1 (store.block_get (transaction, genesis.hash (), &sideband1));

File diff suppressed because it is too large Load diff

View file

@ -452,6 +452,7 @@ TEST (bulk_pull, end_not_owned)
open.hashables.representative = key2.pub;
open.hashables.source = latest;
open.signature = nano::sign_message (key2.prv, key2.pub, open.hash ());
system.nodes[0]->work_generate_blocking (open);
ASSERT_EQ (nano::process_result::progress, system.nodes[0]->process (open).code);
auto connection (std::make_shared<nano::bootstrap_server> (nullptr, system.nodes[0]));
nano::genesis genesis;

View file

@ -1397,6 +1397,8 @@ TEST (node, broadcast_elected)
node0->work_generate_blocking (open_big);
node0->work_generate_blocking (fund_small);
node0->work_generate_blocking (open_small);
node0->work_generate_blocking (fund_other);
node0->work_generate_blocking (open_other);
ASSERT_EQ (nano::process_result::progress, node0->ledger.process (transaction0, fund_big).code);
ASSERT_EQ (nano::process_result::progress, node1->ledger.process (transaction1, fund_big).code);
ASSERT_EQ (nano::process_result::progress, node2->ledger.process (transaction2, fund_big).code);

View file

@ -18,10 +18,11 @@ TEST (processor_service, bad_send_signature)
nano::genesis genesis;
auto transaction (store.tx_begin_write ());
store.initialize (transaction, genesis);
nano::work_pool pool (std::numeric_limits<unsigned>::max ());
nano::account_info info1;
ASSERT_FALSE (store.account_get (transaction, nano::test_genesis_key.pub, info1));
nano::keypair key2;
nano::send_block send (info1.head, nano::test_genesis_key.pub, 50, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0);
nano::send_block send (info1.head, nano::test_genesis_key.pub, 50, nano::test_genesis_key.prv, nano::test_genesis_key.pub, pool.generate (info1.head));
send.signature.bytes[32] ^= 0x1;
ASSERT_EQ (nano::process_result::bad_signature, ledger.process (transaction, send).code);
}
@ -37,14 +38,15 @@ TEST (processor_service, bad_receive_signature)
nano::genesis genesis;
auto transaction (store.tx_begin_write ());
store.initialize (transaction, genesis);
nano::work_pool pool (std::numeric_limits<unsigned>::max ());
nano::account_info info1;
ASSERT_FALSE (store.account_get (transaction, nano::test_genesis_key.pub, info1));
nano::send_block send (info1.head, nano::test_genesis_key.pub, 50, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0);
nano::send_block send (info1.head, nano::test_genesis_key.pub, 50, nano::test_genesis_key.prv, nano::test_genesis_key.pub, pool.generate (info1.head));
nano::block_hash hash1 (send.hash ());
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, send).code);
nano::account_info info2;
ASSERT_FALSE (store.account_get (transaction, nano::test_genesis_key.pub, info2));
nano::receive_block receive (hash1, hash1, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0);
nano::receive_block receive (hash1, hash1, nano::test_genesis_key.prv, nano::test_genesis_key.pub, pool.generate (hash1));
receive.signature.bytes[32] ^= 0x1;
ASSERT_EQ (nano::process_result::bad_signature, ledger.process (transaction, receive).code);
}

View file

@ -1,3 +1,4 @@
#include <nano/lib/work.hpp>
#include <nano/node/common.hpp>
#include <nano/node/stats.hpp>
#include <nano/secure/blockstore.hpp>
@ -707,6 +708,7 @@ nano::uint128_t nano::ledger::account_pending (nano::transaction const & transac
nano::process_return nano::ledger::process (nano::transaction const & transaction_a, nano::block const & block_a, nano::signature_verification verification)
{
assert (!nano::work_validate (block_a));
ledger_processor processor (*this, transaction_a, verification);
block_a.visit (processor);
return processor.result;