diff --git a/src/Application.cpp b/src/Application.cpp index ef00d19fdf..a5d458dc18 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -98,12 +98,14 @@ void Application::run() Log(lsINFO) << "Loading Old Ledger"; loadOldLedger(); } - else - { // TODO: This should really not validate a ledger until it gets the current one from our peers - // but I'll let david make this change since a lot of code assumes we have a ledger - // for now just do what we always were doing + else if (theConfig.START_UP == Config::NETWORK) + { // This should probably become the default once we have a stable network + if (!theConfig.RUN_STANDALONE) + mNetOps.needNetworkLedger(); startNewLedger(); } + else + startNewLedger(); // // Begin validation and ip maintenance. diff --git a/src/Config.h b/src/Config.h index cc2b85ed4b..f4c0d9a96b 100644 --- a/src/Config.h +++ b/src/Config.h @@ -56,7 +56,7 @@ public: std::vector IPS; // Peer IPs from newcoind.cfg. std::vector SNTP_SERVERS; // SNTP servers from newcoind.cfg. - enum StartUpType {FRESH,NORMAL,LOAD}; + enum StartUpType { FRESH, NORMAL, LOAD, NETWORK }; StartUpType START_UP; // Network parameters diff --git a/src/NetworkOPs.cpp b/src/NetworkOPs.cpp index 00bc4e5f69..855128bdf2 100644 --- a/src/NetworkOPs.cpp +++ b/src/NetworkOPs.cpp @@ -26,8 +26,9 @@ SETUP_LOG(); NetworkOPs::NetworkOPs(boost::asio::io_service& io_service, LedgerMaster* pLedgerMaster) : - mMode(omDISCONNECTED),mNetTimer(io_service), mLedgerMaster(pLedgerMaster), mCloseTimeOffset(0), - mLastCloseProposers(0), mLastCloseConvergeTime(1000 * LEDGER_IDLE_INTERVAL), mLastValidationTime(0) + mMode(omDISCONNECTED), mNeedNetworkLedger(false), mNetTimer(io_service), mLedgerMaster(pLedgerMaster), + mCloseTimeOffset(0), mLastCloseProposers(0), mLastCloseConvergeTime(1000 * LEDGER_IDLE_INTERVAL), + mLastValidationTime(0) { } @@ -424,7 +425,8 @@ void NetworkOPs::checkState(const boost::system::error_code& result) // If full or tracking, check only at wobble time! uint256 networkClosed; bool ledgerChange = checkLastClosedLedger(peerList, networkClosed); - if(networkClosed.isZero())return; + if(networkClosed.isZero()) + return; // WRITEME: Unless we are in omFULL and in the process of doing a consensus, // we must count how many nodes share our LCL, how many nodes disagree with our LCL, @@ -435,7 +437,8 @@ void NetworkOPs::checkState(const boost::system::error_code& result) if ((mMode == omCONNECTED) && !ledgerChange) { // count number of peers that agree with us and UNL nodes whose validations we have for LCL // if the ledger is good enough, go to omTRACKING - TODO - setMode(omTRACKING); + if (!mNeedNetworkLedger) + setMode(omTRACKING); } if ((mMode == omTRACKING) && !ledgerChange ) @@ -617,6 +620,7 @@ void NetworkOPs::switchLastClosedLedger(Ledger::pointer newLedger, bool duringCo else cLog(lsERROR) << "JUMP last closed ledger to " << newLedger->getHash(); + mNeedNetworkLedger = false; newLedger->setClosed(); Ledger::pointer openLedger = boost::make_shared(false, boost::ref(*newLedger)); mLedgerMaster->switchLedgers(newLedger, openLedger); diff --git a/src/NetworkOPs.h b/src/NetworkOPs.h index 8f4d3557d1..043ae313b7 100644 --- a/src/NetworkOPs.h +++ b/src/NetworkOPs.h @@ -52,6 +52,7 @@ protected: typedef boost::unordered_map >::iterator subInfoMapIterator; OperatingMode mMode; + bool mNeedNetworkLedger; boost::posix_time::ptime mConnectTime; boost::asio::deadline_timer mNetTimer; boost::shared_ptr mConsensus; @@ -184,6 +185,7 @@ public: void setStandAlone() { setMode(omFULL); } void setStateTimer(); void newLCL(int proposers, int convergeTime, const uint256& ledgerHash); + void needNetworkLedger() { mNeedNetworkLedger = true; } void consensusViewChange(); int getPreviousProposers() { return mLastCloseProposers; } int getPreviousConvergeTime() { return mLastCloseConvergeTime; } diff --git a/src/SerializeProto.h b/src/SerializeProto.h index 736a83a3e8..df7d2f6d5c 100644 --- a/src/SerializeProto.h +++ b/src/SerializeProto.h @@ -24,6 +24,7 @@ // 8-bit integers FIELD(CloseResolution, UINT8, 1) + FIELD(TemplateEntryType, UINT8, 2) // 16-bit integers FIELD(LedgerEntryType, UINT16, 1) @@ -123,9 +124,13 @@ // inner object // OBJECT/1 is reserved for end of object + FIELD(TemplateEntry, OBJECT, 1) // array of objects // ARRAY/1 is reserved for end of array FIELD(SigningAccounts, ARRAY, 2) FIELD(TxnSignatures, ARRAY, 3) FIELD(Signatures, ARRAY, 4) + FIELD(Template, ARRAY, 5) + FIELD(Necessary, ARRAY, 6) + FIELD(Sufficient, ARRAY, 7) diff --git a/src/main.cpp b/src/main.cpp index 63a7812136..17a46eefa2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -98,8 +98,9 @@ int main(int argc, char* argv[]) ("test,t", "Perform unit tests.") ("parameters", po::value< vector >(), "Specify comma separated parameters.") ("verbose,v", "Increase log level.") - ("load","Load the current ledger from the local DB.") - ("start","Start from a fresh Ledger.") + ("load", "Load the current ledger from the local DB.") + ("start", "Start from a fresh Ledger.") + ("net", "Get the initial ledger from the network.") ; // Interpret positional arguments as --parameters. @@ -156,8 +157,9 @@ int main(int argc, char* argv[]) } } - if(vm.count("start")) theConfig.START_UP=Config::FRESH; - else if(vm.count("load")) theConfig.START_UP=Config::LOAD; + if (vm.count("start")) theConfig.START_UP = Config::FRESH; + else if (vm.count("load")) theConfig.START_UP = Config::LOAD; + else if (vm.count("net")) theConfig.START_UP = Config::NETWORK; if (iResult) {