From b2fbe0e2e90e21f6852979b0abf6961751b276f1 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 8 May 2012 03:45:55 -0700 Subject: [PATCH] Fix some peer synchronization issues. --- src/Peer.cpp | 7 +++++-- src/Peer.h | 2 +- src/newcoin.proto | 32 ++++++++++++++++++++++++++++++-- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/Peer.cpp b/src/Peer.cpp index 1db60cbf3..b2c04561f 100644 --- a/src/Peer.cpp +++ b/src/Peer.cpp @@ -81,7 +81,7 @@ void Peer::handleVerifyTimer(const boost::system::error_code& ecResult) nothing(); // Aborter is done. } else if (ecResult) - { + { std::cerr << "Peer verify timer error: " << std::endl; // Can't do anything sound. @@ -525,7 +525,10 @@ void Peer::recvHello(newcoin::TMHello& packet) if ((packet.has_closedledger()) && (packet.closedledger().size() == (256 / 8))) { - memcpy(mClosedLedgerHash.begin(), packet.closedledger().data(), (256 / 8)); + memcpy(mClosedLedgerHash.begin(), packet.closedledger().data(), 256 / 8); + if ((packet.has_previousledger()) && (packet.previousledger().size() == (256 / 8))) + memcpy(mPreviousLedgerHash.begin(), packet.previousledger().data(), 256 / 8); + else mPreviousLedgerHash.zero(); mClosedLedgerTime = boost::posix_time::second_clock::universal_time(); } diff --git a/src/Peer.h b/src/Peer.h index 3a43eb2c0..fbb3b8063 100644 --- a/src/Peer.h +++ b/src/Peer.h @@ -37,7 +37,7 @@ private: uint256 mCookieHash; // network state information - uint256 mClosedLedgerHash; + uint256 mClosedLedgerHash, mPreviousLedgerHash; boost::posix_time::ptime mClosedLedgerTime; boost::asio::ssl::stream mSocketSsl; diff --git a/src/newcoin.proto b/src/newcoin.proto index ab67b2571..8317c7188 100644 --- a/src/newcoin.proto +++ b/src/newcoin.proto @@ -10,7 +10,6 @@ enum MessageType { mtGET_CONTACTS= 10; mtCONTACT= 11; - // operations for 'small' nodes mtSEARCH_TRANSACTION= 20; mtGET_ACCOUNT= 21; @@ -22,6 +21,7 @@ enum MessageType { mtLEDGER= 32; mtPROPOSE_LEDGER= 33; mtCLOSE_LEDGER= 35; + mtSTATUS_CHANGE= 36; // data replication and synchronization mtGET_VALIDATIONS= 40; @@ -41,7 +41,8 @@ message TMHello { optional bytes nodePublic = 4; // node may opt to remain anonymous optional bytes nodeProof = 5; optional uint32 ipv4Port = 6; - optional bytes closedLedger = 7; + optional bytes closedLedger = 7; // our last closed ledger + optional bytes previousLedger = 8; // the ledger before the last closed ledger } @@ -71,6 +72,33 @@ message TMTransaction { optional bytes conflictingTransaction = 13; } + + +enum NodeStatus { + nsCONNECTING = 1; // acquiring connections + nsCONNECTED = 2; // convinced we are connected to the real network + nsMONITORING = 3; // we know what the previous ledger is + nsVALIDATING = 4; // we have the full ledger contents +} + +enum NodeEvent { + neCLOSED_LEDGER = 1; // closing a ledger because its close time has come + neACCEPTED_LEDGER = 2; // accepting a closed ledger, we have finished computing it + neSWITCHED_LEDGER = 3; // switching ledgers due to network consensus + neSHUTTING_DOWN = 4; +} + +message TMStatusChange { + optional NodeStatus newStatus = 1; + optional NodeEvent newEvent = 2; + optional uint32 ledgerSeq = 3; + optional bytes ledgerHash = 4; + optional bytes previousLedgerHash = 5; + optional uint64 networkTime = 6; +} + + + message TMProposeLedger { required uint32 closingSeq = 1; required uint32 secondsSinceClose = 2;