Adding block_store v3 to v4 upgrade function to update pending table.
This commit is contained in:
parent
a9f7db9d6c
commit
361b50bc00
5 changed files with 121 additions and 5 deletions
|
@ -1,5 +1,6 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <rai/node/node.hpp>
|
||||
#include <rai/versioning.hpp>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
|
@ -593,7 +594,6 @@ TEST (block_store, sequence_increment)
|
|||
ASSERT_EQ (31, seq8);
|
||||
}
|
||||
|
||||
|
||||
TEST (block_store, upgrade_v2_v3)
|
||||
{
|
||||
rai::keypair key1;
|
||||
|
@ -637,3 +637,32 @@ TEST (block_store, upgrade_v2_v3)
|
|||
ASSERT_FALSE (store.account_get (transaction, rai::test_genesis_key.pub, info));
|
||||
ASSERT_EQ (change_hash, info.rep_block);
|
||||
}
|
||||
|
||||
TEST (block_store, upgrade_v3_v4)
|
||||
{
|
||||
rai::keypair key1;
|
||||
rai::keypair key2;
|
||||
rai::keypair key3;
|
||||
auto path (rai::unique_path ());
|
||||
{
|
||||
bool init (false);
|
||||
rai::block_store store (init, path);
|
||||
ASSERT_FALSE (init);
|
||||
rai::transaction transaction (store.environment, nullptr, true);
|
||||
store.version_put (transaction, 3);
|
||||
rai::pending_info_v3 info (key1.pub, 100, key2.pub);
|
||||
auto status (mdb_put (transaction, store.pending, key3.pub.val (), info.val (), 0));
|
||||
ASSERT_EQ (0, status);
|
||||
}
|
||||
bool init (false);
|
||||
rai::block_store store (init, path);
|
||||
rai::ledger ledger (store);
|
||||
rai::transaction transaction (store.environment, nullptr, true);
|
||||
ASSERT_FALSE (init);
|
||||
rai::pending_key key (key2.pub, key3.pub);
|
||||
rai::pending_info info;
|
||||
auto error (store.pending_get (transaction, key, info));
|
||||
ASSERT_FALSE (error);
|
||||
ASSERT_EQ (key1.pub, info.source);
|
||||
ASSERT_EQ (rai::amount (100), info.amount);
|
||||
}
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
|
||||
#include <ed25519-donna/ed25519.h>
|
||||
|
||||
#include <queue>
|
||||
|
||||
// Genesis keys for network variants
|
||||
namespace
|
||||
{
|
||||
|
@ -1562,12 +1564,12 @@ void rai::block_store::do_upgrades (MDB_txn * transaction_a)
|
|||
{
|
||||
case 1:
|
||||
upgrade_v1_to_v2 (transaction_a);
|
||||
break;
|
||||
case 2:
|
||||
upgrade_v2_to_v3 (transaction_a);
|
||||
break;
|
||||
case 3:
|
||||
break;
|
||||
upgrade_v3_to_v4 (transaction_a);
|
||||
case 4:
|
||||
break;
|
||||
default:
|
||||
assert (false);
|
||||
}
|
||||
|
@ -1666,6 +1668,24 @@ void rai::block_store::upgrade_v2_to_v3 (MDB_txn * transaction_a)
|
|||
}
|
||||
}
|
||||
|
||||
void rai::block_store::upgrade_v3_to_v4 (MDB_txn * transaction_a)
|
||||
{
|
||||
version_put (transaction_a, 4);
|
||||
std::queue <std::pair <rai::pending_key, rai::pending_info>> items;
|
||||
for (auto i (pending_begin (transaction_a)), n (pending_end ()); i != n; ++i)
|
||||
{
|
||||
rai::block_hash hash (i->first);
|
||||
rai::pending_info_v3 info (i->second);
|
||||
items.push (std::make_pair (rai::pending_key (info.destination, hash), rai::pending_info (info.source, info.amount)));
|
||||
}
|
||||
mdb_drop (transaction_a, pending, 0);
|
||||
while (!items.empty ())
|
||||
{
|
||||
pending_put (transaction_a, items.front ().first, items.front ().second);
|
||||
items.pop ();
|
||||
}
|
||||
}
|
||||
|
||||
void rai::block_store::clear (MDB_dbi db_a)
|
||||
{
|
||||
rai::transaction transaction (environment, nullptr, true);
|
||||
|
|
|
@ -380,6 +380,7 @@ public:
|
|||
void do_upgrades (MDB_txn *);
|
||||
void upgrade_v1_to_v2 (MDB_txn *);
|
||||
void upgrade_v2_to_v3 (MDB_txn *);
|
||||
void upgrade_v3_to_v4 (MDB_txn *);
|
||||
|
||||
void clear (MDB_dbi);
|
||||
|
||||
|
|
|
@ -53,3 +53,55 @@ rai::mdb_val rai::account_info_v1::val () const
|
|||
{
|
||||
return rai::mdb_val (sizeof (*this), const_cast <rai::account_info_v1 *> (this));
|
||||
}
|
||||
|
||||
rai::pending_info_v3::pending_info_v3 () :
|
||||
source (0),
|
||||
amount (0),
|
||||
destination (0)
|
||||
{
|
||||
}
|
||||
|
||||
rai::pending_info_v3::pending_info_v3 (MDB_val const & val_a)
|
||||
{
|
||||
assert(val_a.mv_size == sizeof (*this));
|
||||
static_assert (sizeof (source) + sizeof (amount) + sizeof (destination) == sizeof (*this), "Packed class");
|
||||
std::copy (reinterpret_cast <uint8_t const *> (val_a.mv_data), reinterpret_cast <uint8_t const *> (val_a.mv_data) + sizeof (*this), reinterpret_cast <uint8_t *> (this));
|
||||
}
|
||||
|
||||
rai::pending_info_v3::pending_info_v3 (rai::account const & source_a, rai::amount const & amount_a, rai::account const & destination_a) :
|
||||
source (source_a),
|
||||
amount (amount_a),
|
||||
destination (destination_a)
|
||||
{
|
||||
}
|
||||
|
||||
void rai::pending_info_v3::serialize (rai::stream & stream_a) const
|
||||
{
|
||||
rai::write (stream_a, source.bytes);
|
||||
rai::write (stream_a, amount.bytes);
|
||||
rai::write (stream_a, destination.bytes);
|
||||
}
|
||||
|
||||
bool rai::pending_info_v3::deserialize (rai::stream & stream_a)
|
||||
{
|
||||
auto result (rai::read (stream_a, source.bytes));
|
||||
if (!result)
|
||||
{
|
||||
result = rai::read (stream_a, amount.bytes);
|
||||
if (!result)
|
||||
{
|
||||
result = rai::read (stream_a, destination.bytes);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool rai::pending_info_v3::operator == (rai::pending_info_v3 const & other_a) const
|
||||
{
|
||||
return source == other_a.source && amount == other_a.amount && destination == other_a.destination;
|
||||
}
|
||||
|
||||
rai::mdb_val rai::pending_info_v3::val () const
|
||||
{
|
||||
return rai::mdb_val (sizeof (*this), const_cast <rai::pending_info_v3 *> (this));
|
||||
}
|
||||
|
|
|
@ -19,4 +19,18 @@ public:
|
|||
rai::amount balance;
|
||||
uint64_t modified;
|
||||
};
|
||||
}
|
||||
class pending_info_v3
|
||||
{
|
||||
public:
|
||||
pending_info_v3 ();
|
||||
pending_info_v3 (MDB_val const &);
|
||||
pending_info_v3 (rai::account const &, rai::amount const &, rai::account const &);
|
||||
void serialize (rai::stream &) const;
|
||||
bool deserialize (rai::stream &);
|
||||
bool operator == (rai::pending_info_v3 const &) const;
|
||||
rai::mdb_val val () const;
|
||||
rai::account source;
|
||||
rai::amount amount;
|
||||
rai::account destination;
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue