mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-25 05:25:55 +00:00
Tie in transaction master code.
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include "PubKeyCache.h"
|
||||
#include "ScopedLock.h"
|
||||
#include "LedgerMaster.h"
|
||||
#include "TransactionMaster.h"
|
||||
#include "Wallet.h"
|
||||
#include "Peer.h"
|
||||
#include "NetworkOPs.h"
|
||||
@@ -41,6 +42,7 @@ class Application
|
||||
KnownNodeList mKnownNodes;
|
||||
PubKeyCache mPKCache;
|
||||
LedgerMaster mMasterLedger;
|
||||
TransactionMaster mMasterTransaction;
|
||||
|
||||
DatabaseCon *mTxnDB, *mLedgerDB, *mWalletDB, *mHashNodeDB, *mNetNodeDB;
|
||||
|
||||
@@ -70,6 +72,7 @@ public:
|
||||
boost::asio::io_service& getIOService() { return mIOService; }
|
||||
|
||||
LedgerMaster& getMasterLedger() { return mMasterLedger; }
|
||||
TransactionMaster& getMasterTransaction() { return mMasterTransaction; }
|
||||
|
||||
DatabaseCon* getTxnDB() { return mTxnDB; }
|
||||
DatabaseCon* getLedgerDB() { return mLedgerDB; }
|
||||
|
||||
2
Makefile
2
Makefile
@@ -71,7 +71,7 @@ SRCS= keystore.cpp BitcoinUtil.cpp \
|
||||
Application.cpp TimingService.cpp KnownNodeList.cpp ConnectionPool.cpp Peer.cpp \
|
||||
PeerDoor.cpp RPCDoor.cpp RPCServer.cpp rpc.cpp Conversion.cpp RequestParser.cpp HashedObject.cpp \
|
||||
UniqueNodeList.cpp PubKeyCache.cpp SHAMapDiff.cpp DeterministicKeys.cpp LedgerMaster.cpp \
|
||||
LedgerHistory.cpp NetworkOPs.cpp CallRPC.cpp DBInit.cpp LocalTransaction.cpp
|
||||
LedgerHistory.cpp NetworkOPs.cpp CallRPC.cpp DBInit.cpp LocalTransaction.cpp TransactionMaster.cpp
|
||||
|
||||
DBSRCS= SqliteDatabase.cpp database.cpp
|
||||
DBSRCC= sqlite3.c
|
||||
|
||||
@@ -31,7 +31,7 @@ protected:
|
||||
std::map<key_type, weak_data_ptr> mMap; // Track stored objects
|
||||
|
||||
public:
|
||||
TaggedCache(int size, int age) : mTargetSize(size), mTargetAge(age), mLastSweep(0) { ; }
|
||||
TaggedCache(int size, int age) : mTargetSize(size), mTargetAge(age), mLastSweep(time(NULL)) { ; }
|
||||
int getTargetSize() const;
|
||||
int getTargetAge() const;
|
||||
|
||||
|
||||
@@ -159,6 +159,11 @@ void Transaction::setStatus(TransStatus ts, uint32 lseq)
|
||||
mInLedger=lseq;
|
||||
}
|
||||
|
||||
void Transaction::saveTransaction(Transaction::pointer txn)
|
||||
{
|
||||
txn->save();
|
||||
}
|
||||
|
||||
bool Transaction::save() const
|
||||
{
|
||||
if((mStatus==INVALID)||(mStatus==REMOVED)) return false;
|
||||
|
||||
@@ -82,6 +82,7 @@ public:
|
||||
void setStatus(TransStatus status) { mStatus=status; }
|
||||
|
||||
// database functions
|
||||
static void saveTransaction(Transaction::pointer);
|
||||
bool save() const;
|
||||
static Transaction::pointer load(const uint256& id);
|
||||
static Transaction::pointer findFrom(const uint160& fromID, uint32 seq);
|
||||
|
||||
40
TransactionMaster.cpp
Normal file
40
TransactionMaster.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
|
||||
#include "boost/bind.hpp"
|
||||
|
||||
#include "Application.h"
|
||||
#include "TransactionMaster.h"
|
||||
|
||||
#ifndef CACHED_TRANSACTION_NUM
|
||||
#define CACHED_TRANSACTION_NUM 65536
|
||||
#endif
|
||||
|
||||
#ifndef CACHED_TRANSACTION_AGE
|
||||
#define CACHED_TRANSACTION_AGE 1800
|
||||
#endif
|
||||
|
||||
TransactionMaster::TransactionMaster() : mCache(CACHED_TRANSACTION_NUM, CACHED_TRANSACTION_AGE)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
Transaction::pointer TransactionMaster::fetch(const uint256& txnID, bool checkDisk)
|
||||
{
|
||||
Transaction::pointer txn=mCache.fetch(txnID);
|
||||
if(!checkDisk || txn) return txn;
|
||||
|
||||
txn=Transaction::load(txnID);
|
||||
if(!txn) return txn;
|
||||
|
||||
mCache.canonicalize(txnID, txn);
|
||||
return txn;
|
||||
}
|
||||
|
||||
bool TransactionMaster::canonicalize(Transaction::pointer& txn, bool may_be_new)
|
||||
{
|
||||
uint256 tid=txn->getID();
|
||||
if(!tid) return false;
|
||||
if(mCache.canonicalize(tid, txn)) return true;
|
||||
if(may_be_new)
|
||||
theApp->getIOService().post(boost::bind(&Transaction::saveTransaction, txn));
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user