Merge branch 'ripple'

Conflicts:
	src/TransactionEngine.cpp
This commit is contained in:
Arthur Britto
2012-07-17 13:32:29 -07:00
10 changed files with 573 additions and 518 deletions

View File

@@ -195,7 +195,7 @@ NicknameState::pointer Ledger::getNicknameState(const uint256& uNickname)
return boost::make_shared<NicknameState>(sle); return boost::make_shared<NicknameState>(sle);
} }
RippleState::pointer Ledger::getRippleState(const uint256& uNode) RippleState::pointer Ledger::accessRippleState(const uint256& uNode)
{ {
ScopedLock l(mAccountStateMap->Lock()); ScopedLock l(mAccountStateMap->Lock());
SHAMapItem::pointer item = mAccountStateMap->peekItem(uNode); SHAMapItem::pointer item = mAccountStateMap->peekItem(uNode);

View File

@@ -157,8 +157,8 @@ public:
// high-level functions // high-level functions
AccountState::pointer getAccountState(const NewcoinAddress& acctID); AccountState::pointer getAccountState(const NewcoinAddress& acctID);
LedgerStateParms writeBack(LedgerStateParms parms, SLE::pointer); LedgerStateParms writeBack(LedgerStateParms parms, SLE::pointer);
SLE::pointer getAccountRoot(LedgerStateParms& parms, const uint160& accountID); SLE::pointer getAccountRoot(const uint160& accountID);
SLE::pointer getAccountRoot(LedgerStateParms& parms, const NewcoinAddress& naAccountID); SLE::pointer getAccountRoot(const NewcoinAddress& naAccountID);
// database functions // database functions
static void saveAcceptedLedger(Ledger::pointer); static void saveAcceptedLedger(Ledger::pointer);
@@ -210,14 +210,21 @@ public:
// //
// Order book dirs have a base so we can use next to step through them in quality order. // Order book dirs have a base so we can use next to step through them in quality order.
static uint256 getBookBase(const uint160& uCurrencyIn, const uint160& uAccountIn, static uint256 getBookBase(const uint160& uTakerPaysCurrency, const uint160& uTakerPaysIssuerID,
const uint160& uCurrencyOut, const uint160& uAccountOut); const uint160& uTakerGetsCurrency, const uint160& uTakerGetsIssuerID);
// //
// Offer functions // Offer functions
// //
SLE::pointer getOffer(LedgerStateParms& parms, const uint256& uIndex); SLE::pointer getOffer(LedgerStateParms& parms, const uint256& uIndex);
SLE::pointer getOffer(const uint256& uIndex)
{
LedgerStateParms qry = lepNONE;
return getOffer(qry, uIndex);
}
SLE::pointer getOffer(LedgerStateParms& parms, const uint160& uAccountID, uint32 uSequence) SLE::pointer getOffer(LedgerStateParms& parms, const uint160& uAccountID, uint32 uSequence)
{ return getOffer(parms, getOfferIndex(uAccountID, uSequence)); } { return getOffer(parms, getOfferIndex(uAccountID, uSequence)); }
@@ -261,14 +268,21 @@ public:
// Directory of lines indexed by an account (not all lines are indexed) // Directory of lines indexed by an account (not all lines are indexed)
static uint256 getRippleDirIndex(const uint160& uAccountID); static uint256 getRippleDirIndex(const uint160& uAccountID);
RippleState::pointer getRippleState(const uint256& uNode); RippleState::pointer accessRippleState(const uint256& uNode);
SLE::pointer getRippleState(LedgerStateParms& parms, const uint256& uNode); SLE::pointer getRippleState(LedgerStateParms& parms, const uint256& uNode);
SLE::pointer getRippleState(LedgerStateParms& parms, const NewcoinAddress& naA, const NewcoinAddress& naB, const uint160& uCurrency) SLE::pointer getRippleState(const uint256& uNode)
{ return getRippleState(parms, getRippleStateIndex(naA, naB, uCurrency)); } {
LedgerStateParms qry = lepNONE;
return getRippleState(qry, uNode);
}
SLE::pointer getRippleState(LedgerStateParms& parms, const uint160& uiA, const uint160& uiB, const uint160& uCurrency) SLE::pointer getRippleState(const NewcoinAddress& naA, const NewcoinAddress& naB, const uint160& uCurrency)
{ return getRippleState(parms, getRippleStateIndex(NewcoinAddress::createAccountID(uiA), NewcoinAddress::createAccountID(uiB), uCurrency)); } { return getRippleState(getRippleStateIndex(naA, naB, uCurrency)); }
SLE::pointer getRippleState(const uint160& uiA, const uint160& uiB, const uint160& uCurrency)
{ return getRippleState(getRippleStateIndex(NewcoinAddress::createAccountID(uiA), NewcoinAddress::createAccountID(uiB), uCurrency)); }
// //
// Misc // Misc

View File

@@ -15,6 +15,7 @@ uint256 Ledger::getQualityIndex(const uint256& uBase, const uint64 uNodeDir)
return uNode; return uNode;
} }
// Return the last 64 bits.
uint64 Ledger::getQuality(const uint256& uBase) uint64 Ledger::getQuality(const uint256& uBase)
{ {
return be64toh(((uint64*) uBase.end())[-1]); return be64toh(((uint64*) uBase.end())[-1]);
@@ -41,24 +42,24 @@ uint256 Ledger::getAccountRootIndex(const uint160& uAccountID)
return s.getSHA512Half(); return s.getSHA512Half();
} }
uint256 Ledger::getBookBase(const uint160& uCurrencyIn, const uint160& uAccountIn, uint256 Ledger::getBookBase(const uint160& uTakerPaysCurrency, const uint160& uTakerPaysIssuerID,
const uint160& uCurrencyOut, const uint160& uAccountOut) const uint160& uTakerGetsCurrency, const uint160& uTakerGetsIssuerID)
{ {
bool bInNative = uCurrencyIn.isZero(); bool bInNative = uTakerPaysCurrency.isZero();
bool bOutNative = uCurrencyOut.isZero(); bool bOutNative = uTakerGetsCurrency.isZero();
assert(!bInNative || !bOutNative); // Stamps to stamps not allowed. assert(!bInNative || !bOutNative); // Stamps to stamps not allowed.
assert(bInNative == uAccountIn.isZero()); // Make sure issuer is specified as needed. assert(bInNative == uTakerPaysIssuerID.isZero()); // Make sure issuer is specified as needed.
assert(bOutNative == uAccountOut.isZero()); // Make sure issuer is specified as needed. assert(bOutNative == uTakerGetsIssuerID.isZero()); // Make sure issuer is specified as needed.
assert(uCurrencyIn != uCurrencyOut || uAccountIn != uAccountOut); // Currencies or accounts must differ. assert(uTakerPaysCurrency != uTakerGetsCurrency || uTakerPaysIssuerID != uTakerGetsIssuerID); // Currencies or accounts must differ.
Serializer s(82); Serializer s(82);
s.add16(spaceBookDir); // 2 s.add16(spaceBookDir); // 2
s.add160(uCurrencyIn); // 20 s.add160(uTakerPaysCurrency); // 20
s.add160(uCurrencyOut); // 20 s.add160(uTakerGetsCurrency); // 20
s.add160(uAccountIn); // 20 s.add160(uTakerPaysIssuerID); // 20
s.add160(uAccountOut); // 20 s.add160(uTakerGetsIssuerID); // 20
return getQualityIndex(s.getSHA512Half()); // Return with quality 0. return getQualityIndex(s.getSHA512Half()); // Return with quality 0.
} }

View File

@@ -133,19 +133,20 @@ SLE::pointer Ledger::getASNode(LedgerStateParms& parms, const uint256& nodeID,
parms = parms | lepOKAY; parms = parms | lepOKAY;
return sle; return sle;
} }
SLE::pointer Ledger::getAccountRoot(LedgerStateParms& parms, const uint160& accountID) SLE::pointer Ledger::getAccountRoot(const uint160& accountID)
{ {
uint256 nodeID=getAccountRootIndex(accountID); LedgerStateParms qry = lepNONE;
return getASNode(parms, nodeID, ltACCOUNT_ROOT); return getASNode(qry, getAccountRootIndex(accountID), ltACCOUNT_ROOT);
} }
SLE::pointer Ledger::getAccountRoot(LedgerStateParms& parms, const NewcoinAddress& naAccountID) SLE::pointer Ledger::getAccountRoot(const NewcoinAddress& naAccountID)
{ {
return getAccountRoot(parms, naAccountID.getAccountID()); LedgerStateParms qry = lepNONE;
return getASNode(qry, getAccountRootIndex(naAccountID.getAccountID()), ltACCOUNT_ROOT);
} }
// //

View File

@@ -269,9 +269,9 @@ Json::Value NetworkOPs::getOwnerInfo(Ledger::pointer lpLedger, const NewcoinAddr
// Ripple functions // Ripple functions
// //
RippleState::pointer NetworkOPs::getRippleState(const uint256& uLedger, const uint256& uIndex) RippleState::pointer NetworkOPs::accessRippleState(const uint256& uLedger, const uint256& uIndex)
{ {
return mLedgerMaster->getLedgerByHash(uLedger)->getRippleState(uIndex); return mLedgerMaster->getLedgerByHash(uLedger)->accessRippleState(uIndex);
} }
// //

View File

@@ -149,7 +149,7 @@ public:
return !!mLedgerMaster->getLedgerByHash(uLedger)->getDirNode(lspNode, uRootIndex); return !!mLedgerMaster->getLedgerByHash(uLedger)->getDirNode(lspNode, uRootIndex);
} }
RippleState::pointer getRippleState(const uint256& uLedger, const uint256& uIndex); RippleState::pointer accessRippleState(const uint256& uLedger, const uint256& uIndex);
// raw object operations // raw object operations
bool findRawLedger(const uint256& ledgerHash, std::vector<unsigned char>& rawLedger); bool findRawLedger(const uint256& ledgerHash, std::vector<unsigned char>& rawLedger);

View File

@@ -1256,7 +1256,7 @@ Json::Value RPCServer::doRippleLinesGet(const Json::Value &params)
{ {
Log(lsINFO) << "doRippleLinesGet: line index: " << uNode.ToString(); Log(lsINFO) << "doRippleLinesGet: line index: " << uNode.ToString();
RippleState::pointer rsLine = mNetOps->getRippleState(uCurrent, uNode); RippleState::pointer rsLine = mNetOps->accessRippleState(uCurrent, uNode);
if (rsLine) if (rsLine)
{ {

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,9 @@
#ifndef __TRANSACTIONENGINE__ #ifndef __TRANSACTIONENGINE__
#define __TRANSACTIONENGINE__ #define __TRANSACTIONENGINE__
#include <boost/unordered_set.hpp>
#include <boost/unordered_map.hpp>
#include "Ledger.h" #include "Ledger.h"
#include "SerializedTransaction.h" #include "SerializedTransaction.h"
#include "SerializedLedger.h" #include "SerializedLedger.h"
@@ -93,7 +96,6 @@ enum TransactionAccountAction
taaCREATE, taaCREATE,
taaMODIFY, taaMODIFY,
taaDELETE, taaDELETE,
taaUNFUNDED,
}; };
typedef std::pair<TransactionAccountAction, SerializedLedgerEntry::pointer> AffectedAccount; typedef std::pair<TransactionAccountAction, SerializedLedgerEntry::pointer> AffectedAccount;
@@ -119,6 +121,8 @@ private:
const uint256& uRootIndex, const uint256& uRootIndex,
const uint256& uLedgerIndex); // Item being deleted const uint256& uLedgerIndex); // Item being deleted
void dirFirst(const uint256& uRootIndex, uint256& uEntryIndex, uint64& uEntryNode);
#ifdef WORK_IN_PROGRESS #ifdef WORK_IN_PROGRESS
typedef struct { typedef struct {
STAmount saWanted; // What this node wants from upstream. STAmount saWanted; // What this node wants from upstream.
@@ -135,56 +139,64 @@ private:
} paymentNode; } paymentNode;
typedef struct { typedef struct {
boost::unordered_set<....> offersDeletedAlways;
boost::unordered_set<....> offersDeletedOnSuccess;
std::vector<paymentNode> vpnNodes; std::vector<paymentNode> vpnNodes;
bool bAllowPartial; bool bAllowPartial;
} paymentGroup; } paymentGroup;
#endif #endif
TransactionEngineResult setAuthorized(const SerializedTransaction& txn, SLE::pointer sleSrc, bool bMustSetGenerator); TransactionEngineResult setAuthorized(const SerializedTransaction& txn, bool bMustSetGenerator);
TransactionEngineResult takeOffers( TransactionEngineResult takeOffers(
bool bPassive, bool bPassive,
const uint256& uBookBase, const uint256& uBookBase,
const uint160& uTakerAccountID, const uint160& uTakerAccountID,
const STAmount& saTakerPays, const SLE::pointer& sleTakerAccount,
const STAmount& saTakerGets, const STAmount& saTakerPays,
const STAmount& saTakerFunds, const STAmount& saTakerGets,
STAmount& saTakerPaid, STAmount& saTakerPaid,
STAmount& saTakerGot); STAmount& saTakerGot);
protected: protected:
Ledger::pointer mLedger; Ledger::pointer mLedger;
uint64 mLedgerParentCloseTime; uint64 mLedgerParentCloseTime;
uint160 mTxnAccountID;
SLE::pointer mTxnAccount;
entryMap mEntries; entryMap mEntries;
boost::unordered_set<uint256> mUnfunded; // Indexes that were found unfunded.
SLE::pointer entryCreate(LedgerEntryType letType, const uint256& uIndex); SLE::pointer entryCreate(LedgerEntryType letType, const uint256& uIndex);
void entryDelete(SLE::pointer sleEntry); void entryDelete(SLE::pointer sleEntry);
void entryModify(SLE::pointer sleEntry); void entryModify(SLE::pointer sleEntry);
void entryUnfunded(SLE::pointer sleEntry);
bool entryExists(SLE::pointer sleEntry); bool entryExists(SLE::pointer sleEntry);
STAmount rippleBalance(const uint160& uAccountID, const uint160& uIssuerAccountID, const uint160& uCurrency); STAmount rippleHolds(const uint160& uAccountID, const uint160& uCurrency, const uint160& uIssuerID);
STAmount rippleTransit(const uint160& uSenderID, const uint160& uReceiverID, const uint160& uIssuerID, const STAmount& saAmount);
STAmount rippleSend(const uint160& uSenderID, const uint160& uReceiverID, const STAmount& saAmount);
void rippleCredit(const uint160& uAccountID, const uint160& uIssuerAccountID, const uint160& uCurrency, const STAmount& saCredit); STAmount accountHolds(const uint160& uAccountID, const uint160& uCurrency, const uint160& uIssuerID);
void rippleDebit(const uint160& uAccountID, const uint160& uIssuerAccountID, const uint160& uCurrency, const STAmount& saDebit); STAmount accountSend(const uint160& uSenderID, const uint160& uReceiverID, const STAmount& saAmount);
STAmount accountFunds(const uint160& uAccountID, const STAmount& saDefault);
TransactionEngineResult doAccountSet(const SerializedTransaction& txn, SLE::pointer sleSrc); void txnWrite();
TransactionEngineResult doClaim(const SerializedTransaction& txn, SLE::pointer sleSrc);
TransactionEngineResult doCreditSet(const SerializedTransaction& txn, const uint160& uSrcAccountID); TransactionEngineResult offerDelete(const SLE::pointer& sleOffer, const uint256& uOfferIndex, const uint160& uOwnerID);
TransactionEngineResult doAccountSet(const SerializedTransaction& txn);
TransactionEngineResult doClaim(const SerializedTransaction& txn);
TransactionEngineResult doCreditSet(const SerializedTransaction& txn);
TransactionEngineResult doDelete(const SerializedTransaction& txn); TransactionEngineResult doDelete(const SerializedTransaction& txn);
TransactionEngineResult doInvoice(const SerializedTransaction& txn); TransactionEngineResult doInvoice(const SerializedTransaction& txn);
TransactionEngineResult doOfferCreate(const SerializedTransaction& txn, SLE::pointer sleSrc, const uint160& uSrcAccountID); TransactionEngineResult doOfferCreate(const SerializedTransaction& txn);
TransactionEngineResult doOfferCancel(const SerializedTransaction& txn, const uint160& uSrcAccountID); TransactionEngineResult doOfferCancel(const SerializedTransaction& txn);
TransactionEngineResult doNicknameSet(const SerializedTransaction& txn, SLE::pointer sleSrc, const uint160& uSrcAccountID); TransactionEngineResult doNicknameSet(const SerializedTransaction& txn);
TransactionEngineResult doPasswordFund(const SerializedTransaction& txn, SLE::pointer sleSrc, const uint160& uSrcAccountID); TransactionEngineResult doPasswordFund(const SerializedTransaction& txn);
TransactionEngineResult doPasswordSet(const SerializedTransaction& txn, SLE::pointer sleSrc); TransactionEngineResult doPasswordSet(const SerializedTransaction& txn);
TransactionEngineResult doPayment(const SerializedTransaction& txn, SLE::pointer sleSrc, const uint160& uSrcAccountID); TransactionEngineResult doPayment(const SerializedTransaction& txn);
TransactionEngineResult doStore(const SerializedTransaction& txn); TransactionEngineResult doStore(const SerializedTransaction& txn);
TransactionEngineResult doTake(const SerializedTransaction& txn); TransactionEngineResult doTake(const SerializedTransaction& txn);
TransactionEngineResult doWalletAdd(const SerializedTransaction& txn, SLE::pointer sleSrc); TransactionEngineResult doWalletAdd(const SerializedTransaction& txn);
public: public:
TransactionEngine() { ; } TransactionEngine() { ; }

View File

@@ -68,12 +68,12 @@ public:
return ret; return ret;
} }
base_uint& operator=(uint64 b) base_uint& operator=(uint64 uHost)
{ {
zero(); zero();
// Put in least significant bits. // Put in least significant bits.
((uint64_t *) end())[-1] = htobe64(b); ((uint64_t *) end())[-1] = htobe64(uHost);
return *this; return *this;
} }
@@ -105,8 +105,10 @@ public:
base_uint& operator++() base_uint& operator++()
{ {
// prefix operator // prefix operator
for (int i = WIDTH-1; ++pn[i] == 0 && i; i--) int i = WIDTH;
nothing();
while (i-- && !++pn[i])
;
return *this; return *this;
} }
@@ -122,9 +124,10 @@ public:
base_uint& operator--() base_uint& operator--()
{ {
// prefix operator int i = WIDTH;
for (int i = WIDTH-1; --pn[i] == (unsigned int) -1 && i; i--)
nothing(); while (i-- && !pn[i]--)
;
return *this; return *this;
} }
@@ -142,10 +145,11 @@ public:
{ {
uint64 carry = 0; uint64 carry = 0;
for (int i = 0; i < WIDTH; i++) for (int i = WIDTH; i--;)
{ {
uint64 n = carry + pn[i] + b.pn[i]; uint64 n = carry + be32toh(pn[i]) + be32toh(b.pn[i]);
pn[i] = n & 0xffffffff;
pn[i] = htobe32(n & 0xffffffff);
carry = n >> 32; carry = n >> 32;
} }
@@ -208,8 +212,6 @@ public:
void SetHex(const char* psz) void SetHex(const char* psz)
{ {
zero();
// skip leading spaces // skip leading spaces
while (isspace(*psz)) while (isspace(*psz))
psz++; psz++;
@@ -244,14 +246,21 @@ public:
const unsigned char* pEnd = reinterpret_cast<const unsigned char*>(psz); const unsigned char* pEnd = reinterpret_cast<const unsigned char*>(psz);
const unsigned char* pBegin = pEnd; const unsigned char* pBegin = pEnd;
// Find end.
while (phexdigit[*pEnd] >= 0) while (phexdigit[*pEnd] >= 0)
pEnd++; pEnd++;
// Take only last digits of over long string.
if ((unsigned int)(pEnd-pBegin) > 2*size()) if ((unsigned int)(pEnd-pBegin) > 2*size())
pBegin = pEnd - 2*size(); pBegin = pEnd - 2*size();
unsigned char* pOut = end()-((pEnd-pBegin+1)/2); unsigned char* pOut = end()-((pEnd-pBegin+1)/2);
zero();
if ((pEnd-pBegin) & 1)
*pOut++ = phexdigit[*pBegin++];
while (pBegin != pEnd) while (pBegin != pEnd)
{ {
unsigned char cHigh = phexdigit[*pBegin++] << 4; unsigned char cHigh = phexdigit[*pBegin++] << 4;
@@ -412,12 +421,10 @@ public:
uint160& operator=(uint64 uHost) uint160& operator=(uint64 uHost)
{ {
uint64 uBig = htobe64(uHost);
zero(); zero();
// Put in least significant bits. // Put in least significant bits.
memcpy(((uint64*)end())-1, &uBig, sizeof(uBig)); ((uint64_t *) end())[-1] = htobe64(uHost);
return *this; return *this;
} }
@@ -500,12 +507,12 @@ public:
*this = b; *this = b;
} }
uint256& operator=(uint64 b) uint256& operator=(uint64 uHost)
{ {
zero(); zero();
// Put in least significant bits. // Put in least significant bits.
((uint64_t *) end())[-1] = htobe64(b); ((uint64_t *) end())[-1] = htobe64(uHost);
return *this; return *this;
} }