@@ -475,6 +475,7 @@ TEST_F(PersistedContentAddressedAppendOnlyTreeTest, errors_are_caught_and_handle
475
475
std::string name = random_string ();
476
476
std::string directory = random_temp_directory ();
477
477
std::filesystem::create_directories (directory);
478
+ auto & random_engine = numeric::get_randomness ();
478
479
479
480
{
480
481
LMDBTreeStore::SharedPtr db = std::make_shared<LMDBTreeStore>(_directory, name, 50 , _maxReaders);
@@ -492,9 +493,10 @@ TEST_F(PersistedContentAddressedAppendOnlyTreeTest, errors_are_caught_and_handle
492
493
493
494
// Add lots of values to the tree
494
495
uint32_t num_values_to_add = 16 * 1024 ;
495
- std::vector<fr> values (num_values_to_add, VALUES[ 0 ]) ;
496
+ std::vector<fr> values;
496
497
for (uint32_t i = 0 ; i < num_values_to_add; i++) {
497
- memdb.update_element (i, VALUES[0 ]);
498
+ values.emplace_back (random_engine.get_random_uint256 ());
499
+ memdb.update_element (i, values[i]);
498
500
}
499
501
add_values (tree, values);
500
502
@@ -714,46 +716,31 @@ TEST_F(PersistedContentAddressedAppendOnlyTreeTest, test_find_leaf_index)
714
716
715
717
commit_tree (tree);
716
718
717
- values = { 16 , 4 , 18 , 22 };
719
+ values = { 16 , 4 , 19 , 22 };
718
720
add_values (tree, values);
719
721
720
- // we now have duplicate leaf 18, one committed the other not
721
- check_find_leaf_index (tree, 18 , 5 , true , true );
722
- check_find_leaf_index (tree, 18 , 5 , true , false );
723
-
724
722
// verify the find index from api
725
723
check_find_leaf_index_from (tree, 18 , 0 , 5 , true , true );
726
- check_find_leaf_index_from (tree, 18 , 6 , 10 , true , true );
727
- check_find_leaf_index_from (tree, 18 , 6 , 0 , false , false );
724
+ check_find_leaf_index_from (tree, 19 , 6 , 10 , true , true );
725
+ check_find_leaf_index_from (tree, 19 , 0 , 0 , false , false );
728
726
729
727
commit_tree (tree);
730
728
731
- // add another leaf 18
732
- add_value (tree, 18 );
733
-
734
- // should return the first index
735
- check_find_leaf_index_from (tree, 18 , 0 , 5 , true , false );
736
- check_find_leaf_index_from (tree, 18 , 0 , 5 , true , true );
737
-
738
729
add_value (tree, 88 );
739
- // and another uncommitted 18
740
- add_value (tree, 18 );
741
730
742
731
add_value (tree, 32 );
743
732
744
- // should return the first uncommitted
745
- check_find_leaf_index_from (tree, 18 , 12 , 12 , true , true );
746
- check_find_leaf_index_from (tree, 18 , 14 , 14 , true , true );
747
- check_find_leaf_index_from (tree, 18 , 15 , 0 , false , true );
733
+ check_size (tree, 14 );
734
+ check_size (tree, 12 , false );
748
735
749
736
// look past the last instance of this leaf
750
- check_find_leaf_index_from (tree, 18 , 17 , 0 , false , true );
737
+ check_find_leaf_index_from (tree, 18 , 6 , 0 , false , true );
751
738
752
739
// look beyond the end of uncommitted
753
- check_find_leaf_index_from (tree, 18 , 18 , 0 , false , true );
740
+ check_find_leaf_index_from (tree, 18 , 15 , 0 , false , true );
754
741
755
742
// look beyond the end of committed and don't include uncomitted
756
- check_find_leaf_index_from (tree, 18 , 14 , 0 , false , false );
743
+ check_find_leaf_index_from (tree, 88 , 13 , 0 , false , false );
757
744
}
758
745
759
746
TEST_F (PersistedContentAddressedAppendOnlyTreeTest, can_add_multiple_values)
@@ -975,7 +962,7 @@ TEST_F(PersistedContentAddressedAppendOnlyTreeTest, test_find_historic_leaf_inde
975
962
976
963
commit_tree (tree);
977
964
978
- values = { 16 , 4 , 18 , 22 };
965
+ values = { 16 , 4 , 19 , 22 };
979
966
add_values (tree, values);
980
967
981
968
// should not be present at block 1
@@ -987,15 +974,15 @@ TEST_F(PersistedContentAddressedAppendOnlyTreeTest, test_find_historic_leaf_inde
987
974
check_find_historic_leaf_index_from (tree, 1 , 18 , 2 , 0 , false , false );
988
975
// at block 2 it should be
989
976
check_find_historic_leaf_index_from (tree, 2 , 18 , 2 , 5 , true );
990
- // at block 2, from index 6 it should not be found if looking only at committed
991
- check_find_historic_leaf_index_from (tree, 2 , 18 , 6 , 5 , false , false );
992
- // at block 2, from index 6 it should be found if looking at uncommitted too
993
- check_find_historic_leaf_index_from (tree, 2 , 18 , 6 , 10 , true );
977
+ // at block 2, from index 6, 19 should not be found if looking only at committed
978
+ check_find_historic_leaf_index_from (tree, 2 , 19 , 6 , 5 , false , false );
979
+ // at block 2, from index 6, 19 should be found if looking at uncommitted too
980
+ check_find_historic_leaf_index_from (tree, 2 , 19 , 6 , 10 , true );
994
981
995
982
commit_tree (tree);
996
983
997
- // at block 3, from index 6 it should now be found in committed only
998
- check_find_historic_leaf_index_from (tree, 3 , 18 , 6 , 10 , true , false );
984
+ // at block 3, from index 6, should now be found in committed only
985
+ check_find_historic_leaf_index_from (tree, 3 , 19 , 6 , 10 , true , false );
999
986
}
1000
987
1001
988
TEST_F (PersistedContentAddressedAppendOnlyTreeTest, can_be_filled)
@@ -1418,79 +1405,6 @@ TEST_F(PersistedContentAddressedAppendOnlyTreeTest, can_unwind_all_blocks)
1418
1405
test_unwind (_directory, " DB" , _mapSize, _maxReaders, 10 , 16 , 16 , 16 , second);
1419
1406
}
1420
1407
1421
- TEST_F (PersistedContentAddressedAppendOnlyTreeTest, can_unwind_blocks_with_duplicate_leaves)
1422
- {
1423
- constexpr size_t depth = 4 ;
1424
- std::string name = random_string ();
1425
- LMDBTreeStore::SharedPtr db = std::make_shared<LMDBTreeStore>(_directory, name, _mapSize, _maxReaders);
1426
- std::unique_ptr<Store> store = std::make_unique<Store>(name, depth, db);
1427
- ThreadPoolPtr pool = make_thread_pool (1 );
1428
- TreeType tree (std::move (store), pool);
1429
- MemoryTree<Poseidon2HashPolicy> memdb (depth);
1430
-
1431
- constexpr size_t blockSize = 2 ;
1432
- constexpr size_t numBlocks = 2 ;
1433
- constexpr size_t numBlocksToUnwind = 1 ;
1434
-
1435
- std::vector<fr> values = create_values (blockSize);
1436
-
1437
- // Add the same batch of values many times
1438
- for (size_t i = 0 ; i < numBlocks; i++) {
1439
- for (size_t j = 0 ; j < values.size (); j++) {
1440
- size_t ind = i * blockSize + j;
1441
- memdb.update_element (ind, values[j]);
1442
- }
1443
- add_values (tree, values);
1444
- commit_tree (tree);
1445
- check_block_and_root_data (db, i + 1 , memdb.root (), true );
1446
-
1447
- for (size_t j = 0 ; j < values.size (); j++) {
1448
- size_t ind = i * blockSize + j;
1449
- // query the indices db directly
1450
- check_indices_data (db, values[j], ind, true , true );
1451
- }
1452
- }
1453
-
1454
- for (size_t i = 0 ; i < numBlocks; i++) {
1455
- index_t startIndex = i * blockSize;
1456
- index_t expectedIndex = startIndex + 1 ;
1457
-
1458
- // search for the leaf from start of each batch
1459
- check_find_leaf_index_from (tree, values[1 ], startIndex, expectedIndex, true );
1460
- // search for the leaf from start of the next batch
1461
- check_find_leaf_index_from (tree, values[1 ], startIndex + 2 , expectedIndex + blockSize, i < (numBlocks - 1 ));
1462
- }
1463
-
1464
- const uint32_t blocksToRemove = numBlocksToUnwind;
1465
- for (uint32_t i = 0 ; i < blocksToRemove; i++) {
1466
- const index_t blockNumber = numBlocks - i;
1467
- unwind_block (tree, blockNumber);
1468
-
1469
- const index_t previousValidBlock = blockNumber - 1 ;
1470
- index_t deletedBlockStartIndex = previousValidBlock * blockSize;
1471
-
1472
- check_block_height (tree, previousValidBlock);
1473
- check_size (tree, deletedBlockStartIndex);
1474
-
1475
- for (size_t j = 0 ; j < numBlocks; j++) {
1476
- index_t startIndex = j * blockSize;
1477
- index_t expectedIndex = startIndex + 1 ;
1478
-
1479
- // search for the leaf from start of each batch
1480
- check_find_leaf_index_from (tree, values[1 ], startIndex, expectedIndex, j < previousValidBlock);
1481
- // search for the leaf from start of the next batch
1482
- check_find_leaf_index_from (
1483
- tree, values[1 ], startIndex + 2 , expectedIndex + blockSize, j < (previousValidBlock - 1 ));
1484
-
1485
- for (size_t k = 0 ; k < values.size (); k++) {
1486
- size_t ind = j * blockSize + k;
1487
- // query the indices db directly. If block number == 1 that means the entry should not be present
1488
- check_indices_data (db, values[k], ind, blockNumber > 1 , ind < deletedBlockStartIndex);
1489
- }
1490
- }
1491
- }
1492
- }
1493
-
1494
1408
TEST_F (PersistedContentAddressedAppendOnlyTreeTest, can_sync_and_unwind_large_blocks)
1495
1409
{
1496
1410
@@ -1534,23 +1448,15 @@ TEST_F(PersistedContentAddressedAppendOnlyTreeTest, can_advance_finalised_blocks
1534
1448
1535
1449
index_t expectedFinalisedBlock = i < finalisedBlockDelay ? 0 : i - finalisedBlockDelay;
1536
1450
check_finalised_block_height (tree, expectedFinalisedBlock);
1537
- index_t expectedPresentStart = i < finalisedBlockDelay ? 0 : (expectedFinalisedBlock * blockSize);
1538
- index_t expectedPresentEnd = ((i + 1 ) * blockSize) - 1 ;
1539
- std::vector<fr> toTest (values.begin () + static_cast <int64_t >(expectedPresentStart),
1540
- values.begin () + static_cast <int64_t >(expectedPresentEnd + 1 ));
1541
- check_leaf_keys_are_present (db, expectedPresentStart, expectedPresentEnd, toTest);
1542
1451
1543
1452
if (i >= finalisedBlockDelay) {
1544
1453
1545
1454
index_t blockToFinalise = expectedFinalisedBlock + 1 ;
1546
1455
1547
- // attemnpting to finalise a block that doesn't exist should fail
1456
+ // attempting to finalise a block that doesn't exist should fail
1548
1457
finalise_block (tree, blockToFinalise + numBlocks, false );
1549
1458
1550
1459
finalise_block (tree, blockToFinalise, true );
1551
-
1552
- index_t expectedNotPresentEnd = (blockToFinalise * blockSize) - 1 ;
1553
- check_leaf_keys_are_not_present (db, 0 , expectedNotPresentEnd);
1554
1460
}
1555
1461
}
1556
1462
}
@@ -1585,12 +1491,7 @@ TEST_F(PersistedContentAddressedAppendOnlyTreeTest, can_finalise_multiple_blocks
1585
1491
1586
1492
index_t blockToFinalise = 8 ;
1587
1493
1588
- check_leaf_keys_are_present (db, 0 , (numBlocks * blockSize) - 1 , values);
1589
-
1590
1494
finalise_block (tree, blockToFinalise);
1591
-
1592
- index_t expectedNotPresentEnd = (blockToFinalise * blockSize) - 1 ;
1593
- check_leaf_keys_are_not_present (db, 0 , expectedNotPresentEnd);
1594
1495
}
1595
1496
1596
1497
TEST_F (PersistedContentAddressedAppendOnlyTreeTest, can_not_finalise_block_beyond_pending_chain)
@@ -1630,12 +1531,7 @@ TEST_F(PersistedContentAddressedAppendOnlyTreeTest, can_not_finalise_block_beyon
1630
1531
// finalise the entire chain
1631
1532
index_t blockToFinalise = numBlocks;
1632
1533
1633
- check_leaf_keys_are_present (db, 0 , (numBlocks * blockSize) - 1 , values);
1634
-
1635
1534
finalise_block (tree, blockToFinalise);
1636
-
1637
- index_t expectedNotPresentEnd = (blockToFinalise * blockSize) - 1 ;
1638
- check_leaf_keys_are_not_present (db, 0 , expectedNotPresentEnd);
1639
1535
}
1640
1536
1641
1537
TEST_F (PersistedContentAddressedAppendOnlyTreeTest, can_not_fork_from_unwound_blocks)
0 commit comments