From a9f7db9d6c516f538dd993c064e20f5a6b5fb7ed Mon Sep 17 00:00:00 2001 From: clemahieu Date: Tue, 7 Feb 2017 09:08:54 -0600 Subject: [PATCH] Removing destination account from pending value since it's in the key. --- rai/core_test/block_store.cpp | 3 +- rai/core_test/ledger.cpp | 1 - rai/node/wallet.cpp | 8 +++-- rai/qt/qt.cpp | 18 ++++++----- rai/secure.cpp | 61 +++++++++++++---------------------- rai/secure.hpp | 3 +- 6 files changed, 40 insertions(+), 54 deletions(-) diff --git a/rai/core_test/block_store.cpp b/rai/core_test/block_store.cpp index 27168394..f3dae71e 100644 --- a/rai/core_test/block_store.cpp +++ b/rai/core_test/block_store.cpp @@ -126,7 +126,7 @@ TEST (block_store, pending_iterator) ASSERT_TRUE (!init); rai::transaction transaction (store.environment, nullptr, true); ASSERT_EQ (store.pending_end (), store.pending_begin (transaction)); - store.pending_put (transaction, rai::pending_key (1, 2), {2, 3, 4}); + store.pending_put (transaction, rai::pending_key (1, 2), {2, 3}); auto current (store.pending_begin (transaction)); ASSERT_NE (store.pending_end (), current); rai::pending_key key1 (current->first); @@ -135,7 +135,6 @@ TEST (block_store, pending_iterator) rai::pending_info pending (current->second); ASSERT_EQ (rai::account (2), pending.source); ASSERT_EQ (rai::amount (3), pending.amount); - ASSERT_EQ (rai::account (4), pending.destination); } TEST (block_store, genesis) diff --git a/rai/core_test/ledger.cpp b/rai/core_test/ledger.cpp index 66d0d8ed..9c6c27dd 100644 --- a/rai/core_test/ledger.cpp +++ b/rai/core_test/ledger.cpp @@ -150,7 +150,6 @@ TEST (ledger, process_send) rai::pending_info pending1; ASSERT_FALSE (ledger.store.pending_get (transaction, rai::pending_key (key2.pub, hash1), pending1)); ASSERT_EQ (rai::test_genesis_key.pub, pending1.source); - ASSERT_EQ (key2.pub, pending1.destination); ASSERT_EQ (rai::genesis_amount - 50, pending1.amount.number ()); ASSERT_EQ (0, ledger.account_balance (transaction, key2.pub)); ASSERT_EQ (50, ledger.account_balance (transaction, rai::test_genesis_key.pub)); diff --git a/rai/node/wallet.cpp b/rai/node/wallet.cpp index f9a766be..f295d618 100644 --- a/rai/node/wallet.cpp +++ b/rai/node/wallet.cpp @@ -1195,8 +1195,9 @@ public: std::unordered_set already_searched; for (auto i (wallet->node.store.pending_begin (transaction)), n (wallet->node.store.pending_end ()); i != n; ++i) { + rai::pending_key key (i->first); rai::pending_info pending (i->second); - auto existing (keys.find (pending.destination)); + auto existing (keys.find (key.account)); if (existing != keys.end ()) { rai::account_info info; @@ -1231,10 +1232,11 @@ public: auto representative (wallet->store.representative (transaction)); for (auto i (wallet->node.store.pending_begin (transaction)), n (wallet->node.store.pending_end ()); i != n; ++i) { + rai::pending_key key (i->first); rai::pending_info pending (i->second); if (pending.source == account_a) { - if (wallet->store.exists (transaction, pending.destination)) + if (wallet->store.exists (transaction, key.account)) { if (wallet->store.valid_password (transaction)) { @@ -1255,7 +1257,7 @@ public: } else { - BOOST_LOG (wallet->node.log) << boost::str (boost::format ("Unable to fetch key for: %1%, stopping pending search") % pending.destination.to_account ()); + BOOST_LOG (wallet->node.log) << boost::str (boost::format ("Unable to fetch key for: %1%, stopping pending search") % key.account.to_account ()); } } } diff --git a/rai/qt/qt.cpp b/rai/qt/qt.cpp index 1d5ecddc..c327263b 100644 --- a/rai/qt/qt.cpp +++ b/rai/qt/qt.cpp @@ -1585,18 +1585,19 @@ void rai_qt::block_creation::create_receive () auto send_block (dynamic_cast (block_l.get ())); if (send_block != nullptr) { + rai::pending_key pending_key (send_block->hashables.destination, source_l); rai::pending_info pending; - if (!wallet.node.store.pending_get (transaction, rai::pending_key (send_block->hashables.destination, source_l), pending)) + if (!wallet.node.store.pending_get (transaction, pending_key, pending)) { rai::account_info info; - auto error (wallet.node.store.account_get (transaction, pending.destination, info)); + auto error (wallet.node.store.account_get (transaction, pending_key.account, info)); if (!error) { rai::raw_key key; - auto error (wallet.wallet_m->store.fetch (transaction, pending.destination, key)); + auto error (wallet.wallet_m->store.fetch (transaction, pending_key.account, key)); if (!error) { - rai::receive_block receive (info.head, source_l, key, pending.destination, wallet.wallet_m->work_fetch (transaction, pending.destination, info.head)); + rai::receive_block receive (info.head, source_l, key, pending_key.account, wallet.wallet_m->work_fetch (transaction, pending_key.account, info.head)); std::string block_l; receive.serialize_json (block_l); block->setPlainText (QString (block_l.c_str ())); @@ -1708,18 +1709,19 @@ void rai_qt::block_creation::create_open () auto send_block (dynamic_cast (block_l.get ())); if (send_block != nullptr) { + rai::pending_key pending_key (send_block->hashables.destination, source_l); rai::pending_info pending; - if (!wallet.node.store.pending_get (transaction, rai::pending_key (send_block->hashables.destination, source_l), pending)) + if (!wallet.node.store.pending_get (transaction, pending_key, pending)) { rai::account_info info; - auto error (wallet.node.store.account_get (transaction, pending.destination, info)); + auto error (wallet.node.store.account_get (transaction, pending_key.account, info)); if (error) { rai::raw_key key; - auto error (wallet.wallet_m->store.fetch (transaction, pending.destination, key)); + auto error (wallet.wallet_m->store.fetch (transaction, pending_key.account, key)); if (!error) { - rai::open_block open (source_l, representative_l, pending.destination, key, pending.destination, wallet.wallet_m->work_fetch (transaction, pending.destination, pending.destination)); + rai::open_block open (source_l, representative_l, pending_key.account, key, pending_key.account, wallet.wallet_m->work_fetch (transaction, pending_key.account, pending_key.account)); std::string block_l; open.serialize_json (block_l); block->setPlainText (QString (block_l.c_str ())); diff --git a/rai/secure.cpp b/rai/secure.cpp index 8d41f14f..fe82fe31 100644 --- a/rai/secure.cpp +++ b/rai/secure.cpp @@ -1988,7 +1988,6 @@ void rai::block_store::pending_put (MDB_txn * transaction_a, rai::pending_key co rai::vectorstream stream (vector); rai::write (stream, pending_a.source); rai::write (stream, pending_a.amount); - rai::write (stream, pending_a.destination); } auto status (mdb_put (transaction_a, pending, key_a.val (), pending_a.val (), 0)); assert (status == 0); @@ -2019,14 +2018,12 @@ bool rai::block_store::pending_get (MDB_txn * transaction_a, rai::pending_key co else { result = false; - assert (value.mv_size == sizeof (pending_a.source.bytes) + sizeof (pending_a.amount.bytes) + sizeof (pending_a.destination.bytes)); + assert (value.mv_size == sizeof (pending_a.source.bytes) + sizeof (pending_a.amount.bytes)); rai::bufferstream stream (reinterpret_cast (value.mv_data), value.mv_size); auto error1 (rai::read (stream, pending_a.source)); assert (!error1); auto error2 (rai::read (stream, pending_a.amount)); assert (!error2); - auto error3 (rai::read (stream, pending_a.destination)); - assert (!error3); } return result; } @@ -2051,22 +2048,20 @@ rai::store_iterator rai::block_store::pending_end () rai::pending_info::pending_info () : source (0), -amount (0), -destination (0) +amount (0) { } rai::pending_info::pending_info (MDB_val const & val_a) { assert(val_a.mv_size == sizeof (*this)); - static_assert (sizeof (source) + sizeof (amount) + sizeof (destination) == sizeof (*this), "Packed class"); + static_assert (sizeof (source) + sizeof (amount) == sizeof (*this), "Packed class"); std::copy (reinterpret_cast (val_a.mv_data), reinterpret_cast (val_a.mv_data) + sizeof (*this), reinterpret_cast (this)); } -rai::pending_info::pending_info (rai::account const & source_a, rai::amount const & amount_a, rai::account const & destination_a) : +rai::pending_info::pending_info (rai::account const & source_a, rai::amount const & amount_a) : source (source_a), -amount (amount_a), -destination (destination_a) +amount (amount_a) { } @@ -2074,7 +2069,6 @@ void rai::pending_info::serialize (rai::stream & stream_a) const { rai::write (stream_a, source.bytes); rai::write (stream_a, amount.bytes); - rai::write (stream_a, destination.bytes); } bool rai::pending_info::deserialize (rai::stream & stream_a) @@ -2083,17 +2077,13 @@ bool rai::pending_info::deserialize (rai::stream & stream_a) if (!result) { result = rai::read (stream_a, amount.bytes); - if (!result) - { - result = rai::read (stream_a, destination.bytes); - } } return result; } bool rai::pending_info::operator == (rai::pending_info const & other_a) const { - return source == other_a.source && amount == other_a.amount && destination == other_a.destination; + return source == other_a.source && amount == other_a.amount; } rai::mdb_val rai::pending_info::val () const @@ -2603,7 +2593,7 @@ public: ledger.store.representation_add (transaction, ledger.representative (transaction, hash), 0 - amount); ledger.change_latest (transaction, destination_account, block_a.hashables.previous, representative, ledger.balance (transaction, block_a.hashables.previous)); ledger.store.block_del (transaction, hash); - ledger.store.pending_put (transaction, rai::pending_key (destination_account, block_a.hashables.source), {ledger.account (transaction, block_a.hashables.source), amount, destination_account}); + ledger.store.pending_put (transaction, rai::pending_key (destination_account, block_a.hashables.source), {ledger.account (transaction, block_a.hashables.source), amount}); ledger.store.frontier_del (transaction, hash); ledger.store.frontier_put (transaction, block_a.hashables.previous, destination_account); ledger.store.block_successor_clear (transaction, block_a.hashables.previous); @@ -2624,7 +2614,7 @@ public: ledger.store.representation_add (transaction, ledger.representative (transaction, hash), 0 - amount); ledger.change_latest (transaction, destination_account, 0, representative, 0); ledger.store.block_del (transaction, hash); - ledger.store.pending_put (transaction, rai::pending_key (destination_account, block_a.hashables.source), {ledger.account (transaction, block_a.hashables.source), amount, destination_account}); + ledger.store.pending_put (transaction, rai::pending_key (destination_account, block_a.hashables.source), {ledger.account (transaction, block_a.hashables.source), amount}); ledger.store.frontier_del (transaction, hash); } else @@ -3017,7 +3007,7 @@ void ledger_processor::send_block (rai::send_block const & block_a) ledger.store.representation_add (transaction, info.rep_block, 0 - amount); ledger.store.block_put (transaction, hash, block_a); ledger.change_latest (transaction, account, hash, info.rep_block, block_a.hashables.balance); - ledger.store.pending_put (transaction, rai::pending_key (block_a.hashables.destination, hash), {account, amount, block_a.hashables.destination}); + ledger.store.pending_put (transaction, rai::pending_key (block_a.hashables.destination, hash), {account, amount}); ledger.store.frontier_del (transaction, block_a.hashables.previous); ledger.store.frontier_put (transaction, hash, account); result.account = account; @@ -3051,23 +3041,22 @@ void ledger_processor::receive_block (rai::receive_block const & block_a) result.code = info.head == block_a.hashables.previous ? rai::process_result::progress : rai::process_result::gap_previous; // Block doesn't immediately follow latest block (Harmless) if (result.code == rai::process_result::progress) { - rai::pending_key key (source->hashables.destination, block_a.hashables.source); + rai::pending_key key (account, block_a.hashables.source); rai::pending_info pending; result.code = ledger.store.pending_get (transaction, key, pending) ? rai::process_result::unreceivable : rai::process_result::progress; // Has this source already been received (Malformed) if (result.code == rai::process_result::progress) { - assert (ledger.store.frontier_get (transaction, block_a.hashables.previous) == pending.destination); auto new_balance (info.balance.number () + pending.amount.number ()); rai::account_info source_info; auto error (ledger.store.account_get (transaction, pending.source, source_info)); assert (!error); ledger.store.pending_del (transaction, key); ledger.store.block_put (transaction, hash, block_a); - ledger.change_latest (transaction, pending.destination, hash, info.rep_block, new_balance); + ledger.change_latest (transaction, account, hash, info.rep_block, new_balance); ledger.store.representation_add (transaction, info.rep_block, pending.amount.number ()); ledger.store.frontier_del (transaction, block_a.hashables.previous); - ledger.store.frontier_put (transaction, hash, pending.destination); - result.account = pending.destination; + ledger.store.frontier_put (transaction, hash, account); + result.account = account; result.amount = pending.amount; } } @@ -3104,20 +3093,16 @@ void ledger_processor::open_block (rai::open_block const & block_a) result.code = ledger.store.pending_get (transaction, key, pending) ? rai::process_result::unreceivable : rai::process_result::progress; // Has this source already been received (Malformed) if (result.code == rai::process_result::progress) { - result.code = pending.destination == block_a.hashables.account ? rai::process_result::progress : rai::process_result::account_mismatch; // Does the account listed in the open block match the one named in the send block? (Malformed) - if (result.code == rai::process_result::progress) - { - rai::account_info source_info; - auto error (ledger.store.account_get (transaction, pending.source, source_info)); - assert (!error); - ledger.store.pending_del (transaction, key); - ledger.store.block_put (transaction, hash, block_a); - ledger.change_latest (transaction, pending.destination, hash, hash, pending.amount.number ()); - ledger.store.representation_add (transaction, hash, pending.amount.number ()); - ledger.store.frontier_put (transaction, hash, pending.destination); - result.account = pending.destination; - result.amount = pending.amount; - } + rai::account_info source_info; + auto error (ledger.store.account_get (transaction, pending.source, source_info)); + assert (!error); + ledger.store.pending_del (transaction, key); + ledger.store.block_put (transaction, hash, block_a); + ledger.change_latest (transaction, block_a.hashables.account, hash, hash, pending.amount.number ()); + ledger.store.representation_add (transaction, hash, pending.amount.number ()); + ledger.store.frontier_put (transaction, hash, block_a.hashables.account); + result.account = block_a.hashables.account; + result.amount = pending.amount; } } } diff --git a/rai/secure.hpp b/rai/secure.hpp index f2b80386..6d3e610d 100644 --- a/rai/secure.hpp +++ b/rai/secure.hpp @@ -286,14 +286,13 @@ class pending_info public: pending_info (); pending_info (MDB_val const &); - pending_info (rai::account const &, rai::amount const &, rai::account const &); + pending_info (rai::account const &, rai::amount const &); void serialize (rai::stream &) const; bool deserialize (rai::stream &); bool operator == (rai::pending_info const &) const; rai::mdb_val val () const; rai::account source; rai::amount amount; - rai::account destination; }; class pending_key {