Use vacancy_updated event
		
	This commit is contained in:
		
					parent
					
						
							
								cd5b6bd91f
							
						
					
				
			
			
				commit
				
					
						d834d93371
					
				
			
		
					 5 changed files with 16 additions and 13 deletions
				
			
		| 
						 | 
				
			
			@ -1308,7 +1308,9 @@ TEST (active_elections, vacancy)
 | 
			
		|||
				.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
 | 
			
		||||
				.work (*system.work.generate (nano::dev::genesis->hash ()))
 | 
			
		||||
				.build ();
 | 
			
		||||
	node.active.vacancy_update = [&updated] () { updated = true; };
 | 
			
		||||
	node.active.vacancy_updated.add ([&updated] () {
 | 
			
		||||
		updated = true;
 | 
			
		||||
	});
 | 
			
		||||
	ASSERT_EQ (nano::block_status::progress, node.process (send));
 | 
			
		||||
	ASSERT_EQ (1, node.active.vacancy (nano::election_behavior::priority));
 | 
			
		||||
	ASSERT_EQ (0, node.active.size ());
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -312,7 +312,7 @@ void nano::active_elections::cleanup_election (nano::unique_lock<nano::mutex> &
 | 
			
		|||
		entry.erased_callback (election);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	vacancy_update ();
 | 
			
		||||
	vacancy_updated.notify ();
 | 
			
		||||
 | 
			
		||||
	for (auto const & [hash, block] : blocks_l)
 | 
			
		||||
	{
 | 
			
		||||
| 
						 | 
				
			
			@ -435,7 +435,7 @@ nano::election_insertion_result nano::active_elections::insert (std::shared_ptr<
 | 
			
		|||
 | 
			
		||||
		node.vote_cache_processor.trigger (hash);
 | 
			
		||||
		node.observers.active_started.notify (hash);
 | 
			
		||||
		vacancy_update ();
 | 
			
		||||
		vacancy_updated.notify ();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Votes are generated for inserted or ongoing elections
 | 
			
		||||
| 
						 | 
				
			
			@ -541,8 +541,7 @@ void nano::active_elections::clear ()
 | 
			
		|||
		nano::lock_guard<nano::mutex> guard{ mutex };
 | 
			
		||||
		roots.clear ();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	vacancy_update ();
 | 
			
		||||
	vacancy_updated.notify ();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
nano::container_info nano::active_elections::container_info () const
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,6 +2,7 @@
 | 
			
		|||
 | 
			
		||||
#include <nano/lib/enum_util.hpp>
 | 
			
		||||
#include <nano/lib/numbers.hpp>
 | 
			
		||||
#include <nano/lib/observer_set.hpp>
 | 
			
		||||
#include <nano/node/election_behavior.hpp>
 | 
			
		||||
#include <nano/node/election_insertion_result.hpp>
 | 
			
		||||
#include <nano/node/election_status.hpp>
 | 
			
		||||
| 
						 | 
				
			
			@ -121,10 +122,12 @@ public:
 | 
			
		|||
	 * How many election slots are available for specified election type
 | 
			
		||||
	 */
 | 
			
		||||
	int64_t vacancy (nano::election_behavior behavior) const;
 | 
			
		||||
	std::function<void ()> vacancy_update{ [] () {} };
 | 
			
		||||
 | 
			
		||||
	nano::container_info container_info () const;
 | 
			
		||||
 | 
			
		||||
public: // Events
 | 
			
		||||
	nano::observer_set<> vacancy_updated;
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
	void request_loop ();
 | 
			
		||||
	void request_confirm (nano::unique_lock<nano::mutex> &);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -187,13 +187,6 @@ nano::node::node (std::shared_ptr<boost::asio::io_context> io_ctx_a, std::filesy
 | 
			
		|||
 | 
			
		||||
	if (!init_error ())
 | 
			
		||||
	{
 | 
			
		||||
		// Notify election schedulers when AEC frees election slot
 | 
			
		||||
		active.vacancy_update = [this] () {
 | 
			
		||||
			scheduler.priority.notify ();
 | 
			
		||||
			scheduler.hinted.notify ();
 | 
			
		||||
			scheduler.optimistic.notify ();
 | 
			
		||||
		};
 | 
			
		||||
 | 
			
		||||
		wallets.observer = [this] (bool active) {
 | 
			
		||||
			observers.wallet.notify (active);
 | 
			
		||||
		};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -15,6 +15,12 @@ nano::scheduler::component::component (nano::node_config & node_config, nano::no
 | 
			
		|||
	optimistic{ *optimistic_impl },
 | 
			
		||||
	priority{ *priority_impl }
 | 
			
		||||
{
 | 
			
		||||
	// Notify election schedulers when AEC frees election slot
 | 
			
		||||
	active.vacancy_updated.add ([this] () {
 | 
			
		||||
		priority.notify ();
 | 
			
		||||
		hinted.notify ();
 | 
			
		||||
		optimistic.notify ();
 | 
			
		||||
	});
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
nano::scheduler::component::~component ()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue