mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Remove redundant or broken locks.
This commit is contained in:
@@ -179,7 +179,6 @@ AccountState::pointer Ledger::getAccountState(const RippleAddress& accountID)
|
|||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
// std::cerr << "Ledger:getAccountState(" << accountID.humanAccountID() << ")" << std::endl;
|
// std::cerr << "Ledger:getAccountState(" << accountID.humanAccountID() << ")" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
ScopedLock l(mAccountStateMap->Lock());
|
|
||||||
SHAMapItem::pointer item = mAccountStateMap->peekItem(Ledger::getAccountRootIndex(accountID));
|
SHAMapItem::pointer item = mAccountStateMap->peekItem(Ledger::getAccountRootIndex(accountID));
|
||||||
if (!item)
|
if (!item)
|
||||||
{
|
{
|
||||||
@@ -197,7 +196,6 @@ AccountState::pointer Ledger::getAccountState(const RippleAddress& accountID)
|
|||||||
|
|
||||||
NicknameState::pointer Ledger::getNicknameState(const uint256& uNickname)
|
NicknameState::pointer Ledger::getNicknameState(const uint256& uNickname)
|
||||||
{
|
{
|
||||||
ScopedLock l(mAccountStateMap->Lock());
|
|
||||||
SHAMapItem::pointer item = mAccountStateMap->peekItem(Ledger::getNicknameIndex(uNickname));
|
SHAMapItem::pointer item = mAccountStateMap->peekItem(Ledger::getNicknameIndex(uNickname));
|
||||||
if (!item)
|
if (!item)
|
||||||
{
|
{
|
||||||
@@ -370,81 +368,88 @@ void Ledger::saveAcceptedLedger(bool fromConsensus, LoadEvent::pointer event)
|
|||||||
assert (getTransHash() == mTransactionMap->getHash());
|
assert (getTransHash() == mTransactionMap->getHash());
|
||||||
|
|
||||||
{
|
{
|
||||||
ScopedLock sl(theApp->getLedgerDB()->getDBLock());
|
{
|
||||||
|
ScopedLock sl(theApp->getLedgerDB()->getDBLock());
|
||||||
if (SQL_EXISTS(theApp->getLedgerDB()->getDB(), boost::str(ledgerExists % mLedgerSeq)))
|
if (SQL_EXISTS(theApp->getLedgerDB()->getDB(), boost::str(ledgerExists % mLedgerSeq)))
|
||||||
theApp->getLedgerDB()->getDB()->executeSQL(boost::str(deleteLedger % mLedgerSeq));
|
theApp->getLedgerDB()->getDB()->executeSQL(boost::str(deleteLedger % mLedgerSeq));
|
||||||
|
}
|
||||||
|
|
||||||
SHAMap& txSet = *peekTransactionMap();
|
SHAMap& txSet = *peekTransactionMap();
|
||||||
Database *db = theApp->getTxnDB()->getDB();
|
Database *db = theApp->getTxnDB()->getDB();
|
||||||
ScopedLock dbLock(theApp->getTxnDB()->getDBLock());
|
|
||||||
db->executeSQL("BEGIN TRANSACTION;");
|
|
||||||
SHAMapTreeNode::TNType type;
|
|
||||||
for (SHAMapItem::pointer item = txSet.peekFirstItem(type); !!item;
|
|
||||||
item = txSet.peekNextItem(item->getTag(), type))
|
|
||||||
{
|
{
|
||||||
assert(type == SHAMapTreeNode::tnTRANSACTION_MD);
|
ScopedLock dbLock(theApp->getTxnDB()->getDBLock());
|
||||||
SerializerIterator sit(item->peekSerializer());
|
db->executeSQL("BEGIN TRANSACTION;");
|
||||||
Serializer rawTxn(sit.getVL());
|
SHAMapTreeNode::TNType type;
|
||||||
std::string escMeta(sqlEscape(sit.getVL()));
|
for (SHAMapItem::pointer item = txSet.peekFirstItem(type); !!item;
|
||||||
|
item = txSet.peekNextItem(item->getTag(), type))
|
||||||
SerializerIterator txnIt(rawTxn);
|
|
||||||
SerializedTransaction txn(txnIt);
|
|
||||||
assert(txn.getTransactionID() == item->getTag());
|
|
||||||
|
|
||||||
// Make sure transaction is in AccountTransactions.
|
|
||||||
if (!SQL_EXISTS(db, boost::str(AcctTransExists % item->getTag().GetHex())))
|
|
||||||
{
|
{
|
||||||
// Transaction not in AccountTransactions
|
assert(type == SHAMapTreeNode::tnTRANSACTION_MD);
|
||||||
std::vector<RippleAddress> accts = txn.getAffectedAccounts();
|
SerializerIterator sit(item->peekSerializer());
|
||||||
|
Serializer rawTxn(sit.getVL());
|
||||||
|
std::string escMeta(sqlEscape(sit.getVL()));
|
||||||
|
|
||||||
std::string sql = "INSERT INTO AccountTransactions (TransID, Account, LedgerSeq) VALUES ";
|
SerializerIterator txnIt(rawTxn);
|
||||||
bool first = true;
|
SerializedTransaction txn(txnIt);
|
||||||
for (std::vector<RippleAddress>::iterator it = accts.begin(), end = accts.end(); it != end; ++it)
|
assert(txn.getTransactionID() == item->getTag());
|
||||||
|
|
||||||
|
// Make sure transaction is in AccountTransactions.
|
||||||
|
if (!SQL_EXISTS(db, boost::str(AcctTransExists % item->getTag().GetHex())))
|
||||||
{
|
{
|
||||||
if (!first)
|
// Transaction not in AccountTransactions
|
||||||
sql += ", ('";
|
std::vector<RippleAddress> accts = txn.getAffectedAccounts();
|
||||||
else
|
|
||||||
{
|
|
||||||
sql += "('";
|
|
||||||
first = false;
|
|
||||||
}
|
|
||||||
sql += txn.getTransactionID().GetHex();
|
|
||||||
sql += "','";
|
|
||||||
sql += it->humanAccountID();
|
|
||||||
sql += "',";
|
|
||||||
sql += boost::lexical_cast<std::string>(getLedgerSeq());
|
|
||||||
sql += ")";
|
|
||||||
}
|
|
||||||
sql += ";";
|
|
||||||
Log(lsTRACE) << "ActTx: " << sql;
|
|
||||||
db->executeSQL(sql); // may already be in there
|
|
||||||
}
|
|
||||||
|
|
||||||
if (SQL_EXISTS(db, boost::str(transExists % txn.getTransactionID().GetHex())))
|
std::string sql = "INSERT INTO AccountTransactions (TransID, Account, LedgerSeq) VALUES ";
|
||||||
{
|
bool first = true;
|
||||||
// In Transactions, update LedgerSeq, metadata and Status.
|
for (std::vector<RippleAddress>::iterator it = accts.begin(), end = accts.end(); it != end; ++it)
|
||||||
db->executeSQL(boost::str(updateTx
|
{
|
||||||
% getLedgerSeq()
|
if (!first)
|
||||||
% TXN_SQL_VALIDATED
|
sql += ", ('";
|
||||||
% escMeta
|
else
|
||||||
% txn.getTransactionID().GetHex()));
|
{
|
||||||
}
|
sql += "('";
|
||||||
else
|
first = false;
|
||||||
{
|
}
|
||||||
// Not in Transactions, insert the whole thing..
|
sql += txn.getTransactionID().GetHex();
|
||||||
db->executeSQL(
|
sql += "','";
|
||||||
txn.getMetaSQLInsertHeader() + txn.getMetaSQL(getLedgerSeq(), escMeta) + ";");
|
sql += it->humanAccountID();
|
||||||
|
sql += "',";
|
||||||
|
sql += boost::lexical_cast<std::string>(getLedgerSeq());
|
||||||
|
sql += ")";
|
||||||
|
}
|
||||||
|
sql += ";";
|
||||||
|
Log(lsTRACE) << "ActTx: " << sql;
|
||||||
|
db->executeSQL(sql); // may already be in there
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SQL_EXISTS(db, boost::str(transExists % txn.getTransactionID().GetHex())))
|
||||||
|
{
|
||||||
|
// In Transactions, update LedgerSeq, metadata and Status.
|
||||||
|
db->executeSQL(boost::str(updateTx
|
||||||
|
% getLedgerSeq()
|
||||||
|
% TXN_SQL_VALIDATED
|
||||||
|
% escMeta
|
||||||
|
% txn.getTransactionID().GetHex()));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Not in Transactions, insert the whole thing..
|
||||||
|
db->executeSQL(
|
||||||
|
txn.getMetaSQLInsertHeader() + txn.getMetaSQL(getLedgerSeq(), escMeta) + ";");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
db->executeSQL("COMMIT TRANSACTION;");
|
||||||
}
|
}
|
||||||
db->executeSQL("COMMIT TRANSACTION;");
|
|
||||||
|
|
||||||
theApp->getHashedObjectStore().waitWrite(); // wait until all nodes are written
|
theApp->getHashedObjectStore().waitWrite(); // wait until all nodes are written
|
||||||
theApp->getLedgerDB()->getDB()->executeSQL(boost::str(addLedger %
|
|
||||||
getHash().GetHex() % mLedgerSeq % mParentHash.GetHex() %
|
{
|
||||||
boost::lexical_cast<std::string>(mTotCoins) % mCloseTime % mParentCloseTime %
|
ScopedLock sl(theApp->getLedgerDB()->getDBLock());
|
||||||
mCloseResolution % mCloseFlags %
|
theApp->getLedgerDB()->getDB()->executeSQL(boost::str(addLedger %
|
||||||
mAccountHash.GetHex() % mTransHash.GetHex()));
|
getHash().GetHex() % mLedgerSeq % mParentHash.GetHex() %
|
||||||
|
boost::lexical_cast<std::string>(mTotCoins) % mCloseTime % mParentCloseTime %
|
||||||
|
mCloseResolution % mCloseFlags %
|
||||||
|
mAccountHash.GetHex() % mTransHash.GetHex()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fromConsensus)
|
if (!fromConsensus)
|
||||||
@@ -812,8 +817,6 @@ SLE::pointer Ledger::getAccountRoot(const RippleAddress& naAccountID)
|
|||||||
|
|
||||||
SLE::pointer Ledger::getDirNode(LedgerStateParms& parms, const uint256& uNodeIndex)
|
SLE::pointer Ledger::getDirNode(LedgerStateParms& parms, const uint256& uNodeIndex)
|
||||||
{
|
{
|
||||||
ScopedLock l(mAccountStateMap->Lock());
|
|
||||||
|
|
||||||
return getASNode(parms, uNodeIndex, ltDIR_NODE);
|
return getASNode(parms, uNodeIndex, ltDIR_NODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -823,8 +826,6 @@ SLE::pointer Ledger::getDirNode(LedgerStateParms& parms, const uint256& uNodeInd
|
|||||||
|
|
||||||
SLE::pointer Ledger::getGenerator(LedgerStateParms& parms, const uint160& uGeneratorID)
|
SLE::pointer Ledger::getGenerator(LedgerStateParms& parms, const uint160& uGeneratorID)
|
||||||
{
|
{
|
||||||
ScopedLock l(mAccountStateMap->Lock());
|
|
||||||
|
|
||||||
return getASNode(parms, getGeneratorIndex(uGeneratorID), ltGENERATOR_MAP);
|
return getASNode(parms, getGeneratorIndex(uGeneratorID), ltGENERATOR_MAP);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -834,8 +835,6 @@ SLE::pointer Ledger::getGenerator(LedgerStateParms& parms, const uint160& uGener
|
|||||||
|
|
||||||
SLE::pointer Ledger::getNickname(LedgerStateParms& parms, const uint256& uNickname)
|
SLE::pointer Ledger::getNickname(LedgerStateParms& parms, const uint256& uNickname)
|
||||||
{
|
{
|
||||||
ScopedLock l(mAccountStateMap->Lock());
|
|
||||||
|
|
||||||
return getASNode(parms, uNickname, ltNICKNAME);
|
return getASNode(parms, uNickname, ltNICKNAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -846,8 +845,6 @@ SLE::pointer Ledger::getNickname(LedgerStateParms& parms, const uint256& uNickna
|
|||||||
|
|
||||||
SLE::pointer Ledger::getOffer(LedgerStateParms& parms, const uint256& uIndex)
|
SLE::pointer Ledger::getOffer(LedgerStateParms& parms, const uint256& uIndex)
|
||||||
{
|
{
|
||||||
ScopedLock l(mAccountStateMap->Lock());
|
|
||||||
|
|
||||||
return getASNode(parms, uIndex, ltOFFER);
|
return getASNode(parms, uIndex, ltOFFER);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -857,8 +854,6 @@ SLE::pointer Ledger::getOffer(LedgerStateParms& parms, const uint256& uIndex)
|
|||||||
|
|
||||||
SLE::pointer Ledger::getRippleState(LedgerStateParms& parms, const uint256& uNode)
|
SLE::pointer Ledger::getRippleState(LedgerStateParms& parms, const uint256& uNode)
|
||||||
{
|
{
|
||||||
ScopedLock l(mAccountStateMap->Lock());
|
|
||||||
|
|
||||||
return getASNode(parms, uNode, ltRIPPLE_STATE);
|
return getASNode(parms, uNode, ltRIPPLE_STATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user