Skip to content

Commit a5adf33

Browse files
committed
Rough in doubles schema, table and settings.
1 parent fb94c79 commit a5adf33

14 files changed

+150
-2
lines changed

Makefile.am

+2
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ test_libbitcoin_database_test_SOURCES = \
9999
test/tables/archives/puts.cpp \
100100
test/tables/archives/transaction.cpp \
101101
test/tables/archives/txs.cpp \
102+
test/tables/caches/doubles.cpp \
102103
test/tables/caches/prevout.cpp \
103104
test/tables/caches/validated_bk.cpp \
104105
test/tables/caches/validated_tx.cpp \
@@ -240,6 +241,7 @@ include_bitcoin_database_tables_archives_HEADERS = \
240241

241242
include_bitcoin_database_tables_cachesdir = ${includedir}/bitcoin/database/tables/caches
242243
include_bitcoin_database_tables_caches_HEADERS = \
244+
include/bitcoin/database/tables/caches/doubles.hpp \
243245
include/bitcoin/database/tables/caches/prevout.hpp \
244246
include/bitcoin/database/tables/caches/validated_bk.hpp \
245247
include/bitcoin/database/tables/caches/validated_tx.hpp

builds/cmake/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ if (with-tests)
307307
"../../test/tables/archives/puts.cpp"
308308
"../../test/tables/archives/transaction.cpp"
309309
"../../test/tables/archives/txs.cpp"
310+
"../../test/tables/caches/doubles.cpp"
310311
"../../test/tables/caches/prevout.cpp"
311312
"../../test/tables/caches/validated_bk.cpp"
312313
"../../test/tables/caches/validated_tx.cpp"

builds/msvc/vs2022/libbitcoin-database-test/libbitcoin-database-test.vcxproj

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
<ClCompile Include="..\..\..\..\test\tables\archives\puts.cpp" />
111111
<ClCompile Include="..\..\..\..\test\tables\archives\transaction.cpp" />
112112
<ClCompile Include="..\..\..\..\test\tables\archives\txs.cpp" />
113+
<ClCompile Include="..\..\..\..\test\tables\caches\doubles.cpp" />
113114
<ClCompile Include="..\..\..\..\test\tables\caches\prevout.cpp" />
114115
<ClCompile Include="..\..\..\..\test\tables\caches\validated_bk.cpp" />
115116
<ClCompile Include="..\..\..\..\test\tables\caches\validated_tx.cpp" />

builds/msvc/vs2022/libbitcoin-database-test/libbitcoin-database-test.vcxproj.filters

+3
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@
153153
<ClCompile Include="..\..\..\..\test\tables\archives\txs.cpp">
154154
<Filter>src\tables\archives</Filter>
155155
</ClCompile>
156+
<ClCompile Include="..\..\..\..\test\tables\caches\doubles.cpp">
157+
<Filter>src\tables\caches</Filter>
158+
</ClCompile>
156159
<ClCompile Include="..\..\..\..\test\tables\caches\prevout.cpp">
157160
<Filter>src\tables\caches</Filter>
158161
</ClCompile>

builds/msvc/vs2022/libbitcoin-database/libbitcoin-database.vcxproj

+1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@
133133
<ClInclude Include="..\..\..\..\include\bitcoin\database\tables\archives\point.hpp" />
134134
<ClInclude Include="..\..\..\..\include\bitcoin\database\tables\archives\transaction.hpp" />
135135
<ClInclude Include="..\..\..\..\include\bitcoin\database\tables\archives\txs.hpp" />
136+
<ClInclude Include="..\..\..\..\include\bitcoin\database\tables\caches\doubles.hpp" />
136137
<ClInclude Include="..\..\..\..\include\bitcoin\database\tables\caches\prevout.hpp" />
137138
<ClInclude Include="..\..\..\..\include\bitcoin\database\tables\caches\validated_bk.hpp" />
138139
<ClInclude Include="..\..\..\..\include\bitcoin\database\tables\caches\validated_tx.hpp" />

builds/msvc/vs2022/libbitcoin-database/libbitcoin-database.vcxproj.filters

+3
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,9 @@
242242
<ClInclude Include="..\..\..\..\include\bitcoin\database\tables\archives\txs.hpp">
243243
<Filter>include\bitcoin\database\tables\archives</Filter>
244244
</ClInclude>
245+
<ClInclude Include="..\..\..\..\include\bitcoin\database\tables\caches\doubles.hpp">
246+
<Filter>include\bitcoin\database\tables\caches</Filter>
247+
</ClInclude>
245248
<ClInclude Include="..\..\..\..\include\bitcoin\database\tables\caches\prevout.hpp">
246249
<Filter>include\bitcoin\database\tables\caches</Filter>
247250
</ClInclude>

include/bitcoin/database.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
#include <bitcoin/database/tables/archives/point.hpp>
6565
#include <bitcoin/database/tables/archives/transaction.hpp>
6666
#include <bitcoin/database/tables/archives/txs.hpp>
67+
#include <bitcoin/database/tables/caches/doubles.hpp>
6768
#include <bitcoin/database/tables/caches/prevout.hpp>
6869
#include <bitcoin/database/tables/caches/validated_bk.hpp>
6970
#include <bitcoin/database/tables/caches/validated_tx.hpp>

include/bitcoin/database/settings.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ struct BCD_API settings
9090
uint64_t prevout_size;
9191
uint16_t prevout_rate;
9292

93+
uint32_t doubles_bits;
94+
uint64_t doubles_size;
95+
uint16_t doubles_rate;
96+
9397
uint32_t validated_bk_bits;
9498
uint64_t validated_bk_size;
9599
uint16_t validated_bk_rate;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
* Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS)
3+
*
4+
* This file is part of libbitcoin.
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Affero General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Affero General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Affero General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
#ifndef LIBBITCOIN_DATABASE_TABLES_CACHES_DOUBLES_HPP
20+
#define LIBBITCOIN_DATABASE_TABLES_CACHES_DOUBLES_HPP
21+
22+
#include <utility>
23+
#include <bitcoin/system.hpp>
24+
#include <bitcoin/database/define.hpp>
25+
#include <bitcoin/database/primitives/primitives.hpp>
26+
#include <bitcoin/database/tables/schema.hpp>
27+
28+
namespace libbitcoin {
29+
namespace database {
30+
namespace table {
31+
32+
// TODO: this table isn't actually mapped.
33+
struct doubles
34+
: public hash_map<schema::doubles>
35+
{
36+
using hash_map<schema::doubles>::hashmap;
37+
using ix = linkage<schema::index>;
38+
39+
// This supports only a single record (not too useful).
40+
struct record
41+
: public schema::doubles
42+
{
43+
inline bool from_data(reader& source) NOEXCEPT
44+
{
45+
hash = source.read_hash();
46+
index = source.read_little_endian<ix::integer, ix::size>();
47+
BC_ASSERT(!source || source.get_read_position() == count());
48+
return source;
49+
}
50+
51+
inline bool to_data(finalizer& sink) const NOEXCEPT
52+
{
53+
sink.write_bytes(hash);
54+
sink.write_little_endian<ix::integer, ix::size>(index);
55+
BC_ASSERT(!sink || sink.get_write_position() == count());
56+
return sink;
57+
}
58+
59+
inline bool operator==(const record& other) const NOEXCEPT
60+
{
61+
return hash == other.hash
62+
&& index == other.index;
63+
}
64+
65+
hash_digest hash{};
66+
ix::integer index{};
67+
};
68+
};
69+
70+
} // namespace table
71+
} // namespace database
72+
} // namespace libbitcoin
73+
74+
#endif

include/bitcoin/database/tables/caches/prevout.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
* You should have received a copy of the GNU Affero General Public License
1717
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1818
*/
19-
#ifndef LIBBITCOIN_DATABASE_TABLES_OPTIONALS_BUFFER_HPP
20-
#define LIBBITCOIN_DATABASE_TABLES_OPTIONALS_BUFFER_HPP
19+
#ifndef LIBBITCOIN_DATABASE_TABLES_CACHES_PREVOUT_HPP
20+
#define LIBBITCOIN_DATABASE_TABLES_CACHES_PREVOUT_HPP
2121

2222
#include <utility>
2323
#include <bitcoin/system.hpp>

include/bitcoin/database/tables/schema.hpp

+22
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ namespace schema
6464
namespace caches
6565
{
6666
constexpr auto prevout = "prevout";
67+
constexpr auto duplicate = "duplicate";
6768
constexpr auto validated_bk = "validated_bk";
6869
constexpr auto validated_tx = "validated_tx";
6970
}
@@ -123,6 +124,7 @@ namespace schema
123124
constexpr size_t bk_slab = 3; // ->validated_bk record.
124125
constexpr size_t tx_slab = 5; // ->validated_tk record.
125126
constexpr size_t neutrino_ = 5; // ->neutrino record.
127+
constexpr size_t doubles_ = 4; // doubles bucket (no actual keys).
126128

127129
/// Search keys.
128130
constexpr size_t hash = system::hash_size;
@@ -330,6 +332,26 @@ namespace schema
330332
static_assert(minrow == 6u);
331333
};
332334

335+
// hashmap array
336+
// The hashmap header is a cuckoo filter, which does not link the body.
337+
// The filter data is contained within the buckets. The body is unindexed
338+
// array of duplicated ponts (at least two in the main table). This body
339+
// itself is neither de-deduplicated nor indexed.
340+
struct doubles
341+
{
342+
static constexpr bool align = true;
343+
static constexpr size_t pk = schema::doubles_;
344+
static constexpr size_t sk = schema::point::sk;
345+
static constexpr size_t minsize =
346+
schema::hash +
347+
schema::index;
348+
static constexpr size_t minrow = minsize;
349+
static constexpr size_t size = minsize;
350+
static constexpr linkage<pk> count() NOEXCEPT { return 1; }
351+
static_assert(minsize == 35u);
352+
static_assert(minrow == 35u);
353+
};
354+
333355
// slab hashmap
334356
struct validated_bk
335357
{

src/settings.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ settings::settings() NOEXCEPT
7777
prevout_size{ 1 },
7878
prevout_rate{ 50 },
7979

80+
doubles_bits{ 7 },
81+
doubles_size{ 1 },
82+
doubles_rate{ 50 },
83+
8084
validated_bk_bits{ 7 },
8185
validated_bk_size{ 1 },
8286
validated_bk_rate{ 50 },

test/settings.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ BOOST_AUTO_TEST_CASE(settings__construct__default__expected)
6060
BOOST_REQUIRE_EQUAL(configuration.prevout_buckets, 100u);
6161
BOOST_REQUIRE_EQUAL(configuration.prevout_size, 1u);
6262
BOOST_REQUIRE_EQUAL(configuration.prevout_rate, 50u);
63+
BOOST_REQUIRE_EQUAL(configuration.doubles_bits, 7u);
64+
BOOST_REQUIRE_EQUAL(configuration.doubles_size, 1u);
65+
BOOST_REQUIRE_EQUAL(configuration.doubles_rate, 50u);
6366
BOOST_REQUIRE_EQUAL(configuration.validated_bk_bits, 7u);
6467
BOOST_REQUIRE_EQUAL(configuration.validated_bk_size, 1u);
6568
BOOST_REQUIRE_EQUAL(configuration.validated_bk_rate, 50u);

test/tables/caches/doubles.cpp

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS)
3+
*
4+
* This file is part of libbitcoin.
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Affero General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Affero General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Affero General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
#include "../../test.hpp"
20+
#include "../../mocks/chunk_storage.hpp"
21+
22+
BOOST_AUTO_TEST_SUITE(doubles_tests)
23+
24+
BOOST_AUTO_TEST_CASE(doubles_test)
25+
{
26+
BOOST_REQUIRE(true);
27+
}
28+
29+
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)