mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Merge branch 'pay'
Conflicts: src/NetworkOPs.cpp src/SHAMap.cpp
This commit is contained in:
@@ -36,7 +36,7 @@ Application::Application() :
|
||||
mTxnDB(NULL), mLedgerDB(NULL), mWalletDB(NULL), mHashNodeDB(NULL), mNetNodeDB(NULL),
|
||||
mConnectionPool(mIOService), mPeerDoor(NULL), mRPCDoor(NULL)
|
||||
{
|
||||
nothing();
|
||||
RAND_bytes(mNonce256.begin(), mNonce256.size());
|
||||
}
|
||||
|
||||
extern const char *TxnDBInit[], *LedgerDBInit[], *WalletDBInit[], *HashNodeDBInit[], *NetNodeDBInit[];
|
||||
|
||||
@@ -47,6 +47,8 @@ class Application
|
||||
PeerDoor* mPeerDoor;
|
||||
RPCDoor* mRPCDoor;
|
||||
|
||||
uint256 mNonce256;
|
||||
|
||||
std::map<std::string, Peer::pointer> mPeerMap;
|
||||
boost::recursive_mutex mPeerMapLock;
|
||||
|
||||
@@ -73,8 +75,7 @@ public:
|
||||
DatabaseCon* getHashNodeDB() { return mHashNodeDB; }
|
||||
DatabaseCon* getNetNodeDB() { return mNetNodeDB; }
|
||||
|
||||
//Serializer* getSerializer(){ return(mSerializer); }
|
||||
//void setSerializer(Serializer* ser){ mSerializer=ser; }
|
||||
uint256 getNonce256() { return mNonce256; }
|
||||
|
||||
void run();
|
||||
void stop();
|
||||
|
||||
@@ -144,8 +144,7 @@ public:
|
||||
static Ledger::pointer loadByHash(const uint256& ledgerHash);
|
||||
|
||||
// index calculation functions
|
||||
static uint256 getAccountRootIndex(const uint160& account)
|
||||
{ return uint160extend256(account, lnsAccounts); } // Index is accountID extended to 256 bits
|
||||
static uint256 getAccountRootIndex(const uint160& uAccountID);
|
||||
|
||||
static uint256 getAccountRootIndex(const NewcoinAddress& account)
|
||||
{ return getAccountRootIndex(account.getAccountID()); }
|
||||
@@ -156,8 +155,7 @@ public:
|
||||
|
||||
SLE::pointer getGenerator(LedgerStateParms& parms, const uint160& uGeneratorID);
|
||||
|
||||
static uint256 getGeneratorIndex(const uint160& uGeneratorID)
|
||||
{ return uint160extend256(uGeneratorID, lnsGenerator); } // Index is the generator ID extended to 256 bits in namespace 1
|
||||
static uint256 getGeneratorIndex(const uint160& uGeneratorID);
|
||||
|
||||
//
|
||||
// Ripple functions
|
||||
@@ -169,6 +167,7 @@ public:
|
||||
|
||||
static uint256 getRippleStateIndex(const NewcoinAddress& naA, const NewcoinAddress& naB)
|
||||
{ return getRippleStateIndex(naA, naB, uint160()); }
|
||||
static uint256 getRippleDirIndex(const uint160& uAccountID);
|
||||
|
||||
RippleState::pointer getRippleState(const uint256& uNode);
|
||||
SLE::pointer getRippleState(LedgerStateParms& parms, const uint256& uNode);
|
||||
@@ -194,7 +193,7 @@ public:
|
||||
// Directory functions
|
||||
//
|
||||
|
||||
static uint256 getDirIndex(const uint256& uBase, const LedgerEntryType letKind, const uint64 uNodeDir=0);
|
||||
static uint256 getDirIndex(const uint256& uBase, const uint64 uNodeDir=0);
|
||||
|
||||
SLE::pointer getDirRoot(LedgerStateParms& parms, const uint256& uRootIndex);
|
||||
SLE::pointer getDirNode(LedgerStateParms& parms, const uint256& uNodeIndex);
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "SerializedObject.h"
|
||||
|
||||
// Used as the type of a transaction or the type of a ledger entry.
|
||||
enum LedgerEntryType
|
||||
{
|
||||
ltINVALID = -1,
|
||||
@@ -14,15 +15,19 @@ enum LedgerEntryType
|
||||
ltNICKNAME
|
||||
};
|
||||
|
||||
// In the format 160 + namespace + other.
|
||||
// Used as a prefix for computing ledger indexes (keys).
|
||||
enum LedgerNameSpace
|
||||
{
|
||||
lnsGenerator = -1,
|
||||
lnsAccounts,
|
||||
lnsRipple,
|
||||
lnsBonds,
|
||||
lnsInvoices,
|
||||
lnsMultiSig
|
||||
spaceAccount,
|
||||
spaceGenerator,
|
||||
spaceNickname,
|
||||
spaceRipple,
|
||||
spaceRippleDir,
|
||||
spaceOffer,
|
||||
spaceOfferDir,
|
||||
spaceBond,
|
||||
spaceInvoice,
|
||||
spaceMultiSig,
|
||||
};
|
||||
|
||||
enum LedgerSpecificFlags
|
||||
|
||||
@@ -1,6 +1,16 @@
|
||||
|
||||
#include "Ledger.h"
|
||||
|
||||
uint256 Ledger::getAccountRootIndex(const uint160& uAccountID)
|
||||
{
|
||||
Serializer s;
|
||||
|
||||
s.add8(spaceAccount);
|
||||
s.add160(uAccountID);
|
||||
|
||||
return s.getSHA512Half();
|
||||
}
|
||||
|
||||
uint256 Ledger::getRippleStateIndex(const NewcoinAddress& naA, const NewcoinAddress& naB, const uint160& uCurrency)
|
||||
{
|
||||
uint160 uAID = naA.getAccountID();
|
||||
@@ -8,6 +18,7 @@ uint256 Ledger::getRippleStateIndex(const NewcoinAddress& naA, const NewcoinAddr
|
||||
bool bAltB = uAID < uBID;
|
||||
Serializer s;
|
||||
|
||||
s.add8(spaceRipple);
|
||||
s.add160(bAltB ? uAID : uBID);
|
||||
s.add160(bAltB ? uBID : uAID);
|
||||
s.add160(uCurrency);
|
||||
@@ -15,6 +26,26 @@ uint256 Ledger::getRippleStateIndex(const NewcoinAddress& naA, const NewcoinAddr
|
||||
return s.getSHA512Half();
|
||||
}
|
||||
|
||||
uint256 Ledger::getRippleDirIndex(const uint160& uAccountID)
|
||||
{
|
||||
Serializer s;
|
||||
|
||||
s.add8(spaceRippleDir);
|
||||
s.add160(uAccountID);
|
||||
|
||||
return s.getSHA512Half();
|
||||
}
|
||||
|
||||
uint256 Ledger::getGeneratorIndex(const uint160& uGeneratorID)
|
||||
{
|
||||
Serializer s;
|
||||
|
||||
s.add8(spaceGenerator);
|
||||
s.add160(uGeneratorID);
|
||||
|
||||
return s.getSHA512Half();
|
||||
}
|
||||
|
||||
uint160 Ledger::getOfferBase(const uint160& currencyIn, const uint160& accountIn,
|
||||
const uint160& currencyOut, const uint160& accountOut)
|
||||
{
|
||||
|
||||
@@ -138,28 +138,18 @@ SerializedLedgerEntry::pointer Ledger::getRippleState(LedgerStateParms& parms, c
|
||||
// Directory
|
||||
//
|
||||
|
||||
uint256 Ledger::getDirIndex(const uint256& uBase, const LedgerEntryType letKind, const uint64 uNodeDir)
|
||||
// For a directory entry put in the 64 bit index or quality.
|
||||
uint256 Ledger::getDirIndex(const uint256& uBase, const uint64 uNodeDir)
|
||||
{
|
||||
// Indexes are stored in little endian format.
|
||||
// The low bytes are indexed first, so when printed as a hex stream the hex is in byte order.
|
||||
// Therefore, we place uNodeDir in the 8 right most bytes.
|
||||
Serializer sKey;
|
||||
// Indexes are stored in big endian format: they print as hex as stored.
|
||||
// Most significant bytes are first. Least significant bytes repesent adjcent entries.
|
||||
// We place uNodeDir in the 8 right most bytes to be adjcent.
|
||||
// Want uNodeDir in big endian format so ++ goes to the next entry for indexes.
|
||||
uint256 uNode(uBase);
|
||||
|
||||
sKey.add256(uBase);
|
||||
sKey.add8(letKind);
|
||||
((uint64*) uNode.end())[-1] = htobe64(uNodeDir);
|
||||
|
||||
uint256 uResult = sKey.getSHA512Half();
|
||||
|
||||
Serializer sNode; // Put in a fixed byte order: BIG. YYY
|
||||
|
||||
sNode.add64(uNodeDir);
|
||||
|
||||
// YYY SLOPPY
|
||||
std::vector<unsigned char> vucData = sNode.getData();
|
||||
|
||||
std::copy(vucData.begin(), vucData.end(), uResult.end()-(64/8));
|
||||
|
||||
return uResult;
|
||||
return uNode;
|
||||
}
|
||||
|
||||
SerializedLedgerEntry::pointer Ledger::getDirRoot(LedgerStateParms& parms, const uint256& uRootIndex)
|
||||
|
||||
@@ -163,11 +163,10 @@ SLE::pointer NetworkOPs::getGenerator(const uint256& uLedger, const uint160& uGe
|
||||
bool NetworkOPs::getDirInfo(
|
||||
const uint256& uLedger,
|
||||
const uint256& uBase,
|
||||
const LedgerEntryType letKind,
|
||||
uint256& uDirLineNodeFirst,
|
||||
uint256& uDirLineNodeLast)
|
||||
{
|
||||
uint256 uRootIndex = Ledger::getDirIndex(uBase, letKind);
|
||||
uint256 uRootIndex = Ledger::getDirIndex(uBase, 0);
|
||||
LedgerStateParms lspRoot = lepNONE;
|
||||
SLE::pointer sleRoot = mLedgerMaster->getLedgerByHash(uLedger)->getDirRoot(lspRoot, uRootIndex);
|
||||
|
||||
@@ -177,8 +176,9 @@ bool NetworkOPs::getDirInfo(
|
||||
|
||||
Log(lsTRACE) << "getDirInfo: first: " << strHex(sleRoot->getIFieldU64(sfFirstNode)) ;
|
||||
Log(lsTRACE) << "getDirInfo: last: " << strHex(sleRoot->getIFieldU64(sfLastNode)) ;
|
||||
uDirLineNodeFirst = Ledger::getDirIndex(uBase, letKind, sleRoot->getIFieldU64(sfFirstNode));
|
||||
uDirLineNodeLast = Ledger::getDirIndex(uBase, letKind, sleRoot->getIFieldU64(sfLastNode));
|
||||
|
||||
uDirLineNodeFirst = Ledger::getDirIndex(uBase, sleRoot->getIFieldU64(sfFirstNode));
|
||||
uDirLineNodeLast = Ledger::getDirIndex(uBase, sleRoot->getIFieldU64(sfLastNode));
|
||||
|
||||
Log(lsTRACE) << "getDirInfo: first: " << uDirLineNodeFirst.ToString() ;
|
||||
Log(lsTRACE) << "getDirInfo: last: " << uDirLineNodeLast.ToString() ;
|
||||
|
||||
@@ -75,7 +75,6 @@ public:
|
||||
//
|
||||
|
||||
bool getDirInfo(const uint256& uLedger, const uint256& uBase,
|
||||
const LedgerEntryType letKind,
|
||||
uint256& uDirNodeFirst, uint256& uDirNodeLast);
|
||||
STVector256 getDirNode(const uint256& uLedger, const uint256& uDirLineNode);
|
||||
|
||||
@@ -84,7 +83,7 @@ public:
|
||||
//
|
||||
|
||||
bool getDirLineInfo(const uint256& uLedger, const NewcoinAddress& naAccount, uint256& uDirLineNodeFirst, uint256& uDirLineNodeLast)
|
||||
{ return getDirInfo(uLedger, uint160extend256(naAccount.getAccountID(), 0), ltRIPPLE_STATE, uDirLineNodeFirst, uDirLineNodeLast); }
|
||||
{ return getDirInfo(uLedger, Ledger::getRippleDirIndex(naAccount.getAccountID()), uDirLineNodeFirst, uDirLineNodeLast); }
|
||||
|
||||
RippleState::pointer getRippleState(const uint256& uLedger, const uint256& uIndex);
|
||||
|
||||
|
||||
@@ -389,7 +389,6 @@ Json::Value RPCServer::doAccountLines(Json::Value ¶ms)
|
||||
// We access a committed ledger and need not worry about changes.
|
||||
uint256 uDirLineNodeFirst;
|
||||
uint256 uDirLineNodeLast;
|
||||
// Ledger::getDirIndex(uBase, letKind, uNodeDir)
|
||||
|
||||
if (mNetOps->getDirLineInfo(uLedger, naAccount, uDirLineNodeFirst, uDirLineNodeLast))
|
||||
{
|
||||
|
||||
@@ -12,6 +12,21 @@
|
||||
#include "Serializer.h"
|
||||
#include "BitcoinUtil.h"
|
||||
#include "Log.h"
|
||||
#include "SHAMap.h"
|
||||
#include "Application.h"
|
||||
|
||||
std::size_t hash_SMN::operator() (const SHAMapNode& mn) const
|
||||
{
|
||||
return mn.getDepth()
|
||||
^ *reinterpret_cast<const std::size_t *>(mn.getNodeID().begin())
|
||||
^ *reinterpret_cast<const std::size_t *>(theApp->getNonce256().begin());
|
||||
}
|
||||
|
||||
std::size_t hash_SMN::operator() (const uint256& u) const
|
||||
{
|
||||
return *reinterpret_cast<const std::size_t *>(u.begin())
|
||||
^ *reinterpret_cast<const std::size_t *>(theApp->getNonce256().begin());
|
||||
}
|
||||
|
||||
SHAMap::SHAMap(uint32 seq) : mSeq(seq), mState(Modifying)
|
||||
{
|
||||
|
||||
14
src/SHAMap.h
14
src/SHAMap.h
@@ -77,17 +77,11 @@ public:
|
||||
};
|
||||
|
||||
class hash_SMN
|
||||
{ // These must be randomized for release
|
||||
{
|
||||
public:
|
||||
std::size_t operator() (const SHAMapNode& mn) const
|
||||
#if 0
|
||||
{ return mn.getDepth() ^ static_cast<std::size_t>(mn.getNodeID().GetAt(0)); }
|
||||
#else
|
||||
{ return mn.getDepth() ^ *reinterpret_cast<const std::size_t *>(mn.getNodeID().begin()); }
|
||||
#endif
|
||||
std::size_t operator() (const SHAMapNode& mn) const;
|
||||
|
||||
std::size_t operator() (const uint256& u) const
|
||||
{ return *reinterpret_cast<const std::size_t *>(u.begin()); }
|
||||
std::size_t operator() (const uint256& u) const;
|
||||
};
|
||||
|
||||
class SHAMapItem
|
||||
@@ -176,7 +170,7 @@ public:
|
||||
uint32 getSeq() const { return mSeq; }
|
||||
void setSeq(uint32 s) { mSeq = s; }
|
||||
const uint256& getNodeHash() const { return mHash; }
|
||||
TNType getType() const { return mType; }
|
||||
TNType getType() const { return mType; }
|
||||
|
||||
// type functions
|
||||
bool isLeaf() const { return (mType == tnTRANSACTION) || (mType == tnACCOUNT_STATE); }
|
||||
|
||||
@@ -14,12 +14,11 @@ typedef SerializedLedgerEntry SLE;
|
||||
TransactionEngineResult TransactionEngine::dirAdd(
|
||||
std::vector<AffectedAccount>& accounts,
|
||||
uint64& uNodeDir,
|
||||
const LedgerEntryType letKind,
|
||||
const uint256& uBase,
|
||||
const uint256& uLedgerIndex)
|
||||
{
|
||||
// Get the root.
|
||||
uint256 uRootIndex = Ledger::getDirIndex(uBase, letKind);
|
||||
uint256 uRootIndex = Ledger::getDirIndex(uBase, 0);
|
||||
LedgerStateParms lspRoot = lepNONE;
|
||||
SLE::pointer sleRoot = mLedger->getDirRoot(lspRoot, uRootIndex);
|
||||
bool bRootNew;
|
||||
@@ -50,7 +49,7 @@ TransactionEngineResult TransactionEngine::dirAdd(
|
||||
}
|
||||
|
||||
// Get the last node.
|
||||
uint256 uNodeIndex = Ledger::getDirIndex(uBase, letKind, uNodeDir);
|
||||
uint256 uNodeIndex = Ledger::getDirIndex(uBase, uNodeDir);
|
||||
LedgerStateParms lspNode = lepNONE;
|
||||
SLE::pointer sleNode = bRootNew ? SLE::pointer() : mLedger->getDirNode(lspNode, uNodeIndex);
|
||||
|
||||
@@ -111,12 +110,11 @@ TransactionEngineResult TransactionEngine::dirAdd(
|
||||
TransactionEngineResult TransactionEngine::dirDelete(
|
||||
std::vector<AffectedAccount>& accounts,
|
||||
const uint64& uNodeDir,
|
||||
const LedgerEntryType letKind,
|
||||
const uint256& uBase,
|
||||
const uint256& uLedgerIndex)
|
||||
{
|
||||
uint64 uNodeCur = uNodeDir;
|
||||
uint256 uNodeIndex = Ledger::getDirIndex(uBase, letKind, uNodeCur);
|
||||
uint256 uNodeIndex = Ledger::getDirIndex(uBase, uNodeCur);
|
||||
LedgerStateParms lspNode = lepNONE;
|
||||
SLE::pointer sleNode = mLedger->getDirNode(lspNode, uNodeIndex);
|
||||
|
||||
@@ -141,7 +139,7 @@ TransactionEngineResult TransactionEngine::dirDelete(
|
||||
{
|
||||
// Get root information
|
||||
LedgerStateParms lspRoot = lepNONE;
|
||||
SLE::pointer sleRoot = mLedger->getDirRoot(lspRoot, Ledger::getDirIndex(uBase, letKind));
|
||||
SLE::pointer sleRoot = mLedger->getDirRoot(lspRoot, Ledger::getDirIndex(uBase, 0));
|
||||
|
||||
if (!sleRoot)
|
||||
{
|
||||
@@ -197,7 +195,7 @@ TransactionEngineResult TransactionEngine::dirDelete(
|
||||
|
||||
// Get replacement node.
|
||||
lspNode = lepNONE;
|
||||
sleNode = mLedger->getDirNode(lspNode, Ledger::getDirIndex(uBase, letKind, uNodeCur));
|
||||
sleNode = mLedger->getDirNode(lspNode, Ledger::getDirIndex(uBase, uNodeCur));
|
||||
svIndexes = sleNode->getIFieldV256(sfIndexes);
|
||||
}
|
||||
}
|
||||
@@ -595,7 +593,7 @@ TransactionEngineResult TransactionEngine::doCreditSet(const SerializedTransacti
|
||||
|
||||
bAddIndex = !(sleRippleState->getFlags() & uFlags);
|
||||
|
||||
sleRippleState->setIFieldAmount(bSltD ? sfLowLimit : sfHighID, saLimitAmount);
|
||||
sleRippleState->setIFieldAmount(bSltD ? sfLowLimit : sfHighLimit, saLimitAmount);
|
||||
|
||||
accounts.push_back(std::make_pair(taaMODIFY, sleRippleState));
|
||||
|
||||
@@ -640,7 +638,7 @@ TransactionEngineResult TransactionEngine::doCreditSet(const SerializedTransacti
|
||||
|
||||
// XXX Verify extend is passing the right bits, not the zero bits.
|
||||
// XXX Make dirAdd more flexiable to take vector.
|
||||
terResult = dirAdd(accounts, uSrcRef, ltRIPPLE_STATE, uint160extend256(uSrcAccountID, 0), sleRippleState->getIndex());
|
||||
terResult = dirAdd(accounts, uSrcRef, Ledger::getRippleDirIndex(uSrcAccountID), sleRippleState->getIndex());
|
||||
}
|
||||
|
||||
std::cerr << "doCreditSet<" << std::endl;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#ifndef __TRANSACTIONENGINE__
|
||||
#define __TRANSACTIONENGINE__
|
||||
|
||||
#include "Ledger.h"
|
||||
#include "Ledger.h"
|
||||
#include "SerializedTransaction.h"
|
||||
#include "SerializedLedger.h"
|
||||
@@ -75,14 +74,12 @@ private:
|
||||
TransactionEngineResult dirAdd(
|
||||
std::vector<AffectedAccount>& accounts,
|
||||
uint64& uNodeDir, // Node of entry.
|
||||
const LedgerEntryType letKind,
|
||||
const uint256& uBase,
|
||||
const uint256& uLedgerIndex);
|
||||
|
||||
TransactionEngineResult dirDelete(
|
||||
std::vector<AffectedAccount>& accounts,
|
||||
const uint64& uNodeDir, // Node item is mentioned in.
|
||||
const LedgerEntryType letKind,
|
||||
const uint256& uBase, // Key of item.
|
||||
const uint256& uLedgerIndex); // Item being deleted
|
||||
|
||||
|
||||
@@ -387,12 +387,14 @@ public:
|
||||
*this = b;
|
||||
}
|
||||
|
||||
uint160& operator=(uint64 b)
|
||||
uint160& operator=(uint64 uHost)
|
||||
{
|
||||
uint64 uBig = htobe64(uHost);
|
||||
|
||||
zero();
|
||||
|
||||
// Put in least significant bits.
|
||||
((uint64_t *) end())[-1] = htobe64(b);
|
||||
memcpy(((uint64_t*)end())-1, &uBig, sizeof(uBig));
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -526,8 +528,6 @@ inline const uint256 operator^(const uint256& a, const uint256& b) { return (b
|
||||
inline const uint256 operator&(const uint256& a, const uint256& b) { return (base_uint256)a & (base_uint256)b; }
|
||||
inline const uint256 operator|(const uint256& a, const uint256& b) { return (base_uint256)a | (base_uint256)b; }
|
||||
|
||||
uint256 uint160extend256(const uint160& uSource, uint uNamespace);
|
||||
|
||||
inline int Testuint256AdHoc(std::vector<std::string> vArg)
|
||||
{
|
||||
uint256 g(0);
|
||||
|
||||
@@ -1,18 +1,6 @@
|
||||
#include "utils.h"
|
||||
#include "uint256.h"
|
||||
|
||||
// XXX Assume little-endian.
|
||||
uint256 uint160extend256(const uint160& uSource, uint uNamespace)
|
||||
{
|
||||
uint256 uResult;
|
||||
|
||||
// Place right justified: in most significant bits.
|
||||
memcpy(uResult.end() - uSource.size(), uSource.begin(), uSource.size());
|
||||
uResult.begin()[uResult.size() - uSource.size() - 1] = uNamespace;
|
||||
|
||||
return uResult;
|
||||
}
|
||||
|
||||
//
|
||||
// Time support
|
||||
// We have our own epoch.
|
||||
|
||||
Reference in New Issue
Block a user