Skip to content

Commit

Permalink
Merge pull request #397 from evoskuil/master
Browse files Browse the repository at this point in the history
Restore redundant object guards, use system streamer aliases.
  • Loading branch information
evoskuil committed Feb 12, 2024
2 parents 5a61827 + c11e4b9 commit 9f5e60c
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 124 deletions.
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ include_bitcoin_database_memory_HEADERS = \
include/bitcoin/database/memory/reader.hpp \
include/bitcoin/database/memory/simple_reader.hpp \
include/bitcoin/database/memory/simple_writer.hpp \
include/bitcoin/database/memory/writer.hpp
include/bitcoin/database/memory/streamers.hpp

include_bitcoin_database_memory_interfacesdir = ${includedir}/bitcoin/database/memory/interfaces
include_bitcoin_database_memory_interfaces_HEADERS = \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
<ClInclude Include="..\..\..\..\include\bitcoin\database\memory\reader.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\database\memory\simple_reader.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\database\memory\simple_writer.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\database\memory\writer.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\database\memory\streamers.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\database\primitives\arraymap.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\database\primitives\hashmap.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\database\primitives\head.hpp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
<ClInclude Include="..\..\..\..\include\bitcoin\database\memory\simple_writer.hpp">
<Filter>include\bitcoin\database\memory</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\database\memory\writer.hpp">
<ClInclude Include="..\..\..\..\include\bitcoin\database\memory\streamers.hpp">
<Filter>include\bitcoin\database\memory</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\database\primitives\arraymap.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 @@ -36,7 +36,7 @@
#include <bitcoin/database/memory/reader.hpp>
#include <bitcoin/database/memory/simple_reader.hpp>
#include <bitcoin/database/memory/simple_writer.hpp>
#include <bitcoin/database/memory/writer.hpp>
#include <bitcoin/database/memory/streamers.hpp>
#include <bitcoin/database/memory/interfaces/memory.hpp>
#include <bitcoin/database/memory/interfaces/storage.hpp>
#include <bitcoin/database/primitives/arraymap.hpp>
Expand Down
23 changes: 13 additions & 10 deletions include/bitcoin/database/impl/query/archive.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,10 @@ tx_link CLASS::set_link(const transaction& tx) NOEXCEPT
const auto key = tx.hash(false);

// GUARD (tx redundancy)
////auto tx_fk = to_tx(key);
////if (!tx_fk.is_terminal())
//// return tx_fk;
// This guard is only effective if there is a single database thread.
auto tx_fk = to_tx(key);
if (!tx_fk.is_terminal())
return tx_fk;

// Declare puts record.
const auto& ins = *tx.inputs_ptr();
Expand All @@ -514,7 +515,7 @@ tx_link CLASS::set_link(const transaction& tx) NOEXCEPT
const auto scope = store_.get_transactor();

// Allocate tx record.
const auto tx_fk = store_.tx.allocate(1);
tx_fk = store_.tx.allocate(1);
if (tx_fk.is_terminal())
return {};

Expand Down Expand Up @@ -659,9 +660,10 @@ header_link CLASS::set_link(const header& header, const context& ctx) NOEXCEPT
const auto key = header.hash();

// GUARD (header redundancy)
////auto header_fk = to_header(key);
////if (!header_fk.is_terminal())
//// return header_fk;
// This guard is only effective if there is a single database thread.
auto header_fk = to_header(key);
if (!header_fk.is_terminal())
return header_fk;

// Parent must be missing iff its hash is null.
const auto& parent_sk = header.previous_block_hash();
Expand Down Expand Up @@ -689,9 +691,10 @@ header_link CLASS::set_link(const block& block, const context& ctx) NOEXCEPT
if (header_fk.is_terminal())
return {};

// GUARDED (txs redundancy)
////if (is_associated(header_fk))
//// return header_fk;
// GUARDED (block (txs) redundancy)
// This guard is only effective if there is a single database thread.
if (is_associated(header_fk))
return header_fk;

tx_links links{};
links.reserve(block.transactions_ptr()->size());
Expand Down
5 changes: 2 additions & 3 deletions include/bitcoin/database/memory/finalizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <utility>
#include <bitcoin/system.hpp>
#include <bitcoin/database/define.hpp>
#include <bitcoin/database/memory/writer.hpp>

namespace libbitcoin {
namespace database {
Expand All @@ -33,7 +32,7 @@ namespace database {
BC_PUSH_WARNING(DIAMOND_INHERITANCE)

/// A byte flipper with finalization extentions, that accepts an iostream.
template <typename IOStream = std::iostream>
template <typename IOStream = system::stream::flip::fast>
class finalizer_
: public system::byte_flipper<IOStream>
{
Expand Down Expand Up @@ -69,7 +68,7 @@ class finalizer_
};

/// A finalizing byte reader/writer that copies data from/to a memory_ptr.
using finalizer = finalizer_<system::iostream<>>;
using finalizer = finalizer_<>;

BC_POP_WARNING()

Expand Down
3 changes: 1 addition & 2 deletions include/bitcoin/database/memory/memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <bitcoin/database/memory/interfaces/memory.hpp>
#include <bitcoin/database/memory/interfaces/storage.hpp>
#include <bitcoin/database/memory/map.hpp>
#include <bitcoin/database/memory/reader.hpp>
#include <bitcoin/database/memory/writer.hpp>
#include <bitcoin/database/memory/streamers.hpp>

#endif
35 changes: 1 addition & 34 deletions include/bitcoin/database/memory/reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,40 +26,7 @@
namespace libbitcoin {
namespace database {

/////// Source for ios::stream, copies bytes from memory_ptr.
////class map_source
//// : public system::device<memory>
////{
////public:
//// typedef system::device<memory> base;
//// typedef const memory_ptr& container;
//// struct category
//// : system::ios::input_seekable, system::ios::direct_tag
//// {
//// };
////
//// map_source(const memory_ptr& data) NOEXCEPT
//// : base(system::limit<typename base::size_type>(data->size())),
//// container_(data),
//// next_(data->begin())
//// {
//// }
////
////protected:
//// typename base::sequence do_sequence() const NOEXCEPT override
//// {
//// using char_type = typename base::char_type;
//// return std::make_pair(
//// system::pointer_cast<char_type>(container_->begin()),
//// system::pointer_cast<char_type>(container_->end()));
//// }
////
////private:
//// const memory::ptr container_;
//// typename memory::const_iterator next_;
////};

/// A byte reader that copies data from a memory_ptr.
/// A byte reader that copies data.
using reader = system::byte_reader<system::iostream<>>;

} // namespace database
Expand Down
38 changes: 38 additions & 0 deletions include/bitcoin/database/memory/streamers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Copyright (c) 2011-2023 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_MEMORY_STREAMERS_HPP
#define LIBBITCOIN_DATABASE_MEMORY_STREAMERS_HPP

#include <bitcoin/system.hpp>
#include <bitcoin/database/define.hpp>
#include <bitcoin/database/memory/interfaces/memory.hpp>

namespace libbitcoin {
namespace database {

/// These all operate over a system::iostream.

using reader = system::byte_reader<system::iostream<>>;
using writer = system::byte_writer<system::iostream<>>;
using flipper = system::byte_flipper<system::iostream<>>;

} // namespace database
} // namespace libbitcoin

#endif
71 changes: 0 additions & 71 deletions include/bitcoin/database/memory/writer.hpp

This file was deleted.

0 comments on commit 9f5e60c

Please sign in to comment.