Refactor Ledger and support classes:

This performs a deep refactor on the Ledger class and its supporting
classes, in preparation for the move to shared_ptr<SLE const> in
places where the SLE is immutable and we are currently using
shared_ptr<SLE>.

Member functions are converted to free functions, the SLECache is an
explicit parameter, one line convenience functions are removed to
streamline the interface. Some callers are changed to use <SLE const>
instead of <SLE>

SLECache:
* Moved to its own header file

RippleState:
* Remove unused functions
* Store the SLE as const
* Simplify callers

AccountState:
* Remove unused members
* Simplify existing members

Ledger:
* Replace writeBack with insert and update
* Remove unused functions
* Remove LedgerStateParams
* Move getLastFullLedger to Application
* add entryCacheI, exists, fetch, erase
* Use boost::optional where it makes sense
* Make member functions free functions

Free functions:
* fetch: cache-aware SLE retrieval
* forEachItem, forEachItemAfter
* (various)
This commit is contained in:
Vinnie Falco
2015-06-05 07:25:45 -07:00
parent 454d2f8c45
commit babaac9305
45 changed files with 1224 additions and 1129 deletions

View File

@@ -19,6 +19,7 @@
#include <BeastConfig.h>
#include <ripple/app/ledger/LedgerFees.h>
#include <ripple/app/main/Application.h>
#include <ripple/rpc/impl/TransactionSign.h>
#include <ripple/rpc/impl/KeypairForSignature.h>
#include <ripple/app/paths/FindPaths.h>
@@ -111,7 +112,8 @@ void TxnSignApiFacade::snapshotAccountState (RippleAddress const& accountID)
ledger_ = netOPs_->getCurrentLedger ();
accountID_ = accountID;
accountState_ = netOPs_->getAccountState (ledger_, accountID_);
accountState_ = getAccountState (
*ledger_, accountID_, getApp().getSLECache());
}
bool TxnSignApiFacade::isValidAccount () const
@@ -127,7 +129,7 @@ std::uint32_t TxnSignApiFacade::getSeq () const
if (!ledger_) // Unit testing.
return 0;
return accountState_->getSeq ();
return accountState_->sle().getFieldU32(sfSequence);
}
Transaction::pointer TxnSignApiFacade::processTransaction (
@@ -192,11 +194,8 @@ bool TxnSignApiFacade::hasAccountRoot () const
{
if (!netOPs_) // Unit testing.
return true;
SLE::pointer const sleAccountRoot =
ledger_->getSLEi(getAccountRootIndex(accountID_));
return static_cast <bool> (sleAccountRoot);
return ledger_->exists(
getAccountRootIndex(accountID_));
}
error_code_i acctMatchesPubKey (
@@ -217,7 +216,7 @@ error_code_i acctMatchesPubKey (
}
// If we *can* get to the accountRoot, check for MASTER_DISABLED
STLedgerEntry const& sle = accountState->peekSLE ();
auto const& sle = accountState->sle();
if (isMasterKey)
{
if (sle.isFlag(lsfDisableMaster))
@@ -248,11 +247,13 @@ error_code_i TxnSignApiFacade::multiAcctMatchesPubKey (
RippleAddress const& publicKey) const
{
AccountState::pointer accountState;
// VFALCO Do we need to check netOPs_?
if (netOPs_ && ledger_)
// If it's available, get the AccountState for the multi-signer's
// accountID. It's okay if the AccountState is not available,
// since they might be signing with a phantom (unfunded) account.
accountState = netOPs_->getAccountState (ledger_, accountID);
accountState = getAccountState (
*ledger_, accountID, getApp().getSLECache());
return acctMatchesPubKey (accountState, accountID, publicKey);
}