Guest User

Untitled

a guest
Jul 16th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.36 KB | None | 0 0
  1. diff --git a/rai/blockstore.cpp b/rai/blockstore.cpp
  2. index 335edfe3..320a559e 100644
  3. --- a/rai/blockstore.cpp
  4. +++ b/rai/blockstore.cpp
  5. @@ -554,43 +554,68 @@ void rai::block_store::upgrade_v10_to_v11 (MDB_txn * transaction_a)
  6. void rai::block_store::upgrade_v11_to_v12 (MDB_txn * transaction_a)
  7. {
  8. version_put (transaction_a, 12);
  9. - for (rai::store_iterator i (transaction_a, accounts), n (nullptr); i != n; ++i)
  10. {
  11. - if (i->second.size () + 1 == sizeof (account_info))
  12. + std::vector<std::pair<rai::uint256_union, std::vector<uint8_t>>> new_accounts;
  13. + for (rai::store_iterator i (transaction_a, accounts), n (nullptr); i != n; ++i)
  14. {
  15. - std::vector<uint8_t> bytes ((uint8_t *)i->second.data (), (uint8_t *)i->second.data () + i->second.size ());
  16. - bytes.push_back (0); // version field
  17. - mdb_cursor_put (i.cursor, i->first, rai::mdb_val (bytes.size (), bytes.data ()), MDB_CURRENT);
  18. + if (i->second.size () + 1 == sizeof (account_info))
  19. + {
  20. + std::vector<uint8_t> bytes ((uint8_t *)i->second.data (), (uint8_t *)i->second.data () + i->second.size ());
  21. + bytes.push_back (0); // version field
  22. + new_accounts.push_back (std::make_pair (i->first.uint256 (), bytes));
  23. + }
  24. + else
  25. + {
  26. + assert (i->second.size () == sizeof (account_info));
  27. + }
  28. }
  29. - else
  30. + for (auto new_account : new_accounts)
  31. {
  32. - assert (i->second.size () == sizeof (account_info));
  33. + auto status (mdb_put (transaction_a, accounts, rai::mdb_val (new_account.first), rai::mdb_val (new_account.second.size (), new_account.second.data ()), 0));
  34. + assert (status == 0);
  35. }
  36. }
  37. - for (rai::store_iterator i (transaction_a, pending), n (nullptr); i != n; ++i)
  38. {
  39. - if (i->second.size () + 1 == sizeof (pending_info))
  40. + std::vector<std::pair<std::vector<uint8_t>, std::vector<uint8_t>>> new_pendings;
  41. + for (rai::store_iterator i (transaction_a, pending), n (nullptr); i != n; ++i)
  42. {
  43. - std::vector<uint8_t> bytes ((uint8_t *)i->second.data (), (uint8_t *)i->second.data () + i->second.size ());
  44. - bytes.push_back (0); // min_version field
  45. - mdb_cursor_put (i.cursor, i->first, rai::mdb_val (bytes.size (), bytes.data ()), MDB_CURRENT);
  46. + if (i->second.size () + 1 == sizeof (pending_info))
  47. + {
  48. + std::vector<uint8_t> key ((uint8_t *)i->first.data (), (uint8_t *)i->first.data () + i->first.size ());
  49. + std::vector<uint8_t> bytes ((uint8_t *)i->second.data (), (uint8_t *)i->second.data () + i->second.size ());
  50. + bytes.push_back (0); // min_version field
  51. + new_pendings.push_back (std::make_pair (key, bytes));
  52. + }
  53. + else
  54. + {
  55. + assert (i->second.size () == sizeof (pending_info));
  56. + }
  57. }
  58. - else
  59. + for (auto new_pending : new_pendings)
  60. {
  61. - assert (i->second.size () == sizeof (pending_info));
  62. + auto status (mdb_put (transaction_a, pending, rai::mdb_val (new_pending.first.size (), new_pending.first.data ()), rai::mdb_val (new_pending.second.size (), new_pending.second.data ()), 0));
  63. + assert (status == 0);
  64. }
  65. }
  66. - for (rai::store_iterator i (transaction_a, state_blocks), n (nullptr); i != n; ++i)
  67. {
  68. - if (i->second.size () == rai::state_block::size + sizeof (rai::block_hash))
  69. + std::vector<std::pair<rai::uint256_union, std::vector<uint8_t>>> new_state_blocks;
  70. + for (rai::store_iterator i (transaction_a, state_blocks), n (nullptr); i != n; ++i)
  71. {
  72. - std::vector<uint8_t> bytes ((uint8_t *)i->second.data (), (uint8_t *)i->second.data () + i->second.size ());
  73. - bytes.insert (bytes.begin () + rai::state_block::size, 0); // version field
  74. - mdb_cursor_put (i.cursor, i->first, rai::mdb_val (bytes.size (), bytes.data ()), MDB_CURRENT);
  75. + if (i->second.size () == rai::state_block::size + sizeof (rai::block_hash))
  76. + {
  77. + std::vector<uint8_t> bytes ((uint8_t *)i->second.data (), (uint8_t *)i->second.data () + i->second.size ());
  78. + bytes.insert (bytes.begin () + rai::state_block::size, 0); // version field
  79. + new_state_blocks.push_back (std::make_pair (i->first.uint256 (), bytes));
  80. + }
  81. + else
  82. + {
  83. + assert (i->second.size () == rai::state_block::size + 1 + sizeof (rai::block_hash));
  84. + }
  85. }
  86. - else
  87. + for (auto new_state_block : new_state_blocks)
  88. {
  89. - assert (i->second.size () == rai::state_block::size + 1 + sizeof (rai::block_hash));
  90. + auto status (mdb_put (transaction_a, state_blocks, rai::mdb_val (new_state_block.first), rai::mdb_val (new_state_block.second.size (), new_state_block.second.data ()), 0));
  91. + assert (status == 0);
  92. }
  93. }
  94. }
Add Comment
Please, Sign In to add comment