Encapsulating vote::timestamp field as vote::timestamp_m behind vote::timestamp ().
This commit is contained in:
		
					parent
					
						
							
								fb8e912dfc
							
						
					
				
			
			
				commit
				
					
						f58fbe42a1
					
				
			
		
					 7 changed files with 32 additions and 24 deletions
				
			
		| 
						 | 
				
			
			@ -203,7 +203,7 @@ TEST (vote_processor, no_broadcast_local)
 | 
			
		|||
	auto votes (election->votes ());
 | 
			
		||||
	auto existing (votes.find (nano::dev::genesis_key.pub));
 | 
			
		||||
	ASSERT_NE (votes.end (), existing);
 | 
			
		||||
	ASSERT_EQ (vote->timestamp, existing->second.timestamp);
 | 
			
		||||
	ASSERT_EQ (vote->timestamp (), existing->second.timestamp);
 | 
			
		||||
	// Ensure the vote, from a local representative, was not broadcast on processing - it should be flooded on generation instead
 | 
			
		||||
	ASSERT_EQ (0, node.stats.count (nano::stat::type::message, nano::stat::detail::confirm_ack, nano::stat::dir::out));
 | 
			
		||||
	ASSERT_EQ (1, node.stats.count (nano::stat::type::message, nano::stat::detail::publish, nano::stat::dir::out));
 | 
			
		||||
| 
						 | 
				
			
			@ -236,7 +236,7 @@ TEST (vote_processor, no_broadcast_local)
 | 
			
		|||
	auto votes2 (election2->votes ());
 | 
			
		||||
	auto existing2 (votes2.find (nano::dev::genesis_key.pub));
 | 
			
		||||
	ASSERT_NE (votes2.end (), existing2);
 | 
			
		||||
	ASSERT_EQ (vote2->timestamp, existing2->second.timestamp);
 | 
			
		||||
	ASSERT_EQ (vote2->timestamp (), existing2->second.timestamp);
 | 
			
		||||
	// Ensure the vote was broadcast
 | 
			
		||||
	ASSERT_EQ (1, node.stats.count (nano::stat::type::message, nano::stat::detail::confirm_ack, nano::stat::dir::out));
 | 
			
		||||
	ASSERT_EQ (2, node.stats.count (nano::stat::type::message, nano::stat::detail::publish, nano::stat::dir::out));
 | 
			
		||||
| 
						 | 
				
			
			@ -270,7 +270,7 @@ TEST (vote_processor, no_broadcast_local)
 | 
			
		|||
	auto votes3 (election3->votes ());
 | 
			
		||||
	auto existing3 (votes3.find (nano::dev::genesis_key.pub));
 | 
			
		||||
	ASSERT_NE (votes3.end (), existing3);
 | 
			
		||||
	ASSERT_EQ (vote3->timestamp, existing3->second.timestamp);
 | 
			
		||||
	ASSERT_EQ (vote3->timestamp (), existing3->second.timestamp);
 | 
			
		||||
	// Ensure the vote wass not broadcasst
 | 
			
		||||
	ASSERT_EQ (1, node.stats.count (nano::stat::type::message, nano::stat::detail::confirm_ack, nano::stat::dir::out));
 | 
			
		||||
	ASSERT_EQ (3, node.stats.count (nano::stat::type::message, nano::stat::detail::publish, nano::stat::dir::out));
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -875,7 +875,7 @@ nano::vote_code nano::active_transactions::vote (std::shared_ptr<nano::vote> con
 | 
			
		|||
				}
 | 
			
		||||
				else if (recently_confirmed_by_hash.count (block_hash) == 0)
 | 
			
		||||
				{
 | 
			
		||||
					add_inactive_votes_cache (lock, block_hash, vote_a->account, vote_a->timestamp);
 | 
			
		||||
					add_inactive_votes_cache (lock, block_hash, vote_a->account, vote_a->timestamp ());
 | 
			
		||||
				}
 | 
			
		||||
				else
 | 
			
		||||
				{
 | 
			
		||||
| 
						 | 
				
			
			@ -892,7 +892,7 @@ nano::vote_code nano::active_transactions::vote (std::shared_ptr<nano::vote> con
 | 
			
		|||
				}
 | 
			
		||||
				else if (recently_confirmed_by_hash.count (block->hash ()) == 0)
 | 
			
		||||
				{
 | 
			
		||||
					add_inactive_votes_cache (lock, block->hash (), vote_a->account, vote_a->timestamp);
 | 
			
		||||
					add_inactive_votes_cache (lock, block->hash (), vote_a->account, vote_a->timestamp ());
 | 
			
		||||
				}
 | 
			
		||||
				else
 | 
			
		||||
				{
 | 
			
		||||
| 
						 | 
				
			
			@ -908,7 +908,7 @@ nano::vote_code nano::active_transactions::vote (std::shared_ptr<nano::vote> con
 | 
			
		|||
		bool processed (false);
 | 
			
		||||
		for (auto const & [election, block_hash] : process)
 | 
			
		||||
		{
 | 
			
		||||
			auto const result_l = election->vote (vote_a->account, vote_a->timestamp, block_hash);
 | 
			
		||||
			auto const result_l = election->vote (vote_a->account, vote_a->timestamp (), block_hash);
 | 
			
		||||
			processed = processed || result_l.processed;
 | 
			
		||||
			replay = replay || result_l.replay;
 | 
			
		||||
		}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -474,7 +474,7 @@ public:
 | 
			
		|||
	{
 | 
			
		||||
		if (node.config.logging.network_message_logging ())
 | 
			
		||||
		{
 | 
			
		||||
			node.logger.try_log (boost::str (boost::format ("Received confirm_ack message from %1% for %2% timestamp %3%") % channel->to_string () % message_a.vote->hashes_string () % std::to_string (message_a.vote->timestamp)));
 | 
			
		||||
			node.logger.try_log (boost::str (boost::format ("Received confirm_ack message from %1% for %2% timestamp %3%") % channel->to_string () % message_a.vote->hashes_string () % std::to_string (message_a.vote->timestamp ())));
 | 
			
		||||
		}
 | 
			
		||||
		node.stats.inc (nano::stat::type::message, nano::stat::detail::confirm_ack, nano::stat::dir::in);
 | 
			
		||||
		if (!message_a.vote->account.is_zero ())
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -198,7 +198,7 @@ nano::vote_code nano::vote_processor::vote_blocking (std::shared_ptr<nano::vote>
 | 
			
		|||
	}
 | 
			
		||||
	if (config.logging.vote_logging ())
 | 
			
		||||
	{
 | 
			
		||||
		logger.try_log (boost::str (boost::format ("Vote from: %1% timestamp: %2% block(s): %3%status: %4%") % vote_a->account.to_account () % std::to_string (vote_a->timestamp) % vote_a->hashes_string () % status));
 | 
			
		||||
		logger.try_log (boost::str (boost::format ("Vote from: %1% timestamp: %2% block(s): %3%status: %4%") % vote_a->account.to_account () % std::to_string (vote_a->timestamp ()) % vote_a->hashes_string () % status));
 | 
			
		||||
	}
 | 
			
		||||
	return result;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -75,11 +75,11 @@ void nano::local_vote_history::add (nano::root const & root_a, nano::block_hash
 | 
			
		|||
	auto range (history_by_root.equal_range (root_a));
 | 
			
		||||
	for (auto i (range.first); i != range.second;)
 | 
			
		||||
	{
 | 
			
		||||
		if (i->hash != hash_a || (vote_a->account == i->vote->account && i->vote->timestamp <= vote_a->timestamp))
 | 
			
		||||
		if (i->hash != hash_a || (vote_a->account == i->vote->account && i->vote->timestamp () <= vote_a->timestamp ()))
 | 
			
		||||
		{
 | 
			
		||||
			i = history_by_root.erase (i);
 | 
			
		||||
		}
 | 
			
		||||
		else if (vote_a->account == i->vote->account && i->vote->timestamp > vote_a->timestamp)
 | 
			
		||||
		else if (vote_a->account == i->vote->account && i->vote->timestamp () > vote_a->timestamp ())
 | 
			
		||||
		{
 | 
			
		||||
			add_vote = false;
 | 
			
		||||
			++i;
 | 
			
		||||
| 
						 | 
				
			
			@ -123,7 +123,7 @@ std::vector<std::shared_ptr<nano::vote>> nano::local_vote_history::votes (nano::
 | 
			
		|||
	auto range (history.get<tag_root> ().equal_range (root_a));
 | 
			
		||||
	// clang-format off
 | 
			
		||||
	nano::transform_if (range.first, range.second, std::back_inserter (result),
 | 
			
		||||
		[&hash_a, is_final_a](auto const & entry) { return entry.hash == hash_a && (!is_final_a || entry.vote->timestamp == std::numeric_limits<uint64_t>::max ()); },
 | 
			
		||||
		[&hash_a, is_final_a](auto const & entry) { return entry.hash == hash_a && (!is_final_a || entry.vote->timestamp () == std::numeric_limits<uint64_t>::max ()); },
 | 
			
		||||
		[](auto const & entry) { return entry.vote; });
 | 
			
		||||
	// clang-format on
 | 
			
		||||
	return result;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -473,7 +473,7 @@ bool nano::vote::operator== (nano::vote const & other_a) const
 | 
			
		|||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return timestamp == other_a.timestamp && blocks_equal && account == other_a.account && signature == other_a.signature;
 | 
			
		||||
	return timestamp_m == other_a.timestamp_m && blocks_equal && account == other_a.account && signature == other_a.signature;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool nano::vote::operator!= (nano::vote const & other_a) const
 | 
			
		||||
| 
						 | 
				
			
			@ -485,8 +485,8 @@ void nano::vote::serialize_json (boost::property_tree::ptree & tree) const
 | 
			
		|||
{
 | 
			
		||||
	tree.put ("account", account.to_account ());
 | 
			
		||||
	tree.put ("signature", signature.number ());
 | 
			
		||||
	tree.put ("sequence", std::to_string (timestamp));
 | 
			
		||||
	tree.put ("timestamp", std::to_string (timestamp));
 | 
			
		||||
	tree.put ("sequence", std::to_string (timestamp ()));
 | 
			
		||||
	tree.put ("timestamp", std::to_string (timestamp ()));
 | 
			
		||||
	boost::property_tree::ptree blocks_tree;
 | 
			
		||||
	for (auto block : blocks)
 | 
			
		||||
	{
 | 
			
		||||
| 
						 | 
				
			
			@ -513,8 +513,13 @@ std::string nano::vote::to_json () const
 | 
			
		|||
	return stream.str ();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint64_t nano::vote::timestamp () const
 | 
			
		||||
{
 | 
			
		||||
	return timestamp_m;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
nano::vote::vote (nano::vote const & other_a) :
 | 
			
		||||
	timestamp{ other_a.timestamp },
 | 
			
		||||
	timestamp_m{ other_a.timestamp_m },
 | 
			
		||||
	blocks (other_a.blocks),
 | 
			
		||||
	account (other_a.account),
 | 
			
		||||
	signature (other_a.signature)
 | 
			
		||||
| 
						 | 
				
			
			@ -532,7 +537,7 @@ nano::vote::vote (bool & error_a, nano::stream & stream_a, nano::block_type type
 | 
			
		|||
	{
 | 
			
		||||
		nano::read (stream_a, account.bytes);
 | 
			
		||||
		nano::read (stream_a, signature.bytes);
 | 
			
		||||
		nano::read (stream_a, timestamp);
 | 
			
		||||
		nano::read (stream_a, timestamp_m);
 | 
			
		||||
 | 
			
		||||
		while (stream_a.in_avail () > 0)
 | 
			
		||||
		{
 | 
			
		||||
| 
						 | 
				
			
			@ -565,7 +570,7 @@ nano::vote::vote (bool & error_a, nano::stream & stream_a, nano::block_type type
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
nano::vote::vote (nano::account const & account_a, nano::raw_key const & prv_a, uint64_t timestamp_a, std::shared_ptr<nano::block> const & block_a) :
 | 
			
		||||
	timestamp{ timestamp_a },
 | 
			
		||||
	timestamp_m{ timestamp_a },
 | 
			
		||||
	blocks (1, block_a),
 | 
			
		||||
	account (account_a),
 | 
			
		||||
	signature (nano::sign_message (prv_a, account_a, hash ()))
 | 
			
		||||
| 
						 | 
				
			
			@ -573,7 +578,7 @@ nano::vote::vote (nano::account const & account_a, nano::raw_key const & prv_a,
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
nano::vote::vote (nano::account const & account_a, nano::raw_key const & prv_a, uint64_t timestamp_a, std::vector<nano::block_hash> const & blocks_a) :
 | 
			
		||||
	timestamp{ timestamp_a },
 | 
			
		||||
	timestamp_m{ timestamp_a },
 | 
			
		||||
	account (account_a)
 | 
			
		||||
{
 | 
			
		||||
	debug_assert (!blocks_a.empty ());
 | 
			
		||||
| 
						 | 
				
			
			@ -614,7 +619,7 @@ nano::block_hash nano::vote::hash () const
 | 
			
		|||
		uint64_t qword;
 | 
			
		||||
		std::array<uint8_t, 8> bytes;
 | 
			
		||||
	};
 | 
			
		||||
	qword = timestamp;
 | 
			
		||||
	qword = timestamp_m;
 | 
			
		||||
	blake2b_update (&hash, bytes.data (), sizeof (bytes));
 | 
			
		||||
	blake2b_final (&hash, result.bytes.data (), sizeof (result.bytes));
 | 
			
		||||
	return result;
 | 
			
		||||
| 
						 | 
				
			
			@ -636,7 +641,7 @@ void nano::vote::serialize (nano::stream & stream_a, nano::block_type type) cons
 | 
			
		|||
{
 | 
			
		||||
	write (stream_a, account);
 | 
			
		||||
	write (stream_a, signature);
 | 
			
		||||
	write (stream_a, boost::endian::native_to_little (timestamp));
 | 
			
		||||
	write (stream_a, boost::endian::native_to_little (timestamp_m));
 | 
			
		||||
	for (auto const & block : blocks)
 | 
			
		||||
	{
 | 
			
		||||
		if (block.which ())
 | 
			
		||||
| 
						 | 
				
			
			@ -662,7 +667,7 @@ void nano::vote::serialize (nano::stream & stream_a) const
 | 
			
		|||
{
 | 
			
		||||
	write (stream_a, account);
 | 
			
		||||
	write (stream_a, signature);
 | 
			
		||||
	write (stream_a, boost::endian::native_to_little (timestamp));
 | 
			
		||||
	write (stream_a, boost::endian::native_to_little (timestamp_m));
 | 
			
		||||
	for (auto const & block : blocks)
 | 
			
		||||
	{
 | 
			
		||||
		if (block.which ())
 | 
			
		||||
| 
						 | 
				
			
			@ -684,8 +689,8 @@ bool nano::vote::deserialize (nano::stream & stream_a, nano::block_uniquer * uni
 | 
			
		|||
	{
 | 
			
		||||
		nano::read (stream_a, account);
 | 
			
		||||
		nano::read (stream_a, signature);
 | 
			
		||||
		nano::read (stream_a, timestamp);
 | 
			
		||||
		boost::endian::little_to_native_inplace (timestamp);
 | 
			
		||||
		nano::read (stream_a, timestamp_m);
 | 
			
		||||
		boost::endian::little_to_native_inplace (timestamp_m);
 | 
			
		||||
 | 
			
		||||
		nano::block_type type;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -264,8 +264,11 @@ public:
 | 
			
		|||
	boost::transform_iterator<nano::iterate_vote_blocks_as_hash, nano::vote_blocks_vec_iter> begin () const;
 | 
			
		||||
	boost::transform_iterator<nano::iterate_vote_blocks_as_hash, nano::vote_blocks_vec_iter> end () const;
 | 
			
		||||
	std::string to_json () const;
 | 
			
		||||
	uint64_t timestamp () const;
 | 
			
		||||
private:
 | 
			
		||||
	// Vote timestamp
 | 
			
		||||
	uint64_t timestamp;
 | 
			
		||||
	uint64_t timestamp_m;
 | 
			
		||||
public:
 | 
			
		||||
	// The blocks, or block hashes, that this vote is for
 | 
			
		||||
	std::vector<boost::variant<std::shared_ptr<nano::block>, nano::block_hash>> blocks;
 | 
			
		||||
	// Account that's voting
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue