Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lazy bootstrap possible links and accounts #2315

Merged
merged 30 commits into from
Oct 11, 2019
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
35a8586
Split bootstrap core_test
SergiySW Sep 23, 2019
ad678ab
Support unclear state blocks links pulls
SergiySW Sep 23, 2019
a9c9052
Lazy destinations request
SergiySW Sep 23, 2019
1385baf
Update expected block status with unconfirmed head only if account is…
SergiySW Sep 24, 2019
5f8a273
Remove expected rewrite for stopped pulls
SergiySW Sep 24, 2019
d0e4958
Merge remote-tracking branch 'upstream/master' into bootstrap/lazy_re…
SergiySW Sep 24, 2019
e2061e3
Add bootstrap_hash_or_account class
SergiySW Sep 24, 2019
b6bf777
Formatting
SergiySW Sep 24, 2019
72ab97f
More frequent destinations check & backlog cleanup
SergiySW Sep 24, 2019
59dd4b5
Allow hash_or_account to be concrete
wezrule Sep 25, 2019
0695a3c
Merge remote-tracking branch 'wezrule/allow_hash_or_account_concrete'…
SergiySW Sep 25, 2019
e9f5c80
Fix merge issues
SergiySW Sep 25, 2019
e3444f7
Merge remote-tracking branch 'upstream/master' into bootstrap/lazy_re…
SergiySW Sep 25, 2019
2e17ef1
Higher retry limit for lazy pulls with a lot of processed blocks
SergiySW Sep 25, 2019
c27031c
Improve requeue invalid signature function
SergiySW Sep 25, 2019
ce8e046
Use emplace & emplace_back in bootstrap.cpp
SergiySW Sep 25, 2019
8ca0757
Use lock_guard for regular lazy functions instead of unique_lock
SergiySW Sep 25, 2019
2003b5a
Clarify lazy_destinations_flush_delay_minutes
SergiySW Sep 25, 2019
937a7ad
lazy_destinations_flush_delay in seconds
SergiySW Sep 26, 2019
99bb969
Merge remote-tracking branch 'upstream/master' into bootstrap/lazy_re…
SergiySW Sep 29, 2019
1fbaf08
Merge remote-tracking branch 'upstream/master' into bootstrap/lazy_re…
SergiySW Oct 6, 2019
a8474ab
Fix updated tests
SergiySW Oct 6, 2019
48f86e5
Test for non existing state blocks links
SergiySW Oct 8, 2019
a6e7cd3
List of lazy undefined links
SergiySW Oct 8, 2019
7f28c29
Start lazy bootstrap for not found RPC accounts
SergiySW Oct 8, 2019
1d9f7ab
Merge remote-tracking branch 'upstream/master' into bootstrap/lazy_re…
SergiySW Oct 9, 2019
746ff5b
Merge remote-tracking branch 'upstream/master' into bootstrap/lazy_re…
SergiySW Oct 9, 2019
1e5af7a
Improve lazy_backlog_cleanup (), requeue lazy pulls if expected block…
SergiySW Oct 10, 2019
99a63d2
Add bootstrap attempt duration
SergiySW Oct 10, 2019
be3fdab
Merge remote-tracking branch 'upstream/master' into bootstrap/lazy_re…
SergiySW Oct 10, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions nano/core_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ add_executable (core_test
active_transactions.cpp
block.cpp
block_store.cpp
bootstrap.cpp
conflicts.cpp
difficulty.cpp
distributed_work.cpp
Expand Down
783 changes: 783 additions & 0 deletions nano/core_test/bootstrap.cpp

Large diffs are not rendered by default.

715 changes: 3 additions & 712 deletions nano/core_test/network.cpp

Large diffs are not rendered by default.

46 changes: 18 additions & 28 deletions nano/lib/numbers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -827,39 +827,19 @@ nano::hash_or_account::operator nano::uint256_union const & () const
return raw;
}

nano::link::link (uint64_t value_a) :
hash_or_account (value_a)
{
}

nano::root::root (uint64_t value_a) :
hash_or_account (value_a)
{
}

nano::block_hash const & nano::root::previous () const
{
return hash;
}

bool nano::root::operator== (nano::root const & root_a) const
{
return bytes == root_a.bytes;
}

bool nano::root::operator!= (nano::root const & root_a) const
bool nano::hash_or_account::operator== (nano::hash_or_account const & hash_or_account_a) const
{
return !(*this == root_a);
return bytes == hash_or_account_a.bytes;
}

bool nano::link::operator== (nano::link const & link_a) const
bool nano::hash_or_account::operator!= (nano::hash_or_account const & hash_or_account_a) const
{
return bytes == link_a.bytes;
}

bool nano::link::operator!= (nano::link const & link_a) const
{
return !(*this == link_a);
return !(*this == hash_or_account_a);
}

std::string nano::to_string_hex (uint64_t const value_a)
Expand Down Expand Up @@ -931,20 +911,30 @@ double nano::difficulty::to_multiplier (uint64_t const difficulty_a, uint64_t co

nano::public_key::operator nano::link const & () const
{
return nano::to_link (*this);
return reinterpret_cast<nano::link const &> (*this);
}

nano::public_key::operator nano::root const & () const
{
return nano::to_root (*this);
return reinterpret_cast<nano::root const &> (*this);
}

nano::public_key::operator nano::hash_or_account const & () const
{
return reinterpret_cast<nano::hash_or_account const &> (*this);
}

nano::block_hash::operator nano::link const & () const
{
return nano::to_link (*this);
return reinterpret_cast<nano::link const &> (*this);
}

nano::block_hash::operator nano::root const & () const
{
return nano::to_root (*this);
return reinterpret_cast<nano::root const &> (*this);
}

nano::block_hash::operator nano::hash_or_account const & () const
{
return reinterpret_cast<nano::hash_or_account const &> (*this);
}
53 changes: 11 additions & 42 deletions nano/lib/numbers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ static_assert (std::is_nothrow_move_constructible<uint256_union>::value, "uint25

class link;
class root;
class hash_or_account;

// All keys and hashes are 256 bit.
class block_hash final : public uint256_union
Expand All @@ -108,6 +109,7 @@ class block_hash final : public uint256_union
using uint256_union::uint256_union;
operator nano::link const & () const;
operator nano::root const & () const;
operator nano::hash_or_account const & () const;
};

class public_key final : public uint256_union
Expand All @@ -122,6 +124,7 @@ class public_key final : public uint256_union

operator nano::link const & () const;
operator nano::root const & () const;
operator nano::hash_or_account const & () const;
};

class wallet_id : public uint256_union
Expand All @@ -135,6 +138,9 @@ using account = public_key;
class hash_or_account
{
public:
hash_or_account () = default;
hash_or_account (uint64_t value_a);

bool is_zero () const;
void clear ();
std::string to_string () const;
Expand All @@ -146,40 +152,30 @@ class hash_or_account
operator nano::account const & () const;
operator nano::uint256_union const & () const;

bool operator== (nano::hash_or_account const &) const;
bool operator!= (nano::hash_or_account const &) const;

union
{
std::array<uint8_t, 32> bytes;
nano::uint256_union raw; // This can be used when you don't want to explicitly mention either of the types
nano::account account;
nano::block_hash hash;
};

protected:
// Cannot instantiate a concrete version of this class
hash_or_account () = default;
hash_or_account (uint64_t value_a);
};

// A link can either be a destination account or source hash
class link final : public hash_or_account
{
public:
link () = default;
link (uint64_t value_a);

bool operator== (nano::link const &) const;
bool operator!= (nano::link const &) const;
using hash_or_account::hash_or_account;
};

// A root can either be an open block hash or a previous hash
class root final : public hash_or_account
{
public:
root () = default;
root (uint64_t value_a);

bool operator== (nano::root const &) const;
bool operator!= (nano::root const &) const;
using hash_or_account::hash_or_account;

nano::block_hash const & previous () const;
};
Expand Down Expand Up @@ -227,33 +223,6 @@ class uint512_union
};
static_assert (std::is_nothrow_move_constructible<uint512_union>::value, "uint512_union should be noexcept MoveConstructible");

inline nano::link const & to_link (nano::block_hash const & hash_a)
{
return reinterpret_cast<nano::link const &> (hash_a);
}

inline nano::link const & to_link (nano::account const & account_a)
{
return reinterpret_cast<nano::link const &> (account_a);
}

inline nano::root const & to_root (nano::block_hash const & hash_a)
{
return reinterpret_cast<nano::root const &> (hash_a);
}

inline nano::root const & to_root (nano::account const & account_a)
{
return reinterpret_cast<nano::root const &> (account_a);
}

inline nano::account const & root_as_account (nano::root const & root_a)
{
static_assert (sizeof (nano::root) == sizeof (nano::account), "Sizes do not match");
static_assert (std::is_standard_layout<nano::root>::value && std::is_standard_layout<nano::account>::value, "Both types must have standard layout");
return reinterpret_cast<nano::account const &> (root_a);
}

class signature : public uint512_union
{
public:
Expand Down
9 changes: 5 additions & 4 deletions nano/node/blockprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ void nano::block_processor::verify_state_blocks (nano::unique_lock<std::mutex> &
else
{
blocks_filter.erase (filter_item (hashes[i], blocks_signatures[i]));
requeue_invalid (hashes[i]);
requeue_invalid (hashes[i], item);
}
items.pop_front ();
}
Expand Down Expand Up @@ -478,7 +478,7 @@ nano::process_return nano::block_processor::process_one (nano::write_transaction
{
node.logger.try_log (boost::str (boost::format ("Bad signature for: %1%") % hash.to_string ()));
}
requeue_invalid (hash);
requeue_invalid (hash, info_a);
break;
}
case nano::process_result::negative_spend:
Expand Down Expand Up @@ -574,11 +574,12 @@ nano::block_hash nano::block_processor::filter_item (nano::block_hash const & ha
return result;
}

void nano::block_processor::requeue_invalid (nano::block_hash const & hash_a)
void nano::block_processor::requeue_invalid (nano::block_hash const & hash_a, nano::unchecked_info const & info_a)
{
assert (hash_a == info_a.block->hash ());
auto attempt (node.bootstrap_initiator.current_attempt ());
if (attempt != nullptr && attempt->mode == nano::bootstrap_mode::lazy)
{
attempt->lazy_requeue (hash_a);
attempt->lazy_requeue (hash_a, info_a.block->previous (), info_a.confirmed);
}
}
2 changes: 1 addition & 1 deletion nano/node/blockprocessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class block_processor final
void verify_state_blocks (nano::unique_lock<std::mutex> &, size_t = std::numeric_limits<size_t>::max ());
void process_batch (nano::unique_lock<std::mutex> &);
void process_live (nano::block_hash const &, std::shared_ptr<nano::block>, const bool = false);
void requeue_invalid (nano::block_hash const &);
void requeue_invalid (nano::block_hash const &, nano::unchecked_info const &);
bool stopped;
bool active;
bool awaiting_write{ false };
Expand Down
Loading