nano-node
nano-node copied to clipboard
Improve code related to final votes
We currently implement final votes in a messy way. We use std::numeric_limits<uint64_t>::max()
to check for final votes but it would be clearer and more explicit if we checked against a sentinel or had a function that checked if a function was a final vote.
We also have code like this:
auto timestamp = this->is_final ? nano::vote::timestamp_max : nano::milliseconds_since_epoch ();
uint8_t duration = this->is_final ? nano::vote::duration_max : /*8192ms*/ 0x9;
votes_l.emplace_back (std::make_shared<nano::vote> (pub_a, prv_a, timestamp, duration, hashes_a));
which leaks out of the vote class the way timestamp and duration are packed into bits.
Seems an is_final method on the vote class would sufficiently hide implementation details.
I believe we check for final votes in places where we do not have a nano::vote object and we simply have a timestamp only. In that case, a nano::vote member function would not work. A sentinel would work everywhere. So I am leaning towards a sentinel at this stage but if we can encapsulate it all inside nano::vote, even better.