Request confirmation faster for new blocks (#1518)
* Broadcast new blocks & request confirmation faster * Limit max broadcast_confirm_req * Minimum broadcast of 2 * sqrt or 100 peers * Disable fast broadcast with large broadcast queue * Use std:chrono for confirmation_request_delay * Formatting * Formatting * Braced initialization test * Clang formatting * Move fast broadcast to block_processor::process_receive_one * Remove extra checks * static_cast<size_t> * Fix * FIx merge * Add missing declaration * Check if votes were already requested
This commit is contained in:
		
					parent
					
						
							
								5522a04e3b
							
						
					
				
			
			
				commit
				
					
						37d9720136
					
				
			
		
					 3 changed files with 28 additions and 2 deletions
				
			
		| 
						 | 
				
			
			@ -4,6 +4,8 @@
 | 
			
		|||
#include <nano/node/node.hpp>
 | 
			
		||||
#include <nano/secure/blockstore.hpp>
 | 
			
		||||
 | 
			
		||||
std::chrono::milliseconds constexpr nano::block_processor::confirmation_request_delay;
 | 
			
		||||
 | 
			
		||||
nano::block_processor::block_processor (nano::node & node_a) :
 | 
			
		||||
generator (node_a, nano::is_test_network ? std::chrono::milliseconds (10) : std::chrono::milliseconds (500)),
 | 
			
		||||
stopped (false),
 | 
			
		||||
| 
						 | 
				
			
			@ -349,6 +351,28 @@ void nano::block_processor::process_live (nano::block_hash const & hash_a, std::
 | 
			
		|||
		// Announce our weighted vote to the network
 | 
			
		||||
		generator.add (hash_a);
 | 
			
		||||
	}
 | 
			
		||||
	// Request confirmation for new block with delay
 | 
			
		||||
	std::weak_ptr<nano::node> node_w (node.shared ());
 | 
			
		||||
	node.alarm.add (std::chrono::steady_clock::now () + confirmation_request_delay, [node_w, block_a]() {
 | 
			
		||||
		if (auto node_l = node_w.lock ())
 | 
			
		||||
		{
 | 
			
		||||
			// Check if votes were already requested
 | 
			
		||||
			bool send_request (false);
 | 
			
		||||
			{
 | 
			
		||||
				std::lock_guard<std::mutex> lock (node_l->active.mutex);
 | 
			
		||||
				auto existing (node_l->active.blocks.find (block_a->hash ()));
 | 
			
		||||
				if (existing != node_l->active.blocks.end () && !existing->second->confirmed && !existing->second->stopped && existing->second->announcements == 0)
 | 
			
		||||
				{
 | 
			
		||||
					send_request = true;
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
			// Request votes
 | 
			
		||||
			if (send_request)
 | 
			
		||||
			{
 | 
			
		||||
				node_l->network.broadcast_confirm_req (block_a);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	});
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
nano::process_return nano::block_processor::process_one (nano::transaction const & transaction_a, nano::unchecked_info info_a)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -44,6 +44,8 @@ public:
 | 
			
		|||
	nano::process_return process_one (nano::transaction const &, nano::unchecked_info);
 | 
			
		||||
	nano::process_return process_one (nano::transaction const &, std::shared_ptr<nano::block>);
 | 
			
		||||
	nano::vote_generator generator;
 | 
			
		||||
	// Delay required for average network propagartion before requesting confirmation
 | 
			
		||||
	static std::chrono::milliseconds constexpr confirmation_request_delay{ 1500 };
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
	void queue_unchecked (nano::transaction const &, nano::block_hash const &);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -422,8 +422,8 @@ void nano::network::broadcast_confirm_req (std::shared_ptr<nano::block> block_a)
 | 
			
		|||
	auto list (std::make_shared<std::vector<nano::peer_information>> (node.peers.representatives (std::numeric_limits<size_t>::max ())));
 | 
			
		||||
	if (list->empty () || node.peers.total_weight () < node.config.online_weight_minimum.number ())
 | 
			
		||||
	{
 | 
			
		||||
		// broadcast request to all peers
 | 
			
		||||
		list = std::make_shared<std::vector<nano::peer_information>> (node.peers.list_vector (100));
 | 
			
		||||
		// broadcast request to all peers (with max limit 2 * sqrt (peers count))
 | 
			
		||||
		list = std::make_shared<std::vector<nano::peer_information>> (node.peers.list_vector (std::min (static_cast<size_t> (100), 2 * node.peers.size_sqrt ())));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/*
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue