Use the current snapshot to get immutable ledger optimizations.

This commit is contained in:
JoelKatz
2013-05-16 00:58:44 -07:00
parent eecc9017b1
commit 28f54176f3

View File

@@ -177,8 +177,7 @@ Json::Value RPCHandler::transactionSign(Json::Value jvRequest, bool bSubmit)
return rpcError(rpcINVALID_PARAMS);
}
Ledger::pointer lSnapshot = boost::make_shared<Ledger>(
boost::ref(*mNetOps->getCurrentLedger()), false);
Ledger::pointer lSnapshot = mNetOps->getCurrentSnapshot();
{
ScopedUnlock su(theApp->getMasterLock());
bool bValid;
@@ -1031,6 +1030,9 @@ Json::Value RPCHandler::doAccountLines(Json::Value jvRequest, int& cost, ScopedL
if (!lpLedger)
return jvResult;
if (lpLedger->isImmutable())
MasterLockHolder.unlock();
if (!jvRequest.isMember("account"))
return rpcError(rpcINVALID_PARAMS);
@@ -1065,9 +1067,6 @@ Json::Value RPCHandler::doAccountLines(Json::Value jvRequest, int& cost, ScopedL
AccountState::pointer as = mNetOps->getAccountState(lpLedger, raAccount);
if (lpLedger->isImmutable())
MasterLockHolder.unlock();
if (as)
{
jvResult["account"] = raAccount.humanAccountID();
@@ -1124,6 +1123,9 @@ Json::Value RPCHandler::doAccountOffers(Json::Value jvRequest, int& cost, Scoped
if (!lpLedger)
return jvResult;
if (lpLedger->isImmutable())
MasterLockHolder.unlock();
if (!jvRequest.isMember("account"))
return rpcError(rpcINVALID_PARAMS);
@@ -1860,6 +1862,9 @@ Json::Value RPCHandler::doLedger(Json::Value jvRequest, int& cost, ScopedLock& M
if (!lpLedger)
return jvResult;
if (lpLedger->isImmutable())
MasterLockHolder.unlock();
bool bFull = jvRequest.isMember("full") && jvRequest["full"].asBool();
bool bTransactions = jvRequest.isMember("transactions") && jvRequest["transactions"].asBool();
bool bAccounts = jvRequest.isMember("accounts") && jvRequest["accounts"].asBool();
@@ -1869,15 +1874,6 @@ Json::Value RPCHandler::doLedger(Json::Value jvRequest, int& cost, ScopedLock& M
| (bTransactions ? LEDGER_JSON_DUMP_TXRP : 0)
| (bAccounts ? LEDGER_JSON_DUMP_STATE : 0);
if ((bFull || bAccounts) && !lpLedger->isImmutable())
{ // For full or accounts, it's cheaper to snapshot
lpLedger = boost::make_shared<Ledger>(*lpLedger, false);
assert(lpLedger->isImmutable());
}
if (lpLedger->isImmutable())
MasterLockHolder.unlock();
Json::Value ret(Json::objectValue);
lpLedger->addJson(ret, iOptions);
@@ -2620,7 +2616,7 @@ Json::Value RPCHandler::lookupLedger(Json::Value jvRequest, Ledger::pointer& lpL
switch (iLedgerIndex) {
case LEDGER_CURRENT:
lpLedger = mNetOps->getCurrentLedger();
lpLedger = mNetOps->getCurrentSnapshot();
iLedgerIndex = lpLedger->getLedgerSeq();
break;