Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SHiP: Auto disable-replay-opts instead of exiting with error #1467

Merged
merged 8 commits into from
Jul 31, 2023
3 changes: 1 addition & 2 deletions docs/01_nodeos/02_usage/01_nodeos-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ nodeos \
--plugin eosio::http_plugin \
--plugin eosio::state_history_plugin \
--contracts-console \
--disable-replay-opts \
--access-control-allow-origin='*' \
--http-validate-host=false \
--verbose-http-errors \
Expand All @@ -46,7 +45,7 @@ The above `nodeos` command starts a producing node by:
* setting the blockchain data directory (`--data-dir`)
* setting the `config.ini` directory (`--config-dir`)
* loading plugins `producer_plugin`, `chain_plugin`, `http_plugin`, `state_history_plugin` (`--plugin`)
* passing `chain_plugin` options (`--contracts-console`, `--disable-replay-opts`)
* passing `chain_plugin` options (`--contracts-console`)
* passing `http-plugin` options (`--access-control-allow-origin`, `--http-validate-host`, `--verbose-http-errors`)
* passing `state_history` options (`--state-history-dir`, `--trace-history`, `--chain-state-history`)
* redirecting both `stdout` and `stderr` to the `nodeos.log` file
Expand Down
17 changes: 0 additions & 17 deletions docs/01_nodeos/03_plugins/state_history_plugin/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,6 @@ Config Options for eosio::state_history_plugin:
number of most recent blocks
```

## Examples

## Dependencies

* [`chain_plugin`](../chain_plugin/index.md)

### Load Dependency Examples

```console
# config.ini
plugin = eosio::chain_plugin --disable-replay-opts
```
```sh
# command-line
nodeos ... --plugin eosio::chain_plugin --disable-replay-opts
```

## How-To Guides

* [How to fast start without history on existing chains](10_how-to-fast-start-without-old-history.md)
Expand Down
4 changes: 4 additions & 0 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3050,6 +3050,10 @@ void controller::set_key_blacklist( const flat_set<public_key_type>& new_key_bla
my->conf.key_blacklist = new_key_blacklist;
}

void controller::set_disable_replay_opts( bool v ) {
my->conf.disable_replay_opts = v;
}

uint32_t controller::head_block_num()const {
return my->head->block_num;
}
Expand Down
2 changes: 2 additions & 0 deletions libraries/chain/include/eosio/chain/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ namespace eosio { namespace chain {
void set_action_blacklist( const flat_set< pair<account_name, action_name> >& );
void set_key_blacklist( const flat_set<public_key_type>& );

void set_disable_replay_opts( bool v );

uint32_t head_block_num()const;
time_point head_block_time()const;
block_id_type head_block_id()const;
Expand Down
246 changes: 118 additions & 128 deletions libraries/state_history/include/eosio/state_history/serialization.hpp

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct trace_converter {
std::optional<augmented_transaction_trace> onblock_trace;

void add_transaction(const transaction_trace_ptr& trace, const chain::packed_transaction_ptr& transaction);
void pack(boost::iostreams::filtering_ostreambuf& ds, const chainbase::database& db, bool trace_debug_mode, const block_state_ptr& block_state);
void pack(boost::iostreams::filtering_ostreambuf& ds, bool trace_debug_mode, const block_state_ptr& block_state);
};

} // namespace state_history
Expand Down
4 changes: 2 additions & 2 deletions libraries/state_history/trace_converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void trace_converter::add_transaction(const transaction_trace_ptr& trace, const
}
}

void trace_converter::pack(boost::iostreams::filtering_ostreambuf& obuf, const chainbase::database& db, bool trace_debug_mode, const block_state_ptr& block_state) {
void trace_converter::pack(boost::iostreams::filtering_ostreambuf& obuf, bool trace_debug_mode, const block_state_ptr& block_state) {
std::vector<augmented_transaction_trace> traces;
if (onblock_trace)
traces.push_back(*onblock_trace);
Expand All @@ -34,7 +34,7 @@ void trace_converter::pack(boost::iostreams::filtering_ostreambuf& obuf, const c
onblock_trace.reset();

fc::datastream<boost::iostreams::filtering_ostreambuf&> ds{obuf};
return fc::raw::pack(ds, make_history_context_wrapper(db, trace_debug_mode, traces));
return fc::raw::pack(ds, make_history_context_wrapper(trace_debug_mode, traces));
}

} // namespace state_history
Expand Down
4 changes: 2 additions & 2 deletions plugins/chain_plugin/chain_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,8 @@ void chain_plugin::set_program_options(options_description& cli, options_descrip
"Duration (in seconds) a successful transaction's Finality Status will remain available from being first identified.")
("transaction-finality-status-failure-duration-sec", bpo::value<uint64_t>()->default_value(config::default_max_transaction_finality_status_failure_duration_sec),
"Duration (in seconds) a failed transaction's Finality Status will remain available from being first identified.")
("disable-replay-opts", bpo::bool_switch()->default_value(false),
linh2931 marked this conversation as resolved.
Show resolved Hide resolved
"disable optimizations that specifically target replay")
("integrity-hash-on-start", bpo::bool_switch(), "Log the state integrity hash on startup")
("integrity-hash-on-stop", bpo::bool_switch(), "Log the state integrity hash on shutdown");

Expand All @@ -403,8 +405,6 @@ void chain_plugin::set_program_options(options_description& cli, options_descrip
"extract build environment information as JSON, write into specified file, and exit")
("force-all-checks", bpo::bool_switch()->default_value(false),
"do not skip any validation checks while replaying blocks (useful for replaying blocks from untrusted source)")
("disable-replay-opts", bpo::bool_switch()->default_value(false),
greg7mdp marked this conversation as resolved.
Show resolved Hide resolved
"disable optimizations that specifically target replay")
("replay-blockchain", bpo::bool_switch()->default_value(false),
"clear chain state database and replay all blocks")
("hard-replay-blockchain", bpo::bool_switch()->default_value(false),
Expand Down
11 changes: 7 additions & 4 deletions plugins/state_history_plugin/state_history_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ struct state_history_plugin_impl : std::enable_shared_from_this<state_history_pl
.block_id = block_state->id,
.payload_size = 0};
trace_log->pack_and_write_entry(header, block_state->block->previous, [this, &block_state](auto&& buf) {
trace_converter.pack(buf, chain_plug->chain().db(), trace_debug_mode, block_state);
trace_converter.pack(buf, trace_debug_mode, block_state);
});
}

Expand Down Expand Up @@ -314,12 +314,15 @@ void state_history_plugin::set_program_options(options_description& cli, options

void state_history_plugin_impl::plugin_initialize(const variables_map& options) {
try {
EOS_ASSERT(options.at("disable-replay-opts").as<bool>(), plugin_exception,
"state_history_plugin requires --disable-replay-opts");

chain_plug = app().find_plugin<chain_plugin>();
EOS_ASSERT(chain_plug, chain::missing_chain_plugin_exception, "");
auto& chain = chain_plug->chain();

if (!options.at("disable-replay-opts").as<bool>() && options.at("chain-state-history").as<bool>()) {
greg7mdp marked this conversation as resolved.
Show resolved Hide resolved
ilog("Setting disable-replay-opts=true required by state_history_plugin chain-state-history=true option");
chain.set_disable_replay_opts(true);
}

applied_transaction_connection.emplace(chain.applied_transaction.connect(
[&](std::tuple<const transaction_trace_ptr&, const packed_transaction_ptr&> t) {
on_applied_transaction(std::get<0>(t), std::get<1>(t));
Expand Down
4 changes: 2 additions & 2 deletions plugins/state_history_plugin/tests/plugin_config_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ BOOST_AUTO_TEST_CASE(state_history_plugin_default_tests) {

auto tmp_path = tmp.path().string();
std::array args = {"test_state_history", "--trace-history", "--state-history-stride", "10",
"--disable-replay-opts", "--data-dir", tmp_path.c_str()};
"--data-dir", tmp_path.c_str()};

BOOST_CHECK(app->initialize<eosio::state_history_plugin>(args.size(), const_cast<char**>(args.data())));
auto& plugin = app->get_plugin<eosio::state_history_plugin>();
Expand All @@ -28,7 +28,7 @@ BOOST_AUTO_TEST_CASE(state_history_plugin_retain_blocks_tests) {

auto tmp_path = tmp.path().string();
std::array args = {"test_state_history", "--trace-history", "--state-history-log-retain-blocks", "4242",
"--disable-replay-opts", "--data-dir", tmp_path.c_str()};
"--data-dir", tmp_path.c_str()};

BOOST_CHECK(app->initialize<eosio::state_history_plugin>(args.size(), const_cast<char**>(args.data())));
auto& plugin = app->get_plugin<eosio::state_history_plugin>();
Expand Down
2 changes: 1 addition & 1 deletion tests/nodeos_forked_chain_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def getMinHeadAndLib(prodNodes):
Print("Stand up cluster")
specificExtraNodeosArgs={}
shipNodeNum = 0
specificExtraNodeosArgs[shipNodeNum]="--plugin eosio::state_history_plugin --disable-replay-opts"
specificExtraNodeosArgs[shipNodeNum]="--plugin eosio::state_history_plugin"

# producer nodes will be mapped to 0 through totalProducerNodes-1, so the number totalProducerNodes will be the non-producing node
specificExtraNodeosArgs[totalProducerNodes]="--plugin eosio::test_control_api_plugin"
Expand Down
4 changes: 2 additions & 2 deletions tests/resource_monitor_plugin_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ def testAll():
testCommon("Resmon not enabled: no arguments", "", ["interval set to 2", "threshold set to 90", "Shutdown flag when threshold exceeded set to true", "Creating and starting monitor thread", "snapshots's file system to be monitored", "blocks's file system to be monitored", "state's file system to be monitored"])

# default arguments with registered directories
testCommon("Resmon not enabled: Producer, Chain, State History and Trace Api", "--plugin eosio::state_history_plugin --state-history-dir=/tmp/state-history --disable-replay-opts --plugin eosio::trace_api_plugin --trace-dir=/tmp/trace --trace-no-abis", ["interval set to 2", "threshold set to 90", "Shutdown flag when threshold exceeded set to true", "snapshots's file system to be monitored", "blocks's file system to be monitored", "state's file system to be monitored", "state-history's file system to be monitored", "trace's file system to be monitored", "Creating and starting monitor thread"])
testCommon("Resmon not enabled: Producer, Chain, State History and Trace Api", "--plugin eosio::state_history_plugin --state-history-dir=/tmp/state-history --plugin eosio::trace_api_plugin --trace-dir=/tmp/trace --trace-no-abis", ["interval set to 2", "threshold set to 90", "Shutdown flag when threshold exceeded set to true", "snapshots's file system to be monitored", "blocks's file system to be monitored", "state's file system to be monitored", "state-history's file system to be monitored", "trace's file system to be monitored", "Creating and starting monitor thread"])

testCommon("Resmon enabled: Producer, Chain, State History and Trace Api", "--plugin eosio::resource_monitor_plugin --plugin eosio::state_history_plugin --state-history-dir=/tmp/state-history --disable-replay-opts --plugin eosio::trace_api_plugin --trace-dir=/tmp/trace --trace-no-abis --resource-monitor-space-threshold=80 --resource-monitor-interval-seconds=3", ["snapshots's file system to be monitored", "blocks's file system to be monitored", "state's file system to be monitored", "state-history's file system to be monitored", "trace's file system to be monitored", "Creating and starting monitor thread", "threshold set to 80", "interval set to 3", "Shutdown flag when threshold exceeded set to true"])
testCommon("Resmon enabled: Producer, Chain, State History and Trace Api", "--plugin eosio::resource_monitor_plugin --plugin eosio::state_history_plugin --state-history-dir=/tmp/state-history --plugin eosio::trace_api_plugin --trace-dir=/tmp/trace --trace-no-abis --resource-monitor-space-threshold=80 --resource-monitor-interval-seconds=3", ["snapshots's file system to be monitored", "blocks's file system to be monitored", "state's file system to be monitored", "state-history's file system to be monitored", "trace's file system to be monitored", "Creating and starting monitor thread", "threshold set to 80", "interval set to 3", "Shutdown flag when threshold exceeded set to true"])

# Only test minimum warning threshold (i.e. 6) to trigger warning as much as possible
testInterval("Resmon enabled: set warning interval",
Expand Down
2 changes: 1 addition & 1 deletion tests/ship_streamer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def getLatestSnapshot(nodeId):

shipNodeNum = 1
specificExtraNodeosArgs={}
specificExtraNodeosArgs[shipNodeNum]="--plugin eosio::state_history_plugin --disable-replay-opts --trace-history --chain-state-history --plugin eosio::net_api_plugin --plugin eosio::producer_api_plugin "
specificExtraNodeosArgs[shipNodeNum]="--plugin eosio::state_history_plugin --trace-history --chain-state-history --plugin eosio::net_api_plugin --plugin eosio::producer_api_plugin "
# producer nodes will be mapped to 0 through totalProducerNodes-1, so the number totalProducerNodes will be the non-producing node
specificExtraNodeosArgs[totalProducerNodes]="--plugin eosio::test_control_api_plugin "

Expand Down
2 changes: 1 addition & 1 deletion tests/ship_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
specificExtraNodeosArgs={}
# non-producing nodes are at the end of the cluster's nodes, so reserving the last one for state_history_plugin
shipNodeNum = totalNodes - 1
specificExtraNodeosArgs[shipNodeNum]="--plugin eosio::state_history_plugin --disable-replay-opts --sync-fetch-span 200 --plugin eosio::net_api_plugin "
specificExtraNodeosArgs[shipNodeNum]="--plugin eosio::state_history_plugin --sync-fetch-span 200 --plugin eosio::net_api_plugin "

if args.unix_socket:
specificExtraNodeosArgs[shipNodeNum] += "--state-history-unix-socket-path ship.sock"
Expand Down
4 changes: 2 additions & 2 deletions unittests/state_history_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,8 +624,8 @@ struct state_history_tester : state_history_tester_logs, tester {
.block_id = block_state->id,
.payload_size = 0};

traces_log.pack_and_write_entry(header, block_state->block->previous, [this, &control, &block_state](auto&& buf) {
trace_converter.pack(buf, control.db(), false, block_state);
traces_log.pack_and_write_entry(header, block_state->block->previous, [this, &block_state](auto&& buf) {
trace_converter.pack(buf, false, block_state);
});

chain_state_log.pack_and_write_entry(header, block_state->header.previous, [&control](auto&& buf) {
Expand Down