Skip to content

Commit

Permalink
Merge branch 'pulls/841'
Browse files Browse the repository at this point in the history
  • Loading branch information
clemahieu committed May 3, 2018
2 parents 15f5716 + a47c8bf commit bb5b20f
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 319 deletions.
44 changes: 9 additions & 35 deletions rai/blockstore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ pending (0),
blocks_info (0),
representation (0),
unchecked (0),
unsynced (0),
checksum (0)
{
if (!error_a)
Expand All @@ -268,7 +267,6 @@ checksum (0)
error_a |= mdb_dbi_open (transaction, "blocks_info", MDB_CREATE, &blocks_info) != 0;
error_a |= mdb_dbi_open (transaction, "representation", MDB_CREATE, &representation) != 0;
error_a |= mdb_dbi_open (transaction, "unchecked", MDB_CREATE | MDB_DUPSORT, &unchecked) != 0;
error_a |= mdb_dbi_open (transaction, "unsynced", MDB_CREATE, &unsynced) != 0;
error_a |= mdb_dbi_open (transaction, "checksum", MDB_CREATE, &checksum) != 0;
error_a |= mdb_dbi_open (transaction, "vote", MDB_CREATE, &vote) != 0;
error_a |= mdb_dbi_open (transaction, "meta", MDB_CREATE, &meta) != 0;
Expand Down Expand Up @@ -330,6 +328,8 @@ void rai::block_store::do_upgrades (MDB_txn * transaction_a)
case 9:
upgrade_v9_to_v10 (transaction_a);
case 10:
upgrade_v10_to_v11 (transaction_a);
case 11:
break;
default:
assert (false);
Expand Down Expand Up @@ -524,6 +524,13 @@ void rai::block_store::upgrade_v9_to_v10 (MDB_txn * transaction_a)
//std::cerr << boost::str (boost::format ("Database upgrade is completed\n"));
}

void rai::block_store::upgrade_v10_to_v11 (MDB_txn * transaction_a)
{
MDB_dbi unsynced;
mdb_dbi_open (transaction_a, "unsynced", MDB_CREATE | MDB_DUPSORT, &unsynced);
mdb_drop (transaction_a, unsynced, 1);
}

void rai::block_store::clear (MDB_dbi db_a)
{
rai::transaction transaction (environment, nullptr, true);
Expand Down Expand Up @@ -1117,39 +1124,6 @@ size_t rai::block_store::unchecked_count (MDB_txn * transaction_a)
return result;
}

void rai::block_store::unsynced_put (MDB_txn * transaction_a, rai::block_hash const & hash_a)
{
auto status (mdb_put (transaction_a, unsynced, rai::mdb_val (hash_a), rai::mdb_val (0, nullptr), 0));
assert (status == 0);
}

void rai::block_store::unsynced_del (MDB_txn * transaction_a, rai::block_hash const & hash_a)
{
auto status (mdb_del (transaction_a, unsynced, rai::mdb_val (hash_a), nullptr));
assert (status == 0);
}

bool rai::block_store::unsynced_exists (MDB_txn * transaction_a, rai::block_hash const & hash_a)
{
auto iterator (unsynced_begin (transaction_a, hash_a));
return iterator != rai::store_iterator (nullptr) && rai::block_hash (iterator->first.uint256 ()) == hash_a;
}

rai::store_iterator rai::block_store::unsynced_begin (MDB_txn * transaction_a)
{
return rai::store_iterator (transaction_a, unsynced);
}

rai::store_iterator rai::block_store::unsynced_begin (MDB_txn * transaction_a, rai::uint256_union const & val_a)
{
return rai::store_iterator (transaction_a, unsynced, rai::mdb_val (val_a));
}

rai::store_iterator rai::block_store::unsynced_end ()
{
return rai::store_iterator (nullptr);
}

void rai::block_store::checksum_put (MDB_txn * transaction_a, uint64_t prefix, uint8_t mask, rai::uint256_union const & hash_a)
{
assert ((prefix & 0xff) == 0);
Expand Down
14 changes: 1 addition & 13 deletions rai/blockstore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,6 @@ class block_store
size_t unchecked_count (MDB_txn *);
std::unordered_multimap<rai::block_hash, std::shared_ptr<rai::block>> unchecked_cache;

void unsynced_put (MDB_txn *, rai::block_hash const &);
void unsynced_del (MDB_txn *, rai::block_hash const &);
bool unsynced_exists (MDB_txn *, rai::block_hash const &);
rai::store_iterator unsynced_begin (MDB_txn *, rai::block_hash const &);
rai::store_iterator unsynced_begin (MDB_txn *);
rai::store_iterator unsynced_end ();

void checksum_put (MDB_txn *, uint64_t, uint8_t, rai::checksum const &);
bool checksum_get (MDB_txn *, uint64_t, uint8_t, rai::checksum &);
void checksum_del (MDB_txn *, uint64_t, uint8_t);
Expand Down Expand Up @@ -145,6 +138,7 @@ class block_store
void upgrade_v7_to_v8 (MDB_txn *);
void upgrade_v8_to_v9 (MDB_txn *);
void upgrade_v9_to_v10 (MDB_txn *);
void upgrade_v10_to_v11 (MDB_txn *);

void clear (MDB_dbi);

Expand Down Expand Up @@ -216,12 +210,6 @@ class block_store
*/
MDB_dbi unchecked;

/**
* Blocks that haven't been broadcast.
* rai::block_hash -> (no value)
*/
MDB_dbi unsynced;

/**
* Mapping of region to checksum.
* (uint56_t, uint8_t) -> rai::block_hash
Expand Down
39 changes: 0 additions & 39 deletions rai/core_test/block_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,45 +480,6 @@ TEST (block_store, latest_exists)
ASSERT_FALSE (store.account_exists (transaction, one));
}

TEST (block_store, unsynced)
{
bool init (false);
rai::block_store store (init, rai::unique_path ());
ASSERT_TRUE (!init);
rai::transaction transaction (store.environment, nullptr, true);
ASSERT_EQ (store.unsynced_end (), store.unsynced_begin (transaction));
rai::block_hash hash1 (0);
ASSERT_FALSE (store.unsynced_exists (transaction, hash1));
store.unsynced_put (transaction, hash1);
ASSERT_TRUE (store.unsynced_exists (transaction, hash1));
ASSERT_NE (store.unsynced_end (), store.unsynced_begin (transaction));
ASSERT_EQ (hash1, rai::uint256_union (store.unsynced_begin (transaction)->first.uint256 ()));
store.unsynced_del (transaction, hash1);
ASSERT_FALSE (store.unsynced_exists (transaction, hash1));
ASSERT_EQ (store.unsynced_end (), store.unsynced_begin (transaction));
}

TEST (block_store, unsynced_iteration)
{
bool init (false);
rai::block_store store (init, rai::unique_path ());
ASSERT_TRUE (!init);
rai::transaction transaction (store.environment, nullptr, true);
ASSERT_EQ (store.unsynced_end (), store.unsynced_begin (transaction));
rai::block_hash hash1 (1);
store.unsynced_put (transaction, hash1);
rai::block_hash hash2 (2);
store.unsynced_put (transaction, hash2);
std::unordered_set<rai::block_hash> hashes;
for (auto i (store.unsynced_begin (transaction)), n (store.unsynced_end ()); i != n; ++i)
{
hashes.insert (rai::uint256_union (i->first.uint256 ()));
}
ASSERT_EQ (2, hashes.size ());
ASSERT_TRUE (hashes.find (hash1) != hashes.end ());
ASSERT_TRUE (hashes.find (hash2) != hashes.end ());
}

TEST (block_store, large_iteration)
{
bool init (false);
Expand Down
31 changes: 31 additions & 0 deletions rai/core_test/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,37 @@ TEST (node, DISABLED_bootstrap_no_publish)
}
}

// Check that an outgoing bootstrap request can push blocks
TEST (node, bootstrap_bulk_push)
{
rai::system system0 (24000, 1);
rai::system system1 (24001, 1);
auto node0 (system0.nodes[0]);
auto node1 (system1.nodes[0]);
rai::keypair key0;
// node0 knows about send0 but node1 doesn't.
rai::send_block send0 (system0.nodes[0]->latest (rai::test_genesis_key.pub), key0.pub, 500, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0);
node0->generate_work (send0);
{
rai::transaction transaction (node0->store.environment, nullptr, true);
ASSERT_EQ (rai::process_result::progress, system0.nodes[0]->ledger.process (transaction, send0).code);
}
ASSERT_FALSE (node0->bootstrap_initiator.in_progress ());
ASSERT_FALSE (node1->bootstrap_initiator.in_progress ());
ASSERT_TRUE (node1->active.roots.empty ());
node0->bootstrap_initiator.bootstrap (node1->network.endpoint (), false);
auto iterations1 (0);
while (node1->block (send0.hash ()) == nullptr)
{
system0.poll ();
system1.poll ();
++iterations1;
ASSERT_GT (200, iterations1);
}
// since this uses bulk_push, the new block should be republished
ASSERT_FALSE (node1->active.roots.empty ());
}

// Bootstrapping a forked open block should succeed.
TEST (node, bootstrap_fork_open)
{
Expand Down
2 changes: 1 addition & 1 deletion rai/core_test/wallets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ TEST (wallets, wallet_create_max)
rai::system system (24000, 1);
bool error (false);
rai::wallets wallets (error, *system.nodes[0]);
const int nonWalletDbs = 17;
const int nonWalletDbs = 16;
for (int i = 0; i < system.nodes[0]->config.lmdb_max_dbs - nonWalletDbs; i++)
{
rai::keypair key;
Expand Down
Loading

0 comments on commit bb5b20f

Please sign in to comment.