From 71f35f6cda0597628cf2475fca21e7b71eb94d5d Mon Sep 17 00:00:00 2001 From: Bart Wyatt Date: Fri, 13 Jul 2018 17:47:30 -0400 Subject: [PATCH 1/2] remove speculation when stale in the current default mode, a node attempts to act as a good p2p citizen and relay transactions. This requires creating a speculative block. However, in times when a network has steady transactions and the node is stale, this creates a storm of database activity managing our transaction deduplication list as "time" bounces from current for speculation to stale for applying incoming blocks. The new default is to only open a speculative block when the node is in sync. If transactions come in while the node is out of sync they are queued instead of immidiately executed and relayed. The result is a significant speed up when syncing in to a live network with some traffic on it. The old default can be restored by using the new `enable-stale-speculation` config parameter --- plugins/producer_plugin/producer_plugin.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/plugins/producer_plugin/producer_plugin.cpp b/plugins/producer_plugin/producer_plugin.cpp index bab1828acc6..a7084ececeb 100644 --- a/plugins/producer_plugin/producer_plugin.cpp +++ b/plugins/producer_plugin/producer_plugin.cpp @@ -118,6 +118,7 @@ class producer_plugin_impl : public std::enable_shared_from_thisheader.timestamp.next().to_time_point() >= fc::time_point::now() ) + if( chain.head_block_state()->header.timestamp.next().to_time_point() >= fc::time_point::now() ) { _production_enabled = true; + } if( fc::time_point::now() - block->timestamp < fc::minutes(5) || (block->block_num() % 1000 == 0) ) { @@ -301,6 +303,11 @@ class producer_plugin_impl : public std::enable_shared_from_this next) { chain::controller& chain = app().get_plugin().chain(); + if (!chain.pending_block_state()) { + _pending_incoming_transactions.emplace_back(trx, persist_until_expired, next); + return; + } + auto block_time = chain.pending_block_state()->header.timestamp.to_time_point(); auto send_response = [this, &trx, &next](const fc::static_variant& response) { @@ -370,6 +377,7 @@ class producer_plugin_impl : public std::enable_shared_from_thisnotifier([this](bool e){my->_production_enabled = e;}), "Enable block production, even if the chain is stale.") + ("enable-stale-speculation", boost::program_options::bool_switch()->notifier([this](bool e){my->_enable_stale_speculation = e;}), "Enable speculative execution and relay, even if the chain is stale.") ("pause-on-startup,x", boost::program_options::bool_switch()->notifier([this](bool p){my->_pause_production = p;}), "Start this node in a state where production is paused") ("max-transaction-time", bpo::value()->default_value(30), "Limits the maximum time (in milliseconds) that is allowed a pushed transaction's code to execute before being considered invalid") @@ -798,6 +807,10 @@ producer_plugin_impl::start_block_result producer_plugin_impl::start_block(bool } } + if (_pending_block_mode == pending_block_mode::speculating && !(_enable_stale_speculation || _production_enabled)) { + return start_block_result::waiting; + } + try { uint16_t blocks_to_confirm = 0; @@ -975,6 +988,9 @@ void producer_plugin_impl::schedule_production_loop() { self->schedule_production_loop(); } }); + } else if (result == start_block_result::waiting) { + // nothing to do until more blocks arrive + } else if (_pending_block_mode == pending_block_mode::producing) { // we succeeded but block may be exhausted From c96ba3d4b03df60c9be158168a4419b55851f883 Mon Sep 17 00:00:00 2001 From: Bart Wyatt Date: Sat, 14 Jul 2018 13:07:02 -0400 Subject: [PATCH 2/2] =?UTF-8?q?remove=20ability=20to=20restore=20old=20mod?= =?UTF-8?q?e=20of=20operation,=20this=20branch=20name=20is=20now=20mislead?= =?UTF-8?q?ing=20=C2=AF\=5F(=E3=83=84)=5F/=C2=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/producer_plugin/producer_plugin.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/plugins/producer_plugin/producer_plugin.cpp b/plugins/producer_plugin/producer_plugin.cpp index 53f12982c9a..1fa291d47dd 100644 --- a/plugins/producer_plugin/producer_plugin.cpp +++ b/plugins/producer_plugin/producer_plugin.cpp @@ -118,7 +118,6 @@ class producer_plugin_impl : public std::enable_shared_from_thisnotifier([this](bool e){my->_production_enabled = e;}), "Enable block production, even if the chain is stale.") - ("enable-stale-speculation", boost::program_options::bool_switch()->notifier([this](bool e){my->_enable_stale_speculation = e;}), "Enable speculative execution and relay, even if the chain is stale.") ("pause-on-startup,x", boost::program_options::bool_switch()->notifier([this](bool p){my->_pause_production = p;}), "Start this node in a state where production is paused") ("max-transaction-time", bpo::value()->default_value(30), "Limits the maximum time (in milliseconds) that is allowed a pushed transaction's code to execute before being considered invalid") @@ -834,7 +832,7 @@ producer_plugin_impl::start_block_result producer_plugin_impl::start_block(bool } } - if (_pending_block_mode == pending_block_mode::speculating && !(_enable_stale_speculation || _production_enabled)) { + if (_pending_block_mode == pending_block_mode::speculating && !_production_enabled) { return start_block_result::waiting; }