Skip to content

Commit

Permalink
Merge pull request libbitcoin#533 from evoskuil/master
Browse files Browse the repository at this point in the history
Rename prevouts table to prevout, define schema and read/write.
  • Loading branch information
evoskuil authored Jan 8, 2025
2 parents 537f725 + 96cc113 commit 4221eaf
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 257 deletions.
4 changes: 2 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ test_libbitcoin_database_test_SOURCES = \
test/tables/archives/spend.cpp \
test/tables/archives/transaction.cpp \
test/tables/archives/txs.cpp \
test/tables/caches/prevouts.cpp \
test/tables/caches/prevout.cpp \
test/tables/caches/validated_bk.cpp \
test/tables/caches/validated_tx.cpp \
test/tables/indexes/height.cpp \
Expand Down Expand Up @@ -237,7 +237,7 @@ include_bitcoin_database_tables_archives_HEADERS = \

include_bitcoin_database_tables_cachesdir = ${includedir}/bitcoin/database/tables/caches
include_bitcoin_database_tables_caches_HEADERS = \
include/bitcoin/database/tables/caches/prevouts.hpp \
include/bitcoin/database/tables/caches/prevout.hpp \
include/bitcoin/database/tables/caches/validated_bk.hpp \
include/bitcoin/database/tables/caches/validated_tx.hpp

Expand Down
2 changes: 1 addition & 1 deletion builds/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ if (with-tests)
"../../test/tables/archives/spend.cpp"
"../../test/tables/archives/transaction.cpp"
"../../test/tables/archives/txs.cpp"
"../../test/tables/caches/prevouts.cpp"
"../../test/tables/caches/prevout.cpp"
"../../test/tables/caches/validated_bk.cpp"
"../../test/tables/caches/validated_tx.cpp"
"../../test/tables/indexes/height.cpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
<ClCompile Include="..\..\..\..\test\tables\archives\spend.cpp" />
<ClCompile Include="..\..\..\..\test\tables\archives\transaction.cpp" />
<ClCompile Include="..\..\..\..\test\tables\archives\txs.cpp" />
<ClCompile Include="..\..\..\..\test\tables\caches\prevouts.cpp" />
<ClCompile Include="..\..\..\..\test\tables\caches\prevout.cpp" />
<ClCompile Include="..\..\..\..\test\tables\caches\validated_bk.cpp" />
<ClCompile Include="..\..\..\..\test\tables\caches\validated_tx.cpp" />
<ClCompile Include="..\..\..\..\test\tables\indexes\height.cpp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
<ClCompile Include="..\..\..\..\test\tables\archives\txs.cpp">
<Filter>src\tables\archives</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\test\tables\caches\prevouts.cpp">
<ClCompile Include="..\..\..\..\test\tables\caches\prevout.cpp">
<Filter>src\tables\caches</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\test\tables\caches\validated_bk.cpp">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
<ClInclude Include="..\..\..\..\include\bitcoin\database\tables\archives\spend.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\database\tables\archives\transaction.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\database\tables\archives\txs.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\database\tables\caches\prevouts.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\database\tables\caches\prevout.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\database\tables\caches\validated_bk.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\database\tables\caches\validated_tx.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\database\tables\context.hpp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@
<ClInclude Include="..\..\..\..\include\bitcoin\database\tables\archives\txs.hpp">
<Filter>include\bitcoin\database\tables\archives</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\database\tables\caches\prevouts.hpp">
<ClInclude Include="..\..\..\..\include\bitcoin\database\tables\caches\prevout.hpp">
<Filter>include\bitcoin\database\tables\caches</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\database\tables\caches\validated_bk.hpp">
Expand Down
2 changes: 1 addition & 1 deletion include/bitcoin/database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
#include <bitcoin/database/tables/archives/spend.hpp>
#include <bitcoin/database/tables/archives/transaction.hpp>
#include <bitcoin/database/tables/archives/txs.hpp>
#include <bitcoin/database/tables/caches/prevouts.hpp>
#include <bitcoin/database/tables/caches/prevout.hpp>
#include <bitcoin/database/tables/caches/validated_bk.hpp>
#include <bitcoin/database/tables/caches/validated_tx.hpp>
#include <bitcoin/database/tables/indexes/height.hpp>
Expand Down
77 changes: 77 additions & 0 deletions include/bitcoin/database/tables/caches/prevout.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS)
*
* This file is part of libbitcoin.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LIBBITCOIN_DATABASE_TABLES_OPTIONALS_BUFFER_HPP
#define LIBBITCOIN_DATABASE_TABLES_OPTIONALS_BUFFER_HPP

#include <bitcoin/system.hpp>
#include <bitcoin/database/define.hpp>
#include <bitcoin/database/primitives/primitives.hpp>
#include <bitcoin/database/tables/schema.hpp>

namespace libbitcoin {
namespace database {
namespace table {

/// prevout is an array map index of previous outputs by block.
struct prevout
: public array_map<schema::prevout>
{
using tx = linkage<schema::tx>;
using spend = linkage<schema::spend_>;
using array_map<schema::prevout>::arraymap;

struct record
: public schema::prevout
{
inline bool from_data(reader& source) NOEXCEPT
{
coinbase = source.read_byte();
spend_fk = source.read_little_endian<spend::integer, spend::size>();
output_tx_fk = source.read_little_endian<tx::integer, tx::size>();
BC_ASSERT(source.get_read_position() == count());
return source;
}

inline bool to_data(finalizer& sink) const NOEXCEPT
{
sink.write_byte(coinbase);
sink.write_little_endian<spend::integer, spend::size>(spend_fk);
sink.write_little_endian<tx::integer, tx::size>(output_tx_fk);
BC_ASSERT(sink.get_write_position() == count());
return sink;
}

inline bool operator==(const record& other) const NOEXCEPT
{
return coinbase == other.coinbase
&& spend_fk == other.spend_fk
&& output_tx_fk == other.output_tx_fk;
}

bool coinbase{};
spend::integer spend_fk{};
tx::integer output_tx_fk{};
};
};

} // namespace table
} // namespace database
} // namespace libbitcoin

#endif
117 changes: 0 additions & 117 deletions include/bitcoin/database/tables/caches/prevouts.hpp

This file was deleted.

18 changes: 17 additions & 1 deletion include/bitcoin/database/tables/schema.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ namespace schema

namespace caches
{
constexpr auto prevout = "prevout";
constexpr auto validated_bk = "validated_bk";
constexpr auto validated_tx = "validated_tx";
}
Expand Down Expand Up @@ -120,7 +121,6 @@ namespace schema
constexpr size_t bk_slab = 3; // ->validated_bk record.
constexpr size_t tx_slab = 5; // ->validated_tk record.
constexpr size_t neutrino_ = 5; // ->neutrino record.
////constexpr size_t buffer_ = 5; // ->buffer record (guestimate).

/// Search keys.
constexpr size_t hash = system::hash_size;
Expand Down Expand Up @@ -355,6 +355,22 @@ namespace schema
static_assert(minrow == 23u);
};

// record arraymap
struct prevout
{
static constexpr size_t pk = schema::spend_;
static constexpr size_t sk = zero;
static constexpr size_t minsize =
schema::bit + // TODO: merge bit.
schema::spend_ +
schema::tx;
static constexpr size_t minrow = minsize;
static constexpr size_t size = minsize;
static constexpr linkage<pk> count() NOEXCEPT { return 1; }
static_assert(minsize == 9u);
static_assert(minrow == 9u);
};

// slab hashmap
struct neutrino
{
Expand Down
26 changes: 26 additions & 0 deletions test/tables/caches/prevout.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS)
*
* This file is part of libbitcoin.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "../../test.hpp"
#include "../../mocks/chunk_storage.hpp"

BOOST_AUTO_TEST_SUITE(prevout_tests)

using namespace system;

BOOST_AUTO_TEST_SUITE_END()
Loading

0 comments on commit 4221eaf

Please sign in to comment.