Push transactions only from locally controlled accounts.

This commit is contained in:
clemahieu 2017-06-21 15:20:28 -05:00
commit 07a4a7aa1a
4 changed files with 27 additions and 4 deletions

View file

@ -614,6 +614,9 @@ TEST (bootstrap_processor, push_diamond)
rai::node_init init1;
auto node1 (std::make_shared <rai::node> (init1, system.service, 24002, rai::unique_path (), system.alarm, system.logging, system.work));
ASSERT_FALSE (init1.error ());
auto wallet1 (node1->wallets.create (100));
wallet1->insert_adhoc (rai::test_genesis_key.prv);
wallet1->insert_adhoc (key.prv);
std::unique_ptr <rai::send_block> send1 (new rai::send_block (system.nodes [0]->latest (rai::test_genesis_key.pub), key.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (system.nodes [0]->latest (rai::test_genesis_key.pub))));
ASSERT_EQ (rai::process_result::progress, node1->process (*send1).code);
std::unique_ptr <rai::open_block> open (new rai::open_block (send1->hash (), 1, key.pub, key.prv, key.pub, system.work.generate (key.pub)));

View file

@ -302,9 +302,12 @@ void rai::frontier_req_client::received_frontier (boost::system::error_code cons
{
while (!current.is_zero () && current < account)
{
rai::transaction transaction (connection->node->store.environment, nullptr, true);
// We know about an account they don't.
unsynced (transaction, info.head, 0);
rai::transaction transaction (connection->node->store.environment, nullptr, true);
if (connection->node->wallets.exists (transaction, current))
{
unsynced (transaction, info.head, 0);
}
next ();
}
if (!current.is_zero ())
@ -321,7 +324,10 @@ void rai::frontier_req_client::received_frontier (boost::system::error_code cons
if (connection->node->store.block_exists (transaction, latest))
{
// We know about a block they don't.
unsynced (transaction, info.head, latest);
if (connection->node->wallets.exists (transaction, current))
{
unsynced (transaction, info.head, latest);
}
}
else
{
@ -350,7 +356,10 @@ void rai::frontier_req_client::received_frontier (boost::system::error_code cons
while (!current.is_zero ())
{
// We know about an account they don't.
unsynced (transaction, info.head, 0);
if (connection->node->wallets.exists (transaction, current))
{
unsynced (transaction, info.head, 0);
}
next ();
}
}

View file

@ -1499,6 +1499,16 @@ void rai::wallets::foreach_representative (MDB_txn * transaction_a, std::functio
}
}
bool rai::wallets::exists (MDB_txn * transaction_a, rai::public_key const & account_a)
{
auto result (false);
for (auto i (items.begin ()), n (items.end ()); !result && i != n; ++i)
{
result = i->second->store.exists (transaction_a, account_a);
}
return result;
}
rai::uint128_t const rai::wallets::generate_priority = std::numeric_limits <rai::uint128_t>::max ();
rai::uint128_t const rai::wallets::high_priority = std::numeric_limits <rai::uint128_t>::max () - 1;

View file

@ -190,6 +190,7 @@ public:
void do_wallet_actions (rai::account const &);
void queue_wallet_action (rai::account const &, rai::uint128_t const &, std::function <void ()> const &);
void foreach_representative (MDB_txn *, std::function <void (rai::public_key const &, rai::raw_key const &)> const &);
bool exists (MDB_txn *, rai::public_key const &);
std::function <void (rai::account const &, bool)> observer;
std::unordered_map <rai::uint256_union, std::shared_ptr <rai::wallet>> items;
std::unordered_map <rai::account, std::multimap <rai::uint128_t, std::function <void ()>, std::greater <rai::uint128_t>>> pending_actions;