Require explicit conversion from root/link to block hash or account (#2761)

This commit is contained in:
Wesley Shillingford 2020-09-10 11:44:22 +01:00 committed by GitHub
commit 47c2740add
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 68 additions and 67 deletions

View file

@ -3046,7 +3046,7 @@ TEST (node, epoch_conflict_confirm)
.work (*system.work.generate (send->hash ())) .work (*system.work.generate (send->hash ()))
.build_shared (); .build_shared ();
auto epoch_open = builder.make_block () auto epoch_open = builder.make_block ()
.account (change->root ()) .account (change->root ().as_account ())
.previous (0) .previous (0)
.representative (0) .representative (0)
.balance (0) .balance (0)

View file

@ -830,12 +830,12 @@ std::string nano::hash_or_account::to_account () const
return account.to_account (); return account.to_account ();
} }
nano::hash_or_account::operator nano::block_hash const & () const nano::block_hash const & nano::hash_or_account::as_block_hash () const
{ {
return hash; return hash;
} }
nano::hash_or_account::operator nano::account const & () const nano::account const & nano::hash_or_account::as_account () const
{ {
return account; return account;
} }

View file

@ -147,8 +147,9 @@ public:
bool decode_account (std::string const &); bool decode_account (std::string const &);
std::string to_account () const; std::string to_account () const;
operator nano::block_hash const & () const; nano::account const & as_account () const;
operator nano::account const & () const; nano::block_hash const & as_block_hash () const;
operator nano::uint256_union const & () const; operator nano::uint256_union const & () const;
bool operator== (nano::hash_or_account const &) const; bool operator== (nano::hash_or_account const &) const;

View file

@ -959,7 +959,7 @@ int main (int argc, char * const * argv)
auto send = builder.state () auto send = builder.state ()
.account (keys[j].pub) .account (keys[j].pub)
.previous (frontiers[j]) .previous (frontiers[j].as_block_hash ())
.representative (keys[j].pub) .representative (keys[j].pub)
.balance (balances[j]) .balance (balances[j])
.link (keys[other].pub) .link (keys[other].pub)
@ -974,10 +974,10 @@ int main (int argc, char * const * argv)
auto receive = builder.state () auto receive = builder.state ()
.account (keys[other].pub) .account (keys[other].pub)
.previous (frontiers[other]) .previous (frontiers[other].as_block_hash ())
.representative (keys[other].pub) .representative (keys[other].pub)
.balance (balances[other]) .balance (balances[other])
.link (static_cast<nano::block_hash const &> (frontiers[j])) .link (frontiers[j].as_block_hash ())
.sign (keys[other].prv, keys[other].pub) .sign (keys[other].prv, keys[other].pub)
.work (*work.generate (nano::work_version::work_1, frontiers[other], node->network_params.network.publish_thresholds.epoch_1)) .work (*work.generate (nano::work_version::work_1, frontiers[other], node->network_params.network.publish_thresholds.epoch_1))
.build (); .build ();
@ -1529,7 +1529,7 @@ int main (int argc, char * const * argv)
{ {
// State receive // State receive
block_details_error = !sideband.details.is_receive || sideband.details.is_send || sideband.details.is_epoch; block_details_error = !sideband.details.is_receive || sideband.details.is_send || sideband.details.is_epoch;
block_details_error |= !node->store.block_exists (transaction, block->link ()); block_details_error |= !node->store.block_exists (transaction, block->link ().as_block_hash ());
} }
} }
} }
@ -1540,7 +1540,7 @@ int main (int argc, char * const * argv)
// Check link epoch version // Check link epoch version
if (sideband.details.is_receive) if (sideband.details.is_receive)
{ {
if (sideband.source_epoch != node->store.block_version (transaction, block->link ())) if (sideband.source_epoch != node->store.block_version (transaction, block->link ().as_block_hash ()))
{ {
print_error_message (boost::str (boost::format ("Incorrect source epoch for block %1%\n") % hash.to_string ())); print_error_message (boost::str (boost::format ("Incorrect source epoch for block %1%\n") % hash.to_string ()));
} }
@ -1666,7 +1666,7 @@ int main (int argc, char * const * argv)
{ {
if (node->ledger.is_send (transaction, *state)) if (node->ledger.is_send (transaction, *state))
{ {
destination = state->hashables.link; destination = state->hashables.link.as_account ();
} }
} }
else if (auto send = dynamic_cast<nano::send_block *> (block.get ())) else if (auto send = dynamic_cast<nano::send_block *> (block.get ()))

View file

@ -435,20 +435,20 @@ void nano::bulk_pull_server::set_current_end ()
request->end.clear (); request->end.clear ();
} }
if (connection->node->store.block_exists (transaction, request->start)) if (connection->node->store.block_exists (transaction, request->start.as_block_hash ()))
{ {
if (connection->node->config.logging.bulk_pull_logging ()) if (connection->node->config.logging.bulk_pull_logging ())
{ {
connection->node->logger.try_log (boost::str (boost::format ("Bulk pull request for block hash: %1%") % request->start.to_string ())); connection->node->logger.try_log (boost::str (boost::format ("Bulk pull request for block hash: %1%") % request->start.to_string ()));
} }
current = request->start; current = request->start.as_block_hash ();
include_start = true; include_start = true;
} }
else else
{ {
nano::account_info info; nano::account_info info;
auto no_address (connection->node->store.account_get (transaction, request->start, info)); auto no_address (connection->node->store.account_get (transaction, request->start.as_account (), info));
if (no_address) if (no_address)
{ {
if (connection->node->config.logging.bulk_pull_logging ()) if (connection->node->config.logging.bulk_pull_logging ())

View file

@ -416,7 +416,7 @@ void nano::bootstrap_connections::requeue_pull (nano::pull_info const & pull_a,
else if (attempt_l->mode == nano::bootstrap_mode::lazy && (pull.retry_limit == std::numeric_limits<unsigned>::max () || pull.attempts <= pull.retry_limit + (pull.processed / node.network_params.bootstrap.lazy_max_pull_blocks))) else if (attempt_l->mode == nano::bootstrap_mode::lazy && (pull.retry_limit == std::numeric_limits<unsigned>::max () || pull.attempts <= pull.retry_limit + (pull.processed / node.network_params.bootstrap.lazy_max_pull_blocks)))
{ {
debug_assert (pull.account_or_head == pull.head); debug_assert (pull.account_or_head == pull.head);
if (!attempt_l->lazy_processed_or_exists (pull.account_or_head)) if (!attempt_l->lazy_processed_or_exists (pull.account_or_head.as_block_hash ()))
{ {
{ {
nano::lock_guard<std::mutex> lock (mutex); nano::lock_guard<std::mutex> lock (mutex);

View file

@ -31,9 +31,9 @@ void nano::bootstrap_attempt_lazy::lazy_start (nano::hash_or_account const & has
nano::unique_lock<std::mutex> lock (mutex); nano::unique_lock<std::mutex> lock (mutex);
// Add start blocks, limit 1024 (4k with disabled legacy bootstrap) // Add start blocks, limit 1024 (4k with disabled legacy bootstrap)
size_t max_keys (node->flags.disable_legacy_bootstrap ? 4 * 1024 : 1024); size_t max_keys (node->flags.disable_legacy_bootstrap ? 4 * 1024 : 1024);
if (lazy_keys.size () < max_keys && lazy_keys.find (hash_or_account_a) == lazy_keys.end () && !lazy_blocks_processed (hash_or_account_a)) if (lazy_keys.size () < max_keys && lazy_keys.find (hash_or_account_a.as_block_hash ()) == lazy_keys.end () && !lazy_blocks_processed (hash_or_account_a.as_block_hash ()))
{ {
lazy_keys.insert (hash_or_account_a); lazy_keys.insert (hash_or_account_a.as_block_hash ());
lazy_pulls.emplace_back (hash_or_account_a, confirmed ? std::numeric_limits<unsigned>::max () : node->network_params.bootstrap.lazy_retry_limit); lazy_pulls.emplace_back (hash_or_account_a, confirmed ? std::numeric_limits<unsigned>::max () : node->network_params.bootstrap.lazy_retry_limit);
lock.unlock (); lock.unlock ();
condition.notify_all (); condition.notify_all ();
@ -44,7 +44,7 @@ void nano::bootstrap_attempt_lazy::lazy_add (nano::hash_or_account const & hash_
{ {
// Add only unknown blocks // Add only unknown blocks
debug_assert (!mutex.try_lock ()); debug_assert (!mutex.try_lock ());
if (!lazy_blocks_processed (hash_or_account_a)) if (!lazy_blocks_processed (hash_or_account_a.as_block_hash ()))
{ {
lazy_pulls.emplace_back (hash_or_account_a, retry_limit); lazy_pulls.emplace_back (hash_or_account_a, retry_limit);
} }
@ -103,10 +103,10 @@ void nano::bootstrap_attempt_lazy::lazy_pull_flush (nano::unique_lock<std::mutex
auto pull_start (lazy_pulls.front ()); auto pull_start (lazy_pulls.front ());
lazy_pulls.pop_front (); lazy_pulls.pop_front ();
// Recheck if block was already processed // Recheck if block was already processed
if (!lazy_blocks_processed (pull_start.first) && !node->store.block_exists (transaction, pull_start.first)) if (!lazy_blocks_processed (pull_start.first.as_block_hash ()) && !node->store.block_exists (transaction, pull_start.first.as_block_hash ()))
{ {
lock_a.unlock (); lock_a.unlock ();
node->bootstrap_initiator.connections->add_pull (nano::pull_info (pull_start.first, pull_start.first, nano::block_hash (0), incremental_id, batch_count, pull_start.second)); node->bootstrap_initiator.connections->add_pull (nano::pull_info (pull_start.first, pull_start.first.as_block_hash (), nano::block_hash (0), incremental_id, batch_count, pull_start.second));
++pulling; ++pulling;
++count; ++count;
lock_a.lock (); lock_a.lock ();
@ -300,7 +300,7 @@ void nano::bootstrap_attempt_lazy::lazy_block_state (std::shared_ptr<nano::block
nano::uint128_t balance (block_l->hashables.balance.number ()); nano::uint128_t balance (block_l->hashables.balance.number ());
auto const & link (block_l->hashables.link); auto const & link (block_l->hashables.link);
// If link is not epoch link or 0. And if block from link is unknown // If link is not epoch link or 0. And if block from link is unknown
if (!link.is_zero () && !node->ledger.is_epoch_link (link) && !lazy_blocks_processed (link) && !node->store.block_exists (transaction, link)) if (!link.is_zero () && !node->ledger.is_epoch_link (link) && !lazy_blocks_processed (link.as_block_hash ()) && !node->store.block_exists (transaction, link.as_block_hash ()))
{ {
auto const & previous (block_l->hashables.previous); auto const & previous (block_l->hashables.previous);
// If state block previous is 0 then source block required // If state block previous is 0 then source block required
@ -317,7 +317,7 @@ void nano::bootstrap_attempt_lazy::lazy_block_state (std::shared_ptr<nano::block
} }
else else
{ {
lazy_destinations_increment (link); lazy_destinations_increment (link.as_account ());
} }
} }
// Search balance of already processed previous blocks // Search balance of already processed previous blocks
@ -332,7 +332,7 @@ void nano::bootstrap_attempt_lazy::lazy_block_state (std::shared_ptr<nano::block
} }
else else
{ {
lazy_destinations_increment (link); lazy_destinations_increment (link.as_account ());
} }
lazy_balances.erase (previous_balance); lazy_balances.erase (previous_balance);
} }
@ -362,14 +362,14 @@ void nano::bootstrap_attempt_lazy::lazy_block_state_backlog_check (std::shared_p
} }
else else
{ {
lazy_destinations_increment (next_block.link); lazy_destinations_increment (next_block.link.as_account ());
} }
} }
// Assumption for other legacy block types // Assumption for other legacy block types
else if (lazy_undefined_links.find (next_block.link) == lazy_undefined_links.end ()) else if (lazy_undefined_links.find (next_block.link.as_block_hash ()) == lazy_undefined_links.end ())
{ {
lazy_add (next_block.link, node->network_params.bootstrap.lazy_retry_limit); // Head is not confirmed. It can be account or hash or non-existing lazy_add (next_block.link, node->network_params.bootstrap.lazy_retry_limit); // Head is not confirmed. It can be account or hash or non-existing
lazy_undefined_links.insert (next_block.link); lazy_undefined_links.insert (next_block.link.as_block_hash ());
} }
lazy_state_backlog.erase (find_state); lazy_state_backlog.erase (find_state);
} }
@ -390,7 +390,7 @@ void nano::bootstrap_attempt_lazy::lazy_backlog_cleanup ()
} }
else else
{ {
lazy_destinations_increment (next_block.link); lazy_destinations_increment (next_block.link.as_account ());
} }
it = lazy_state_backlog.erase (it); it = lazy_state_backlog.erase (it);
} }

View file

@ -241,7 +241,7 @@ bool nano::confirmation_height_bounded::iterate (nano::read_transaction const &
auto source (block->source ()); auto source (block->source ());
if (source.is_zero ()) if (source.is_zero ())
{ {
source = block->link (); source = block->link ().as_block_hash ();
} }
if (!source.is_zero () && !ledger.is_epoch_link (source) && ledger.store.block_exists (transaction_a, source)) if (!source.is_zero () && !ledger.is_epoch_link (source) && ledger.store.block_exists (transaction_a, source))

View file

@ -191,7 +191,7 @@ void nano::confirmation_height_unbounded::collect_unconfirmed_receive_and_source
auto source (block->source ()); auto source (block->source ());
if (source.is_zero ()) if (source.is_zero ())
{ {
source = block->link (); source = block->link ().as_block_hash ();
} }
if (!source.is_zero () && !ledger.is_epoch_link (source) && ledger.store.block_exists (transaction_a, source)) if (!source.is_zero () && !ledger.is_epoch_link (source) && ledger.store.block_exists (transaction_a, source))

View file

@ -43,15 +43,15 @@ nano::distributed_work::~distributed_work ()
nano::websocket::message_builder builder; nano::websocket::message_builder builder;
if (status == work_generation_status::success) if (status == work_generation_status::success)
{ {
node_l->websocket_server->broadcast (builder.work_generation (request.version, request.root, work_result, request.difficulty, node_l->default_difficulty (request.version), elapsed.value (), winner, bad_peers)); node_l->websocket_server->broadcast (builder.work_generation (request.version, request.root.as_block_hash (), work_result, request.difficulty, node_l->default_difficulty (request.version), elapsed.value (), winner, bad_peers));
} }
else if (status == work_generation_status::cancelled) else if (status == work_generation_status::cancelled)
{ {
node_l->websocket_server->broadcast (builder.work_cancelled (request.version, request.root, request.difficulty, node_l->default_difficulty (request.version), elapsed.value (), bad_peers)); node_l->websocket_server->broadcast (builder.work_cancelled (request.version, request.root.as_block_hash (), request.difficulty, node_l->default_difficulty (request.version), elapsed.value (), bad_peers));
} }
else if (status == work_generation_status::failure_local || status == work_generation_status::failure_peers) else if (status == work_generation_status::failure_local || status == work_generation_status::failure_peers)
{ {
node_l->websocket_server->broadcast (builder.work_failed (request.version, request.root, request.difficulty, node_l->default_difficulty (request.version), elapsed.value (), bad_peers)); node_l->websocket_server->broadcast (builder.work_failed (request.version, request.root.as_block_hash (), request.difficulty, node_l->default_difficulty (request.version), elapsed.value (), bad_peers));
} }
} }
stop_once (true); stop_once (true);

View file

@ -394,8 +394,8 @@ uint64_t nano::json_handler::difficulty_ledger (nano::block const & block_a)
auto link (block_a.link ()); auto link (block_a.link ());
if (!link.is_zero () && !details.is_send) if (!link.is_zero () && !details.is_send)
{ {
auto block_link (node.store.block_get (transaction, link)); auto block_link (node.store.block_get (transaction, link.as_block_hash ()));
if (block_link != nullptr && node.store.pending_exists (transaction, nano::pending_key (block_a.account (), link))) if (block_link != nullptr && node.store.pending_exists (transaction, nano::pending_key (block_a.account (), link.as_block_hash ())))
{ {
details.epoch = std::max (details.epoch, block_link->sideband ().details.epoch); details.epoch = std::max (details.epoch, block_link->sideband ().details.epoch);
details.is_receive = true; details.is_receive = true;
@ -2246,7 +2246,7 @@ public:
auto previous_balance (handler.node.ledger.balance (transaction, block_a.hashables.previous)); auto previous_balance (handler.node.ledger.balance (transaction, block_a.hashables.previous));
if (balance < previous_balance) if (balance < previous_balance)
{ {
if (should_ignore_account (block_a.hashables.link)) if (should_ignore_account (block_a.hashables.link.as_account ()))
{ {
tree.clear (); tree.clear ();
return; return;
@ -2281,7 +2281,7 @@ public:
} }
else else
{ {
auto account (handler.node.ledger.account (transaction, block_a.hashables.link)); auto account (handler.node.ledger.account (transaction, block_a.hashables.link.as_block_hash ()));
if (should_ignore_account (account)) if (should_ignore_account (account))
{ {
tree.clear (); tree.clear ();

View file

@ -673,7 +673,7 @@ void nano::mdb_store::upgrade_v18_to_v19 (nano::write_transaction const & transa
// Source block v18 epoch // Source block v18 epoch
if (old_sideband.details.is_receive) if (old_sideband.details.is_receive)
{ {
auto db_val (block_raw_get_by_type_v18 (transaction_a, block_w_sideband_v18.block->link (), type_state)); auto db_val (block_raw_get_by_type_v18 (transaction_a, block_w_sideband_v18.block->link ().as_block_hash (), type_state));
if (db_val.is_initialized ()) if (db_val.is_initialized ())
{ {
nano::bufferstream stream (reinterpret_cast<uint8_t const *> (db_val.get ().data ()), db_val.get ().size ()); nano::bufferstream stream (reinterpret_cast<uint8_t const *> (db_val.get ().data ()), db_val.get ().size ());

View file

@ -536,13 +536,13 @@ void nano::node::process_fork (nano::transaction const & transaction_a, std::sha
nano::account account{ 0 }; nano::account account{ 0 };
if (root_block_type == nano::block_type::receive || root_block_type == nano::block_type::send || root_block_type == nano::block_type::change || root_block_type == nano::block_type::open) if (root_block_type == nano::block_type::receive || root_block_type == nano::block_type::send || root_block_type == nano::block_type::change || root_block_type == nano::block_type::open)
{ {
account = this_l->ledger.store.frontier_get (transaction, root); account = this_l->ledger.store.frontier_get (transaction, root.as_block_hash ());
} }
if (!account.is_zero ()) if (!account.is_zero ())
{ {
this_l->bootstrap_initiator.connections->requeue_pull (nano::pull_info (account, root, root, attempt->incremental_id)); this_l->bootstrap_initiator.connections->requeue_pull (nano::pull_info (account, root.as_block_hash (), root.as_block_hash (), attempt->incremental_id));
} }
else if (this_l->ledger.store.account_exists (transaction, root)) else if (this_l->ledger.store.account_exists (transaction, root.as_account ()))
{ {
this_l->bootstrap_initiator.connections->requeue_pull (nano::pull_info (root, nano::block_hash (0), nano::block_hash (0), attempt->incremental_id)); this_l->bootstrap_initiator.connections->requeue_pull (nano::pull_info (root, nano::block_hash (0), nano::block_hash (0), attempt->incremental_id));
} }
@ -1211,7 +1211,7 @@ public:
} }
void state_block (nano::state_block const & block_a) override void state_block (nano::state_block const & block_a) override
{ {
scan_receivable (block_a.hashables.link); scan_receivable (block_a.hashables.link.as_account ());
} }
void send_block (nano::send_block const & block_a) override void send_block (nano::send_block const & block_a) override
{ {
@ -1265,7 +1265,7 @@ void nano::node::process_confirmed_data (nano::transaction const & transaction_a
{ {
is_state_send_a = true; is_state_send_a = true;
} }
pending_account_a = state->hashables.link; pending_account_a = state->hashables.link.as_account ();
} }
if (auto send = dynamic_cast<nano::send_block *> (block_a.get ())) if (auto send = dynamic_cast<nano::send_block *> (block_a.get ()))
{ {

View file

@ -174,12 +174,12 @@ std::vector<std::pair<nano::root, nano::block_hash>> nano::request_aggregator::a
if (block == nullptr && !hash_root.second.is_zero ()) if (block == nullptr && !hash_root.second.is_zero ())
{ {
// Search for block root // Search for block root
auto successor (ledger.store.block_successor (transaction_a, hash_root.second)); auto successor (ledger.store.block_successor (transaction_a, hash_root.second.as_block_hash ()));
// Search for account root // Search for account root
if (successor.is_zero ()) if (successor.is_zero ())
{ {
nano::account_info info; nano::account_info info;
auto error (ledger.store.account_get (transaction_a, hash_root.second, info)); auto error (ledger.store.account_get (transaction_a, hash_root.second.as_account (), info));
if (!error) if (!error)
{ {
successor = info.open_block; successor = info.open_block;

View file

@ -559,7 +559,7 @@ public:
{ {
type = "Send"; type = "Send";
amount = previous_balance - balance; amount = previous_balance - balance;
account = block_a.hashables.link; account = block_a.hashables.link.as_account ();
} }
else else
{ {
@ -576,7 +576,7 @@ public:
else else
{ {
type = "Receive"; type = "Receive";
account = ledger.account (transaction, block_a.hashables.link); account = ledger.account (transaction, block_a.hashables.link.as_block_hash ());
} }
amount = balance - previous_balance; amount = balance - previous_balance;
} }

View file

@ -2820,7 +2820,7 @@ TEST (rpc, work_generate_block_high)
rpc.start (); rpc.start ();
nano::keypair key; nano::keypair key;
nano::state_block block (key.pub, 0, nano::dev_genesis_key.pub, nano::Gxrb_ratio, 123, key.prv, key.pub, *node->work_generate_blocking (key.pub)); nano::state_block block (key.pub, 0, nano::dev_genesis_key.pub, nano::Gxrb_ratio, 123, key.prv, key.pub, *node->work_generate_blocking (key.pub));
nano::block_hash hash (block.root ()); nano::block_hash hash (block.root ().as_block_hash ());
auto block_difficulty (nano::work_difficulty (nano::work_version::work_1, hash, block.block_work ())); auto block_difficulty (nano::work_difficulty (nano::work_version::work_1, hash, block.block_work ()));
boost::property_tree::ptree request; boost::property_tree::ptree request;
request.put ("action", "work_generate"); request.put ("action", "work_generate");
@ -2853,8 +2853,8 @@ TEST (rpc, work_generate_block_low)
nano::keypair key; nano::keypair key;
nano::state_block block (key.pub, 0, nano::dev_genesis_key.pub, nano::Gxrb_ratio, 123, key.prv, key.pub, 0); nano::state_block block (key.pub, 0, nano::dev_genesis_key.pub, nano::Gxrb_ratio, 123, key.prv, key.pub, 0);
auto threshold (node->default_difficulty (block.work_version ())); auto threshold (node->default_difficulty (block.work_version ()));
block.block_work_set (system.work_generate_limited (block.root (), threshold, nano::difficulty::from_multiplier (node->config.max_work_generate_multiplier / 10, threshold))); block.block_work_set (system.work_generate_limited (block.root ().as_block_hash (), threshold, nano::difficulty::from_multiplier (node->config.max_work_generate_multiplier / 10, threshold)));
nano::block_hash hash (block.root ()); nano::block_hash hash (block.root ().as_block_hash ());
auto block_difficulty (block.difficulty ()); auto block_difficulty (block.difficulty ());
boost::property_tree::ptree request; boost::property_tree::ptree request;
request.put ("action", "work_generate"); request.put ("action", "work_generate");
@ -2935,8 +2935,8 @@ TEST (rpc, work_generate_block_ledger_epoch_2)
rpc.start (); rpc.start ();
nano::state_block block (key.pub, 0, nano::dev_genesis_key.pub, nano::Gxrb_ratio, send_block->hash (), key.prv, key.pub, 0); nano::state_block block (key.pub, 0, nano::dev_genesis_key.pub, nano::Gxrb_ratio, send_block->hash (), key.prv, key.pub, 0);
auto threshold (nano::work_threshold (block.work_version (), nano::block_details (nano::epoch::epoch_2, false, true, false))); auto threshold (nano::work_threshold (block.work_version (), nano::block_details (nano::epoch::epoch_2, false, true, false)));
block.block_work_set (system.work_generate_limited (block.root (), 1, threshold - 1)); block.block_work_set (system.work_generate_limited (block.root ().as_block_hash (), 1, threshold - 1));
nano::block_hash hash (block.root ()); nano::block_hash hash (block.root ().as_block_hash ());
boost::property_tree::ptree request; boost::property_tree::ptree request;
request.put ("action", "work_generate"); request.put ("action", "work_generate");
request.put ("hash", hash.to_string ()); request.put ("hash", hash.to_string ());

View file

@ -155,7 +155,7 @@ public:
bool root_exists (nano::transaction const & transaction_a, nano::root const & root_a) override bool root_exists (nano::transaction const & transaction_a, nano::root const & root_a) override
{ {
return block_exists (transaction_a, root_a) || account_exists (transaction_a, root_a); return block_exists (transaction_a, root_a.as_block_hash ()) || account_exists (transaction_a, root_a.as_account ());
} }
nano::account block_account (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const override nano::account block_account (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const override

View file

@ -133,18 +133,18 @@ public:
if (is_send) if (is_send)
{ {
nano::pending_key key (block_a.hashables.link, hash); nano::pending_key key (block_a.hashables.link.as_account (), hash);
while (!error && !ledger.store.pending_exists (transaction, key)) while (!error && !ledger.store.pending_exists (transaction, key))
{ {
error = ledger.rollback (transaction, ledger.latest (transaction, block_a.hashables.link), list); error = ledger.rollback (transaction, ledger.latest (transaction, block_a.hashables.link.as_account ()), list);
} }
ledger.store.pending_del (transaction, key); ledger.store.pending_del (transaction, key);
ledger.stats.inc (nano::stat::type::rollback, nano::stat::detail::send); ledger.stats.inc (nano::stat::type::rollback, nano::stat::detail::send);
} }
else if (!block_a.hashables.link.is_zero () && !ledger.is_epoch_link (block_a.hashables.link)) else if (!block_a.hashables.link.is_zero () && !ledger.is_epoch_link (block_a.hashables.link))
{ {
nano::pending_info pending_info (ledger.account (transaction, block_a.hashables.link), block_a.hashables.balance.number () - balance, block_a.sideband ().source_epoch); nano::pending_info pending_info (ledger.account (transaction, block_a.hashables.link.as_block_hash ()), block_a.hashables.balance.number () - balance, block_a.sideband ().source_epoch);
ledger.store.pending_put (transaction, nano::pending_key (block_a.hashables.account, block_a.hashables.link), pending_info); ledger.store.pending_put (transaction, nano::pending_key (block_a.hashables.account, block_a.hashables.link.as_block_hash ()), pending_info);
ledger.stats.inc (nano::stat::type::rollback, nano::stat::detail::receive); ledger.stats.inc (nano::stat::type::rollback, nano::stat::detail::receive);
} }
@ -316,10 +316,10 @@ void ledger_processor::state_block_impl (nano::state_block & block_a)
{ {
if (!block_a.hashables.link.is_zero ()) if (!block_a.hashables.link.is_zero ())
{ {
result.code = ledger.store.block_exists (transaction, block_a.hashables.link) ? nano::process_result::progress : nano::process_result::gap_source; // Have we seen the source block already? (Harmless) result.code = ledger.store.block_exists (transaction, block_a.hashables.link.as_block_hash ()) ? nano::process_result::progress : nano::process_result::gap_source; // Have we seen the source block already? (Harmless)
if (result.code == nano::process_result::progress) if (result.code == nano::process_result::progress)
{ {
nano::pending_key key (block_a.hashables.account, block_a.hashables.link); nano::pending_key key (block_a.hashables.account, block_a.hashables.link.as_block_hash ());
nano::pending_info pending; nano::pending_info pending;
result.code = ledger.store.pending_get (transaction, key, pending) ? nano::process_result::unreceivable : nano::process_result::progress; // Has this source already been received (Malformed) result.code = ledger.store.pending_get (transaction, key, pending) ? nano::process_result::unreceivable : nano::process_result::progress; // Has this source already been received (Malformed)
if (result.code == nano::process_result::progress) if (result.code == nano::process_result::progress)
@ -360,13 +360,13 @@ void ledger_processor::state_block_impl (nano::state_block & block_a)
if (is_send) if (is_send)
{ {
nano::pending_key key (block_a.hashables.link, hash); nano::pending_key key (block_a.hashables.link.as_account (), hash);
nano::pending_info info (block_a.hashables.account, amount.number (), epoch); nano::pending_info info (block_a.hashables.account, amount.number (), epoch);
ledger.store.pending_put (transaction, key, info); ledger.store.pending_put (transaction, key, info);
} }
else if (!block_a.hashables.link.is_zero ()) else if (!block_a.hashables.link.is_zero ())
{ {
ledger.store.pending_del (transaction, nano::pending_key (block_a.hashables.account, block_a.hashables.link)); ledger.store.pending_del (transaction, nano::pending_key (block_a.hashables.account, block_a.hashables.link.as_block_hash ()));
} }
nano::account_info new_info (hash, block_a.representative (), info.open_block.is_zero () ? hash : info.open_block, block_a.hashables.balance, nano::seconds_since_epoch (), info.block_count + 1, epoch); nano::account_info new_info (hash, block_a.representative (), info.open_block.is_zero () ? hash : info.open_block, block_a.hashables.balance, nano::seconds_since_epoch (), info.block_count + 1, epoch);
@ -883,7 +883,7 @@ nano::account const & nano::ledger::block_destination (nano::transaction const &
} }
else if (state_block != nullptr && is_send (transaction_a, *state_block)) else if (state_block != nullptr && is_send (transaction_a, *state_block))
{ {
return state_block->hashables.link; return state_block->hashables.link.as_account ();
} }
static nano::account result (0); static nano::account result (0);
return result; return result;
@ -904,7 +904,7 @@ nano::block_hash nano::ledger::block_source (nano::transaction const & transacti
nano::state_block const * state_block (dynamic_cast<nano::state_block const *> (&block_a)); nano::state_block const * state_block (dynamic_cast<nano::state_block const *> (&block_a));
if (state_block != nullptr && !is_send (transaction_a, *state_block)) if (state_block != nullptr && !is_send (transaction_a, *state_block))
{ {
result = state_block->hashables.link; result = state_block->hashables.link.as_block_hash ();
} }
return result; return result;
} }
@ -1086,7 +1086,7 @@ public:
void state_block (nano::state_block const & block_a) override void state_block (nano::state_block const & block_a) override
{ {
result[0] = block_a.hashables.previous; result[0] = block_a.hashables.previous;
result[1] = block_a.hashables.link; result[1] = block_a.hashables.link.as_block_hash ();
// ledger.is_send will check the sideband first, if block_a has a loaded sideband the check that previous block exists can be skipped // ledger.is_send will check the sideband first, if block_a has a loaded sideband the check that previous block exists can be skipped
if (ledger.is_epoch_link (block_a.hashables.link) || ((block_a.has_sideband () || ledger.store.block_exists (transaction, block_a.hashables.previous)) && ledger.is_send (transaction, block_a))) if (ledger.is_epoch_link (block_a.hashables.link) || ((block_a.has_sideband () || ledger.store.block_exists (transaction, block_a.hashables.previous)) && ledger.is_send (transaction, block_a)))
{ {
@ -1148,7 +1148,7 @@ std::shared_ptr<nano::block> nano::ledger::successor (nano::transaction const &
if (root_a.previous ().is_zero ()) if (root_a.previous ().is_zero ())
{ {
nano::account_info info; nano::account_info info;
if (!store.account_get (transaction_a, root_a.root (), info)) if (!store.account_get (transaction_a, root_a.root ().as_account (), info))
{ {
successor = info.open_block; successor = info.open_block;
} }
@ -1179,12 +1179,12 @@ std::shared_ptr<nano::block> nano::ledger::forked_block (nano::transaction const
{ {
debug_assert (!store.block_exists (transaction_a, block_a.hash ())); debug_assert (!store.block_exists (transaction_a, block_a.hash ()));
auto root (block_a.root ()); auto root (block_a.root ());
debug_assert (store.block_exists (transaction_a, root) || store.account_exists (transaction_a, root)); debug_assert (store.block_exists (transaction_a, root.as_block_hash ()) || store.account_exists (transaction_a, root.as_account ()));
auto result (store.block_get (transaction_a, store.block_successor (transaction_a, root))); auto result (store.block_get (transaction_a, store.block_successor (transaction_a, root.as_block_hash ())));
if (result == nullptr) if (result == nullptr)
{ {
nano::account_info info; nano::account_info info;
auto error (store.account_get (transaction_a, root, info)); auto error (store.account_get (transaction_a, root.as_account (), info));
(void)error; (void)error;
debug_assert (!error); debug_assert (!error);
result = store.block_get (transaction_a, info.open_block); result = store.block_get (transaction_a, info.open_block);