Support "standalone" mode (-a or --standalone) in which we do not connect

to the network and do not close ledgers. This mode makes it much easier to
test transactions as they are only applied once to the open ledger.
This commit is contained in:
JoelKatz
2012-08-14 15:35:30 -07:00
parent 4b2ae556bd
commit e473ce8424
8 changed files with 39 additions and 6 deletions

View File

@@ -95,13 +95,14 @@ void Application::run()
//
// Set up UNL.
//
getUNL().nodeBootstrap();
if (!theConfig.RUN_STANDALONE)
getUNL().nodeBootstrap();
//
// Allow peer connections.
//
if (!theConfig.PEER_IP.empty() && theConfig.PEER_PORT)
if (!theConfig.RUN_STANDALONE && !theConfig.PEER_IP.empty() && theConfig.PEER_PORT)
{
mPeerDoor = new PeerDoor(mIOService);
}
@@ -127,7 +128,8 @@ void Application::run()
//
// Begin connecting to network.
//
mConnectionPool.start();
if (!theConfig.RUN_STANDALONE)
mConnectionPool.start();
// New stuff.
NewcoinAddress rootSeedMaster = NewcoinAddress::createSeedGeneric("masterpassphrase");
@@ -155,7 +157,14 @@ void Application::run()
}
mNetOps.setStateTimer();
if (theConfig.RUN_STANDALONE)
{
Log(lsWARNING) << "Running in standalone mode";
mNetOps.setStandAlone();
mMasterLedger.runStandAlone();
}
else
mNetOps.setStateTimer();
mIOService.run(); // This blocks

View File

@@ -40,6 +40,11 @@
Config theConfig;
void Config::init()
{
RUN_STANDALONE = false;
}
void Config::setup(const std::string& strConf)
{
boost::system::error_code ec;

View File

@@ -63,6 +63,7 @@ public:
int LEDGER_PROPOSAL_DELAY_SECONDS;
int LEDGER_AVALANCHE_SECONDS;
bool LEDGER_CREATOR; // should be false unless we are starting a new ledger
bool RUN_STANDALONE;
// Note: The following parameters do not relate to the UNL or trust at all
unsigned int NETWORK_QUORUM; // Minimum number of nodes to consider the network present
@@ -100,6 +101,7 @@ public:
// Client behavior
int ACCOUNT_PROBE_MAX; // How far to scan for accounts.
void init();
void setup(const std::string& strConf);
void load();
};

View File

@@ -42,6 +42,9 @@ ConnectionPool::ConnectionPool(boost::asio::io_service& io_service) :
void ConnectionPool::start()
{
if (theConfig.RUN_STANDALONE)
return;
// Start running policy.
policyEnforce();
@@ -243,6 +246,8 @@ void ConnectionPool::relayMessage(Peer* fromPeer, PackedMessage::pointer msg)
// Requires sane IP and port.
void ConnectionPool::connectTo(const std::string& strIp, int iPort)
{
if (theConfig.RUN_STANDALONE)
return;
{
Database* db = theApp->getWalletDB()->getDB();
ScopedLock sl(theApp->getWalletDB()->getDBLock());

View File

@@ -43,6 +43,8 @@ public:
// The finalized ledger is the last closed/accepted ledger
Ledger::pointer getClosedLedger() { return mFinalizedLedger; }
void runStandAlone() { mFinalizedLedger = mCurrentLedger; }
TransactionEngineResult doTransaction(const SerializedTransaction& txn, uint32 targetLedger,
TransactionEngineParams params);

View File

@@ -333,7 +333,7 @@ public:
void NetworkOPs::checkState(const boost::system::error_code& result)
{ // Network state machine
if (result == boost::asio::error::operation_aborted)
if ((result == boost::asio::error::operation_aborted) || theConfig.RUN_STANDALONE)
return;
setStateTimer();
@@ -680,7 +680,7 @@ void NetworkOPs::setMode(OperatingMode om)
mConnectTime = boost::posix_time::second_clock::universal_time();
Log l((om < mMode) ? lsWARNING : lsINFO);
if (om == omDISCONNECTED)
l << "STATE->Disonnected";
l << "STATE->Disconnected";
else if (om == omCONNECTED)
l << "STATE->Connected";
else if (om == omTRACKING)

View File

@@ -832,6 +832,9 @@ Json::Value RPCServer::doAccountWalletSet(const Json::Value& params) {
Json::Value RPCServer::doConnect(const Json::Value& params)
{
if (theConfig.RUN_STANDALONE)
return "cannot connect in standalone mode";
// connect <ip> [port]
std::string strIp;
int iPort = -1;

View File

@@ -84,6 +84,7 @@ int main(int argc, char* argv[])
int iResult = 0;
po::variables_map vm; // Map of options.
bool bTest = false;
theConfig.init();
//
// Set up option parsing.
@@ -93,6 +94,7 @@ int main(int argc, char* argv[])
("help,h", "Display this message.")
("conf", po::value<std::string>(), "Specify the configuration file.")
("rpc", "Perform rpc command (default).")
("standalone,a", "Run with no peers.")
("test,t", "Perform unit tests.")
("parameters", po::value< vector<string> >(), "Specify comma separated parameters.")
("verbose,v", "Increase log level")
@@ -142,6 +144,11 @@ int main(int argc, char* argv[])
Log::setMinSeverity(lsTRACE);
}
if (vm.count("standalone"))
{
theConfig.RUN_STANDALONE = true;
}
if (!iResult)
{
theConfig.setup(vm.count("conf") ? vm["conf"].as<std::string>() : "");