Skip to content

Commit

Permalink
Logic to handle requests for frontiers in bootstrap server
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Nov 8, 2023
1 parent fb7d8d2 commit 7c28758
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions nano/node/bootstrap/bootstrap_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <nano/node/transport/channel.hpp>
#include <nano/node/transport/transport.hpp>
#include <nano/secure/ledger.hpp>
#include <nano/store/account.hpp>
#include <nano/store/block.hpp>
#include <nano/store/component.hpp>
#include <nano/store/confirmation_height.hpp>
Expand Down Expand Up @@ -71,7 +72,7 @@ bool nano::bootstrap_server::verify (const nano::asc_pull_req & message) const
}
bool operator() (nano::asc_pull_req::frontiers_payload const & pld) const
{
return pld.count > 0 && pld.count <= max_frontiers && !pld.start.is_zero ();
return pld.count > 0 && pld.count <= max_frontiers;
}
};

Expand Down Expand Up @@ -215,7 +216,7 @@ nano::asc_pull_ack nano::bootstrap_server::process (store::transaction const & t

nano::asc_pull_ack nano::bootstrap_server::prepare_response (store::transaction const & transaction, nano::asc_pull_req::id_t id, nano::block_hash start_block, std::size_t count)
{
debug_assert (count <= max_blocks);
debug_assert (count <= max_blocks); // Should be filtered out earlier

auto blocks = prepare_blocks (transaction, start_block, count);
debug_assert (blocks.size () <= count);
Expand All @@ -224,7 +225,7 @@ nano::asc_pull_ack nano::bootstrap_server::prepare_response (store::transaction
response.id = id;
response.type = nano::asc_pull_type::blocks;

nano::asc_pull_ack::blocks_payload response_payload;
nano::asc_pull_ack::blocks_payload response_payload{};
response_payload.blocks = blocks;
response.payload = response_payload;

Expand All @@ -247,7 +248,7 @@ nano::asc_pull_ack nano::bootstrap_server::prepare_empty_blocks_response (nano::

std::vector<std::shared_ptr<nano::block>> nano::bootstrap_server::prepare_blocks (store::transaction const & transaction, nano::block_hash start_block, std::size_t count) const
{
debug_assert (count <= max_blocks);
debug_assert (count <= max_blocks); // Should be filtered out earlier

std::vector<std::shared_ptr<nano::block>> result;
if (!start_block.is_zero ())
Expand Down Expand Up @@ -320,7 +321,20 @@ nano::asc_pull_ack nano::bootstrap_server::process (const store::transaction & t

nano::asc_pull_ack nano::bootstrap_server::process (const store::transaction & transaction, nano::asc_pull_req::id_t id, const nano::asc_pull_req::frontiers_payload & request)
{
debug_assert (false, "not implemented");
nano::asc_pull_ack ack{ network_constants };
return ack;
debug_assert (request.count <= max_frontiers); // Should be filtered out earlier

nano::asc_pull_ack response{ network_constants };
response.id = id;
response.type = nano::asc_pull_type::frontiers;

nano::asc_pull_ack::frontiers_payload response_payload{};

for (auto it = store.account.begin (transaction, request.start), end = store.account.end (); it != end && response_payload.frontiers.size () < request.count; ++it)
{
response_payload.frontiers.emplace_back (it->first, it->second.head);
}

response.payload = response_payload;
response.update_header ();
return response;
}

0 comments on commit 7c28758

Please sign in to comment.