nano-node icon indicating copy to clipboard operation
nano-node copied to clipboard

Improve code related to final votes

Open dsiganos opened this issue 2 years ago • 2 comments

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.

dsiganos avatar Feb 03 '22 13:02 dsiganos

Seems an is_final method on the vote class would sufficiently hide implementation details.

clemahieu avatar Feb 03 '22 14:02 clemahieu

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.

dsiganos avatar Feb 03 '22 14:02 dsiganos