Skip to content

Commit

Permalink
Lazy bootstrap cleanup & basic improvements (#2292)
Browse files Browse the repository at this point in the history
* Lazy bootstrap cleanup
* Increase lazy pulls flushing speed
* Lazy backlog cleanup check
* Block count cache fix
  • Loading branch information
SergiySW authored Sep 11, 2019
1 parent ce00d62 commit d9ed92a
Show file tree
Hide file tree
Showing 14 changed files with 210 additions and 139 deletions.
15 changes: 15 additions & 0 deletions nano/lib/blocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ nano::qualified_root nano::block::qualified_root () const
return nano::qualified_root (previous (), root ());
}

nano::amount nano::block::balance () const
{
return 0;
}

void nano::send_block::visit (nano::block_visitor & visitor_a) const
{
visitor_a.send_block (*this);
Expand Down Expand Up @@ -378,6 +383,11 @@ nano::block_hash nano::send_block::root () const
return hashables.previous;
}

nano::amount nano::send_block::balance () const
{
return hashables.balance;
}

nano::signature nano::send_block::block_signature () const
{
return signature;
Expand Down Expand Up @@ -1187,6 +1197,11 @@ nano::account nano::state_block::representative () const
return hashables.representative;
}

nano::amount nano::state_block::balance () const
{
return hashables.balance;
}

nano::signature nano::state_block::block_signature () const
{
return signature;
Expand Down
3 changes: 3 additions & 0 deletions nano/lib/blocks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class block
// Link field for state blocks, zero otherwise.
virtual nano::block_hash link () const;
virtual nano::account representative () const;
virtual nano::amount balance () const;
virtual void serialize (nano::stream &) const = 0;
virtual void serialize_json (std::string &, bool = false) const = 0;
virtual void serialize_json (boost::property_tree::ptree &) const = 0;
Expand Down Expand Up @@ -115,6 +116,7 @@ class send_block : public nano::block
void block_work_set (uint64_t) override;
nano::block_hash previous () const override;
nano::block_hash root () const override;
nano::amount balance () const override;
void serialize (nano::stream &) const override;
bool deserialize (nano::stream &);
void serialize_json (std::string &, bool = false) const override;
Expand Down Expand Up @@ -310,6 +312,7 @@ class state_block : public nano::block
nano::block_hash root () const override;
nano::block_hash link () const override;
nano::account representative () const override;
nano::amount balance () const override;
void serialize (nano::stream &) const override;
bool deserialize (nano::stream &);
void serialize_json (std::string &, bool = false) const override;
Expand Down
11 changes: 11 additions & 0 deletions nano/node/blockprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +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]);
}
items.pop_front ();
}
Expand Down Expand Up @@ -477,6 +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);
break;
}
case nano::process_result::negative_spend:
Expand Down Expand Up @@ -571,3 +573,12 @@ nano::block_hash nano::block_processor::filter_item (nano::block_hash const & ha
blake2b_final (&state, result.bytes.data (), sizeof (result.bytes));
return result;
}

void nano::block_processor::requeue_invalid (nano::block_hash const & hash_a)
{
auto attempt (node.bootstrap_initiator.current_attempt ());
if (attempt != nullptr && attempt->mode == nano::bootstrap_mode::lazy)
{
attempt->lazy_requeue (hash_a);
}
}
1 change: 1 addition & 0 deletions nano/node/blockprocessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +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 &);
bool stopped;
bool active;
bool awaiting_write{ false };
Expand Down
Loading

0 comments on commit d9ed92a

Please sign in to comment.