2#include "../fixtures.hpp"
3#include "../memory_tree.hpp"
4#include "../test_fixtures.hpp"
45 std::filesystem::create_directories(
_directory);
63 EXPECT_EQ(response.success,
true);
64 EXPECT_EQ(response.inner.meta.size, expected_size);
67 tree.get_meta_data(includeUncommitted, completion);
75 EXPECT_EQ(response.success,
true);
76 EXPECT_EQ(response.inner.meta.finalizedBlockHeight, expected_finalized_block);
79 tree.get_meta_data(
false, completion);
87 EXPECT_EQ(response.success,
true);
88 EXPECT_EQ(response.inner.meta.unfinalizedBlockHeight, expected_block_height);
91 tree.get_meta_data(
true, completion);
99 EXPECT_EQ(response.success,
true);
100 EXPECT_EQ(response.inner.meta.root, expected_root);
103 tree.get_meta_data(includeUncommitted, completion);
110 bool includeUncommitted =
true,
117 EXPECT_EQ(response.inner.path, expected_sibling_path);
129 bool includeUncommitted =
true,
136 EXPECT_TRUE(response.inner.leaf_paths[0].has_value());
137 EXPECT_EQ(response.inner.leaf_paths[0].value().path, expected_sibling_path);
138 EXPECT_EQ(response.inner.leaf_paths[0].value().index, expected_index);
142 tree.find_leaf_sibling_paths({
value }, includeUncommitted, completion);
150 bool expected_success =
true)
154 EXPECT_EQ(response.success, expected_success);
155 if (response.success) {
156 EXPECT_EQ(response.inner.path, expected_sibling_path);
169 bool expected_success =
true)
173 EXPECT_EQ(response.success, expected_success);
174 if (expected_success) {
175 EXPECT_TRUE(response.inner.leaf_paths[0].has_value());
176 EXPECT_EQ(response.inner.leaf_paths[0].value().path, expected_sibling_path);
177 EXPECT_EQ(response.inner.leaf_paths[0].value().index, expected_index);
181 tree.find_leaf_sibling_paths({
value }, blockNumber,
false, completion);
189 EXPECT_EQ(response.success, expected_success);
192 tree.commit(completion);
200 EXPECT_EQ(response.success, expected_success);
203 tree.remove_historic_block(blockNumber, completion);
211 EXPECT_EQ(response.success, expected_success);
214 tree.unwind_block(blockNumber, completion);
222 EXPECT_EQ(response.success,
true);
226 tree.add_value(
value, completion);
234 EXPECT_EQ(response.success,
true);
238 tree.add_values(values, completion);
245 auto completion = [&](
const Response& response) ->
void {
246 EXPECT_EQ(response.success, expected_success);
247 if (!response.success && expected_success) {
252 tree.finalize_block(blockNumber, completion);
257 TreeType& tree,
const fr& leaf,
index_t leaf_index,
bool expected_success,
bool includeUncommitted =
true)
261 EXPECT_EQ(response.
success, expected_success);
263 EXPECT_EQ(response.
inner.leaf, leaf);
274 bool expected_success,
275 bool includeUncommitted =
true)
279 EXPECT_EQ(response.
success, expected_success);
281 EXPECT_EQ(response.
inner.leaf, leaf);
293 for (
const auto& i : sibling_path) {
294 if (index % 2 == 0) {
306 EXPECT_EQ(
hash, expected_root);
310 const std::vector<index_t>& indices,
315 blockNumbers = response.
inner.blockNumbers;
323 const std::vector<index_t>& indices,
328 blockNumbers = response.
inner.blockNumbers;
336 constexpr size_t depth = 10;
339 EXPECT_NO_THROW(
Store store(name, depth, db));
352 constexpr size_t depth = 10;
355 EXPECT_NO_THROW(
Store store(name, depth, db));
391 constexpr size_t depth = 10;
396 EXPECT_ANY_THROW(
Store store_wrong_name(
"Wrong name", depth, db));
397 EXPECT_ANY_THROW(
Store store_wrong_depth(name, depth + 1, db));
402 constexpr size_t depth = 3;
425 constexpr size_t depth = 4;
434 std::vector<fr> values;
435 for (uint32_t i = 0; i < 16; i++) {
436 values.push_back(VALUES[i]);
440 std::stringstream ss;
441 ss <<
"Unable to append leaves to tree " << name <<
" new size: 17 max size: 16";
445 EXPECT_EQ(response.success,
false);
446 EXPECT_EQ(response.message, ss.str());
449 tree.add_value(VALUES[16], add_completion);
456 constexpr size_t depth = 16;
459 std::filesystem::create_directories(directory);
473 fr empty_root = memdb.
root();
476 uint32_t num_values_to_add = 16 * 1024;
477 std::vector<fr> values;
478 for (uint32_t i = 0; i < num_values_to_add; i++) {
491 EXPECT_EQ(response.success,
false);
495 tree.commit(completion);
529 fr empty_root = memdb.
root();
559 constexpr size_t depth = 5;
629 constexpr size_t depth = 10;
657 constexpr size_t depth = 5;
671 check_find_leaf_index<fr, TreeType>(tree, {
fr(10) }, {
std::nullopt },
true,
false);
673 check_find_leaf_index<fr, TreeType>(tree, {
fr(15) }, {
std::nullopt },
true,
true);
674 check_find_leaf_index<fr, TreeType>(tree, {
fr(15) }, {
std::nullopt },
true,
false);
680 check_find_leaf_index<fr, TreeType>(tree, {
fr(40) }, {
std::nullopt },
true,
false);
681 check_find_leaf_index<fr, TreeType>(tree, {
fr(30) }, {
std::nullopt },
true,
false);
682 check_find_leaf_index<fr, TreeType>(tree, {
fr(20) }, {
std::nullopt },
true,
false);
686 std::vector<fr> values{ 15, 18, 26, 2 };
696 check_find_leaf_index<fr, TreeType>(tree, {
fr(18) }, {
std::nullopt },
true,
false);
700 values = { 16, 4, 19, 22 };
706 check_find_leaf_index_from<fr, TreeType>(tree, {
fr(19) }, 0, {
std::nullopt },
true,
false);
718 check_find_leaf_index_from<fr, TreeType>(tree, {
fr(18) }, 6, {
std::nullopt },
true,
true);
721 check_find_leaf_index_from<fr, TreeType>(tree, {
fr(18) }, 15, {
std::nullopt },
true,
true);
724 check_find_leaf_index_from<fr, TreeType>(tree, {
fr(88) }, 13, {
std::nullopt },
true,
false);
729 constexpr size_t depth = 10;
752 constexpr size_t depth = 3;
760 std::vector<fr> to_add;
762 for (
size_t i = 0; i < 4; ++i) {
764 to_add.push_back(VALUES[i]);
777 constexpr size_t depth = 10;
785 std::vector<fr> to_add(32,
fr::zero());
786 to_add[0] = VALUES[0];
788 for (
size_t i = 0; i < 32; ++i) {
803 constexpr size_t depth = 8;
811 std::vector<fr> to_add(32,
fr::zero());
812 to_add[0] = VALUES[0];
814 for (
size_t i = 0; i < 32; ++i) {
820 check_find_leaf_index<fr, TreeType>(tree, { leaf }, {
std::nullopt },
true);
821 check_historic_find_leaf_index<fr, TreeType>(tree, { leaf }, 1, {
std::nullopt },
true);
822 check_find_leaf_index_from<fr, TreeType>(tree, { leaf }, 0, {
std::nullopt },
true);
823 check_historic_find_leaf_index_from<fr, TreeType>(tree, { leaf }, 1, 0, {
std::nullopt },
true);
828 constexpr size_t depth = 10;
836 auto check = [&](
index_t expected_size,
index_t expected_unfinalized_block_height) {
844 constexpr uint32_t num_blocks = 10;
845 constexpr uint32_t batch_size = 4;
846 for (uint32_t i = 0; i < num_blocks; i++) {
847 std::vector<fr> to_add;
849 for (
size_t j = 0; j < batch_size; ++j) {
850 size_t ind = i * batch_size + j;
852 to_add.push_back(VALUES[ind]);
854 index_t expected_size = (i + 1) * batch_size;
856 check(expected_size, i);
858 check(expected_size, i + 1);
865 constexpr size_t depth = 10;
873 auto check = [&](
index_t expected_size,
index_t expected_unfinalized_block_height) {
881 std::vector<size_t> batchSize = { 8, 20, 64, 32 };
884 for (uint32_t i = 0; i < batchSize.size(); i++) {
885 std::vector<fr> to_add;
887 for (
size_t j = 0; j < batchSize[i]; ++j) {
888 size_t ind = expected_size + j;
890 to_add.push_back(VALUES[ind]);
892 expected_size += batchSize[i];
894 check(expected_size, i);
896 check(expected_size, i + 1);
903 constexpr size_t depth = 10;
911 constexpr uint32_t num_blocks = 10;
912 constexpr uint32_t batch_size = 4;
917 auto check = [&](
index_t expected_size,
index_t expected_unfinalized_block_height) {
924 for (uint32_t i = 0; i < historicPathsZeroIndex.size(); i++) {
927 index_t maxSizeAtBlock = ((i + 1) * batch_size) - 1;
930 tree, VALUES[maxSizeAtBlock], historicPathsMaxIndex[i], maxSizeAtBlock, i + 1);
934 for (uint32_t i = 0; i < num_blocks; i++) {
935 std::vector<fr> to_add;
937 for (
size_t j = 0; j < batch_size; ++j) {
938 size_t ind = i * batch_size + j;
940 to_add.push_back(VALUES[ind]);
942 index_t expected_size = (i + 1) * batch_size;
944 check(expected_size, i);
946 check(expected_size, i + 1);
954 constexpr size_t depth = 10;
962 constexpr uint32_t num_blocks = 10;
963 constexpr uint32_t batch_size = 4;
965 for (uint32_t i = 0; i < num_blocks; i++) {
966 std::vector<fr> to_add;
968 for (
size_t j = 0; j < batch_size; ++j) {
969 size_t ind = i * batch_size + j;
971 to_add.push_back(VALUES[ind]);
977 for (uint32_t i = 0; i < num_blocks; i++) {
978 for (uint32_t j = 0; j < num_blocks; j++) {
979 index_t indexToQuery = j * batch_size;
980 fr expectedLeaf = j <= i ? VALUES[indexToQuery] :
fr::zero();
988 constexpr size_t depth = 5;
995 std::vector<fr> values{ 30, 10, 20, 40 };
1000 values = { 15, 18, 26, 2 };
1005 values = { 16, 4, 19, 22 };
1009 check_historic_find_leaf_index<fr, TreeType>(tree, {
fr(26) }, 1, {
std::nullopt },
true);
1014 check_historic_find_leaf_index_from<fr, TreeType>(tree, {
fr(18) }, 1, 2, {
std::nullopt },
true,
false);
1018 check_historic_find_leaf_index_from<fr, TreeType>(tree, {
fr(19) }, 2, 6, {
std::nullopt },
true,
false);
1030 constexpr size_t depth = 3;
1041 for (
size_t i = 0; i < 8; i++) {
1053 constexpr size_t depth = 10;
1059 uint32_t num_reads = 16 * 1024;
1071 Signal signal(1 + num_reads);
1075 tree.commit(commit_completion);
1077 tree.add_value(VALUES[0], add_completion);
1079 for (
size_t i = 0; i < num_reads; i++) {
1081 paths[i] = response.inner.path;
1089 for (
auto& path : paths) {
1090 EXPECT_TRUE(path == initial_path || path == final_sibling_path);
1096 constexpr size_t depth = 3;
1115 constexpr size_t depth = 4;
1131 tree.get_subtree_sibling_path(
1135 EXPECT_EQ(resp.inner.path, expected_sibling_path);
1144 tree.get_subtree_sibling_path(
1148 EXPECT_EQ(resp.inner.path, expected_sibling_path);
1158 constexpr size_t depth = 5;
1168 std::vector<fr> values{ 30, 10, 20, 40 };
1170 for (
auto v : values) {
1180 values = { 15, 18, 26, 2 };
1182 for (
auto v : values) {
1190 fr block2Root = memdb.
root();
1195 values = { 16, 4, 18, 22 };
1197 for (
auto v : values) {
1221 check_find_leaf_index<fr, TreeType>(treeAtBlock2, {
fr(4) }, {
std::nullopt },
true);
1238 check_historic_find_leaf_index<fr, TreeType>(treeAtBlock2, {
fr(16) }, 2, {
std::nullopt },
true,
false);
1240 check_historic_find_leaf_index_from<fr, TreeType>(treeAtBlock2, {
fr(18) }, 1, 3, {
std::nullopt },
true,
false);
1251 constexpr size_t depth = 10;
1259 constexpr uint32_t numBlocks = 50;
1260 constexpr uint32_t batchSize = 16;
1261 constexpr uint32_t windowSize = 8;
1265 std::vector<fr> roots;
1267 auto check = [&](
index_t expectedSize,
index_t expectedBlockHeight) {
1274 for (uint32_t i = 0; i < historicPathsZeroIndex.size(); i++) {
1277 const bool expectedSuccess =
1278 expectedBlockHeight <= windowSize || blockNumber > (expectedBlockHeight - windowSize);
1280 index_t maxSizeAtBlock = ((i + 1) * batchSize) - 1;
1290 for (uint32_t i = 0; i < numBlocks; i++) {
1291 std::vector<fr> to_add;
1293 for (
size_t j = 0; j < batchSize; ++j) {
1294 size_t ind = i * batchSize + j;
1296 to_add.push_back(VALUES[ind]);
1298 index_t expected_size = (i + 1) * batchSize;
1300 check(expected_size, i);
1307 historicPathsMaxIndex.push_back(memdb.
get_sibling_path(expected_size - 1));
1308 roots.push_back(memdb.
root());
1311 if (i >= windowSize) {
1316 if (oldestBlock > 1) {
1321 fr rootToRemove = roots[oldestBlock - 1];
1330 check(expected_size, i + 1);
1340 uint64_t maxReaders,
1344 uint32_t numBlocksToUnwind,
1345 std::vector<fr> values)
1353 uint32_t batchSize = blockSize;
1357 std::vector<fr> roots;
1359 fr initialRoot = memdb.
root();
1362 for (uint32_t i = 0; i < numBlocks; i++) {
1363 std::vector<fr> to_add;
1365 for (
size_t j = 0; j < batchSize; ++j) {
1366 size_t ind = i * batchSize + j;
1368 to_add.push_back(values[ind]);
1370 index_t expected_size = (i + 1) * batchSize;
1384 historicPathsMaxIndex.push_back(memdb.
get_sibling_path(expected_size - 1));
1385 roots.push_back(memdb.
root());
1394 const uint32_t blocksToRemove = numBlocksToUnwind;
1395 for (uint32_t i = 0; i < blocksToRemove; i++) {
1403 if (blockNumber > 1) {
1410 const auto last = roots.begin() + long(blockNumber - 1);
1412 std::find_if(roots.begin(), last, [=](
const fr& r) ->
bool { return r == roots[blockNumber - 1]; });
1415 const index_t previousValidBlock = blockNumber - 1;
1416 index_t deletedBlockStartIndex = previousValidBlock * batchSize;
1420 check_root(tree, previousValidBlock == 0 ? initialRoot : roots[previousValidBlock - 1]);
1425 previousValidBlock == 0 ? initialPath : historicPathsZeroIndex[previousValidBlock - 1],
1430 check_leaf(tree, values[1 + deletedBlockStartIndex], 1 + deletedBlockStartIndex,
false);
1431 check_find_leaf_index<fr, TreeType>(tree, { values[1 + deletedBlockStartIndex] }, {
std::nullopt },
true);
1435 bool expectedSuccess = historicBlockNumber <= previousValidBlock;
1437 index_t maxSizeAtBlock = ((j + 1) * batchSize) - 1;
1439 tree, maxSizeAtBlock, historicPathsMaxIndex[j], historicBlockNumber, expectedSuccess);
1442 check_historic_leaf(tree, historicBlockNumber, values[leafIndex], leafIndex, expectedSuccess);
1445 if (expectedSuccess) {
1446 if (values[leafIndex] !=
fr::zero()) {
1454 check_historic_find_leaf_index<fr, TreeType>(
1455 tree, { values[leafIndex] }, historicBlockNumber, expected_results, expectedSuccess);
1456 check_historic_find_leaf_index_from<fr, TreeType>(
1457 tree, { values[leafIndex] }, historicBlockNumber, 0, expected_results, expectedSuccess);
1464 std::vector<fr> first = create_values(1024);
1465 test_unwind(_directory,
"DB", _mapSize, _maxReaders, 10, 16, 16, 8, first);
1470 std::vector<fr> first = create_values(1024);
1471 test_unwind(_directory,
"DB", _mapSize, _maxReaders, 10, 16, 16, 16, first);
1472 std::vector<fr> second = create_values(1024);
1473 test_unwind(_directory,
"DB", _mapSize, _maxReaders, 10, 16, 16, 16, second);
1478 const size_t block_size = 16;
1479 const uint32_t num_blocks = 16;
1481 std::vector<fr> first(1024,
fr::zero());
1482 test_unwind(_directory,
"DB", _mapSize, _maxReaders, 10, block_size, num_blocks, num_blocks, first);
1484 std::vector<fr> second = create_values(1024);
1486 for (
size_t i = 0; i < block_size; i++) {
1489 test_unwind(_directory,
"DB", _mapSize, _maxReaders, 10, block_size, num_blocks, num_blocks, second);
1492 std::vector<fr> third = create_values(1024);
1493 size_t offset = block_size * 2;
1494 for (
size_t i = 0; i < block_size * 2; i++) {
1497 test_unwind(_directory,
"DB", _mapSize, _maxReaders, 10, block_size, num_blocks, num_blocks, third);
1500 std::vector<fr> fourth = create_values(1024);
1501 test_unwind(_directory,
"DB", _mapSize, _maxReaders, 10, block_size, num_blocks, num_blocks, fourth);
1507 constexpr uint32_t numBlocks = 4;
1508 constexpr uint32_t numBlocksToUnwind = 2;
1509 std::vector<uint32_t> blockSizes = { 2, 4, 8, 16, 32 };
1510 for (
const uint32_t& size : blockSizes) {
1511 uint32_t actualSize = size * 1024;
1512 std::vector<fr> values = create_values(actualSize * numBlocks);
1513 std::stringstream ss;
1514 ss <<
"DB " << actualSize;
1515 test_unwind(_directory, ss.str(), _mapSize, _maxReaders, 20, actualSize, numBlocks, numBlocksToUnwind, values);
1522 constexpr uint32_t depth = 10;
1532 uint32_t batchSize = 64;
1536 values.emplace_back();
1538 values.emplace_back();
1540 values.push_back(create_values(batchSize));
1542 values.emplace_back();
1543 values.emplace_back();
1545 values.push_back(create_values(batchSize));
1549 for (
auto& blockValues : values) {
1553 for (
const auto& blockValue : blockValues) {
1566 while (blockNumber > 0) {
1574 if (blockNumber > 0) {
1584 constexpr uint32_t depth = 10;
1594 uint32_t batchSize = 64;
1598 values.emplace_back();
1600 values.emplace_back();
1602 values.push_back(create_values(batchSize));
1604 values.emplace_back();
1605 values.emplace_back();
1607 values.push_back(create_values(batchSize));
1611 for (
auto& blockValues : values) {
1615 for (
const auto& blockValue : blockValues) {
1630 while (blockToRemove < blockNumber) {
1646 constexpr uint32_t depth = 10;
1652 const size_t block_size = 32;
1654 for (
size_t i = 0; i < 5; i++) {
1655 std::vector<fr> values = create_values(block_size);
1659 std::vector<index_t> indices{ 12, 33, 63, 64, 65, 80, 96, 159, 160 };
1664 EXPECT_EQ(blockNumbers.size(), indices.size());
1666 index_t maxIndex = 5 * block_size - 1;
1667 for (
size_t i = 0; i < blockNumbers.size(); i++) {
1668 bool present = indices[i] <= maxIndex;
1671 EXPECT_EQ(blockNumbers[i].
value(), expected);
1673 EXPECT_EQ(blockNumbers[i].has_value(), present);
1678 EXPECT_EQ(blockNumbers.size(), indices.size());
1680 maxIndex = 2 * block_size - 1;
1681 for (
size_t i = 0; i < blockNumbers.size(); i++) {
1682 bool present = indices[i] <= maxIndex;
1685 EXPECT_EQ(blockNumbers[i].
value(), expected);
1687 EXPECT_EQ(blockNumbers[i].has_value(), present);
1694 EXPECT_EQ(blockNumbers.size(), indices.size());
1695 maxIndex = 3 * block_size - 1;
1696 for (
size_t i = 0; i < blockNumbers.size(); i++) {
1697 bool present = indices[i] <= maxIndex;
1700 EXPECT_EQ(blockNumbers[i].
value(), expected);
1702 EXPECT_EQ(blockNumbers[i].has_value(), present);
1711 EXPECT_EQ(blockNumbers.size(), indices.size());
1713 maxIndex = block_size - 1;
1714 for (
size_t i = 0; i < blockNumbers.size(); i++) {
1715 bool present = indices[i] <= maxIndex;
1718 EXPECT_EQ(blockNumbers[i].
value(), expected);
1720 EXPECT_EQ(blockNumbers[i].has_value(), present);
1725 EXPECT_EQ(blockNumbers.size(), indices.size());
1727 maxIndex = block_size - 1;
1728 for (
size_t i = 0; i < blockNumbers.size(); i++) {
1729 bool present = indices[i] <= maxIndex;
1732 EXPECT_EQ(blockNumbers[i].
value(), expected);
1734 EXPECT_EQ(blockNumbers[i].has_value(), present);
1741 constexpr uint32_t depth = 10;
1748 uint32_t blockSize = 16;
1749 uint32_t numBlocks = 16;
1750 uint32_t finalizedBlockDelay = 4;
1751 std::vector<fr> values = create_values(blockSize * numBlocks);
1753 for (uint32_t i = 0; i < numBlocks; i++) {
1754 std::vector<fr> to_add;
1756 for (
size_t j = 0; j < blockSize; ++j) {
1757 size_t ind = i * blockSize + j;
1759 to_add.push_back(values[ind]);
1764 block_number_t expectedFinalizedBlock = i < finalizedBlockDelay ? 0 : i - finalizedBlockDelay;
1767 if (i >= finalizedBlockDelay) {
1785 constexpr uint32_t depth = 10;
1792 uint32_t blockSize = 16;
1793 uint32_t numBlocks = 16;
1794 std::vector<fr> values = create_values(blockSize * numBlocks);
1796 for (uint32_t i = 0; i < numBlocks; i++) {
1797 std::vector<fr> to_add;
1799 for (
size_t j = 0; j < blockSize; ++j) {
1800 size_t ind = i * blockSize + j;
1802 to_add.push_back(values[ind]);
1818 constexpr uint32_t depth = 10;
1825 uint32_t blockSize = 16;
1826 uint32_t numBlocks = 16;
1827 std::vector<fr> values = create_values(blockSize * numBlocks);
1832 for (uint32_t i = 0; i < numBlocks; i++) {
1833 std::vector<fr> to_add;
1835 for (
size_t j = 0; j < blockSize; ++j) {
1836 size_t ind = i * blockSize + j;
1838 to_add.push_back(values[ind]);
1858 uint32_t depth = 20;
1864 for (uint32_t i = 0; i < 5; i++) {
1865 std::vector<fr> values = create_values(1024);
1873 EXPECT_THROW(
Store(name, depth, 5, db), std::runtime_error);
1874 EXPECT_THROW(
Store(name, depth, 4, db), std::runtime_error);
1880 uint32_t depth = 20;
1886 for (uint32_t i = 0; i < 5; i++) {
1887 std::vector<fr> values = create_values(1024);
1896 EXPECT_THROW(
Store(name, depth, 1, db), std::runtime_error);
1897 EXPECT_THROW(
Store(name, depth, 2, db), std::runtime_error);
1902 uint32_t depth = 20;
1909 uint32_t numBlocks = 5;
1911 const fr initialRoot = memdb.
root();
1914 for (uint32_t i = 0; i < numBlocks; i++) {
1915 std::vector<fr> values = create_values(1024);
1922 EXPECT_NO_THROW(
Store(name, depth, 0, db));
1934 constexpr uint32_t depth = 10;
1941 uint32_t blockSize = 16;
1942 uint32_t numBlocks = 16;
1943 std::vector<fr> values = create_values(blockSize * numBlocks);
1945 for (uint32_t i = 0; i < numBlocks; i++) {
1946 std::vector<fr> to_add;
1948 for (
size_t j = 0; j < blockSize; ++j) {
1949 size_t ind = i * blockSize + j;
1951 to_add.push_back(values[ind]);
1963 for (uint32_t i = numBlocks; i > blockToFinalize; i--) {
1972 constexpr uint32_t depth = 10;
1979 uint32_t blockSize = 16;
1980 uint32_t numBlocks = 16;
1981 std::vector<fr> values = create_values(blockSize * numBlocks);
1983 for (uint32_t i = 0; i < numBlocks; i++) {
1984 std::vector<fr> to_add;
1986 for (
size_t j = 0; j < blockSize; ++j) {
1987 size_t ind = i * blockSize + j;
1989 to_add.push_back(values[ind]);
2001 for (uint32_t i = 0; i < blockToFinalize - 1; i++) {
2009 constexpr size_t depth = 10;
2010 uint32_t blockSize = 16;
2020 std::vector<fr> values = create_values(blockSize);
2031 uint32_t stackDepth = 20;
2035 for (; index < stackDepth - 1; index++) {
2036 std::vector<fr> values = create_values(blockSize);
2043 }
catch (std::exception& e) {
2050 std::vector<fr> values = create_values(blockSize);
2055 index_t checkpointIndex = index;
2062 for (; index > stackDepth / 2; index--) {
2063 if (index % 2 == 0) {
2065 checkpointIndex = index - 1;
2074 for (; index < stackDepth - 1; index++) {
2075 std::vector<fr> values = create_values(blockSize);
2082 }
catch (std::exception& e) {
2089 std::vector<fr> values = create_values(blockSize);
2095 checkpointIndex = index;
2100 for (; index > 0; index--) {
2101 if (index % 2 == 0) {
2103 checkpointIndex = index - 1;
2118 constexpr size_t depth = 10;
2119 uint32_t blockSize = 16;
2129 std::vector<fr> values = create_values(blockSize);
2140 uint32_t stackDepth = 20;
2144 for (; index < stackDepth - 1; index++) {
2145 std::vector<fr> values = create_values(blockSize);
2152 }
catch (std::exception& e) {
2170 constexpr size_t depth = 10;
2171 uint32_t blockSize = 16;
2181 std::vector<fr> values = create_values(blockSize);
2192 uint32_t stackDepth = 20;
2196 for (; index < stackDepth - 1; index++) {
2197 std::vector<fr> values = create_values(blockSize);
2204 }
catch (std::exception& e) {
static std::string _directory
static uint64_t _maxReaders
Implements a simple append-only merkle tree All methods are asynchronous unless specified as otherwis...
std::function< void(TypedResponse< CommitResponse > &)> CommitCallback
Serves as a key-value node store for merkle trees. Caches all changes in memory before persisting the...
std::shared_ptr< LMDBTreeStore > SharedPtr
fr update_element(size_t index, fr const &value)
fr get_node(uint32_t level, size_t index) const
fr_sibling_path get_sibling_path(size_t index) const
fr_sibling_path get_sibling_path(index_t index)
Used in parallel insertions in the the IndexedTree. Workers signal to other following workes as they ...
void signal_level(uint32_t level=0)
Signals that the given level has been passed.
void signal_decrement(uint32_t delta=1)
void wait_for_level(uint32_t level=0)
Causes the thread to wait until the required level has been signalled.
void add_value(TreeType &tree, const fr &value)
void check_size(TreeType &tree, index_t expected_size, bool includeUncommitted=true)
void check_historic_sibling_path_by_value(TreeType &tree, fr value, fr_sibling_path expected_sibling_path, index_t expected_index, block_number_t blockNumber, bool expected_success=true)
void test_unwind(std::string directory, std::string name, uint64_t mapSize, uint64_t maxReaders, uint32_t depth, uint32_t blockSize, uint32_t numBlocks, uint32_t numBlocksToUnwind, std::vector< fr > values)
ContentAddressedCachedTreeStore< bb::fr > Store
void get_blocks_for_indices(TreeType &tree, const std::vector< index_t > &indices, std::vector< std::optional< block_number_t > > &blockNumbers)
void check_finalized_block_height(TreeType &tree, block_number_t expected_finalized_block)
void check_sibling_path_by_value(TreeType &tree, fr value, fr_sibling_path expected_sibling_path, index_t expected_index, bool includeUncommitted=true, bool expected_result=true)
void check_block_height(TreeType &tree, index_t expected_block_height)
void remove_historic_block(TreeType &tree, const block_number_t &blockNumber, bool expected_success=true)
void unwind_block(TreeType &tree, const block_number_t &blockNumber, bool expected_success=true)
void add_values(TreeType &tree, const std::vector< fr > &values)
void finalize_block(TreeType &tree, const block_number_t &blockNumber, bool expected_success=true)
void check_historic_leaf(TreeType &tree, const block_number_t &blockNumber, const fr &leaf, index_t leaf_index, bool expected_success, bool includeUncommitted=true)
void check_historic_sibling_path(TreeType &tree, index_t index, fr_sibling_path expected_sibling_path, block_number_t blockNumber, bool expected_success=true)
void check_leaf(TreeType &tree, const fr &leaf, index_t leaf_index, bool expected_success, bool includeUncommitted=true)
void check_sibling_path(TreeType &tree, index_t index, fr_sibling_path expected_sibling_path, bool includeUncommitted=true, bool expected_result=true)
void commit_tree(TreeType &tree, bool expected_success=true)
void check_root(TreeType &tree, fr expected_root, bool includeUncommitted=true)
void hash(State &state) noexcept
void checkpoint_tree(TreeType &tree)
ThreadPoolPtr make_thread_pool(uint64_t numThreads)
void commit_all_tree_checkpoints(TreeType &tree, bool expected_success=true)
void rollback_tree(TreeType &tree)
const uint32_t NUM_VALUES
void check_historic_find_leaf_index_from(TypeOfTree &tree, const std::vector< LeafValueType > &leaves, block_number_t blockNumber, index_t start_index, const std::vector< std::optional< index_t > > &expected_indices, bool expected_success, bool includeUncommitted=true)
std::string random_temp_directory()
void check_find_leaf_index(TypeOfTree &tree, const std::vector< LeafValueType > &leaves, const std::vector< std::optional< index_t > > &expected_indices, bool expected_success, bool includeUncommitted=true)
void check_block_and_root_data(LMDBTreeStore::SharedPtr db, block_number_t blockNumber, fr root, bool expectedSuccess)
void check_find_leaf_index_from(TypeOfTree &tree, const std::vector< LeafValueType > &leaves, index_t start_index, const std::vector< std::optional< index_t > > &expected_indices, bool expected_success, bool includeUncommitted=true)
std::string random_string()
std::shared_ptr< ThreadPool > ThreadPoolPtr
void check_block_and_size_data(LMDBTreeStore::SharedPtr db, block_number_t blockNumber, index_t expectedSize, bool expectedSuccess)
void commit_checkpoint_tree(TreeType &tree, bool expected_success=true)
std::vector< fr > fr_sibling_path
void revert_checkpoint_tree(TreeType &tree, bool expected_success=true)
void revert_all_tree_checkpoints(TreeType &tree, bool expected_success=true)
void check_historic_find_leaf_index(TypeOfTree &tree, const std::vector< LeafValueType > &leaves, block_number_t blockNumber, const std::vector< std::optional< index_t > > &expected_indices, bool expected_success, bool includeUncommitted=true)
fr_sibling_path get_sibling_path(TypeOfTree &tree, index_t index, bool includeUncommitted=true, bool expected_success=true)
Entry point for Barretenberg command-line interface.
TEST_F(IPATest, ChallengesAreZero)
field< Bn254FrParams > fr
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
static fr hash_pair(const fr &lhs, const fr &rhs)
static constexpr field zero()