Adding work to confirm_ack and short-circuiting work generation by copying.
This commit is contained in:
parent
6f2bdf9a66
commit
4e8073f805
5 changed files with 104 additions and 52 deletions
|
@ -319,8 +319,19 @@ void rai::network::receive_action (boost::system::error_code const & error, size
|
|||
receive ();
|
||||
if (!error)
|
||||
{
|
||||
++confirm_ack_count;
|
||||
client.processor.process_message (incoming, sender);
|
||||
if (!work.validate (client.store.root (*incoming.vote.block), incoming.work))
|
||||
{
|
||||
++confirm_ack_count;
|
||||
client.processor.process_message (incoming, sender);
|
||||
}
|
||||
else
|
||||
{
|
||||
++insufficient_work_count;
|
||||
if (insufficient_work_logging ())
|
||||
{
|
||||
client.log.add ("Insufficient work for confirm_ack");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1029,7 +1040,7 @@ void rai::election::announce_vote ()
|
|||
{
|
||||
auto winner_l (votes.winner ());
|
||||
assert (winner_l.first != nullptr);
|
||||
client->network.confirm_block (std::move (winner_l.first), votes.sequence);
|
||||
client->network.confirm_block (std::move (winner_l.first), work, votes.sequence);
|
||||
auto now (std::chrono::system_clock::now ());
|
||||
if (now - last_vote < std::chrono::seconds (15))
|
||||
{
|
||||
|
@ -1038,11 +1049,12 @@ void rai::election::announce_vote ()
|
|||
}
|
||||
}
|
||||
|
||||
void rai::network::confirm_block (std::unique_ptr <rai::block> block_a, uint64_t sequence_a)
|
||||
void rai::network::confirm_block (std::unique_ptr <rai::block> block_a, rai::uint256_union const & work_a, uint64_t sequence_a)
|
||||
{
|
||||
rai::confirm_ack confirm (std::move (block_a));
|
||||
confirm.vote.address = client.representative;
|
||||
confirm.vote.sequence = sequence_a;
|
||||
confirm.work = work_a;
|
||||
rai::private_key prv;
|
||||
auto error (client.wallet.fetch (client.representative, prv));
|
||||
assert (!error);
|
||||
|
@ -1070,13 +1082,13 @@ void rai::network::confirm_block (std::unique_ptr <rai::block> block_a, uint64_t
|
|||
}
|
||||
}
|
||||
|
||||
void rai::processor::process_receive_republish (std::unique_ptr <rai::block> incoming, rai::endpoint const & sender_a)
|
||||
void rai::processor::process_receive_republish (std::unique_ptr <rai::block> incoming, std::function <rai::uint256_union (rai::block const &)> work_a, rai::endpoint const & sender_a)
|
||||
{
|
||||
std::unique_ptr <rai::block> block (std::move (incoming));
|
||||
do
|
||||
{
|
||||
auto hash (block->hash ());
|
||||
auto process_result (process_receive (*block));
|
||||
auto process_result (process_receive (*block, work_a));
|
||||
switch (process_result)
|
||||
{
|
||||
case rai::process_result::progress:
|
||||
|
@ -1100,9 +1112,10 @@ namespace
|
|||
class receivable_visitor : public rai::block_visitor
|
||||
{
|
||||
public:
|
||||
receivable_visitor (rai::client & client_a, rai::block const & incoming_a) :
|
||||
receivable_visitor (rai::client & client_a, rai::block const & incoming_a, rai::uint256_union const & work_a) :
|
||||
client (client_a),
|
||||
incoming (incoming_a)
|
||||
incoming (incoming_a),
|
||||
work (work_a)
|
||||
{
|
||||
}
|
||||
void send_block (rai::send_block const & block_a) override
|
||||
|
@ -1111,7 +1124,7 @@ public:
|
|||
{
|
||||
auto root (incoming.previous ());
|
||||
assert (!root.is_zero ());
|
||||
client.conflicts.start (block_a, true);
|
||||
client.conflicts.start (block_a, work, true);
|
||||
}
|
||||
}
|
||||
void receive_block (rai::receive_block const &) override
|
||||
|
@ -1125,6 +1138,7 @@ public:
|
|||
}
|
||||
rai::client & client;
|
||||
rai::block const & incoming;
|
||||
rai::uint256_union work;
|
||||
};
|
||||
|
||||
class progress_log_visitor : public rai::block_visitor
|
||||
|
@ -1170,7 +1184,7 @@ public:
|
|||
};
|
||||
}
|
||||
|
||||
rai::process_result rai::processor::process_receive (rai::block const & block_a)
|
||||
rai::process_result rai::processor::process_receive (rai::block const & block_a, std::function <rai::uint256_union (rai::block const &)> work_a)
|
||||
{
|
||||
auto result (client.ledger.process (block_a));
|
||||
switch (result)
|
||||
|
@ -1182,7 +1196,7 @@ rai::process_result rai::processor::process_receive (rai::block const & block_a)
|
|||
progress_log_visitor logger (client);
|
||||
block_a.visit (logger);
|
||||
}
|
||||
receivable_visitor visitor (client, block_a);
|
||||
receivable_visitor visitor (client, block_a, work_a (block_a));
|
||||
block_a.visit (visitor);
|
||||
break;
|
||||
}
|
||||
|
@ -1252,7 +1266,7 @@ rai::process_result rai::processor::process_receive (rai::block const & block_a)
|
|||
{
|
||||
client.log.add (boost::str (boost::format ("Fork source for: %1%") % block_a.hash ().to_string ()));
|
||||
}
|
||||
client.conflicts.start (*client.ledger.successor (client.store.root (block_a)), false);
|
||||
client.conflicts.start (*client.ledger.successor (client.store.root (block_a)), work_a (block_a), false);
|
||||
break;
|
||||
}
|
||||
case rai::process_result::fork_previous:
|
||||
|
@ -1261,7 +1275,7 @@ rai::process_result rai::processor::process_receive (rai::block const & block_a)
|
|||
{
|
||||
client.log.add (boost::str (boost::format ("Fork previous for: %1%") % block_a.hash ().to_string ()));
|
||||
}
|
||||
client.conflicts.start (*client.ledger.successor (client.store.root (block_a)), false);
|
||||
client.conflicts.start (*client.ledger.successor (client.store.root (block_a)), work_a (block_a), false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1395,7 +1409,7 @@ void rai::processor::process_unknown (rai::vectorstream & stream_a)
|
|||
outgoing.serialize (stream_a);
|
||||
}
|
||||
|
||||
void rai::processor::process_confirmation (rai::block const & block_a, rai::endpoint const & sender)
|
||||
void rai::processor::process_confirmation (rai::block const & block_a, rai::uint256_union const & work_a, rai::endpoint const & sender)
|
||||
{
|
||||
std::shared_ptr <std::vector <uint8_t>> bytes (new std::vector <uint8_t>);
|
||||
{
|
||||
|
@ -1419,6 +1433,7 @@ void rai::processor::process_confirmation (rai::block const & block_a, rai::endp
|
|||
rai::confirm_ack outgoing (block_a.clone ());
|
||||
outgoing.vote.address = client.representative;
|
||||
outgoing.vote.sequence = 0;
|
||||
outgoing.work = work_a;
|
||||
rai::sign_message (prv, client.representative, outgoing.vote.hash (), outgoing.vote.signature);
|
||||
assert (!rai::validate_message (client.representative, outgoing.vote.hash (), outgoing.vote.signature));
|
||||
outgoing.serialize (stream);
|
||||
|
@ -1475,8 +1490,12 @@ bool rai::confirm_ack::deserialize (rai::stream & stream_a)
|
|||
result = read (stream_a, vote.sequence);
|
||||
if (!result)
|
||||
{
|
||||
vote.block = rai::deserialize_block (stream_a, block_type ());
|
||||
result = vote.block == nullptr;
|
||||
result = read (stream_a, work);
|
||||
if (!result)
|
||||
{
|
||||
vote.block = rai::deserialize_block (stream_a, block_type ());
|
||||
result = vote.block == nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1490,12 +1509,13 @@ void rai::confirm_ack::serialize (rai::stream & stream_a)
|
|||
write (stream_a, vote.address);
|
||||
write (stream_a, vote.signature);
|
||||
write (stream_a, vote.sequence);
|
||||
write (stream_a, work);
|
||||
vote.block->serialize (stream_a);
|
||||
}
|
||||
|
||||
bool rai::confirm_ack::operator == (rai::confirm_ack const & other_a) const
|
||||
{
|
||||
auto result (vote.address == other_a.vote.address && *vote.block == *other_a.vote.block && vote.signature == other_a.vote.signature && vote.sequence == other_a.vote.sequence);
|
||||
auto result (vote.address == other_a.vote.address && *vote.block == *other_a.vote.block && vote.signature == other_a.vote.signature && vote.sequence == other_a.vote.sequence && work == other_a.work);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -2678,7 +2698,11 @@ bool rai::bulk_req_initiator::process_end ()
|
|||
block = connection->client->store.bootstrap_get (expecting);
|
||||
if (block != nullptr)
|
||||
{
|
||||
processing = connection->client->processor.process_receive (*block);
|
||||
auto connection_l (connection);
|
||||
processing = connection->client->processor.process_receive (*block, [connection_l] (rai::block const & block_a)
|
||||
{
|
||||
return connection_l->client->create_work (block_a);
|
||||
});
|
||||
expecting = block->hash ();
|
||||
}
|
||||
} while (block != nullptr && processing == rai::process_result::progress);
|
||||
|
@ -3341,6 +3365,14 @@ bool rai::peer_container::known_peer (rai::endpoint const & endpoint_a)
|
|||
return existing != peers.end () && existing->last_contact > std::chrono::system_clock::now () - rai::processor::cutoff;
|
||||
}
|
||||
|
||||
rai::uint256_union rai::client::create_work (rai::block const & block_a)
|
||||
{
|
||||
auto root (store.root (block_a));
|
||||
rai::work work;
|
||||
auto proof (work.create (root));
|
||||
return proof;
|
||||
}
|
||||
|
||||
std::shared_ptr <rai::client> rai::client::shared ()
|
||||
{
|
||||
return shared_from_this ();
|
||||
|
@ -3485,13 +3517,14 @@ bool rai::transactions::receive (rai::send_block const & send_a, rai::private_ke
|
|||
{
|
||||
rai::frontier frontier;
|
||||
auto new_address (client.ledger.store.latest_get (send_a.hashables.destination, frontier));
|
||||
std::unique_ptr <rai::block> block;
|
||||
if (new_address)
|
||||
{
|
||||
auto open (new rai::open_block);
|
||||
open->hashables.source = hash;
|
||||
open->hashables.representative = representative_a;
|
||||
rai::sign_message (prv_a, send_a.hashables.destination, open->hash (), open->signature);
|
||||
client.processor.process_receive_republish (std::unique_ptr <rai::block> (open), rai::endpoint {});
|
||||
block.reset (open);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -3499,8 +3532,12 @@ bool rai::transactions::receive (rai::send_block const & send_a, rai::private_ke
|
|||
receive->hashables.previous = frontier.hash;
|
||||
receive->hashables.source = hash;
|
||||
rai::sign_message (prv_a, send_a.hashables.destination, receive->hash (), receive->signature);
|
||||
client.processor.process_receive_republish (std::unique_ptr <rai::block> (receive), rai::endpoint {});
|
||||
block.reset (receive);
|
||||
}
|
||||
auto root (client.store.root (*block));
|
||||
rai::work work;
|
||||
auto proof (work.create (root));
|
||||
client.processor.process_receive_republish (std::move (block), [proof] (rai::block const &) {return proof;}, rai::endpoint {});
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
|
@ -3523,7 +3560,10 @@ bool rai::transactions::send (rai::address const & address_a, rai::uint128_t con
|
|||
{
|
||||
for (auto i (blocks.begin ()), j (blocks.end ()); i != j; ++i)
|
||||
{
|
||||
client.processor.process_receive_republish (std::move (*i), rai::endpoint {});
|
||||
auto root (client.store.root (**i));
|
||||
rai::work work;
|
||||
auto proof (work.create (root));
|
||||
client.processor.process_receive_republish (std::move (*i), [proof] (rai::block const &) {return proof;}, rai::endpoint {});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3534,11 +3574,12 @@ bool rai::transactions::send (rai::address const & address_a, rai::uint128_t con
|
|||
return result;
|
||||
}
|
||||
|
||||
rai::election::election (std::shared_ptr <rai::client> client_a, rai::block const & block_a) :
|
||||
rai::election::election (std::shared_ptr <rai::client> client_a, rai::block const & block_a, rai::uint256_union const & work_a) :
|
||||
votes (client_a->ledger, block_a),
|
||||
client (client_a),
|
||||
last_vote (std::chrono::system_clock::now ()),
|
||||
confirmed (false)
|
||||
confirmed (false),
|
||||
work (work_a)
|
||||
{
|
||||
assert (client_a->store.block_exists (block_a.hash ()));
|
||||
rai::keypair anonymous;
|
||||
|
@ -3593,14 +3634,14 @@ rai::uint256_t rai::election::contested_threshold ()
|
|||
return (client->ledger.supply () / 16) * 15;
|
||||
}
|
||||
|
||||
void rai::conflicts::start (rai::block const & block_a, bool request_a)
|
||||
void rai::conflicts::start (rai::block const & block_a, rai::uint256_union const & work_a, bool request_a)
|
||||
{
|
||||
std::lock_guard <std::mutex> lock (mutex);
|
||||
auto root (client.store.root (block_a));
|
||||
auto existing (roots.find (root));
|
||||
if (existing == roots.end ())
|
||||
{
|
||||
auto election (std::make_shared <rai::election> (client.shared (), block_a));
|
||||
auto election (std::make_shared <rai::election> (client.shared (), block_a, work_a));
|
||||
client.service.add (std::chrono::system_clock::now (), [election] () {election->start ();});
|
||||
roots.insert (std::make_pair (root, election));
|
||||
if (request_a)
|
||||
|
@ -3637,7 +3678,7 @@ namespace
|
|||
class network_message_visitor : public rai::message_visitor
|
||||
{
|
||||
public:
|
||||
network_message_visitor (rai::client & client_a, rai::endpoint const & sender_a) :
|
||||
network_message_visitor (rai::client & client_a, rai::endpoint const & sender_a) :
|
||||
client (client_a),
|
||||
sender (sender_a),
|
||||
bootstrap_count (0)
|
||||
|
@ -3665,7 +3706,8 @@ public:
|
|||
{
|
||||
client.log.add (boost::str (boost::format ("Received publish req from %1%") % sender));
|
||||
}
|
||||
client.processor.process_receive_republish (message_a.block->clone (), sender);
|
||||
auto proof (message_a.work);
|
||||
client.processor.process_receive_republish (message_a.block->clone (), [proof] (rai::block const &) {return proof;}, sender);
|
||||
}
|
||||
void confirm_req (rai::confirm_req const & message_a) override
|
||||
{
|
||||
|
@ -3673,10 +3715,11 @@ public:
|
|||
{
|
||||
client.log.add (boost::str (boost::format ("Received confirm req from %1%") % sender));
|
||||
}
|
||||
client.processor.process_receive_republish (message_a.block->clone (), sender);
|
||||
auto proof (message_a.work);
|
||||
client.processor.process_receive_republish (message_a.block->clone (), [proof] (rai::block const &) {return proof;}, sender);
|
||||
if (client.store.block_exists (message_a.block->hash ()))
|
||||
{
|
||||
client.processor.process_confirmation (*message_a.block, sender);
|
||||
client.processor.process_confirmation (*message_a.block, proof, sender);
|
||||
}
|
||||
}
|
||||
void confirm_ack (rai::confirm_ack const & message_a) override
|
||||
|
@ -3685,7 +3728,8 @@ public:
|
|||
{
|
||||
client.log.add (boost::str (boost::format ("Received Confirm from %1%") % sender));
|
||||
}
|
||||
client.processor.process_receive_republish (message_a.vote.block->clone (), sender);
|
||||
auto proof (message_a.work);
|
||||
client.processor.process_receive_republish (message_a.vote.block->clone (), [proof] (rai::block const &) {return proof;}, sender);
|
||||
client.conflicts.update (message_a.vote);
|
||||
}
|
||||
void confirm_unk (rai::confirm_unk const &) override
|
||||
|
|
|
@ -98,7 +98,7 @@ namespace rai {
|
|||
class election : public std::enable_shared_from_this <rai::election>
|
||||
{
|
||||
public:
|
||||
election (std::shared_ptr <rai::client>, rai::block const &);
|
||||
election (std::shared_ptr <rai::client>, rai::block const &, rai::uint256_union const &);
|
||||
void start ();
|
||||
void vote (rai::vote const &);
|
||||
void announce_vote ();
|
||||
|
@ -110,12 +110,13 @@ namespace rai {
|
|||
std::shared_ptr <rai::client> client;
|
||||
std::chrono::system_clock::time_point last_vote;
|
||||
bool confirmed;
|
||||
rai::uint256_union work;
|
||||
};
|
||||
class conflicts
|
||||
{
|
||||
public:
|
||||
conflicts (rai::client &);
|
||||
void start (rai::block const &, bool);
|
||||
void start (rai::block const &, rai::uint256_union const &, bool);
|
||||
void update (rai::vote const &);
|
||||
void stop (rai::block_hash const &);
|
||||
std::unordered_map <rai::block_hash, std::shared_ptr <rai::election>> roots;
|
||||
|
@ -371,12 +372,12 @@ namespace rai {
|
|||
void find_network (std::vector <std::pair <std::string, std::string>> const &);
|
||||
void bootstrap (rai::tcp_endpoint const &, std::function <void ()> const &);
|
||||
void connect_bootstrap (std::vector <std::string> const &);
|
||||
rai::process_result process_receive (rai::block const &);
|
||||
void process_receive_republish (std::unique_ptr <rai::block>, rai::endpoint const &);
|
||||
rai::process_result process_receive (rai::block const &, std::function <rai::uint256_union (rai::block const &)>);
|
||||
void process_receive_republish (std::unique_ptr <rai::block>, std::function <rai::uint256_union (rai::block const &)>, rai::endpoint const &);
|
||||
void republish (std::unique_ptr <rai::block>, rai::endpoint const &);
|
||||
void process_message (rai::message &, rai::endpoint const &);
|
||||
void process_unknown (rai::vectorstream &);
|
||||
void process_confirmation (rai::block const &, rai::endpoint const &);
|
||||
void process_confirmation (rai::block const &, rai::uint256_union const &, rai::endpoint const &);
|
||||
void process_confirmed (rai::block const &);
|
||||
void ongoing_keepalive ();
|
||||
rai::client & client;
|
||||
|
@ -462,7 +463,7 @@ namespace rai {
|
|||
void receive_action (boost::system::error_code const &, size_t);
|
||||
void rpc_action (boost::system::error_code const &, size_t);
|
||||
void publish_block (rai::endpoint const &, std::unique_ptr <rai::block>);
|
||||
void confirm_block (std::unique_ptr <rai::block>, uint64_t);
|
||||
void confirm_block (std::unique_ptr <rai::block>, rai::uint256_union const &, uint64_t);
|
||||
void merge_peers (std::array <rai::endpoint, 8> const &);
|
||||
void maintain_keepalive (rai::endpoint const &);
|
||||
void send_confirm_req (rai::endpoint const &, rai::block const &);
|
||||
|
@ -622,6 +623,7 @@ namespace rai {
|
|||
std::shared_ptr <rai::client> shared ();
|
||||
bool is_representative ();
|
||||
void representative_vote (rai::election &, rai::block const &);
|
||||
rai::uint256_union create_work (rai::block const &);
|
||||
rai::log log;
|
||||
rai::address representative;
|
||||
rai::block_store store;
|
||||
|
|
|
@ -125,8 +125,8 @@ TEST (client, send_out_of_order)
|
|||
send2.hashables.destination = key2.pub;
|
||||
send2.hashables.previous = send1.hash ();
|
||||
rai::sign_message (rai::test_genesis_key.prv, rai::test_genesis_key.pub, send2.hash (), send2.signature);
|
||||
system.clients [0]->processor.process_receive_republish (std::unique_ptr <rai::block> (new rai::send_block (send2)), rai::endpoint {});
|
||||
system.clients [0]->processor.process_receive_republish (std::unique_ptr <rai::block> (new rai::send_block (send1)), rai::endpoint {});
|
||||
system.clients [0]->processor.process_receive_republish (std::unique_ptr <rai::block> (new rai::send_block (send2)), [&system] (rai::block const & block_a) {return system.clients [0]->create_work (block_a);}, rai::endpoint {});
|
||||
system.clients [0]->processor.process_receive_republish (std::unique_ptr <rai::block> (new rai::send_block (send1)), [&system] (rai::block const & block_a) {return system.clients [0]->create_work (block_a);}, rai::endpoint {});
|
||||
while (std::any_of (system.clients.begin (), system.clients.end (), [&] (std::shared_ptr <rai::client> const & client_a) {return client_a->ledger.account_balance (rai::test_genesis_key.pub) != std::numeric_limits <rai::uint128_t>::max () - 2000;}))
|
||||
{
|
||||
system.service->run_one ();
|
||||
|
|
|
@ -795,7 +795,7 @@ TEST (votes, add_unsigned)
|
|||
send1.hashables.destination = key1.pub;
|
||||
rai::sign_message (rai::test_genesis_key.prv, rai::test_genesis_key.pub, send1.hash (), send1.signature);
|
||||
ASSERT_EQ (rai::process_result::progress, client1.ledger.process (send1));
|
||||
client1.conflicts.start (send1, false);
|
||||
client1.conflicts.start (send1, client1.create_work (send1), false);
|
||||
auto votes1 (client1.conflicts.roots.find (client1.store.root (send1))->second);
|
||||
ASSERT_NE (nullptr, votes1);
|
||||
ASSERT_EQ (1, votes1->votes.rep_votes.size ());
|
||||
|
@ -819,7 +819,7 @@ TEST (votes, add_one)
|
|||
send1.hashables.destination = key1.pub;
|
||||
rai::sign_message (rai::test_genesis_key.prv, rai::test_genesis_key.pub, send1.hash (), send1.signature);
|
||||
ASSERT_EQ (rai::process_result::progress, client1.ledger.process (send1));
|
||||
client1.conflicts.start (send1, false);
|
||||
client1.conflicts.start (send1, client1.create_work (send1), false);
|
||||
auto votes1 (client1.conflicts.roots.find (client1.store.root (send1))->second);
|
||||
ASSERT_EQ (1, votes1->votes.rep_votes.size ());
|
||||
rai::vote vote1;
|
||||
|
@ -849,7 +849,7 @@ TEST (votes, add_two)
|
|||
send1.hashables.destination = key1.pub;
|
||||
rai::sign_message (rai::test_genesis_key.prv, rai::test_genesis_key.pub, send1.hash (), send1.signature);
|
||||
ASSERT_EQ (rai::process_result::progress, client1.ledger.process (send1));
|
||||
client1.conflicts.start (send1, false);
|
||||
client1.conflicts.start (send1, client1.create_work (send1), false);
|
||||
auto votes1 (client1.conflicts.roots.find (client1.store.root (send1))->second);
|
||||
rai::vote vote1;
|
||||
vote1.sequence = 1;
|
||||
|
@ -890,7 +890,7 @@ TEST (votes, add_existing)
|
|||
send1.hashables.destination = key1.pub;
|
||||
rai::sign_message (rai::test_genesis_key.prv, rai::test_genesis_key.pub, send1.hash (), send1.signature);
|
||||
ASSERT_EQ (rai::process_result::progress, client1.ledger.process (send1));
|
||||
client1.conflicts.start (send1, false);
|
||||
client1.conflicts.start (send1, client1.create_work (send1), false);
|
||||
auto votes1 (client1.conflicts.roots.find (client1.store.root (send1))->second);
|
||||
rai::vote vote1;
|
||||
vote1.sequence = 1;
|
||||
|
@ -929,7 +929,7 @@ TEST (votes, add_old)
|
|||
send1.hashables.destination = key1.pub;
|
||||
rai::sign_message (rai::test_genesis_key.prv, rai::test_genesis_key.pub, send1.hash (), send1.signature);
|
||||
ASSERT_EQ (rai::process_result::progress, client1.ledger.process (send1));
|
||||
client1.conflicts.start (send1, false);
|
||||
client1.conflicts.start (send1, client1.create_work (send1), false);
|
||||
auto votes1 (client1.conflicts.roots.find (client1.store.root (send1))->second);
|
||||
rai::vote vote1;
|
||||
vote1.sequence = 2;
|
||||
|
@ -969,7 +969,7 @@ TEST (conflicts, start_stop)
|
|||
rai::sign_message (rai::test_genesis_key.prv, rai::test_genesis_key.pub, send1.hash (), send1.signature);
|
||||
ASSERT_EQ (rai::process_result::progress, client1.ledger.process (send1));
|
||||
ASSERT_EQ (0, client1.conflicts.roots.size ());
|
||||
client1.conflicts.start (send1, false);
|
||||
client1.conflicts.start (send1, client1.create_work (send1), false);
|
||||
ASSERT_EQ (1, client1.conflicts.roots.size ());
|
||||
auto root1 (client1.store.root (send1));
|
||||
auto existing1 (client1.conflicts.roots.find (root1));
|
||||
|
@ -993,14 +993,14 @@ TEST (conflicts, add_existing)
|
|||
send1.hashables.destination = key1.pub;
|
||||
rai::sign_message (rai::test_genesis_key.prv, rai::test_genesis_key.pub, send1.hash (), send1.signature);
|
||||
ASSERT_EQ (rai::process_result::progress, client1.ledger.process (send1));
|
||||
client1.conflicts.start (send1, false);
|
||||
client1.conflicts.start (send1, client1.create_work (send1), false);
|
||||
rai::send_block send2;
|
||||
rai::keypair key2;
|
||||
send2.hashables.previous = genesis.hash ();
|
||||
send2.hashables.balance.clear ();
|
||||
send2.hashables.destination = key2.pub;
|
||||
rai::sign_message (rai::test_genesis_key.prv, rai::test_genesis_key.pub, send2.hash (), send2.signature);
|
||||
client1.conflicts.start (send2, false);
|
||||
client1.conflicts.start (send2, client1.create_work (send2), false);
|
||||
ASSERT_EQ (1, client1.conflicts.roots.size ());
|
||||
rai::vote vote1;
|
||||
vote1.address = key2.pub;
|
||||
|
@ -1027,7 +1027,7 @@ TEST (conflicts, add_two)
|
|||
send1.hashables.destination = key1.pub;
|
||||
rai::sign_message (rai::test_genesis_key.prv, rai::test_genesis_key.pub, send1.hash (), send1.signature);
|
||||
ASSERT_EQ (rai::process_result::progress, client1.ledger.process (send1));
|
||||
client1.conflicts.start (send1, false);
|
||||
client1.conflicts.start (send1, client1.create_work (send1), false);
|
||||
rai::send_block send2;
|
||||
rai::keypair key2;
|
||||
send2.hashables.previous = send1.hash ();
|
||||
|
@ -1035,7 +1035,7 @@ TEST (conflicts, add_two)
|
|||
send2.hashables.destination = key2.pub;
|
||||
rai::sign_message (rai::test_genesis_key.prv, rai::test_genesis_key.pub, send2.hash (), send2.signature);
|
||||
ASSERT_EQ (rai::process_result::progress, client1.ledger.process (send2));
|
||||
client1.conflicts.start (send2, false);
|
||||
client1.conflicts.start (send2, client1.create_work (send2), false);
|
||||
ASSERT_EQ (2, client1.conflicts.roots.size ());
|
||||
}
|
||||
|
||||
|
@ -1119,6 +1119,7 @@ TEST (ledger, fork_keep)
|
|||
rai::sign_message (rai::test_genesis_key.prv, rai::test_genesis_key.pub, send1->hash (), send1->signature);
|
||||
rai::publish publish1;
|
||||
publish1.block = std::move (send1);
|
||||
publish1.work = client1.create_work (*publish1.block);
|
||||
rai::keypair key2;
|
||||
std::unique_ptr <rai::send_block> send2 (new rai::send_block);
|
||||
send2->hashables.previous = genesis.hash ();
|
||||
|
@ -1127,6 +1128,7 @@ TEST (ledger, fork_keep)
|
|||
rai::sign_message (rai::test_genesis_key.prv, rai::test_genesis_key.pub, send2->hash (), send2->signature);
|
||||
rai::publish publish2;
|
||||
publish2.block = std::move (send2);
|
||||
publish2.work = client1.create_work (*publish2.block);
|
||||
client1.processor.process_message (publish1, rai::endpoint {});
|
||||
client2.processor.process_message (publish1, rai::endpoint {});
|
||||
ASSERT_EQ (0, client1.conflicts.roots.size ());
|
||||
|
@ -1173,6 +1175,7 @@ TEST (ledger, fork_flip)
|
|||
rai::sign_message (rai::test_genesis_key.prv, rai::test_genesis_key.pub, send1->hash (), send1->signature);
|
||||
rai::publish publish1;
|
||||
publish1.block = std::move (send1);
|
||||
publish1.work = client1.create_work (*publish1.block);
|
||||
rai::keypair key2;
|
||||
std::unique_ptr <rai::send_block> send2 (new rai::send_block);
|
||||
send2->hashables.previous = genesis.hash ();
|
||||
|
@ -1181,6 +1184,7 @@ TEST (ledger, fork_flip)
|
|||
rai::sign_message (rai::test_genesis_key.prv, rai::test_genesis_key.pub, send2->hash (), send2->signature);
|
||||
rai::publish publish2;
|
||||
publish2.block = std::move (send2);
|
||||
publish2.work = client1.create_work (*publish2.block);
|
||||
client1.processor.process_message (publish1, rai::endpoint {});
|
||||
client2.processor.process_message (publish2, rai::endpoint {});
|
||||
ASSERT_EQ (0, client1.conflicts.roots.size ());
|
||||
|
@ -1228,6 +1232,7 @@ TEST (ledger, fork_multi_flip)
|
|||
rai::sign_message (rai::test_genesis_key.prv, rai::test_genesis_key.pub, send1->hash (), send1->signature);
|
||||
rai::publish publish1;
|
||||
publish1.block = std::move (send1);
|
||||
publish1.work = client1.create_work (*publish1.block);
|
||||
rai::keypair key2;
|
||||
std::unique_ptr <rai::send_block> send2 (new rai::send_block);
|
||||
send2->hashables.previous = genesis.hash ();
|
||||
|
@ -1236,6 +1241,7 @@ TEST (ledger, fork_multi_flip)
|
|||
rai::sign_message (rai::test_genesis_key.prv, rai::test_genesis_key.pub, send2->hash (), send2->signature);
|
||||
rai::publish publish2;
|
||||
publish2.block = std::move (send2);
|
||||
publish2.work = client1.create_work (*publish2.block);
|
||||
std::unique_ptr <rai::send_block> send3 (new rai::send_block);
|
||||
send3->hashables.previous = publish2.block->hash ();
|
||||
send3->hashables.balance.clear ();
|
||||
|
|
|
@ -248,7 +248,7 @@ TEST (network, send_valid_publish)
|
|||
rai::sign_message (rai::test_genesis_key.prv, rai::test_genesis_key.pub, hash2, block2.signature);
|
||||
rai::frontier frontier2;
|
||||
ASSERT_FALSE (system.clients [1]->store.latest_get (rai::test_genesis_key.pub, frontier2));
|
||||
system.clients [0]->processor.process_receive_republish (std::unique_ptr <rai::block> (new rai::send_block (block2)), system.clients [0]->network.endpoint ());
|
||||
system.clients [0]->processor.process_receive_republish (std::unique_ptr <rai::block> (new rai::send_block (block2)), [&system] (rai::block const & block_a) {return system.clients [0]->create_work (block_a);}, system.clients [0]->network.endpoint ());
|
||||
auto iterations (0);
|
||||
while (system.clients [1]->network.publish_req_count == 0)
|
||||
{
|
||||
|
@ -299,7 +299,7 @@ TEST (receivable_processor, confirm_insufficient_pos)
|
|||
block1.hashables.balance.clear ();
|
||||
rai::sign_message (rai::test_genesis_key.prv, rai::test_genesis_key.pub, block1.hash (), block1.signature);
|
||||
ASSERT_EQ (rai::process_result::progress, client1.ledger.process (block1));
|
||||
client1.conflicts.start (block1, true);
|
||||
client1.conflicts.start (block1, client1.create_work (block1), true);
|
||||
rai::keypair key1;
|
||||
rai::confirm_ack con1;
|
||||
con1.vote.address = key1.pub;
|
||||
|
@ -318,7 +318,7 @@ TEST (receivable_processor, confirm_sufficient_pos)
|
|||
block1.hashables.balance.clear ();
|
||||
rai::sign_message (rai::test_genesis_key.prv, rai::test_genesis_key.pub, block1.hash (), block1.signature);
|
||||
ASSERT_EQ (rai::process_result::progress, client1.ledger.process (block1));
|
||||
client1.conflicts.start (block1, true);
|
||||
client1.conflicts.start (block1, client1.create_work (block1), true);
|
||||
rai::keypair key1;
|
||||
rai::confirm_ack con1;
|
||||
con1.vote.address = key1.pub;
|
||||
|
@ -351,7 +351,7 @@ TEST (receivable_processor, send_with_receive)
|
|||
ASSERT_EQ (0, system.clients [0]->ledger.account_balance (key2.pub));
|
||||
ASSERT_EQ (amount - 100, system.clients [1]->ledger.account_balance (rai::test_genesis_key.pub));
|
||||
ASSERT_EQ (0, system.clients [1]->ledger.account_balance (key2.pub));
|
||||
system.clients [1]->conflicts.start (*block1, true);
|
||||
system.clients [1]->conflicts.start (*block1, system.clients [1]->create_work (*block1), true);
|
||||
while (system.clients [0]->network.publish_req_count != 1)
|
||||
{
|
||||
system.service->run_one ();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue