Merge pull request #171 from SergiySW/fix_republish_block
Fix republish_block transaction. More than one transaction cannot be open in the same thread.
This commit is contained in:
commit
782fc16c4f
7 changed files with 36 additions and 27 deletions
|
@ -149,9 +149,10 @@ TEST (network, send_discarded_publish)
|
|||
{
|
||||
rai::system system (24000, 2);
|
||||
auto block (std::make_shared <rai::send_block> (1, 1, 2, rai::keypair ().prv, 4, system.work.generate (1)));
|
||||
system.nodes [0]->network.republish_block (block);
|
||||
rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false);
|
||||
system.nodes [0]->network.republish_block (transaction, block);
|
||||
rai::genesis genesis;
|
||||
ASSERT_EQ (genesis.hash (), system.nodes [0]->latest (rai::test_genesis_key.pub));
|
||||
ASSERT_EQ (genesis.hash (), system.nodes [0]->ledger.latest (transaction, rai::test_genesis_key.pub));
|
||||
ASSERT_EQ (genesis.hash (), system.nodes [1]->latest (rai::test_genesis_key.pub));
|
||||
auto iterations (0);
|
||||
while (system.nodes [1]->network.incoming.publish == 0)
|
||||
|
@ -160,7 +161,7 @@ TEST (network, send_discarded_publish)
|
|||
++iterations;
|
||||
ASSERT_LT (iterations, 200);
|
||||
}
|
||||
ASSERT_EQ (genesis.hash (), system.nodes [0]->latest (rai::test_genesis_key.pub));
|
||||
ASSERT_EQ (genesis.hash (), system.nodes [0]->ledger.latest (transaction, rai::test_genesis_key.pub));
|
||||
ASSERT_EQ (genesis.hash (), system.nodes [1]->latest (rai::test_genesis_key.pub));
|
||||
}
|
||||
|
||||
|
@ -168,9 +169,10 @@ TEST (network, send_invalid_publish)
|
|||
{
|
||||
rai::system system (24000, 2);
|
||||
auto block (std::make_shared <rai::send_block> (1, 1, 20, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (1)));
|
||||
system.nodes [0]->network.republish_block (block);
|
||||
rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false);
|
||||
system.nodes [0]->network.republish_block (transaction, block);
|
||||
rai::genesis genesis;
|
||||
ASSERT_EQ (genesis.hash (), system.nodes [0]->latest (rai::test_genesis_key.pub));
|
||||
ASSERT_EQ (genesis.hash (), system.nodes [0]->ledger.latest (transaction, rai::test_genesis_key.pub));
|
||||
ASSERT_EQ (genesis.hash (), system.nodes [1]->latest (rai::test_genesis_key.pub));
|
||||
auto iterations (0);
|
||||
while (system.nodes [1]->network.incoming.publish == 0)
|
||||
|
@ -179,7 +181,7 @@ TEST (network, send_invalid_publish)
|
|||
++iterations;
|
||||
ASSERT_LT (iterations, 200);
|
||||
}
|
||||
ASSERT_EQ (genesis.hash (), system.nodes [0]->latest (rai::test_genesis_key.pub));
|
||||
ASSERT_EQ (genesis.hash (), system.nodes [0]->ledger.latest (transaction, rai::test_genesis_key.pub));
|
||||
ASSERT_EQ (genesis.hash (), system.nodes [1]->latest (rai::test_genesis_key.pub));
|
||||
}
|
||||
|
||||
|
|
|
@ -636,7 +636,8 @@ TEST (node, confirm_locked)
|
|||
system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv);
|
||||
system.wallet (0)->enter_password ("1");
|
||||
auto block (std::make_shared <rai::send_block> (0, 0, 0, rai::keypair ().prv, 0, 0));
|
||||
system.nodes [0]->network.republish_block (block);
|
||||
rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false);
|
||||
system.nodes [0]->network.republish_block (transaction, block);
|
||||
}
|
||||
|
||||
TEST (node_config, random_rep)
|
||||
|
@ -655,7 +656,7 @@ TEST (node, block_replace)
|
|||
system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv);
|
||||
auto block1 (system.wallet (0)->send_action (rai::test_genesis_key.pub, 0, rai::Gxrb_ratio));
|
||||
auto block3 (system.wallet (0)->send_action (rai::test_genesis_key.pub, 0, rai::Gxrb_ratio));
|
||||
ASSERT_NE (nullptr, block1);
|
||||
ASSERT_NE (nullptr, block1);
|
||||
auto initial_work (block1->block_work ());
|
||||
while (system.work.work_value (block1->root (), block1->block_work ()) <= system.work.work_value (block1->root (), initial_work))
|
||||
{
|
||||
|
@ -665,7 +666,11 @@ TEST (node, block_replace)
|
|||
rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false);
|
||||
ASSERT_EQ (block3->hash (), system.nodes [0]->store.block_successor (transaction, block1->hash ()));
|
||||
}
|
||||
system.nodes [1]->network.republish_block (block1);
|
||||
for (auto i (0); i < 1; ++i)
|
||||
{
|
||||
rai::transaction transaction_a (system.nodes [1]->store.environment, nullptr, false);
|
||||
system.nodes [1]->network.republish_block (transaction_a, block1);
|
||||
}
|
||||
auto iterations1 (0);
|
||||
std::unique_ptr <rai::block> block2;
|
||||
while (block2 == nullptr)
|
||||
|
|
|
@ -165,16 +165,15 @@ void rai::network::rebroadcast_reps (std::shared_ptr <rai::block> block_a)
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
bool confirm_block (rai::node & node_a, T & list_a, std::shared_ptr <rai::block> block_a)
|
||||
bool confirm_block (MDB_txn * transaction_a, rai::node & node_a, T & list_a, std::shared_ptr <rai::block> block_a)
|
||||
{
|
||||
bool result (false);
|
||||
if (node_a.config.enable_voting)
|
||||
{
|
||||
rai::transaction transaction (node_a.store.environment, nullptr, false);
|
||||
node_a.wallets.foreach_representative (transaction, [&result, &block_a, &list_a, &node_a, &transaction] (rai::public_key const & pub_a, rai::raw_key const & prv_a)
|
||||
node_a.wallets.foreach_representative (transaction_a, [&result, &block_a, &list_a, &node_a, &transaction_a] (rai::public_key const & pub_a, rai::raw_key const & prv_a)
|
||||
{
|
||||
result = true;
|
||||
auto sequence (node_a.store.sequence_atomic_inc (transaction, pub_a));
|
||||
auto sequence (node_a.store.sequence_atomic_inc (transaction_a, pub_a));
|
||||
rai::vote vote (pub_a, prv_a, sequence, block_a);
|
||||
rai::confirm_ack confirm (vote);
|
||||
std::shared_ptr <std::vector <uint8_t>> bytes (new std::vector <uint8_t>);
|
||||
|
@ -192,21 +191,21 @@ bool confirm_block (rai::node & node_a, T & list_a, std::shared_ptr <rai::block>
|
|||
}
|
||||
|
||||
template <>
|
||||
bool confirm_block (rai::node & node_a, rai::endpoint & peer_a, std::shared_ptr <rai::block> block_a)
|
||||
bool confirm_block (MDB_txn * transaction_a, rai::node & node_a, rai::endpoint & peer_a, std::shared_ptr <rai::block> block_a)
|
||||
{
|
||||
std::array <rai::endpoint, 1> endpoints;
|
||||
endpoints [0] = peer_a;
|
||||
auto result (confirm_block (node_a, endpoints, std::move (block_a)));
|
||||
auto result (confirm_block (transaction_a, node_a, endpoints, std::move (block_a)));
|
||||
return result;
|
||||
}
|
||||
|
||||
void rai::network::republish_block (std::shared_ptr <rai::block> block)
|
||||
void rai::network::republish_block (MDB_txn * transaction, std::shared_ptr <rai::block> block)
|
||||
{
|
||||
rebroadcast_reps (block);
|
||||
auto hash (block->hash ());
|
||||
auto list (node.peers.list_sqrt ());
|
||||
// If we're a representative, broadcast a signed confirm, otherwise an unsigned publish
|
||||
if (!confirm_block (node, list, block))
|
||||
if (!confirm_block (transaction, node, list, block))
|
||||
{
|
||||
rai::publish message (block);
|
||||
std::shared_ptr <std::vector <uint8_t>> bytes (new std::vector <uint8_t>);
|
||||
|
@ -371,9 +370,10 @@ public:
|
|||
node.peers.contacted (sender, message_a.version_using);
|
||||
node.peers.insert (sender, message_a.version_using);
|
||||
node.process_receive_republish (message_a.block);
|
||||
if (node.ledger.block_exists (message_a.block->hash ()))
|
||||
rai::transaction transaction_a (node.store.environment, nullptr, false);
|
||||
if (node.store.block_exists (transaction_a, message_a.block->hash ()))
|
||||
{
|
||||
confirm_block (node, sender, message_a.block);
|
||||
confirm_block (transaction_a, node, sender, message_a.block);
|
||||
}
|
||||
}
|
||||
void confirm_ack (rai::confirm_ack const & message_a) override
|
||||
|
@ -2600,7 +2600,8 @@ void rai::election::broadcast_winner ()
|
|||
rai::transaction transaction (node.store.environment, nullptr, true);
|
||||
compute_rep_votes (transaction);
|
||||
}
|
||||
node.network.republish_block (last_winner);
|
||||
rai::transaction transaction_a (node.store.environment, nullptr, false);
|
||||
node.network.republish_block (transaction_a, last_winner);
|
||||
}
|
||||
|
||||
rai::uint128_t rai::election::quorum_threshold (MDB_txn * transaction_a, rai::ledger & ledger_a)
|
||||
|
|
|
@ -276,7 +276,7 @@ public:
|
|||
void rpc_action (boost::system::error_code const &, size_t);
|
||||
void rebroadcast_reps (std::shared_ptr <rai::block>);
|
||||
void republish_vote (std::chrono::system_clock::time_point const &, rai::vote const &);
|
||||
void republish_block (std::shared_ptr <rai::block>);
|
||||
void republish_block (MDB_txn *, std::shared_ptr <rai::block>);
|
||||
void republish (rai::block_hash const &, std::shared_ptr <std::vector <uint8_t>>, rai::endpoint);
|
||||
void publish_broadcast (std::vector <rai::peer_information> &, std::unique_ptr <rai::block>);
|
||||
void confirm_send (rai::confirm_ack const &, std::shared_ptr <std::vector <uint8_t>>, rai::endpoint const &);
|
||||
|
|
|
@ -2045,13 +2045,13 @@ void rai::rpc_handler::republish ()
|
|||
for (auto & hash_l : hashes)
|
||||
{
|
||||
block_a = node.store.block_get (transaction, hash_l);
|
||||
node.network.republish_block (std::move (block_a));
|
||||
node.network.republish_block (transaction, std::move (block_a));
|
||||
boost::property_tree::ptree entry_l;
|
||||
entry_l.put ("", hash_l.to_string ());
|
||||
blocks.push_back (std::make_pair ("", entry_l));
|
||||
}
|
||||
}
|
||||
node.network.republish_block (std::move (block)); // Republish block
|
||||
node.network.republish_block (transaction, std::move (block)); // Republish block
|
||||
boost::property_tree::ptree entry;
|
||||
entry.put ("", hash.to_string ());
|
||||
blocks.push_back (std::make_pair ("", entry));
|
||||
|
@ -2084,7 +2084,7 @@ void rai::rpc_handler::republish ()
|
|||
for (auto & hash_l : hashes)
|
||||
{
|
||||
block_d = node.store.block_get (transaction, hash_l);
|
||||
node.network.republish_block (std::move (block_d));
|
||||
node.network.republish_block (transaction, std::move (block_d));
|
||||
boost::property_tree::ptree entry_l;
|
||||
entry_l.put ("", hash_l.to_string ());
|
||||
blocks.push_back (std::make_pair ("", entry_l));
|
||||
|
@ -2927,7 +2927,7 @@ void rai::rpc_handler::wallet_republish ()
|
|||
for (auto & hash : hashes)
|
||||
{
|
||||
block = node.store.block_get (transaction, hash);
|
||||
node.network.republish_block (std::move (block));;
|
||||
node.network.republish_block (transaction, std::move (block));;
|
||||
boost::property_tree::ptree entry;
|
||||
entry.put ("", hash.to_string ());
|
||||
blocks.push_back (std::make_pair ("", entry));
|
||||
|
|
|
@ -629,7 +629,7 @@ void rai_qt::block_viewer::rebroadcast_action (rai::uint256_union const & hash_a
|
|||
auto block (wallet.node.store.block_get (transaction, hash_a));
|
||||
if (block != nullptr)
|
||||
{
|
||||
wallet.node.network.republish_block (std::move (block));
|
||||
wallet.node.network.republish_block (transaction, std::move (block));
|
||||
auto successor (wallet.node.store.block_successor (transaction, hash_a));
|
||||
if (!successor.is_zero ())
|
||||
{
|
||||
|
|
|
@ -193,7 +193,8 @@ TEST (node, fork_storm)
|
|||
system.nodes [i]->generate_work (*open);
|
||||
auto open_result (system.nodes [i]->process (*open));
|
||||
ASSERT_EQ (rai::process_result::progress, open_result.code);
|
||||
system.nodes [i]->network.republish_block (open);
|
||||
rai::transaction transaction (system.nodes [i]->store.environment, nullptr, false);
|
||||
system.nodes [i]->network.republish_block (transaction, open);
|
||||
}
|
||||
}
|
||||
auto again (true);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue