Skip to content

Commit

Permalink
Merge pull request #621 from evoskuil/master
Browse files Browse the repository at this point in the history
Make initial log toggles (levels) configurable, style, presentation.
  • Loading branch information
evoskuil committed May 15, 2024
2 parents 073191d + 3778743 commit 40ba740
Show file tree
Hide file tree
Showing 29 changed files with 836 additions and 130 deletions.
2 changes: 2 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ src_libbitcoin_node_la_SOURCES = \
src/chasers/chaser_header.cpp \
src/chasers/chaser_preconfirm.cpp \
src/chasers/chaser_snapshot.cpp \
src/chasers/chaser_storage.cpp \
src/chasers/chaser_template.cpp \
src/chasers/chaser_transaction.cpp \
src/protocols/protocol.cpp \
Expand Down Expand Up @@ -141,6 +142,7 @@ include_bitcoin_node_chasers_HEADERS = \
include/bitcoin/node/chasers/chaser_organize.hpp \
include/bitcoin/node/chasers/chaser_preconfirm.hpp \
include/bitcoin/node/chasers/chaser_snapshot.hpp \
include/bitcoin/node/chasers/chaser_storage.hpp \
include/bitcoin/node/chasers/chaser_template.hpp \
include/bitcoin/node/chasers/chaser_transaction.hpp \
include/bitcoin/node/chasers/chasers.hpp
Expand Down
1 change: 1 addition & 0 deletions builds/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ add_library( ${CANONICAL_LIB_NAME}
"../../src/chasers/chaser_header.cpp"
"../../src/chasers/chaser_preconfirm.cpp"
"../../src/chasers/chaser_snapshot.cpp"
"../../src/chasers/chaser_storage.cpp"
"../../src/chasers/chaser_template.cpp"
"../../src/chasers/chaser_transaction.cpp"
"../../src/protocols/protocol.cpp"
Expand Down
2 changes: 2 additions & 0 deletions builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
<ClCompile Include="..\..\..\..\src\chasers\chaser_header.cpp" />
<ClCompile Include="..\..\..\..\src\chasers\chaser_preconfirm.cpp" />
<ClCompile Include="..\..\..\..\src\chasers\chaser_snapshot.cpp" />
<ClCompile Include="..\..\..\..\src\chasers\chaser_storage.cpp" />
<ClCompile Include="..\..\..\..\src\chasers\chaser_template.cpp" />
<ClCompile Include="..\..\..\..\src\chasers\chaser_transaction.cpp" />
<ClCompile Include="..\..\..\..\src\configuration.cpp" />
Expand Down Expand Up @@ -115,6 +116,7 @@
<ClInclude Include="..\..\..\..\include\bitcoin\node\chasers\chaser_organize.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\chasers\chaser_preconfirm.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\chasers\chaser_snapshot.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\chasers\chaser_storage.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\chasers\chaser_template.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\chasers\chaser_transaction.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\chasers\chasers.hpp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@
<ClCompile Include="..\..\..\..\src\chasers\chaser_snapshot.cpp">
<Filter>src\chasers</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\src\chasers\chaser_storage.cpp">
<Filter>src\chasers</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\src\chasers\chaser_template.cpp">
<Filter>src\chasers</Filter>
</ClCompile>
Expand Down Expand Up @@ -170,6 +173,9 @@
<ClInclude Include="..\..\..\..\include\bitcoin\node\chasers\chaser_snapshot.hpp">
<Filter>include\bitcoin\node\chasers</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\node\chasers\chaser_storage.hpp">
<Filter>include\bitcoin\node\chasers</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\node\chasers\chaser_template.hpp">
<Filter>include\bitcoin\node\chasers</Filter>
</ClInclude>
Expand Down
115 changes: 71 additions & 44 deletions console/executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ const std::unordered_map<uint8_t, std::string> executor::menu_
{
{ menu::backup, "[b]ackup the store" },
{ menu::close, "[c]lose the node" },
{ menu::errors, "display any store [e]rrors" },
{ menu::errors, "[e]rrors in store display" },
{ menu::go, "[g]o network communication" },
{ menu::hold, "[h]old network communication" },
{ menu::info, "display node [i]nformation" },
{ menu::test, "execute built-in [t]est" },
{ menu::work, "display [w]ork distribution" },
{ menu::zeroize, "[z]eroize store disk full error" }
{ menu::info, "[i]nformation display" },
{ menu::test, "[t]est built-in case" },
{ menu::work, "[w]ork distribution display" },
{ menu::zeroize, "[z]eroize disk full error" }
};
const std::unordered_map<std::string, uint8_t> executor::toggles_
{
Expand All @@ -98,21 +98,21 @@ const std::unordered_map<std::string, uint8_t> executor::toggles_
};
const std::unordered_map<uint8_t, std::string> executor::display_
{
{ levels::application, "toggle Application" },
{ levels::news, "toggle News" },
{ levels::session, "toggle Session" },
{ levels::protocol, "toggle Protocol" },
{ levels::proxy, "toggle proXy" },
{ levels::wire, "toggle Wire" }, // unused
{ levels::remote, "toggle Remote" },
{ levels::fault, "toggle Fault" },
{ levels::quit, "toggle Quitting" },
{ levels::objects, "toggle Objects" },
{ levels::verbose, "toggle Verbose" }
{ levels::application, "[a]pplication" },
{ levels::news, "[n]ews" },
{ levels::session, "[s]ession" },
{ levels::protocol, "[p]rotocol" },
{ levels::proxy, "pro[x]y" },
{ levels::wire, "[w]ire" }, // unused
{ levels::remote, "[r]emote" },
{ levels::fault, "[f]ault" },
{ levels::quit, "[q]uitting" },
{ levels::objects, "[o]bjects" },
{ levels::verbose, "[v]erbose" }
};
const std::unordered_map<uint8_t, bool> executor::defined_
{
{ levels::application, true },
{ levels::application, levels::application_defined },
{ levels::news, levels::news_defined },
{ levels::session, levels::session_defined },
{ levels::protocol, levels::protocol_defined },
Expand Down Expand Up @@ -162,7 +162,21 @@ executor::executor(parser& metadata, std::istream& input, std::ostream& output,
store_(metadata.configured.database),
query_(store_),
input_(input),
output_(output)
output_(output),
toggle_
{
metadata.configured.log.application,
metadata.configured.log.news,
metadata.configured.log.session,
metadata.configured.log.protocol,
metadata.configured.log.proxy,
metadata.configured.log.wire,
metadata.configured.log.remote,
metadata.configured.log.fault,
metadata.configured.log.quit,
metadata.configured.log.objects,
metadata.configured.log.verbose
}
{
// Turn of console echoing from std::cin to std:cout.
system::unset_console_echo();
Expand Down Expand Up @@ -2131,7 +2145,7 @@ void executor::do_close()
// [e]rrors
void executor::do_report_condition() const
{
store_.report_errors([&](const auto& ec, auto table)
store_.report_condition([&](const auto& ec, auto table)
{
logger(format(BN_CONDITION) % full_node::store::tables.at(table) %
ec.message());
Expand Down Expand Up @@ -2209,7 +2223,7 @@ void executor::do_reset_store()
return;
}

store_.clear_errors();
query_.reset_full();
logger(BN_NODE_DISK_FULL_RESET);
return;
}
Expand Down Expand Up @@ -2357,6 +2371,33 @@ void executor::subscribe_capture()
return true;
}

if (token == "2")
{
for (const auto& toggle: display_)
logger(format("Toggle: %1%") % toggle.second);

return true;
}

if (toggles_.contains(token))
{
const auto toggle = toggles_.at(token);
if (defined_.at(toggle))
{
toggle_.at(toggle) = !toggle_.at(toggle);
logger(format("CONSOLE: toggle %1% logging (%2%).") %
display_.at(toggle) %
(toggle_.at(toggle) ? "+" : "-"));
}
else
{
logger(format("CONSOLE: %1% logging is not compiled.") %
display_.at(toggle));
}

return true;
}

if (options_.contains(token))
{
switch (options_.at(token))
Expand Down Expand Up @@ -2414,24 +2455,6 @@ void executor::subscribe_capture()
}
}

if (toggles_.contains(token))
{
const auto toggle = toggles_.at(token);
if (defined_.at(toggle))
{
toggle_.at(toggle) = !toggle_.at(toggle);
logger("CONSOLE: " + display_.at(toggle) + (toggle_.at(toggle) ?
" logging (+)." : " logging (-)."));
}
else
{
// Selected log level was not compiled.
logger("CONSOLE: " + display_.at(toggle) + " logging (~).");
}

return true;
}

logger("CONSOLE: '" + line + "'");
return !ec;
},
Expand Down Expand Up @@ -2530,8 +2553,12 @@ bool executor::do_run()
if (check_store_path())
{
auto ec = open_store_coded(true);
if ((ec == database::error::flush_lock) && !restore_store(true))
ec = error::store_integrity;
if (ec == database::error::flush_lock)
{
ec = error::success;
if (!restore_store(true))
ec = error::store_integrity;
}

if (ec)
{
Expand All @@ -2548,8 +2575,8 @@ bool executor::do_run()
dump_body_sizes();
dump_records();
dump_buckets();
logger(BN_MEASURE_PROGRESS_START);
dump_progress();
////logger(BN_MEASURE_PROGRESS_START);
////dump_progress();

// Stopped by stopper.
capture_.start();
Expand Down Expand Up @@ -2578,8 +2605,8 @@ bool executor::do_run()
// Sizes and records change, buckets don't.
dump_body_sizes();
dump_records();
logger(BN_MEASURE_PROGRESS_START);
dump_progress();
////logger(BN_MEASURE_PROGRESS_START);
////dump_progress();

if (!close_store(true))
{
Expand Down
15 changes: 1 addition & 14 deletions console/executor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +158,7 @@ class executor
std::ostream& output_;
network::logger log_{};
network::capture capture_{ input_, close_ };
std_array<std::atomic_bool, add1(network::levels::verbose)> toggle_
{
network::levels::application_defined,
network::levels::news_defined,
network::levels::session_defined,
false, //network::levels::protocol_defined,
false, //network::levels::proxy_defined,
false, //network::levels::wire_defined,
network::levels::remote_defined,
network::levels::fault_defined,
false, // network::levels::quit_defined
false, //network::levels::objects_defined,
false //network::levels::verbose_defined
};
std_array<std::atomic_bool, add1(network::levels::verbose)> toggle_;
};

} // namespace node
Expand Down
1 change: 1 addition & 0 deletions include/bitcoin/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <bitcoin/node/chasers/chaser_organize.hpp>
#include <bitcoin/node/chasers/chaser_preconfirm.hpp>
#include <bitcoin/node/chasers/chaser_snapshot.hpp>
#include <bitcoin/node/chasers/chaser_storage.hpp>
#include <bitcoin/node/chasers/chaser_template.hpp>
#include <bitcoin/node/chasers/chaser_transaction.hpp>
#include <bitcoin/node/chasers/chasers.hpp>
Expand Down
13 changes: 11 additions & 2 deletions include/bitcoin/node/chasers/chaser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,21 @@ class BCN_API chaser
/// Node threadpool is stopped and may still be joining.
virtual bool closed() const NOEXCEPT;

/// Network connections are suspended (incoming and/or outgoing).
virtual bool suspended() const NOEXCEPT;

/// Suspend all existing and future network connections.
/// A race condition could result in an unsuspended connection.
virtual code suspend(const code& ec) const NOEXCEPT;
virtual code suspend_network(const code& ec) NOEXCEPT;

/// Resume all network connections.
virtual void resume_network() NOEXCEPT;

/// Snapshot the store, suspends and resumes network.
code snapshot(const store::event_handler& handler) NOEXCEPT;
virtual code snapshot(const store::event_handler& handler) NOEXCEPT;

/// Reset store disk full condition.
virtual void reset_full() NOEXCEPT;

/// Events.
/// -----------------------------------------------------------------------
Expand Down
7 changes: 3 additions & 4 deletions include/bitcoin/node/chasers/chaser_snapshot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,12 @@ class BCN_API chaser_snapshot
code start() NOEXCEPT override;

protected:
virtual void do_full(height_t height) NOEXCEPT;
virtual void do_confirm(height_t height) NOEXCEPT;
virtual void do_archive(height_t height) NOEXCEPT;
virtual bool handle_event(const code& ec, chase event_,
event_value value) NOEXCEPT;

virtual void do_archive(height_t height) NOEXCEPT;
virtual void do_confirm(height_t height) NOEXCEPT;
virtual void do_full(height_t height) NOEXCEPT;

private:
bool update_bytes() NOEXCEPT;
bool update_valid(height_t height) NOEXCEPT;
Expand Down
59 changes: 59 additions & 0 deletions include/bitcoin/node/chasers/chaser_storage.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* 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_NODE_CHASERS_CHASER_STORAGE_HPP
#define LIBBITCOIN_NODE_CHASERS_CHASER_STORAGE_HPP

#include <bitcoin/network.hpp>
#include <bitcoin/node/chasers/chaser.hpp>
#include <bitcoin/node/define.hpp>

namespace libbitcoin {
namespace node {

class full_node;

/// Monitor storage capacity following a disk full condition.
/// Clear disk full condition and restart network given increased capacity.
class BCN_API chaser_storage
: public chaser
{
public:
DELETE_COPY_MOVE_DESTRUCT(chaser_storage);

chaser_storage(full_node& node) NOEXCEPT;

code start() NOEXCEPT override;

protected:
virtual void do_full(size_t height) NOEXCEPT;
virtual void do_stop(size_t height) NOEXCEPT;
virtual bool handle_event(const code& ec, chase event_,
event_value value) NOEXCEPT;

private:
void handle_timer(const code& ec) NOEXCEPT;
bool is_full() const NOEXCEPT;

network::deadline::ptr disk_timer_{};
};

} // namespace node
} // namespace libbitcoin

#endif
1 change: 1 addition & 0 deletions include/bitcoin/node/chasers/chasers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <bitcoin/node/chasers/chaser_organize.hpp>
#include <bitcoin/node/chasers/chaser_preconfirm.hpp>
#include <bitcoin/node/chasers/chaser_snapshot.hpp>
#include <bitcoin/node/chasers/chaser_storage.hpp>
#include <bitcoin/node/chasers/chaser_template.hpp>
#include <bitcoin/node/chasers/chaser_transaction.hpp>

Expand Down
Loading

0 comments on commit 40ba740

Please sign in to comment.