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);
75 EXPECT_EQ(response.success,
true);
76 EXPECT_EQ(response.inner.meta.finalizedBlockHeight, expected_finalized_block);
87 EXPECT_EQ(response.success,
true);
88 EXPECT_EQ(response.inner.meta.unfinalizedBlockHeight, expected_block_height);
99 EXPECT_EQ(response.success,
true);
100 EXPECT_EQ(response.inner.meta.root, expected_root);
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);
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);
189 EXPECT_EQ(response.success, expected_success);
200 EXPECT_EQ(response.success, expected_success);
211 EXPECT_EQ(response.success, expected_success);
222 EXPECT_EQ(response.success,
true);
234 EXPECT_EQ(response.success,
true);
245 auto completion = [&](
const Response& response) ->
void {
246 EXPECT_EQ(response.success, expected_success);
247 if (!response.success && expected_success) {
259 bool expected_success,
260 bool expected_match =
true,
261 bool includeUncommitted =
true)
265 EXPECT_EQ(response.
success, expected_success);
266 if (response.
success && expected_match) {
267 EXPECT_EQ(response.
inner.leaf, leaf);
278 bool expected_success,
279 bool expected_match =
true,
280 bool includeUncommitted =
true)
284 EXPECT_EQ(response.
success, expected_success);
285 if (response.
success && expected_match) {
286 EXPECT_EQ(response.
inner.leaf, leaf);
298 for (
const auto& i : sibling_path) {
299 if (
index % 2 == 0) {
311 EXPECT_EQ(hash, expected_root);
315 const std::vector<index_t>& indices,
320 blockNumbers = response.
inner.blockNumbers;
328 const std::vector<index_t>& indices,
333 blockNumbers = response.
inner.blockNumbers;
341 constexpr size_t depth = 10;
344 EXPECT_NO_THROW(
Store store(name, depth, db));
357 constexpr size_t depth = 10;
360 EXPECT_NO_THROW(
Store store(name, depth, db));
396 constexpr size_t depth = 10;
401 EXPECT_ANY_THROW(
Store store_wrong_name(
"Wrong name", depth, db));
402 EXPECT_ANY_THROW(
Store store_wrong_depth(name, depth + 1, db));
407 constexpr size_t depth = 3;
430 constexpr size_t depth = 4;
438 std::vector<fr> values;
440 for (uint32_t i = 0; i < 16; i++) {
445 std::stringstream ss;
446 ss <<
"Unable to append leaves to tree " << name <<
" new size: 17 max size: 16";
450 EXPECT_EQ(response.success,
false);
451 EXPECT_EQ(response.message, ss.str());
460 constexpr size_t depth = 4;
468 std::vector<fr> values;
470 for (uint32_t i = 0; i < 16; i++) {
477 std::string str =
"Unable to get leaf at index 17, leaf index out of tree range.";
480 EXPECT_EQ(response.success,
false);
481 EXPECT_EQ(response.message, str);
484 tree.
get_leaf(17,
true, get_completion);
489 std::string str =
"Unable to get leaf at index 17 for block 1, leaf index out of tree range.";
492 EXPECT_EQ(response.success,
false);
493 EXPECT_EQ(response.message, str);
496 tree.
get_leaf(17, 1,
true, get_completion);
504 constexpr size_t depth = 16;
507 std::filesystem::create_directories(directory);
521 fr empty_root = memdb.
root();
524 uint32_t num_values_to_add = 16 * 1024;
525 std::vector<fr> values;
526 for (uint32_t i = 0; i < num_values_to_add; i++) {
539 EXPECT_EQ(response.success,
false);
577 fr empty_root = memdb.
root();
607 constexpr size_t depth = 5;
677 constexpr size_t depth = 10;
705 constexpr size_t depth = 5;
719 check_find_leaf_index<fr, TreeType>(tree, {
fr(10) }, {
std::nullopt },
true,
false);
721 check_find_leaf_index<fr, TreeType>(tree, {
fr(15) }, {
std::nullopt },
true,
true);
722 check_find_leaf_index<fr, TreeType>(tree, {
fr(15) }, {
std::nullopt },
true,
false);
728 check_find_leaf_index<fr, TreeType>(tree, {
fr(40) }, {
std::nullopt },
true,
false);
729 check_find_leaf_index<fr, TreeType>(tree, {
fr(30) }, {
std::nullopt },
true,
false);
730 check_find_leaf_index<fr, TreeType>(tree, {
fr(20) }, {
std::nullopt },
true,
false);
734 std::vector<fr> values{ 15, 18, 26, 2 };
744 check_find_leaf_index<fr, TreeType>(tree, {
fr(18) }, {
std::nullopt },
true,
false);
748 values = { 16, 4, 19, 22 };
754 check_find_leaf_index_from<fr, TreeType>(tree, {
fr(19) }, 0, {
std::nullopt },
true,
false);
766 check_find_leaf_index_from<fr, TreeType>(tree, {
fr(18) }, 6, {
std::nullopt },
true,
true);
769 check_find_leaf_index_from<fr, TreeType>(tree, {
fr(18) }, 15, {
std::nullopt },
true,
true);
772 check_find_leaf_index_from<fr, TreeType>(tree, {
fr(88) }, 13, {
std::nullopt },
true,
false);
777 constexpr size_t depth = 10;
800 constexpr size_t depth = 3;
808 std::vector<fr> to_add;
810 for (
size_t i = 0; i < 4; ++i) {
825 constexpr size_t depth = 10;
833 std::vector<fr> to_add(32,
fr::zero());
836 for (
size_t i = 0; i < 32; ++i) {
851 constexpr size_t depth = 8;
859 std::vector<fr> to_add(32,
fr::zero());
862 for (
size_t i = 0; i < 32; ++i) {
868 check_find_leaf_index<fr, TreeType>(tree, { leaf }, {
std::nullopt },
true);
869 check_historic_find_leaf_index<fr, TreeType>(tree, { leaf }, 1, {
std::nullopt },
true);
870 check_find_leaf_index_from<fr, TreeType>(tree, { leaf }, 0, {
std::nullopt },
true);
871 check_historic_find_leaf_index_from<fr, TreeType>(tree, { leaf }, 1, 0, {
std::nullopt },
true);
876 constexpr size_t depth = 10;
884 auto check = [&](
index_t expected_size,
index_t expected_unfinalized_block_height) {
892 constexpr uint32_t num_blocks = 10;
893 constexpr uint32_t batch_size = 4;
894 for (uint32_t i = 0; i < num_blocks; i++) {
895 std::vector<fr> to_add;
897 for (
size_t j = 0; j < batch_size; ++j) {
898 size_t ind = i * batch_size + j;
902 index_t expected_size = (i + 1) * batch_size;
904 check(expected_size, i);
906 check(expected_size, i + 1);
913 constexpr size_t depth = 10;
921 auto check = [&](
index_t expected_size,
index_t expected_unfinalized_block_height) {
929 std::vector<size_t> batchSize = { 8, 20, 64, 32 };
932 for (uint32_t i = 0; i < batchSize.size(); i++) {
933 std::vector<fr> to_add;
935 for (
size_t j = 0; j < batchSize[i]; ++j) {
936 size_t ind = expected_size + j;
940 expected_size += batchSize[i];
942 check(expected_size, i);
944 check(expected_size, i + 1);
951 constexpr size_t depth = 10;
959 constexpr uint32_t num_blocks = 10;
960 constexpr uint32_t batch_size = 4;
965 auto check = [&](
index_t expected_size,
index_t expected_unfinalized_block_height) {
972 for (uint32_t i = 0; i < historicPathsZeroIndex.size(); i++) {
975 index_t maxSizeAtBlock = ((i + 1) * batch_size) - 1;
978 tree,
get_value(maxSizeAtBlock), historicPathsMaxIndex[i], maxSizeAtBlock, i + 1);
982 for (uint32_t i = 0; i < num_blocks; i++) {
983 std::vector<fr> to_add;
985 for (
size_t j = 0; j < batch_size; ++j) {
986 size_t ind = i * batch_size + j;
990 index_t expected_size = (i + 1) * batch_size;
992 check(expected_size, i);
994 check(expected_size, i + 1);
1002 constexpr size_t depth = 10;
1010 constexpr uint32_t num_blocks = 10;
1011 constexpr uint32_t batch_size = 4;
1013 for (uint32_t i = 0; i < num_blocks; i++) {
1014 std::vector<fr> to_add;
1016 for (
size_t j = 0; j < batch_size; ++j) {
1017 size_t ind = i * batch_size + j;
1025 uint64_t block_tree_size = 0;
1027 for (uint32_t i = 0; i < num_blocks; i++) {
1029 tree.
get_meta_data(i + 1,
false, [&](
auto response) ->
void {
1030 block_tree_size = response.inner.meta.size;
1034 for (uint32_t j = 0; j < num_blocks; j++) {
1035 index_t indexToQuery = j * batch_size;
1037 check_historic_leaf(tree, i + 1, expectedLeaf, indexToQuery, indexToQuery < block_tree_size,
true,
false);
1044 constexpr size_t depth = 5;
1051 std::vector<fr> values{ 30, 10, 20, 40 };
1056 values = { 15, 18, 26, 2 };
1061 values = { 16, 4, 19, 22 };
1065 check_historic_find_leaf_index<fr, TreeType>(tree, {
fr(26) }, 1, {
std::nullopt },
true);
1070 check_historic_find_leaf_index_from<fr, TreeType>(tree, {
fr(18) }, 1, 2, {
std::nullopt },
true,
false);
1074 check_historic_find_leaf_index_from<fr, TreeType>(tree, {
fr(19) }, 2, 6, {
std::nullopt },
true,
false);
1086 constexpr size_t depth = 3;
1097 for (
size_t i = 0; i < 8; i++) {
1109 constexpr size_t depth = 10;
1115 uint32_t num_reads = 16 * 1024;
1127 Signal signal(1 + num_reads);
1131 tree.
commit(commit_completion);
1135 for (
size_t i = 0; i < num_reads; i++) {
1137 paths[i] = response.inner.path;
1145 for (
auto& path : paths) {
1146 EXPECT_TRUE(path == initial_path || path == final_sibling_path);
1152 constexpr size_t depth = 3;
1173 constexpr size_t depth = 4;
1193 EXPECT_EQ(resp.inner.path, expected_sibling_path);
1206 EXPECT_EQ(resp.inner.path, expected_sibling_path);
1216 constexpr size_t depth = 5;
1226 std::vector<fr> values{ 30, 10, 20, 40 };
1228 for (
auto v : values) {
1238 values = { 15, 18, 26, 2 };
1240 for (
auto v : values) {
1248 fr block2Root = memdb.
root();
1253 values = { 16, 4, 18, 22 };
1255 for (
auto v : values) {
1279 check_find_leaf_index<fr, TreeType>(treeAtBlock2, {
fr(4) }, {
std::nullopt },
true);
1296 check_historic_find_leaf_index<fr, TreeType>(treeAtBlock2, {
fr(16) }, 2, {
std::nullopt },
true,
false);
1298 check_historic_find_leaf_index_from<fr, TreeType>(treeAtBlock2, {
fr(18) }, 1, 3, {
std::nullopt },
true,
false);
1309 constexpr size_t depth = 10;
1317 constexpr uint32_t numBlocks = 50;
1318 constexpr uint32_t batchSize = 16;
1319 constexpr uint32_t windowSize = 8;
1323 std::vector<fr> roots;
1325 auto check = [&](
index_t expectedSize,
index_t expectedBlockHeight) {
1332 for (uint32_t i = 0; i < historicPathsZeroIndex.size(); i++) {
1335 const bool expectedSuccess =
1336 expectedBlockHeight <= windowSize || blockNumber > (expectedBlockHeight - windowSize);
1338 index_t maxSizeAtBlock = ((i + 1) * batchSize) - 1;
1348 for (uint32_t i = 0; i < numBlocks; i++) {
1349 std::vector<fr> to_add;
1351 for (
size_t j = 0; j < batchSize; ++j) {
1352 size_t ind = i * batchSize + j;
1356 index_t expected_size = (i + 1) * batchSize;
1358 check(expected_size, i);
1365 historicPathsMaxIndex.push_back(memdb.
get_sibling_path(expected_size - 1));
1366 roots.push_back(memdb.
root());
1369 if (i >= windowSize) {
1374 if (oldestBlock > 1) {
1379 fr rootToRemove = roots[oldestBlock - 1];
1388 check(expected_size, i + 1);
1398 uint64_t maxReaders,
1402 uint32_t numBlocksToUnwind,
1403 std::vector<fr> values)
1411 uint32_t batchSize = blockSize;
1415 std::vector<fr> roots;
1417 fr initialRoot = memdb.
root();
1420 for (uint32_t i = 0; i < numBlocks; i++) {
1421 std::vector<fr> to_add;
1423 for (
size_t j = 0; j < batchSize; ++j) {
1424 size_t ind = i * batchSize + j;
1426 to_add.push_back(values[ind]);
1428 index_t expected_size = (i + 1) * batchSize;
1442 historicPathsMaxIndex.push_back(memdb.
get_sibling_path(expected_size - 1));
1443 roots.push_back(memdb.
root());
1452 const uint32_t blocksToRemove = numBlocksToUnwind;
1453 for (uint32_t i = 0; i < blocksToRemove; i++) {
1461 if (blockNumber > 1) {
1468 const auto last = roots.begin() + long(blockNumber - 1);
1470 std::find_if(roots.begin(), last, [=](
const fr& r) ->
bool { return r == roots[blockNumber - 1]; });
1473 const index_t previousValidBlock = blockNumber - 1;
1474 index_t deletedBlockStartIndex = previousValidBlock * batchSize;
1478 check_root(tree, previousValidBlock == 0 ? initialRoot : roots[previousValidBlock - 1]);
1483 previousValidBlock == 0 ? initialPath : historicPathsZeroIndex[previousValidBlock - 1],
1488 check_leaf(tree, values[1 + deletedBlockStartIndex], 1 + deletedBlockStartIndex,
true,
false);
1489 check_find_leaf_index<fr, TreeType>(tree, { values[1 + deletedBlockStartIndex] }, {
std::nullopt },
true);
1493 bool expectedSuccess = historicBlockNumber <= previousValidBlock;
1495 index_t maxSizeAtBlock = ((j + 1) * batchSize) - 1;
1497 tree, maxSizeAtBlock, historicPathsMaxIndex[j], historicBlockNumber, expectedSuccess);
1500 check_historic_leaf(tree, historicBlockNumber, values[leafIndex], leafIndex, expectedSuccess);
1503 if (expectedSuccess) {
1504 if (values[leafIndex] !=
fr::zero()) {
1512 check_historic_find_leaf_index<fr, TreeType>(
1513 tree, { values[leafIndex] }, historicBlockNumber, expected_results, expectedSuccess);
1514 check_historic_find_leaf_index_from<fr, TreeType>(
1515 tree, { values[leafIndex] }, historicBlockNumber, 0, expected_results, expectedSuccess);
1522 std::vector<fr> first = create_values(1024);
1523 test_unwind(_directory,
"DB", _mapSize, _maxReaders, 10, 16, 16, 8, first);
1528 std::vector<fr> first = create_values(1024);
1529 test_unwind(_directory,
"DB", _mapSize, _maxReaders, 10, 16, 16, 16, first);
1530 std::vector<fr> second = create_values(1024);
1531 test_unwind(_directory,
"DB", _mapSize, _maxReaders, 10, 16, 16, 16, second);
1536 const size_t block_size = 16;
1537 const uint32_t num_blocks = 16;
1539 std::vector<fr> first(1024,
fr::zero());
1540 test_unwind(_directory,
"DB", _mapSize, _maxReaders, 10, block_size, num_blocks, num_blocks, first);
1542 std::vector<fr> second = create_values(1024);
1544 for (
size_t i = 0; i < block_size; i++) {
1547 test_unwind(_directory,
"DB", _mapSize, _maxReaders, 10, block_size, num_blocks, num_blocks, second);
1550 std::vector<fr> third = create_values(1024);
1551 size_t offset = block_size * 2;
1552 for (
size_t i = 0; i < block_size * 2; i++) {
1555 test_unwind(_directory,
"DB", _mapSize, _maxReaders, 10, block_size, num_blocks, num_blocks, third);
1558 std::vector<fr> fourth = create_values(1024);
1559 test_unwind(_directory,
"DB", _mapSize, _maxReaders, 10, block_size, num_blocks, num_blocks, fourth);
1565 constexpr uint32_t numBlocks = 4;
1566 constexpr uint32_t numBlocksToUnwind = 2;
1567 std::vector<uint32_t> blockSizes = { 2, 4, 8, 16, 32 };
1568 for (
const uint32_t& size : blockSizes) {
1569 uint32_t actualSize = size * 1024;
1570 std::vector<fr> values = create_values(actualSize * numBlocks);
1571 std::stringstream ss;
1572 ss <<
"DB " << actualSize;
1573 test_unwind(_directory, ss.str(), _mapSize, _maxReaders, 20, actualSize, numBlocks, numBlocksToUnwind, values);
1580 constexpr uint32_t depth = 10;
1590 uint32_t batchSize = 64;
1594 values.emplace_back();
1596 values.emplace_back();
1598 values.push_back(create_values(batchSize));
1600 values.emplace_back();
1601 values.emplace_back();
1603 values.push_back(create_values(batchSize));
1607 for (
auto& blockValues : values) {
1611 for (
const auto& blockValue : blockValues) {
1624 while (blockNumber > 0) {
1632 if (blockNumber > 0) {
1642 constexpr uint32_t depth = 10;
1652 uint32_t batchSize = 64;
1656 values.emplace_back();
1658 values.emplace_back();
1660 values.push_back(create_values(batchSize));
1662 values.emplace_back();
1663 values.emplace_back();
1665 values.push_back(create_values(batchSize));
1669 for (
auto& blockValues : values) {
1673 for (
const auto& blockValue : blockValues) {
1688 while (blockToRemove < blockNumber) {
1704 constexpr uint32_t depth = 10;
1710 const size_t block_size = 32;
1712 for (
size_t i = 0; i < 5; i++) {
1713 std::vector<fr> values = create_values(block_size);
1717 std::vector<index_t> indices{ 12, 33, 63, 64, 65, 80, 96, 159, 160 };
1722 EXPECT_EQ(blockNumbers.size(), indices.size());
1724 index_t maxIndex = 5 * block_size - 1;
1725 for (
size_t i = 0; i < blockNumbers.size(); i++) {
1726 bool present = indices[i] <= maxIndex;
1730 EXPECT_EQ(blockNumbers[i].
value(), expected);
1732 EXPECT_EQ(blockNumbers[i].has_value(), present);
1737 EXPECT_EQ(blockNumbers.size(), indices.size());
1739 maxIndex = 2 * block_size - 1;
1740 for (
size_t i = 0; i < blockNumbers.size(); i++) {
1741 bool present = indices[i] <= maxIndex;
1745 EXPECT_EQ(blockNumbers[i].
value(), expected);
1747 EXPECT_EQ(blockNumbers[i].has_value(), present);
1754 EXPECT_EQ(blockNumbers.size(), indices.size());
1755 maxIndex = 3 * block_size - 1;
1756 for (
size_t i = 0; i < blockNumbers.size(); i++) {
1757 bool present = indices[i] <= maxIndex;
1761 EXPECT_EQ(blockNumbers[i].
value(), expected);
1763 EXPECT_EQ(blockNumbers[i].has_value(), present);
1772 EXPECT_EQ(blockNumbers.size(), indices.size());
1774 maxIndex = block_size - 1;
1775 for (
size_t i = 0; i < blockNumbers.size(); i++) {
1776 bool present = indices[i] <= maxIndex;
1780 EXPECT_EQ(blockNumbers[i].
value(), expected);
1782 EXPECT_EQ(blockNumbers[i].has_value(), present);
1787 EXPECT_EQ(blockNumbers.size(), indices.size());
1789 maxIndex = block_size - 1;
1790 for (
size_t i = 0; i < blockNumbers.size(); i++) {
1791 bool present = indices[i] <= maxIndex;
1795 EXPECT_EQ(blockNumbers[i].
value(), expected);
1797 EXPECT_EQ(blockNumbers[i].has_value(), present);
1804 constexpr uint32_t depth = 10;
1811 uint32_t blockSize = 16;
1812 uint32_t numBlocks = 16;
1813 uint32_t finalizedBlockDelay = 4;
1814 std::vector<fr> values = create_values(blockSize * numBlocks);
1816 for (uint32_t i = 0; i < numBlocks; i++) {
1817 std::vector<fr> to_add;
1819 for (
size_t j = 0; j < blockSize; ++j) {
1820 size_t ind = i * blockSize + j;
1822 to_add.push_back(values[ind]);
1827 block_number_t expectedFinalizedBlock = i < finalizedBlockDelay ? 0 : i - finalizedBlockDelay;
1830 if (i >= finalizedBlockDelay) {
1848 constexpr uint32_t depth = 10;
1855 uint32_t blockSize = 16;
1856 uint32_t numBlocks = 16;
1857 std::vector<fr> values = create_values(blockSize * numBlocks);
1859 for (uint32_t i = 0; i < numBlocks; i++) {
1860 std::vector<fr> to_add;
1862 for (
size_t j = 0; j < blockSize; ++j) {
1863 size_t ind = i * blockSize + j;
1865 to_add.push_back(values[ind]);
1881 constexpr uint32_t depth = 10;
1888 uint32_t blockSize = 16;
1889 uint32_t numBlocks = 16;
1890 std::vector<fr> values = create_values(blockSize * numBlocks);
1895 for (uint32_t i = 0; i < numBlocks; i++) {
1896 std::vector<fr> to_add;
1898 for (
size_t j = 0; j < blockSize; ++j) {
1899 size_t ind = i * blockSize + j;
1901 to_add.push_back(values[ind]);
1921 uint32_t depth = 20;
1927 for (uint32_t i = 0; i < 5; i++) {
1928 std::vector<fr> values = create_values(1024);
1936 EXPECT_THROW(
Store(name, depth, 5, db), std::runtime_error);
1937 EXPECT_THROW(
Store(name, depth, 4, db), std::runtime_error);
1943 uint32_t depth = 20;
1949 for (uint32_t i = 0; i < 5; i++) {
1950 std::vector<fr> values = create_values(1024);
1959 EXPECT_THROW(
Store(name, depth, 1, db), std::runtime_error);
1960 EXPECT_THROW(
Store(name, depth, 2, db), std::runtime_error);
1965 uint32_t depth = 20;
1972 uint32_t numBlocks = 5;
1974 const fr initialRoot = memdb.
root();
1977 for (uint32_t i = 0; i < numBlocks; i++) {
1978 std::vector<fr> values = create_values(1024);
1985 EXPECT_NO_THROW(
Store(name, depth, 0, db));
1997 constexpr uint32_t depth = 10;
2004 uint32_t blockSize = 16;
2005 uint32_t numBlocks = 16;
2006 std::vector<fr> values = create_values(blockSize * numBlocks);
2008 for (uint32_t i = 0; i < numBlocks; i++) {
2009 std::vector<fr> to_add;
2011 for (
size_t j = 0; j < blockSize; ++j) {
2012 size_t ind = i * blockSize + j;
2014 to_add.push_back(values[ind]);
2026 for (uint32_t i = numBlocks; i > blockToFinalize; i--) {
2035 constexpr uint32_t depth = 10;
2042 uint32_t blockSize = 16;
2043 uint32_t numBlocks = 16;
2044 std::vector<fr> values = create_values(blockSize * numBlocks);
2046 for (uint32_t i = 0; i < numBlocks; i++) {
2047 std::vector<fr> to_add;
2049 for (
size_t j = 0; j < blockSize; ++j) {
2050 size_t ind = i * blockSize + j;
2052 to_add.push_back(values[ind]);
2064 for (uint32_t i = 0; i < blockToFinalize - 1; i++) {
2072 constexpr size_t depth = 10;
2073 uint32_t blockSize = 16;
2083 std::vector<fr> values = create_values(blockSize);
2094 uint32_t stackDepth = 20;
2099 std::vector<fr> values = create_values(blockSize);
2106 }
catch (std::exception& e) {
2113 std::vector<fr> values = create_values(blockSize);
2126 if (
index % 2 == 0) {
2128 checkpointIndex =
index - 1;
2138 std::vector<fr> values = create_values(blockSize);
2145 }
catch (std::exception& e) {
2152 std::vector<fr> values = create_values(blockSize);
2158 checkpointIndex =
index;
2164 if (
index % 2 == 0) {
2166 checkpointIndex =
index - 1;
2181 constexpr size_t depth = 10;
2182 uint32_t blockSize = 16;
2192 std::vector<fr> values = create_values(blockSize);
2203 uint32_t stackDepth = 20;
2208 std::vector<fr> values = create_values(blockSize);
2215 }
catch (std::exception& e) {
2233 constexpr size_t depth = 10;
2234 uint32_t blockSize = 16;
2244 std::vector<fr> values = create_values(blockSize);
2255 uint32_t stackDepth = 20;
2260 std::vector<fr> values = create_values(blockSize);
2267 }
catch (std::exception& e) {
2285 constexpr size_t depth = 10;
2286 uint32_t blockSize = 16;
2294 std::vector<fr> values = create_values(blockSize);
2332 constexpr size_t depth = 10;
2333 uint32_t blockSize = 16;
2341 std::vector<fr> values = create_values(blockSize);
static std::string _directory
static uint64_t _maxReaders
Implements a simple append-only merkle tree All methods are asynchronous unless specified as otherwis...
void get_leaf(const index_t &index, bool includeUncommitted, const GetLeafCallback &completion) const
Returns the leaf value at the provided index.
void remove_historic_block(const block_number_t &blockNumber, const RemoveHistoricBlockCallback &on_completion)
void get_sibling_path(const index_t &index, const HashPathCallback &on_completion, bool includeUncommitted) const
Returns the sibling path from the leaf at the given index to the root.
void commit(const CommitCallback &on_completion)
Commit the tree to the backing store.
virtual void add_values(const std::vector< fr > &values, const AppendCompletionCallback &on_completion)
Adds the given set of values to the end of the tree.
void get_meta_data(bool includeUncommitted, const MetaDataCallback &on_completion) const
Returns the tree meta data.
void find_block_numbers(const std::vector< index_t > &indices, const GetBlockForIndexCallback &on_completion) const
Returns the block numbers that correspond to the given indices values.
void unwind_block(const block_number_t &blockNumber, const UnwindBlockCallback &on_completion)
virtual void add_value(const fr &value, const AppendCompletionCallback &on_completion)
Adds a single value to the end of the tree.
void get_subtree_sibling_path(uint32_t subtree_depth, const HashPathCallback &on_completion, bool includeUncommitted) const
Get the subtree sibling path object.
std::function< void(TypedResponse< CommitResponse > &)> CommitCallback
void finalize_block(const block_number_t &blockNumber, const FinalizeBlockCallback &on_completion)
void find_leaf_sibling_paths(const std::vector< typename Store::LeafType > &leaves, bool includeUncommitted, const FindSiblingPathCallback &on_completion) const
Returns the sibling paths for the provided leaves in the tree.
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
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 check_historic_leaf(TreeType &tree, const block_number_t &blockNumber, const fr &leaf, index_t leaf_index, bool expected_success, bool expected_match=true, bool includeUncommitted=true)
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_leaf(TreeType &tree, const fr &leaf, index_t leaf_index, bool expected_success, bool expected_match=true, bool includeUncommitted=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_sibling_path(TreeType &tree, index_t index, fr_sibling_path expected_sibling_path, block_number_t blockNumber, bool expected_success=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)
ThreadPoolPtr make_thread_pool(uint64_t numThreads)
void commit_all_tree_checkpoints(TreeType &tree, bool expected_success=true)
void rollback_tree(TreeType &tree)
const fr & get_value(size_t index)
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 revert_tree_to_depth(TreeType &tree, uint32_t depth, bool expected_success=true)
uint32_t checkpoint_tree(TreeType &tree)
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 commit_tree_to_depth(TreeType &tree, uint32_t depth, bool expected_success=true)
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()