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

Block method refactor #1535

Merged
merged 2 commits into from
Jan 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
75 changes: 30 additions & 45 deletions nano/lib/blocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,26 @@ nano::block_hash nano::block::full_hash () const
return result;
}

nano::account nano::block::representative () const
{
return 0;
}

nano::block_hash nano::block::source () const
{
return 0;
}

nano::block_hash nano::block::link () const
{
return 0;
}

nano::account nano::block::account () const
{
return 0;
}

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

nano::block_hash nano::send_block::source () const
{
return 0;
}

nano::block_hash nano::send_block::root () const
{
return hashables.previous;
}

nano::block_hash nano::send_block::link () const
{
return 0;
}

nano::account nano::send_block::representative () const
{
return 0;
}

nano::signature nano::send_block::block_signature () const
{
return signature;
Expand Down Expand Up @@ -479,6 +484,11 @@ nano::block_hash nano::open_block::previous () const
return result;
}

nano::account nano::open_block::account () const
{
return hashables.account;
}

void nano::open_block::serialize (nano::stream & stream_a) const
{
write (stream_a, hashables.source);
Expand Down Expand Up @@ -597,11 +607,6 @@ nano::block_hash nano::open_block::root () const
return hashables.account;
}

nano::block_hash nano::open_block::link () const
{
return 0;
}

nano::account nano::open_block::representative () const
{
return hashables.representative;
Expand Down Expand Up @@ -828,21 +833,11 @@ bool nano::change_block::valid_predecessor (nano::block const & block_a) const
return result;
}

nano::block_hash nano::change_block::source () const
{
return 0;
}

nano::block_hash nano::change_block::root () const
{
return hashables.previous;
}

nano::block_hash nano::change_block::link () const
{
return 0;
}

nano::account nano::change_block::representative () const
{
return hashables.representative;
Expand Down Expand Up @@ -1000,6 +995,11 @@ nano::block_hash nano::state_block::previous () const
return hashables.previous;
}

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

void nano::state_block::serialize (nano::stream & stream_a) const
{
write (stream_a, hashables.account);
Expand Down Expand Up @@ -1132,11 +1132,6 @@ bool nano::state_block::valid_predecessor (nano::block const & block_a) const
return true;
}

nano::block_hash nano::state_block::source () const
{
return 0;
}

nano::block_hash nano::state_block::root () const
{
return !hashables.previous.is_zero () ? hashables.previous : hashables.account;
Expand Down Expand Up @@ -1485,16 +1480,6 @@ nano::block_hash nano::receive_block::root () const
return hashables.previous;
}

nano::block_hash nano::receive_block::link () const
{
return 0;
}

nano::account nano::receive_block::representative () const
{
return 0;
}

nano::signature nano::receive_block::block_signature () const
{
return signature;
Expand Down
18 changes: 6 additions & 12 deletions nano/lib/blocks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,16 @@ class block
virtual void hash (blake2b_state &) const = 0;
virtual uint64_t block_work () const = 0;
virtual void block_work_set (uint64_t) = 0;
virtual nano::account account () const;
// Previous block in account's chain, zero for open block
virtual nano::block_hash previous () const = 0;
// Source block for open/receive blocks, zero otherwise.
virtual nano::block_hash source () const = 0;
virtual nano::block_hash source () const;
// Previous block or account number for open blocks
virtual nano::block_hash root () const = 0;
// Link field for state blocks, zero otherwise.
virtual nano::block_hash link () const = 0;
virtual nano::account representative () const = 0;
virtual nano::block_hash link () const;
virtual nano::account representative () const;
virtual void serialize (nano::stream &) const = 0;
virtual void serialize_json (std::string &) const = 0;
virtual void visit (nano::block_visitor &) const = 0;
Expand Down Expand Up @@ -96,10 +97,7 @@ class send_block : public nano::block
uint64_t block_work () const override;
void block_work_set (uint64_t) override;
nano::block_hash previous () const override;
nano::block_hash source () const override;
nano::block_hash root () const override;
nano::block_hash link () const override;
nano::account representative () const override;
void serialize (nano::stream &) const override;
void serialize_json (std::string &) const override;
bool deserialize (nano::stream &);
Expand Down Expand Up @@ -143,8 +141,6 @@ class receive_block : public nano::block
nano::block_hash previous () const override;
nano::block_hash source () const override;
nano::block_hash root () const override;
nano::block_hash link () const override;
nano::account representative () const override;
void serialize (nano::stream &) const override;
void serialize_json (std::string &) const override;
bool deserialize (nano::stream &);
Expand Down Expand Up @@ -188,9 +184,9 @@ class open_block : public nano::block
uint64_t block_work () const override;
void block_work_set (uint64_t) override;
nano::block_hash previous () const override;
nano::account account () const override;
nano::block_hash source () const override;
nano::block_hash root () const override;
nano::block_hash link () const override;
nano::account representative () const override;
void serialize (nano::stream &) const override;
void serialize_json (std::string &) const override;
Expand Down Expand Up @@ -233,9 +229,7 @@ class change_block : public nano::block
uint64_t block_work () const override;
void block_work_set (uint64_t) override;
nano::block_hash previous () const override;
nano::block_hash source () const override;
nano::block_hash root () const override;
nano::block_hash link () const override;
nano::account representative () const override;
void serialize (nano::stream &) const override;
void serialize_json (std::string &) const override;
Expand Down Expand Up @@ -291,7 +285,7 @@ class state_block : public nano::block
uint64_t block_work () const override;
void block_work_set (uint64_t) override;
nano::block_hash previous () const override;
nano::block_hash source () const override;
nano::account account () const override;
nano::block_hash root () const override;
nano::block_hash link () const override;
nano::account representative () const override;
Expand Down
2 changes: 1 addition & 1 deletion nano/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2510,7 +2510,7 @@ class distributed_work : public std::enable_shared_from_this<distributed_work>
auto callback_l (callback);
std::weak_ptr<nano::node> node_w (node);
auto next_backoff (std::min (backoff * 2, (unsigned int)60 * 5));
node->alarm.add (now + std::chrono::seconds (backoff), [node_w, root_l, callback_l, next_backoff, difficulty = difficulty] {
node->alarm.add (now + std::chrono::seconds (backoff), [ node_w, root_l, callback_l, next_backoff, difficulty = difficulty ] {
if (auto node_l = node_w.lock ())
{
auto work_generation (std::make_shared<distributed_work> (next_backoff, node_l, root_l, callback_l, difficulty));
Expand Down