Merge branch 'master' of github.com:jedmccaleb/NewCoin

This commit is contained in:
Arthur Britto
2012-11-23 18:30:55 -08:00
17 changed files with 98 additions and 62 deletions

View File

@@ -38,7 +38,7 @@ DatabaseCon::~DatabaseCon()
}
Application::Application() :
mIOWork(mIOService), mAuxWork(mAuxService), mUNL(mIOService), mNetOps(mIOService, &mMasterLedger),
mIOWork(mIOService), mAuxWork(mAuxService), mUNL(mIOService), mNetOps(mIOService, &mLedgerMaster),
mTempNodeCache("NodeCache", 16384, 90), mHashedObjectStore(16384, 300),
mSNTPClient(mAuxService), mRPCHandler(&mNetOps),
mRpcDB(NULL), mTxnDB(NULL), mLedgerDB(NULL), mWalletDB(NULL), mHashNodeDB(NULL), mNetNodeDB(NULL),
@@ -122,7 +122,7 @@ void Application::run()
{
Ledger::pointer ledger = Ledger::getLastFullLedger();
if (ledger)
mMasterLedger.setLedgerRangePresent(0, ledger->getLedgerSeq());
mLedgerMaster.setLedgerRangePresent(0, ledger->getLedgerSeq());
}
//
@@ -216,7 +216,7 @@ void Application::sweep()
{
mMasterTransaction.sweep();
mHashedObjectStore.sweep();
mMasterLedger.sweep();
mLedgerMaster.sweep();
mTempNodeCache.sweep();
mValidations.sweep();
mSweepTimer.expires_from_now(boost::posix_time::seconds(60));
@@ -249,12 +249,12 @@ void Application::startNewLedger()
firstLedger->updateHash();
firstLedger->setClosed();
firstLedger->setAccepted();
mMasterLedger.pushLedger(firstLedger);
mLedgerMaster.pushLedger(firstLedger);
Ledger::pointer secondLedger = boost::make_shared<Ledger>(true, boost::ref(*firstLedger));
secondLedger->setClosed();
secondLedger->setAccepted();
mMasterLedger.pushLedger(secondLedger, boost::make_shared<Ledger>(true, boost::ref(*secondLedger)), false);
mLedgerMaster.pushLedger(secondLedger, boost::make_shared<Ledger>(true, boost::ref(*secondLedger)), false);
assert(!!secondLedger->getAccountState(rootAddress));
mNetOps.setLastCloseTime(secondLedger->getCloseTimeNC());
}
@@ -293,10 +293,10 @@ void Application::loadOldLedger()
cLog(lsFATAL) << "Ledger is not sane.";
exit(-1);
}
mMasterLedger.setLedgerRangePresent(0, lastLedger->getLedgerSeq());
mLedgerMaster.setLedgerRangePresent(0, lastLedger->getLedgerSeq());
Ledger::pointer openLedger = boost::make_shared<Ledger>(false, boost::ref(*lastLedger));
mMasterLedger.switchLedgers(lastLedger, openLedger);
mLedgerMaster.switchLedgers(lastLedger, openLedger);
mNetOps.setLastCloseTime(lastLedger->getCloseTimeNC());
}
catch (SHAMapMissingNode& mn)

View File

@@ -47,7 +47,7 @@ class Application
Wallet mWallet;
UniqueNodeList mUNL;
LedgerMaster mMasterLedger;
LedgerMaster mLedgerMaster;
LedgerAcquireMaster mMasterLedgerAcquire;
TransactionMaster mMasterTransaction;
NetworkOPs mNetOps;
@@ -92,7 +92,7 @@ public:
boost::asio::io_service& getIOService() { return mIOService; }
boost::asio::io_service& getAuxService() { return mAuxService; }
LedgerMaster& getMasterLedger() { return mMasterLedger; }
LedgerMaster& getLedgerMaster() { return mLedgerMaster; }
LedgerAcquireMaster& getMasterLedgerAcquire() { return mMasterLedgerAcquire; }
TransactionMaster& getMasterTransaction() { return mMasterTransaction; }
NodeCache& getTempNodeCache() { return mTempNodeCache; }

View File

@@ -23,8 +23,9 @@ const char* Job::toString(JobType t)
case jtCLIENT: return "clientCommand";
case jtPEER: return "peerCommand";
case jtDISK: return "diskAccess";
case jtLEDGER: return "acceptLedger";
case jtRPC: return "rpc";
case jtACCEPTLEDGER: return "acceptLedger";
case jtPUBLEDGER: return "pubLedger";
default: assert(false); return "unknown";
}
}

View File

@@ -36,10 +36,11 @@ enum JobType
jtCLIENT = 10,
jtPEER = 11,
jtDISK = 12,
jtLEDGER = 13,
jtRPC = 14,
jtRPC = 13,
jtACCEPTLEDGER = 14,
jtPUBLEDGER = 15,
};
#define NUM_JOB_TYPES 16
#define NUM_JOB_TYPES 24
class Job
{

View File

@@ -438,7 +438,8 @@ void Ledger::saveAcceptedLedger(bool fromConsensus)
return;
}
theApp->getMasterLedger().setFullLedger(shared_from_this());
theApp->getLedgerMaster().setFullLedger(shared_from_this());
event = LoadEvent::pointer();
theApp->getOPs().pubLedger(shared_from_this());

View File

@@ -176,7 +176,7 @@ void LedgerAcquire::done()
{
if (mAccept)
mLedger->setAccepted();
theApp->getMasterLedger().storeLedger(mLedger);
theApp->getLedgerMaster().storeLedger(mLedger);
}
for (unsigned int i = 0; i < triggers.size(); ++i)

View File

@@ -407,7 +407,7 @@ void LedgerConsensus::handleLCL(const uint256& lclHash)
if (mPreviousLedger->getHash() != mPrevLedgerHash)
{ // we need to switch the ledger we're working from
Ledger::pointer newLCL = theApp->getMasterLedger().getLedgerByHash(lclHash);
Ledger::pointer newLCL = theApp->getLedgerMaster().getLedgerByHash(lclHash);
if (newLCL)
mPreviousLedger = newLCL;
else if (!mAcquiringLedger || (mAcquiringLedger->getHash() != mPrevLedgerHash))
@@ -578,7 +578,7 @@ int LedgerConsensus::startup()
void LedgerConsensus::statePreClose()
{ // it is shortly before ledger close time
bool anyTransactions = theApp->getMasterLedger().getCurrentLedger()->peekTransactionMap()->getHash().isNonZero();
bool anyTransactions = theApp->getLedgerMaster().getCurrentLedger()->peekTransactionMap()->getHash().isNonZero();
int proposersClosed = mPeerPositions.size();
// This ledger is open. This computes how long since the last ledger closed
@@ -613,7 +613,7 @@ void LedgerConsensus::closeLedger()
mCloseTime = theApp->getOPs().getCloseTimeNC();
theApp->getOPs().setLastCloseTime(mCloseTime);
statusChange(ripple::neCLOSING_LEDGER, *mPreviousLedger);
takeInitialPosition(*theApp->getMasterLedger().closeLedger(true));
takeInitialPosition(*theApp->getLedgerMaster().closeLedger(true));
}
void LedgerConsensus::stateEstablish()
@@ -813,7 +813,7 @@ SHAMap::pointer LedgerConsensus::getTransactionTree(const uint256& hash, bool do
if (mState == lcsPRE_CLOSE)
{
SHAMap::pointer currentMap = theApp->getMasterLedger().getCurrentLedger()->peekTransactionMap();
SHAMap::pointer currentMap = theApp->getLedgerMaster().getCurrentLedger()->peekTransactionMap();
if (currentMap->getHash() == hash)
{
cLog(lsINFO) << "node proposes our open transaction set";
@@ -1027,7 +1027,7 @@ void LedgerConsensus::beginAccept(bool synchronous)
else
{
theApp->getIOService().post(boost::bind(&LedgerConsensus::accept, shared_from_this(), consensusSet,
theApp->getJobQueue().getLoadEvent(jtLEDGER)));
theApp->getJobQueue().getLoadEvent(jtACCEPTLEDGER)));
}
}
@@ -1251,7 +1251,7 @@ void LedgerConsensus::accept(SHAMap::ref set, LoadEvent::pointer)
cLog(lsINFO) << "CNF newLCL " << newLCLHash;
Ledger::pointer newOL = boost::make_shared<Ledger>(true, boost::ref(*newLCL));
ScopedLock sl = theApp->getMasterLedger().getLock();
ScopedLock sl = theApp->getLedgerMaster().getLock();
// Apply disputed transactions that didn't get in
TransactionEngine engine(newOL);
@@ -1274,9 +1274,9 @@ void LedgerConsensus::accept(SHAMap::ref set, LoadEvent::pointer)
}
cLog(lsINFO) << "Applying transactions from current ledger";
applyTransactions(theApp->getMasterLedger().getCurrentLedger()->peekTransactionMap(), newOL, newLCL,
applyTransactions(theApp->getLedgerMaster().getCurrentLedger()->peekTransactionMap(), newOL, newLCL,
failedTransactions, true);
theApp->getMasterLedger().pushLedger(newLCL, newOL, !mConsensusFail);
theApp->getLedgerMaster().pushLedger(newLCL, newOL, !mConsensusFail);
mNewLedgerHash = newLCL->getHash();
mState = lcsACCEPTED;
sl.unlock();

View File

@@ -946,7 +946,7 @@ Json::Value NetworkOPs::getServerInfo()
if (mNeedNetworkLedger)
info["networkLedger"] = "waiting";
info["completeLedgers"] = theApp->getMasterLedger().getCompleteLedgers();
info["completeLedgers"] = theApp->getLedgerMaster().getCompleteLedgers();
info["peers"] = theApp->getConnectionPool().getPeerCount();
Json::Value lastClose = Json::objectValue;
@@ -985,7 +985,7 @@ void NetworkOPs::pubProposedTransaction(Ledger::ref lpCurrent, const SerializedT
Json::Value jvObj = transJson(stTxn, terResult, false, lpCurrent, "transaction");
{
boost::interprocess::sharable_lock<boost::interprocess::interprocess_upgradable_mutex> sl(mMonitorLock);
boost::recursive_mutex::scoped_lock sl(mMonitorLock);
BOOST_FOREACH(InfoSub* ispListener, mSubRTTransactions)
{
ispListener->send(jvObj);
@@ -1002,8 +1002,10 @@ void NetworkOPs::pubLedger(Ledger::ref lpAccepted)
if (NetworkOPs::omDISCONNECTED == getOperatingMode())
return;
LoadEvent::pointer event = theApp->getJobQueue().getLoadEvent(jtPUBLEDGER);
{
boost::interprocess::sharable_lock<boost::interprocess::interprocess_upgradable_mutex> sl(mMonitorLock);
boost::recursive_mutex::scoped_lock sl(mMonitorLock);
if (!mSubLedger.empty())
{
@@ -1076,7 +1078,7 @@ void NetworkOPs::pubAcceptedTransaction(Ledger::ref lpCurrent, const SerializedT
Json::Value jvObj = transJson(stTxn, terResult, true, lpCurrent, "transaction");
{
boost::interprocess::sharable_lock<boost::interprocess::interprocess_upgradable_mutex> sl(mMonitorLock);
boost::recursive_mutex::scoped_lock sl(mMonitorLock);
BOOST_FOREACH(InfoSub* ispListener, mSubTransactions)
{
ispListener->send(jvObj);
@@ -1097,7 +1099,7 @@ void NetworkOPs::pubAccountTransaction(Ledger::ref lpCurrent, const SerializedTr
boost::unordered_set<InfoSub*> notify;
{
boost::interprocess::sharable_lock<boost::interprocess::interprocess_upgradable_mutex> sl(mMonitorLock);
boost::recursive_mutex::scoped_lock sl(mMonitorLock);
if(!bAccepted && mSubRTAccount.empty()) return;
@@ -1183,7 +1185,7 @@ void NetworkOPs::subAccount(InfoSub* ispListener, const boost::unordered_set<Rip
subInfoMapType& subMap=mSubAccount;
if(rt) subMap=mSubRTAccount;
boost::interprocess::scoped_lock<boost::interprocess::interprocess_upgradable_mutex> sl(mMonitorLock);
boost::recursive_mutex::scoped_lock sl(mMonitorLock);
BOOST_FOREACH(const RippleAddress& naAccountID, vnaAccountIDs)
{
@@ -1208,7 +1210,7 @@ void NetworkOPs::unsubAccount(InfoSub* ispListener, const boost::unordered_set<R
{
subInfoMapType& subMap= rt ? mSubRTAccount : mSubAccount;
boost::interprocess::scoped_lock<boost::interprocess::interprocess_upgradable_mutex> sl(mMonitorLock);
boost::recursive_mutex::scoped_lock sl(mMonitorLock);
BOOST_FOREACH(const RippleAddress& naAccountID, vnaAccountIDs)
{

View File

@@ -1,8 +1,7 @@
#ifndef __NETWORK_OPS__
#define __NETWORK_OPS__
#include <boost/interprocess/sync/interprocess_upgradable_mutex.hpp>
#include <boost/interprocess/sync/sharable_lock.hpp>
#include <boost/thread/recursive_mutex.hpp>
#include <boost/unordered_map.hpp>
#include <boost/unordered_set.hpp>
@@ -89,7 +88,7 @@ protected:
// XXX Split into more locks.
boost::interprocess::interprocess_upgradable_mutex mMonitorLock;
boost::recursive_mutex mMonitorLock;
subInfoMapType mSubAccount;
subInfoMapType mSubRTAccount;
subSubmitMapType mSubmitMap; // TODO: probably dump this

View File

@@ -80,9 +80,9 @@ PathOption::PathOption(PathOption::pointer other)
// functionality is left to the future.
//
Pathfinder::Pathfinder(const RippleAddress& srcAccountID, const RippleAddress& dstAccountID, const uint160& srcCurrencyID, const uint160& srcIssuerID, const STAmount& dstAmount)
: mSrcAccountID(srcAccountID.getAccountID()), mDstAccountID(dstAccountID.getAccountID()), mDstAmount(dstAmount), mSrcCurrencyID(srcCurrencyID), mSrcIssuerID(srcIssuerID), mOrderBook(theApp->getMasterLedger().getCurrentLedger())
: mSrcAccountID(srcAccountID.getAccountID()), mDstAccountID(dstAccountID.getAccountID()), mDstAmount(dstAmount), mSrcCurrencyID(srcCurrencyID), mSrcIssuerID(srcIssuerID), mOrderBook(theApp->getLedgerMaster().getCurrentLedger())
{
mLedger=theApp->getMasterLedger().getCurrentLedger();
mLedger=theApp->getLedgerMaster().getCurrentLedger();
}
// If possible, returns a single path.

View File

@@ -1237,7 +1237,7 @@ void Peer::recvGetLedger(ripple::TMGetLedger& packet)
return;
}
memcpy(ledgerhash.begin(), packet.ledgerhash().data(), 32);
ledger = theApp->getMasterLedger().getLedgerByHash(ledgerhash);
ledger = theApp->getLedgerMaster().getLedgerByHash(ledgerhash);
tLog(!ledger, lsINFO) << "Don't have ledger " << ledgerhash;
if (!ledger && (packet.has_querytype() && !packet.has_requestcookie()))
@@ -1264,16 +1264,16 @@ void Peer::recvGetLedger(ripple::TMGetLedger& packet)
}
else if (packet.has_ledgerseq())
{
ledger = theApp->getMasterLedger().getLedgerBySeq(packet.ledgerseq());
ledger = theApp->getLedgerMaster().getLedgerBySeq(packet.ledgerseq());
tLog(!ledger, lsINFO) << "Don't have ledger " << packet.ledgerseq();
}
else if (packet.has_ltype() && (packet.ltype() == ripple::ltCURRENT))
ledger = theApp->getMasterLedger().getCurrentLedger();
ledger = theApp->getLedgerMaster().getCurrentLedger();
else if (packet.has_ltype() && (packet.ltype() == ripple::ltCLOSED) )
{
ledger = theApp->getMasterLedger().getClosedLedger();
ledger = theApp->getLedgerMaster().getClosedLedger();
if (ledger && !ledger->isClosed())
ledger = theApp->getMasterLedger().getLedgerBySeq(ledger->getLedgerSeq() - 1);
ledger = theApp->getLedgerMaster().getLedgerBySeq(ledger->getLedgerSeq() - 1);
}
else
{
@@ -1529,7 +1529,7 @@ void Peer::sendHello()
h.set_ipv4port(theConfig.PEER_PORT);
h.set_nodeprivate(theConfig.PEER_PRIVATE);
Ledger::pointer closedLedger = theApp->getMasterLedger().getClosedLedger();
Ledger::pointer closedLedger = theApp->getLedgerMaster().getClosedLedger();
if (closedLedger && closedLedger->isClosed())
{
uint256 hash = closedLedger->getHash();

View File

@@ -1225,8 +1225,8 @@ Json::Value RPCHandler::doLedger(const Json::Value& params)
if (getParamCount(params) == 0)
{
Json::Value ret(Json::objectValue), current(Json::objectValue), closed(Json::objectValue);
theApp->getMasterLedger().getCurrentLedger()->addJson(current, 0);
theApp->getMasterLedger().getClosedLedger()->addJson(closed, 0);
theApp->getLedgerMaster().getCurrentLedger()->addJson(current, 0);
theApp->getLedgerMaster().getClosedLedger()->addJson(closed, 0);
ret["open"] = current;
ret["closed"] = closed;
return ret;
@@ -1240,13 +1240,13 @@ Json::Value RPCHandler::doLedger(const Json::Value& params)
Ledger::pointer ledger;
if (param == "current")
ledger = theApp->getMasterLedger().getCurrentLedger();
ledger = theApp->getLedgerMaster().getCurrentLedger();
else if ((param == "lastclosed") || (param == "lastaccepted"))
ledger = theApp->getMasterLedger().getClosedLedger();
ledger = theApp->getLedgerMaster().getClosedLedger();
else if (param.size() > 12)
ledger = theApp->getMasterLedger().getLedgerByHash(uint256(param));
ledger = theApp->getLedgerMaster().getLedgerByHash(uint256(param));
else
ledger = theApp->getMasterLedger().getLedgerBySeq(lexical_cast_s<uint32>(param));
ledger = theApp->getLedgerMaster().getLedgerBySeq(lexical_cast_s<uint32>(param));
if (!ledger)
return rpcError(rpcLGR_NOT_FOUND);
@@ -1308,7 +1308,7 @@ Json::Value RPCHandler::doAccountTransactions(const Json::Value& params)
else
{
txn->setLedger(it->first);
ret["transactions"].append(txn->getJson(0));
ret["transactions"].append(txn->getJson(1));
}
}
@@ -1854,7 +1854,7 @@ Json::Value RPCHandler::doTransactionEntry(const Json::Value& jvRequest)
// XXX Relying on trusted WSS client. Would be better to have a strict routine, returning success or failure.
uLedgerID.SetHex(jvRequest["ledger_hash"].asString());
Ledger::pointer lpLedger = theApp->getMasterLedger().getLedgerByHash(uLedgerID);
Ledger::pointer lpLedger = theApp->getLedgerMaster().getLedgerByHash(uLedgerID);
if (!lpLedger) {
jvResult["error"] = "ledgerNotFound";

View File

@@ -22,7 +22,7 @@ void RippleLines::printRippleLines()
RippleLines::RippleLines(const uint160& accountID )
{
fillLines(accountID,theApp->getMasterLedger().getCurrentLedger());
fillLines(accountID,theApp->getLedgerMaster().getCurrentLedger());
}
void RippleLines::fillLines(const uint160& accountID, Ledger::ref ledger)

View File

@@ -306,11 +306,25 @@ bool Transaction::convertToTransactions(uint32 firstLedgerSeq, uint32 secondLedg
return true;
}
// options 1 to include the date of the transaction
Json::Value Transaction::getJson(int options) const
{
Json::Value ret(mTransaction->getJson(0));
if (mInLedger) ret["inLedger"]=mInLedger;
if (mInLedger)
{
ret["inLedger"]=mInLedger;
if(options==1)
{
Ledger::pointer ledger=theApp->getLedgerMaster().getLedgerBySeq(mInLedger);
if(ledger)
{
ret["date"]=ledger->getCloseTimeNC();
}
}
}
switch (mStatus)
{

View File

@@ -148,7 +148,7 @@ Request.prototype.ripple_state = function (account, issuer, currency) {
return this;
};
Request.prototype.accounts = function (accounts) {
Request.prototype.accounts = function (accounts, realtime) {
if ("object" !== typeof accounts) {
accounts = [accounts];
}
@@ -158,11 +158,19 @@ Request.prototype.accounts = function (accounts) {
for (var i = 0, l = accounts.length; i < l; i++) {
procAccounts.push(UInt160.json_rewrite(accounts[i]));
}
this.message.accounts = procAccounts;
if (realtime) {
this.message.rt_accounts = procAccounts;
} else {
this.message.accounts = procAccounts;
}
return this;
};
Request.prototype.rt_accounts = function (accounts) {
return this.accounts(accounts, true);
};
//
// Remote - access to a remote Ripple server via websocket.
//
@@ -181,6 +189,7 @@ var Remote = function (opts, trace) {
this.trusted = opts.trusted;
this.websocket_ip = opts.websocket_ip;
this.websocket_port = opts.websocket_port;
this.local_sequence = opts.local_sequence;
this.id = 0;
this.trace = opts.trace || trace;
this._ledger_current_index = undefined;
@@ -479,7 +488,12 @@ Remote.prototype._connect_message = function (ws, json) {
this.emit('ledger_closed', message.ledger_hash, message.ledger_index);
break;
// Account subscription event
case 'account':
if (this.trace) console.log("remote: account: %s", JSON.stringify(message, undefined, 2));
break;
default:
unexpected = true;
break;
@@ -547,7 +561,7 @@ Remote.prototype.request_ledger = function (params) {
// Only for unit testing.
Remote.prototype.request_ledger_hash = function () {
assert(this.trusted); // If not trusted, need to check proof.
//assert(this.trusted); // If not trusted, need to check proof.
return new Request(this, 'ledger_closed');
};
@@ -569,7 +583,7 @@ Remote.prototype.request_ledger_current = function () {
// .ledger_index()
// .offer_id()
Remote.prototype.request_ledger_entry = function (type) {
assert(this.trusted); // If not trusted, need to check proof, maybe talk packet protocol.
//assert(this.trusted); // If not trusted, need to check proof, maybe talk packet protocol.
var self = this;
var request = new Request(this, 'ledger_entry');
@@ -652,7 +666,7 @@ Remote.prototype.request_unsubscribe = function (streams) {
};
Remote.prototype.request_transaction_entry = function (hash) {
assert(this.trusted); // If not trusted, need to check proof, maybe talk packet protocol.
//assert(this.trusted); // If not trusted, need to check proof, maybe talk packet protocol.
return (new Request(this, 'transaction_entry'))
.tx_hash(hash);
@@ -706,12 +720,12 @@ Remote.prototype.submit = function (transaction) {
});
}
else {
if (!transaction.tx_json.Sequence) {
if (self.local_sequence && !transaction.tx_json.Sequence) {
transaction.tx_json.Sequence = this.account_seq(transaction.tx_json.Account, 'ADVANCE');
// console.log("Sequence: %s", transaction.tx_json.Sequence);
}
if (!transaction.tx_json.Sequence) {
if (self.local_sequence && !transaction.tx_json.Sequence) {
// Look in the last closed ledger.
this.account_seq_cache(transaction.tx_json.Account, false)
.on('success_account_seq_cache', function () {

View File

@@ -21,6 +21,7 @@ exports.servers = {
'rpc_port' : 5005,
'websocket_ip' : "127.0.0.1",
'websocket_port' : 5006,
'local_sequence' : true,
// 'validation_seed' : "shhDFVsmS2GSu5vUyZSPXYfj1r79h",
// 'validators' : "n9L8LZZCwsdXzKUN9zoVxs4YznYXZ9hEhsQZY7aVpxtFaSceiyDZ beta"
}

View File

@@ -3,9 +3,12 @@ var webpack = require("webpack");
var async = require("async");
var extend = require("extend");
var programPath = __dirname + "/src/js/remote.js";
var cfg = {
// General settings
baseName: pkg.name,
programPath: __dirname + "/src/js/remote.js",
// CLI-configurable options
watch: false,
outputDir: __dirname + "/build"
};
@@ -41,7 +44,7 @@ function build(opts) {
opts.output = cfg.outputDir + "/"+opts.filename;
return function (callback) {
var filename = opts.filename;
webpack(programPath, opts, function (err, result) {
webpack(cfg.programPath, opts, function (err, result) {
console.log(' '+filename, result.hash, '['+result.modulesCount+']');
if ("function" === typeof callback) {
callback(err);