Moving functions around.
This commit is contained in:
parent
e18df12b5e
commit
8fce9fa22b
5 changed files with 348 additions and 303 deletions
|
@ -1845,66 +1845,12 @@ void rai::rpc::operator () (boost::network::http::server <rai::rpc>::request con
|
|||
}
|
||||
}
|
||||
|
||||
rai::uint128_t rai::block_store::representation_get (rai::account const & account_a)
|
||||
{
|
||||
std::string value;
|
||||
auto status (representation->Get (leveldb::ReadOptions (), leveldb::Slice (account_a.chars.data (), account_a.chars.size ()), &value));
|
||||
assert (status.ok () || status.IsNotFound ());
|
||||
rai::uint128_t result;
|
||||
if (status.ok ())
|
||||
{
|
||||
rai::uint128_union rep;
|
||||
rai::bufferstream stream (reinterpret_cast <uint8_t const *> (value.data ()), value.size ());
|
||||
auto error (rai::read (stream, rep));
|
||||
assert (!error);
|
||||
result = rep.number ();
|
||||
}
|
||||
else
|
||||
{
|
||||
result = 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void rai::block_store::representation_put (rai::account const & account_a, rai::uint128_t const & representation_a)
|
||||
{
|
||||
rai::uint128_union rep (representation_a);
|
||||
auto status (representation->Put (leveldb::WriteOptions (), leveldb::Slice (account_a.chars.data (), account_a.chars.size ()), leveldb::Slice (rep.chars.data (), rep.chars.size ())));
|
||||
assert (status.ok ());
|
||||
}
|
||||
|
||||
void rai::confirm_unk::serialize (rai::stream & stream_a)
|
||||
{
|
||||
write_header (stream_a);
|
||||
write (stream_a, rep_hint);
|
||||
}
|
||||
|
||||
std::unique_ptr <rai::block> rai::block_store::fork_get (rai::block_hash const & hash_a)
|
||||
{
|
||||
std::string value;
|
||||
auto status (forks->Get (leveldb::ReadOptions (), leveldb::Slice (hash_a.chars.data (), hash_a.chars.size ()), &value));
|
||||
assert (status.ok () || status.IsNotFound ());
|
||||
std::unique_ptr <rai::block> result;
|
||||
if (status.ok ())
|
||||
{
|
||||
rai::bufferstream stream (reinterpret_cast <uint8_t const *> (value.data ()), value.size ());
|
||||
result = rai::deserialize_block (stream);
|
||||
assert (result != nullptr);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void rai::block_store::fork_put (rai::block_hash const & hash_a, rai::block const & block_a)
|
||||
{
|
||||
std::vector <uint8_t> vector;
|
||||
{
|
||||
rai::vectorstream stream (vector);
|
||||
rai::serialize_block (stream, block_a);
|
||||
}
|
||||
auto status (forks->Put (leveldb::WriteOptions (), leveldb::Slice (hash_a.chars.data (), hash_a.chars.size ()), leveldb::Slice (reinterpret_cast <char const *> (vector.data ()), vector.size ())));
|
||||
assert (status.ok ());
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
class rollback_visitor : public rai::block_visitor
|
||||
|
@ -2826,38 +2772,6 @@ bool rai::block_store::block_exists (rai::block_hash const & hash_a)
|
|||
return result;
|
||||
}
|
||||
|
||||
void rai::block_store::bootstrap_put (rai::block_hash const & hash_a, rai::block const & block_a)
|
||||
{
|
||||
std::vector <uint8_t> vector;
|
||||
{
|
||||
rai::vectorstream stream (vector);
|
||||
rai::serialize_block (stream, block_a);
|
||||
}
|
||||
auto status (bootstrap->Put (leveldb::WriteOptions (), leveldb::Slice (hash_a.chars.data (), hash_a.chars.size ()), leveldb::Slice (reinterpret_cast <char const *> (vector.data ()), vector.size ())));
|
||||
assert (status.ok () | status.IsNotFound ());
|
||||
}
|
||||
|
||||
std::unique_ptr <rai::block> rai::block_store::bootstrap_get (rai::block_hash const & hash_a)
|
||||
{
|
||||
std::string value;
|
||||
auto status (bootstrap->Get (leveldb::ReadOptions (), leveldb::Slice (hash_a.chars.data (), hash_a.chars.size ()), &value));
|
||||
assert (status.ok () || status.IsNotFound ());
|
||||
std::unique_ptr <rai::block> result;
|
||||
if (status.ok ())
|
||||
{
|
||||
rai::bufferstream stream (reinterpret_cast <uint8_t const *> (value.data ()), value.size ());
|
||||
result = rai::deserialize_block (stream);
|
||||
assert (result != nullptr);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void rai::block_store::bootstrap_del (rai::block_hash const & hash_a)
|
||||
{
|
||||
auto status (bootstrap->Delete (leveldb::WriteOptions (), leveldb::Slice (hash_a.chars.data (), hash_a.chars.size ())));
|
||||
assert (status.ok ());
|
||||
}
|
||||
|
||||
rai::endpoint rai::network::endpoint ()
|
||||
{
|
||||
return rai::endpoint (boost::asio::ip::address_v6::loopback (), socket.local_endpoint ().port ());
|
||||
|
@ -3621,43 +3535,6 @@ void rai::bulk_push_client::push_block ()
|
|||
});
|
||||
}
|
||||
|
||||
void rai::block_store::checksum_put (uint64_t prefix, uint8_t mask, rai::uint256_union const & hash_a)
|
||||
{
|
||||
assert ((prefix & 0xff) == 0);
|
||||
uint64_t key (prefix | mask);
|
||||
auto status (checksum->Put (leveldb::WriteOptions (), leveldb::Slice (reinterpret_cast <char const *> (&key), sizeof (uint64_t)), leveldb::Slice (hash_a.chars.data (), hash_a.chars.size ())));
|
||||
assert (status.ok ());
|
||||
}
|
||||
|
||||
bool rai::block_store::checksum_get (uint64_t prefix, uint8_t mask, rai::uint256_union & hash_a)
|
||||
{
|
||||
assert ((prefix & 0xff) == 0);
|
||||
std::string value;
|
||||
uint64_t key (prefix | mask);
|
||||
auto status (checksum->Get (leveldb::ReadOptions (), leveldb::Slice (reinterpret_cast <char const *> (&key), sizeof (uint64_t)), &value));
|
||||
assert (status.ok () || status.IsNotFound ());
|
||||
bool result;
|
||||
if (status.ok ())
|
||||
{
|
||||
result = false;
|
||||
rai::bufferstream stream (reinterpret_cast <uint8_t const *> (value.data ()), value.size ());
|
||||
auto error (rai::read (stream, hash_a));
|
||||
assert (!error);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void rai::block_store::checksum_del (uint64_t prefix, uint8_t mask)
|
||||
{
|
||||
assert ((prefix & 0xff) == 0);
|
||||
uint64_t key (prefix | mask);
|
||||
checksum->Delete (leveldb::WriteOptions (), leveldb::Slice (reinterpret_cast <char const *> (&key), sizeof (uint64_t)));
|
||||
}
|
||||
|
||||
bool rai::keepalive::operator == (rai::keepalive const & other_a) const
|
||||
{
|
||||
return peers == other_a.peers;
|
||||
|
|
|
@ -227,181 +227,6 @@ TEST (send_block, copy)
|
|||
ASSERT_EQ (block1, block2);
|
||||
}
|
||||
|
||||
TEST (block_store, empty_blocks)
|
||||
{
|
||||
leveldb::Status init;
|
||||
rai::block_store store (init, rai::block_store_temp);
|
||||
ASSERT_TRUE (init.ok ());
|
||||
auto begin (store.blocks_begin ());
|
||||
auto end (store.blocks_end ());
|
||||
ASSERT_EQ (end, begin);
|
||||
}
|
||||
|
||||
TEST (block_store, empty_accounts)
|
||||
{
|
||||
leveldb::Status init;
|
||||
rai::block_store store (init, rai::block_store_temp);
|
||||
ASSERT_TRUE (init.ok ());
|
||||
auto begin (store.latest_begin ());
|
||||
auto end (store.latest_end ());
|
||||
ASSERT_EQ (end, begin);
|
||||
}
|
||||
|
||||
TEST (block_store, one_block)
|
||||
{
|
||||
leveldb::Status init;
|
||||
rai::block_store store (init, rai::block_store_temp);
|
||||
ASSERT_TRUE (init.ok ());
|
||||
rai::send_block block1;
|
||||
store.block_put (block1.hash (), block1);
|
||||
auto begin (store.blocks_begin ());
|
||||
auto end (store.blocks_end ());
|
||||
ASSERT_NE (end, begin);
|
||||
auto hash1 (begin->first);
|
||||
ASSERT_EQ (block1.hash (), hash1);
|
||||
auto block2 (begin->second->clone ());
|
||||
ASSERT_EQ (block1, *block2);
|
||||
++begin;
|
||||
ASSERT_EQ (end, begin);
|
||||
}
|
||||
|
||||
TEST (block_store, frontier_retrieval)
|
||||
{
|
||||
leveldb::Status init;
|
||||
rai::block_store store (init, rai::block_store_temp);
|
||||
ASSERT_TRUE (init.ok ());;
|
||||
rai::account account1;
|
||||
rai::frontier frontier1;
|
||||
store.latest_put (account1, frontier1);
|
||||
rai::frontier frontier2;
|
||||
store.latest_get (account1, frontier2);
|
||||
ASSERT_EQ (frontier1, frontier2);
|
||||
}
|
||||
|
||||
TEST (block_store, one_account)
|
||||
{
|
||||
leveldb::Status init;
|
||||
rai::block_store store (init, rai::block_store_temp);
|
||||
ASSERT_TRUE (init.ok ());
|
||||
rai::account account;
|
||||
rai::block_hash hash;
|
||||
store.latest_put (account, {hash, account, 42, 100});
|
||||
auto begin (store.latest_begin ());
|
||||
auto end (store.latest_end ());
|
||||
ASSERT_NE (end, begin);
|
||||
ASSERT_EQ (account, begin->first);
|
||||
ASSERT_EQ (hash, begin->second.hash);
|
||||
ASSERT_EQ (42, begin->second.balance.number ());
|
||||
ASSERT_EQ (100, begin->second.time);
|
||||
++begin;
|
||||
ASSERT_EQ (end, begin);
|
||||
}
|
||||
|
||||
TEST (block_store, two_block)
|
||||
{
|
||||
leveldb::Status init;
|
||||
rai::block_store store (init, rai::block_store_temp);
|
||||
ASSERT_TRUE (init.ok ());
|
||||
rai::send_block block1;
|
||||
block1.hashables.destination = 1;
|
||||
block1.hashables.balance = 2;
|
||||
std::vector <rai::block_hash> hashes;
|
||||
std::vector <rai::send_block> blocks;
|
||||
hashes.push_back (block1.hash ());
|
||||
blocks.push_back (block1);
|
||||
store.block_put (hashes [0], block1);
|
||||
rai::send_block block2;
|
||||
block2.hashables.destination = 3;
|
||||
block2.hashables.balance = 4;
|
||||
hashes.push_back (block2.hash ());
|
||||
blocks.push_back (block2);
|
||||
store.block_put (hashes [1], block2);
|
||||
auto begin (store.blocks_begin ());
|
||||
auto end (store.blocks_end ());
|
||||
ASSERT_NE (end, begin);
|
||||
auto hash1 (begin->first);
|
||||
ASSERT_NE (hashes.end (), std::find (hashes.begin (), hashes.end (), hash1));
|
||||
auto block3 (begin->second->clone ());
|
||||
ASSERT_NE (blocks.end (), std::find (blocks.begin (), blocks.end (), *block3));
|
||||
++begin;
|
||||
ASSERT_NE (end, begin);
|
||||
auto hash2 (begin->first);
|
||||
ASSERT_NE (hashes.end (), std::find (hashes.begin (), hashes.end (), hash2));
|
||||
auto block4 (begin->second->clone ());
|
||||
ASSERT_NE (blocks.end (), std::find (blocks.begin (), blocks.end (), *block4));
|
||||
++begin;
|
||||
ASSERT_EQ (end, begin);
|
||||
}
|
||||
|
||||
TEST (block_store, two_account)
|
||||
{
|
||||
leveldb::Status init;
|
||||
rai::block_store store (init, rai::block_store_temp);
|
||||
ASSERT_TRUE (init.ok ());
|
||||
rai::account account1 (1);
|
||||
rai::block_hash hash1 (2);
|
||||
rai::account account2 (3);
|
||||
rai::block_hash hash2 (4);
|
||||
store.latest_put (account1, {hash1, account1, 42, 100});
|
||||
store.latest_put (account2, {hash2, account2, 84, 200});
|
||||
auto begin (store.latest_begin ());
|
||||
auto end (store.latest_end ());
|
||||
ASSERT_NE (end, begin);
|
||||
ASSERT_EQ (account1, begin->first);
|
||||
ASSERT_EQ (hash1, begin->second.hash);
|
||||
ASSERT_EQ (42, begin->second.balance.number ());
|
||||
ASSERT_EQ (100, begin->second.time);
|
||||
++begin;
|
||||
ASSERT_NE (end, begin);
|
||||
ASSERT_EQ (account2, begin->first);
|
||||
ASSERT_EQ (hash2, begin->second.hash);
|
||||
ASSERT_EQ (84, begin->second.balance.number ());
|
||||
ASSERT_EQ (200, begin->second.time);
|
||||
++begin;
|
||||
ASSERT_EQ (end, begin);
|
||||
}
|
||||
|
||||
TEST (block_store, latest_find)
|
||||
{
|
||||
leveldb::Status init;
|
||||
rai::block_store store (init, rai::block_store_temp);
|
||||
ASSERT_TRUE (init.ok ());
|
||||
rai::account account1 (1);
|
||||
rai::block_hash hash1 (2);
|
||||
rai::account account2 (3);
|
||||
rai::block_hash hash2 (4);
|
||||
store.latest_put (account1, {hash1, account1, 100});
|
||||
store.latest_put (account2, {hash2, account2, 200});
|
||||
auto first (store.latest_begin ());
|
||||
auto second (store.latest_begin ());
|
||||
++second;
|
||||
auto find1 (store.latest_begin (1));
|
||||
ASSERT_EQ (first, find1);
|
||||
auto find2 (store.latest_begin (3));
|
||||
ASSERT_EQ (second, find2);
|
||||
auto find3 (store.latest_begin (2));
|
||||
ASSERT_EQ (second, find3);
|
||||
}
|
||||
|
||||
TEST (block_store, bad_path)
|
||||
{
|
||||
leveldb::Status init;
|
||||
rai::block_store store (init, boost::filesystem::path {});
|
||||
ASSERT_FALSE (init.ok ());
|
||||
}
|
||||
|
||||
TEST (block_store, already_open)
|
||||
{
|
||||
auto path (boost::filesystem::unique_path ());
|
||||
boost::filesystem::create_directories (path);
|
||||
std::ofstream file;
|
||||
file.open ((path / "accounts.ldb").string ().c_str ());
|
||||
ASSERT_TRUE (file.is_open ());
|
||||
leveldb::Status init;
|
||||
rai::block_store store (init, path);
|
||||
ASSERT_FALSE (init.ok ());
|
||||
}
|
||||
|
||||
TEST (gap_cache, add_new)
|
||||
{
|
||||
rai::gap_cache cache;
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <rai/core/core.hpp>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
TEST (block_store, construction)
|
||||
{
|
||||
leveldb::Status init;
|
||||
|
@ -197,6 +199,209 @@ TEST (checksum, simple)
|
|||
ASSERT_TRUE (store.checksum_get (0x100, 0x10, hash3));
|
||||
}
|
||||
|
||||
TEST (block_store, empty_blocks)
|
||||
{
|
||||
leveldb::Status init;
|
||||
rai::block_store store (init, rai::block_store_temp);
|
||||
ASSERT_TRUE (init.ok ());
|
||||
auto begin (store.blocks_begin ());
|
||||
auto end (store.blocks_end ());
|
||||
ASSERT_EQ (end, begin);
|
||||
}
|
||||
|
||||
TEST (block_store, empty_accounts)
|
||||
{
|
||||
leveldb::Status init;
|
||||
rai::block_store store (init, rai::block_store_temp);
|
||||
ASSERT_TRUE (init.ok ());
|
||||
auto begin (store.latest_begin ());
|
||||
auto end (store.latest_end ());
|
||||
ASSERT_EQ (end, begin);
|
||||
}
|
||||
|
||||
TEST (block_store, one_block)
|
||||
{
|
||||
leveldb::Status init;
|
||||
rai::block_store store (init, rai::block_store_temp);
|
||||
ASSERT_TRUE (init.ok ());
|
||||
rai::send_block block1;
|
||||
store.block_put (block1.hash (), block1);
|
||||
auto begin (store.blocks_begin ());
|
||||
auto end (store.blocks_end ());
|
||||
ASSERT_NE (end, begin);
|
||||
auto hash1 (begin->first);
|
||||
ASSERT_EQ (block1.hash (), hash1);
|
||||
auto block2 (begin->second->clone ());
|
||||
ASSERT_EQ (block1, *block2);
|
||||
++begin;
|
||||
ASSERT_EQ (end, begin);
|
||||
}
|
||||
|
||||
TEST (block_store, empty_bootstrap)
|
||||
{
|
||||
leveldb::Status init;
|
||||
rai::block_store store (init, rai::block_store_temp);
|
||||
ASSERT_TRUE (init.ok ());
|
||||
auto begin (store.bootstrap_begin ());
|
||||
auto end (store.bootstrap_end ());
|
||||
ASSERT_EQ (end, begin);
|
||||
}
|
||||
|
||||
TEST (block_store, one_bootstrap)
|
||||
{
|
||||
leveldb::Status init;
|
||||
rai::block_store store (init, rai::block_store_temp);
|
||||
ASSERT_TRUE (init.ok ());
|
||||
rai::send_block block1;
|
||||
store.bootstrap_put (block1.hash (), block1);
|
||||
auto begin (store.bootstrap_begin ());
|
||||
auto end (store.bootstrap_end ());
|
||||
ASSERT_NE (end, begin);
|
||||
auto hash1 (begin->first);
|
||||
ASSERT_EQ (block1.hash (), hash1);
|
||||
auto block2 (begin->second->clone ());
|
||||
ASSERT_EQ (block1, *block2);
|
||||
++begin;
|
||||
ASSERT_EQ (end, begin);
|
||||
}
|
||||
|
||||
TEST (block_store, frontier_retrieval)
|
||||
{
|
||||
leveldb::Status init;
|
||||
rai::block_store store (init, rai::block_store_temp);
|
||||
ASSERT_TRUE (init.ok ());;
|
||||
rai::account account1;
|
||||
rai::frontier frontier1;
|
||||
store.latest_put (account1, frontier1);
|
||||
rai::frontier frontier2;
|
||||
store.latest_get (account1, frontier2);
|
||||
ASSERT_EQ (frontier1, frontier2);
|
||||
}
|
||||
|
||||
TEST (block_store, one_account)
|
||||
{
|
||||
leveldb::Status init;
|
||||
rai::block_store store (init, rai::block_store_temp);
|
||||
ASSERT_TRUE (init.ok ());
|
||||
rai::account account;
|
||||
rai::block_hash hash;
|
||||
store.latest_put (account, {hash, account, 42, 100});
|
||||
auto begin (store.latest_begin ());
|
||||
auto end (store.latest_end ());
|
||||
ASSERT_NE (end, begin);
|
||||
ASSERT_EQ (account, begin->first);
|
||||
ASSERT_EQ (hash, begin->second.hash);
|
||||
ASSERT_EQ (42, begin->second.balance.number ());
|
||||
ASSERT_EQ (100, begin->second.time);
|
||||
++begin;
|
||||
ASSERT_EQ (end, begin);
|
||||
}
|
||||
|
||||
TEST (block_store, two_block)
|
||||
{
|
||||
leveldb::Status init;
|
||||
rai::block_store store (init, rai::block_store_temp);
|
||||
ASSERT_TRUE (init.ok ());
|
||||
rai::send_block block1;
|
||||
block1.hashables.destination = 1;
|
||||
block1.hashables.balance = 2;
|
||||
std::vector <rai::block_hash> hashes;
|
||||
std::vector <rai::send_block> blocks;
|
||||
hashes.push_back (block1.hash ());
|
||||
blocks.push_back (block1);
|
||||
store.block_put (hashes [0], block1);
|
||||
rai::send_block block2;
|
||||
block2.hashables.destination = 3;
|
||||
block2.hashables.balance = 4;
|
||||
hashes.push_back (block2.hash ());
|
||||
blocks.push_back (block2);
|
||||
store.block_put (hashes [1], block2);
|
||||
auto begin (store.blocks_begin ());
|
||||
auto end (store.blocks_end ());
|
||||
ASSERT_NE (end, begin);
|
||||
auto hash1 (begin->first);
|
||||
ASSERT_NE (hashes.end (), std::find (hashes.begin (), hashes.end (), hash1));
|
||||
auto block3 (begin->second->clone ());
|
||||
ASSERT_NE (blocks.end (), std::find (blocks.begin (), blocks.end (), *block3));
|
||||
++begin;
|
||||
ASSERT_NE (end, begin);
|
||||
auto hash2 (begin->first);
|
||||
ASSERT_NE (hashes.end (), std::find (hashes.begin (), hashes.end (), hash2));
|
||||
auto block4 (begin->second->clone ());
|
||||
ASSERT_NE (blocks.end (), std::find (blocks.begin (), blocks.end (), *block4));
|
||||
++begin;
|
||||
ASSERT_EQ (end, begin);
|
||||
}
|
||||
|
||||
TEST (block_store, two_account)
|
||||
{
|
||||
leveldb::Status init;
|
||||
rai::block_store store (init, rai::block_store_temp);
|
||||
ASSERT_TRUE (init.ok ());
|
||||
rai::account account1 (1);
|
||||
rai::block_hash hash1 (2);
|
||||
rai::account account2 (3);
|
||||
rai::block_hash hash2 (4);
|
||||
store.latest_put (account1, {hash1, account1, 42, 100});
|
||||
store.latest_put (account2, {hash2, account2, 84, 200});
|
||||
auto begin (store.latest_begin ());
|
||||
auto end (store.latest_end ());
|
||||
ASSERT_NE (end, begin);
|
||||
ASSERT_EQ (account1, begin->first);
|
||||
ASSERT_EQ (hash1, begin->second.hash);
|
||||
ASSERT_EQ (42, begin->second.balance.number ());
|
||||
ASSERT_EQ (100, begin->second.time);
|
||||
++begin;
|
||||
ASSERT_NE (end, begin);
|
||||
ASSERT_EQ (account2, begin->first);
|
||||
ASSERT_EQ (hash2, begin->second.hash);
|
||||
ASSERT_EQ (84, begin->second.balance.number ());
|
||||
ASSERT_EQ (200, begin->second.time);
|
||||
++begin;
|
||||
ASSERT_EQ (end, begin);
|
||||
}
|
||||
|
||||
TEST (block_store, latest_find)
|
||||
{
|
||||
leveldb::Status init;
|
||||
rai::block_store store (init, rai::block_store_temp);
|
||||
ASSERT_TRUE (init.ok ());
|
||||
rai::account account1 (1);
|
||||
rai::block_hash hash1 (2);
|
||||
rai::account account2 (3);
|
||||
rai::block_hash hash2 (4);
|
||||
store.latest_put (account1, {hash1, account1, 100});
|
||||
store.latest_put (account2, {hash2, account2, 200});
|
||||
auto first (store.latest_begin ());
|
||||
auto second (store.latest_begin ());
|
||||
++second;
|
||||
auto find1 (store.latest_begin (1));
|
||||
ASSERT_EQ (first, find1);
|
||||
auto find2 (store.latest_begin (3));
|
||||
ASSERT_EQ (second, find2);
|
||||
auto find3 (store.latest_begin (2));
|
||||
ASSERT_EQ (second, find3);
|
||||
}
|
||||
|
||||
TEST (block_store, bad_path)
|
||||
{
|
||||
leveldb::Status init;
|
||||
rai::block_store store (init, boost::filesystem::path {});
|
||||
ASSERT_FALSE (init.ok ());
|
||||
}
|
||||
|
||||
TEST (block_store, already_open)
|
||||
{
|
||||
auto path (boost::filesystem::unique_path ());
|
||||
boost::filesystem::create_directories (path);
|
||||
std::ofstream file;
|
||||
file.open ((path / "accounts.ldb").string ().c_str ());
|
||||
ASSERT_TRUE (file.is_open ());
|
||||
leveldb::Status init;
|
||||
rai::block_store store (init, path);
|
||||
ASSERT_FALSE (init.ok ());
|
||||
}
|
||||
|
||||
TEST (block_store, delete_iterator_entry)
|
||||
{
|
||||
leveldb::Status init;
|
||||
|
@ -214,5 +419,6 @@ TEST (block_store, delete_iterator_entry)
|
|||
++current;
|
||||
ASSERT_NE (store.blocks_end (), current);
|
||||
store.block_del (current->first);
|
||||
++current;
|
||||
ASSERT_EQ (store.blocks_end (), current);
|
||||
}
|
135
rai/secure.cpp
135
rai/secure.cpp
|
@ -1716,6 +1716,141 @@ bool rai::block_store::pending_get (rai::block_hash const & hash_a, rai::account
|
|||
return result;
|
||||
}
|
||||
|
||||
rai::uint128_t rai::block_store::representation_get (rai::account const & account_a)
|
||||
{
|
||||
std::string value;
|
||||
auto status (representation->Get (leveldb::ReadOptions (), leveldb::Slice (account_a.chars.data (), account_a.chars.size ()), &value));
|
||||
assert (status.ok () || status.IsNotFound ());
|
||||
rai::uint128_t result;
|
||||
if (status.ok ())
|
||||
{
|
||||
rai::uint128_union rep;
|
||||
rai::bufferstream stream (reinterpret_cast <uint8_t const *> (value.data ()), value.size ());
|
||||
auto error (rai::read (stream, rep));
|
||||
assert (!error);
|
||||
result = rep.number ();
|
||||
}
|
||||
else
|
||||
{
|
||||
result = 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void rai::block_store::representation_put (rai::account const & account_a, rai::uint128_t const & representation_a)
|
||||
{
|
||||
rai::uint128_union rep (representation_a);
|
||||
auto status (representation->Put (leveldb::WriteOptions (), leveldb::Slice (account_a.chars.data (), account_a.chars.size ()), leveldb::Slice (rep.chars.data (), rep.chars.size ())));
|
||||
assert (status.ok ());
|
||||
}
|
||||
|
||||
void rai::block_store::fork_put (rai::block_hash const & hash_a, rai::block const & block_a)
|
||||
{
|
||||
std::vector <uint8_t> vector;
|
||||
{
|
||||
rai::vectorstream stream (vector);
|
||||
rai::serialize_block (stream, block_a);
|
||||
}
|
||||
auto status (forks->Put (leveldb::WriteOptions (), leveldb::Slice (hash_a.chars.data (), hash_a.chars.size ()), leveldb::Slice (reinterpret_cast <char const *> (vector.data ()), vector.size ())));
|
||||
assert (status.ok ());
|
||||
}
|
||||
|
||||
std::unique_ptr <rai::block> rai::block_store::fork_get (rai::block_hash const & hash_a)
|
||||
{
|
||||
std::string value;
|
||||
auto status (forks->Get (leveldb::ReadOptions (), leveldb::Slice (hash_a.chars.data (), hash_a.chars.size ()), &value));
|
||||
assert (status.ok () || status.IsNotFound ());
|
||||
std::unique_ptr <rai::block> result;
|
||||
if (status.ok ())
|
||||
{
|
||||
rai::bufferstream stream (reinterpret_cast <uint8_t const *> (value.data ()), value.size ());
|
||||
result = rai::deserialize_block (stream);
|
||||
assert (result != nullptr);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void rai::block_store::bootstrap_put (rai::block_hash const & hash_a, rai::block const & block_a)
|
||||
{
|
||||
std::vector <uint8_t> vector;
|
||||
{
|
||||
rai::vectorstream stream (vector);
|
||||
rai::serialize_block (stream, block_a);
|
||||
}
|
||||
auto status (bootstrap->Put (leveldb::WriteOptions (), leveldb::Slice (hash_a.chars.data (), hash_a.chars.size ()), leveldb::Slice (reinterpret_cast <char const *> (vector.data ()), vector.size ())));
|
||||
assert (status.ok () | status.IsNotFound ());
|
||||
}
|
||||
|
||||
std::unique_ptr <rai::block> rai::block_store::bootstrap_get (rai::block_hash const & hash_a)
|
||||
{
|
||||
std::string value;
|
||||
auto status (bootstrap->Get (leveldb::ReadOptions (), leveldb::Slice (hash_a.chars.data (), hash_a.chars.size ()), &value));
|
||||
assert (status.ok () || status.IsNotFound ());
|
||||
std::unique_ptr <rai::block> result;
|
||||
if (status.ok ())
|
||||
{
|
||||
rai::bufferstream stream (reinterpret_cast <uint8_t const *> (value.data ()), value.size ());
|
||||
result = rai::deserialize_block (stream);
|
||||
assert (result != nullptr);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void rai::block_store::bootstrap_del (rai::block_hash const & hash_a)
|
||||
{
|
||||
auto status (bootstrap->Delete (leveldb::WriteOptions (), leveldb::Slice (hash_a.chars.data (), hash_a.chars.size ())));
|
||||
assert (status.ok ());
|
||||
}
|
||||
|
||||
rai::block_iterator rai::block_store::bootstrap_begin ()
|
||||
{
|
||||
rai::block_iterator result (*bootstrap);
|
||||
return result;
|
||||
}
|
||||
|
||||
rai::block_iterator rai::block_store::bootstrap_end ()
|
||||
{
|
||||
rai::block_iterator result (*bootstrap, nullptr);
|
||||
return result;
|
||||
}
|
||||
|
||||
void rai::block_store::checksum_put (uint64_t prefix, uint8_t mask, rai::uint256_union const & hash_a)
|
||||
{
|
||||
assert ((prefix & 0xff) == 0);
|
||||
uint64_t key (prefix | mask);
|
||||
auto status (checksum->Put (leveldb::WriteOptions (), leveldb::Slice (reinterpret_cast <char const *> (&key), sizeof (uint64_t)), leveldb::Slice (hash_a.chars.data (), hash_a.chars.size ())));
|
||||
assert (status.ok ());
|
||||
}
|
||||
|
||||
bool rai::block_store::checksum_get (uint64_t prefix, uint8_t mask, rai::uint256_union & hash_a)
|
||||
{
|
||||
assert ((prefix & 0xff) == 0);
|
||||
std::string value;
|
||||
uint64_t key (prefix | mask);
|
||||
auto status (checksum->Get (leveldb::ReadOptions (), leveldb::Slice (reinterpret_cast <char const *> (&key), sizeof (uint64_t)), &value));
|
||||
assert (status.ok () || status.IsNotFound ());
|
||||
bool result;
|
||||
if (status.ok ())
|
||||
{
|
||||
result = false;
|
||||
rai::bufferstream stream (reinterpret_cast <uint8_t const *> (value.data ()), value.size ());
|
||||
auto error (rai::read (stream, hash_a));
|
||||
assert (!error);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void rai::block_store::checksum_del (uint64_t prefix, uint8_t mask)
|
||||
{
|
||||
assert ((prefix & 0xff) == 0);
|
||||
uint64_t key (prefix | mask);
|
||||
checksum->Delete (leveldb::WriteOptions (), leveldb::Slice (reinterpret_cast <char const *> (&key), sizeof (uint64_t)));
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
class root_visitor : public rai::block_visitor
|
||||
|
|
|
@ -388,16 +388,16 @@ namespace rai
|
|||
std::unique_ptr <rai::block> block_get (rai::block_hash const &);
|
||||
void block_del (rai::block_hash const &);
|
||||
bool block_exists (rai::block_hash const &);
|
||||
block_iterator blocks_begin ();
|
||||
block_iterator blocks_end ();
|
||||
rai::block_iterator blocks_begin ();
|
||||
rai::block_iterator blocks_end ();
|
||||
|
||||
void latest_put (rai::account const &, rai::frontier const &);
|
||||
bool latest_get (rai::account const &, rai::frontier &);
|
||||
void latest_del (rai::account const &);
|
||||
bool latest_exists (rai::account const &);
|
||||
account_iterator latest_begin (rai::account const &);
|
||||
account_iterator latest_begin ();
|
||||
account_iterator latest_end ();
|
||||
rai::account_iterator latest_begin (rai::account const &);
|
||||
rai::account_iterator latest_begin ();
|
||||
rai::account_iterator latest_end ();
|
||||
|
||||
void pending_put (rai::block_hash const &, rai::account const &, rai::amount const &, rai::account const &);
|
||||
void pending_del (rai::block_hash const &);
|
||||
|
@ -413,6 +413,8 @@ namespace rai
|
|||
void bootstrap_put (rai::block_hash const &, rai::block const &);
|
||||
std::unique_ptr <rai::block> bootstrap_get (rai::block_hash const &);
|
||||
void bootstrap_del (rai::block_hash const &);
|
||||
rai::block_iterator bootstrap_begin ();
|
||||
rai::block_iterator bootstrap_end ();
|
||||
|
||||
void checksum_put (uint64_t, uint8_t, rai::checksum const &);
|
||||
bool checksum_get (uint64_t, uint8_t, rai::checksum &);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue