Skip to content

Commit

Permalink
Allow more hashes in vote
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Nov 8, 2023
1 parent f36f879 commit d4a7a87
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
7 changes: 4 additions & 3 deletions nano/node/messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,9 +526,10 @@ nano::confirm_req::confirm_req (nano::network_constants const & constants, std::
message (constants, nano::message_type::confirm_req),
roots_hashes (roots_hashes_a)
{
debug_assert (roots_hashes.size () <= nano::vote::max_hashes);

// not_a_block (1) block type for hashes + roots request
header.block_type_set (nano::block_type::not_a_block);
debug_assert (roots_hashes.size () < 16);
header.count_set (static_cast<uint8_t> (roots_hashes.size ()));
}

Expand All @@ -537,9 +538,10 @@ nano::confirm_req::confirm_req (nano::network_constants const & constants, nano:
roots_hashes (std::vector<std::pair<nano::block_hash, nano::root>> (1, std::make_pair (hash_a, root_a)))
{
debug_assert (!roots_hashes.empty ());
debug_assert (roots_hashes.size () <= nano::vote::max_hashes);

// not_a_block (1) block type for hashes + roots request
header.block_type_set (nano::block_type::not_a_block);
debug_assert (roots_hashes.size () < 16);
header.count_set (static_cast<uint8_t> (roots_hashes.size ()));
}

Expand Down Expand Up @@ -684,7 +686,6 @@ nano::confirm_ack::confirm_ack (nano::network_constants const & constants, std::
vote (vote_a)
{
header.block_type_set (nano::block_type::not_a_block);
debug_assert (vote_a->hashes.size () < 16);
header.count_set (static_cast<uint8_t> (vote_a->hashes.size ()));
}

Expand Down
6 changes: 5 additions & 1 deletion nano/secure/vote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ nano::vote::vote (nano::account const & account_a, nano::raw_key const & prv_a,
timestamp_m{ packed_timestamp (timestamp_a, duration) },
account{ account_a }
{
debug_assert (hashes.size () <= max_hashes);

signature = nano::sign_message (prv_a, account_a, hash ());
}

void nano::vote::serialize (nano::stream & stream_a) const
{
debug_assert (hashes.size () <= max_hashes);

write (stream_a, account);
write (stream_a, signature);
write (stream_a, boost::endian::native_to_little (timestamp_m));
Expand All @@ -36,7 +40,7 @@ bool nano::vote::deserialize (nano::stream & stream_a)
nano::read (stream_a, signature.bytes);
nano::read (stream_a, timestamp_m);

while (stream_a.in_avail () > 0)
while (stream_a.in_avail () > 0 && hashes.size () < max_hashes)
{
nano::block_hash block_hash;
nano::read (stream_a, block_hash);
Expand Down
2 changes: 2 additions & 0 deletions nano/secure/vote.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class vote final
static uint64_t constexpr timestamp_min = { 0x0000'0000'0000'0010ULL };
static uint8_t constexpr duration_max = { 0x0fu };

static std::size_t constexpr max_hashes = 256;

/* Check if timestamp represents a final vote */
static bool is_final_timestamp (uint64_t timestamp);

Expand Down

0 comments on commit d4a7a87

Please sign in to comment.