Inline calls to cachedRead:

Problem:
- There are only a few call sites to cachedRead, and all of them
  currently do more work than is required since we know the type in each
  case.

Solution:
- "Inline" the codepath to cachedRead, but do not check if the type is
  valid. In all such call sites, we know the keylet to read directly.

This fixes #2550
This commit is contained in:
Joe Loser
2018-11-01 20:20:49 -04:00
committed by Nik Bougalis
parent ad4bbd8dff
commit c587012e5c
3 changed files with 10 additions and 21 deletions

View File

@@ -410,17 +410,6 @@ std::pair<std::shared_ptr<
STObject const>>
deserializeTxPlusMeta (SHAMapItem const& item);
// DEPRECATED
inline
std::shared_ptr<SLE const>
cachedRead (ReadView const& ledger, uint256 const& key,
boost::optional<LedgerEntryType> type = boost::none)
{
if (type)
return ledger.read(Keylet(*type, key));
return ledger.read(keylet::unchecked(key));
}
} // ripple
#endif

View File

@@ -150,8 +150,9 @@ public:
return true;
if (view.txExists(txn.getID()))
return true;
auto const sle = cachedRead(view,
keylet::account(txn.getAccount()).key, ltACCOUNT_ROOT);
std::shared_ptr<SLE const> sle = view.read(
keylet::account(txn.getAccount()));
if (! sle)
return false;
return sle->getFieldU32 (sfSequence) > txn.getSeq ();

View File

@@ -374,8 +374,8 @@ transactionPreProcessImpl (
if (!verify && !tx_json.isMember (jss::Sequence))
return RPC::missing_field_error ("tx_json.Sequence");
std::shared_ptr<SLE const> sle = cachedRead(*ledger,
keylet::account(srcAddressID).key, ltACCOUNT_ROOT);
std::shared_ptr<SLE const> sle = ledger->read(
keylet::account(srcAddressID));
if (verify && !sle)
{
@@ -981,12 +981,11 @@ Json::Value transactionSignFor (
return preprocResult.first;
{
std::shared_ptr<SLE const> account_state = ledger->read(
keylet::account(*signerAccountID));
// Make sure the account and secret belong together.
auto const err = acctMatchesPubKey (
cachedRead(
*ledger,
keylet::account(*signerAccountID).key,
ltACCOUNT_ROOT),
account_state,
*signerAccountID,
multiSignPubKey);
@@ -1060,8 +1059,8 @@ Json::Value transactionSubmitMultiSigned (
auto const srcAddressID = txJsonResult.second;
std::shared_ptr<SLE const> sle = cachedRead(*ledger,
keylet::account(srcAddressID).key, ltACCOUNT_ROOT);
std::shared_ptr<SLE const> sle = ledger->read(
keylet::account(srcAddressID));
if (!sle)
{