From c7c1d79176c0611ebd22a220fdac9495c5b36993 Mon Sep 17 00:00:00 2001
From: Gav Wood <i@gavwood.com>
Date: Sun, 7 Jun 2015 22:44:24 +0900
Subject: [PATCH] Frontier parameters in.

---
 libethcore/Common.cpp      |  6 ++++++
 libethcore/Common.h        |  8 ++++++++
 libethcore/Params.cpp      |  3 ++-
 libethereum/BlockQueue.cpp |  2 +-
 libethereum/Client.cpp     |  2 +-
 libethereum/State.cpp      |  2 +-
 libp2p/RLPxHandshake.cpp   | 15 ++++++++-------
 7 files changed, 27 insertions(+), 11 deletions(-)

diff --git a/libethcore/Common.cpp b/libethcore/Common.cpp
index ed2f8a3d3..63f4a19f9 100644
--- a/libethcore/Common.cpp
+++ b/libethcore/Common.cpp
@@ -46,6 +46,12 @@ const unsigned c_databaseBaseVersion = 9;
 const unsigned c_databaseVersionModifier = 0;
 #endif
 
+#if ETH_FRONTIER
+Network const c_network = Network::Frontier;
+#else
+Network const c_network = Network::Olympic;
+#endif
+
 const unsigned c_databaseVersion = c_databaseBaseVersion + (c_databaseVersionModifier << 8) + (ProofOfWork::revision() << 9);
 
 vector<pair<u256, string>> const& units()
diff --git a/libethcore/Common.h b/libethcore/Common.h
index 1d48803cb..87ebffab7 100644
--- a/libethcore/Common.h
+++ b/libethcore/Common.h
@@ -43,6 +43,14 @@ extern const unsigned c_minorProtocolVersion;
 /// Current database version.
 extern const unsigned c_databaseVersion;
 
+/// The network id.
+enum class Network
+{
+	Olympic = 0,
+	Frontier = 1
+};
+extern const Network c_network;
+
 /// User-friendly string representation of the amount _b in wei.
 std::string formatBalance(bigint const& _b);
 
diff --git a/libethcore/Params.cpp b/libethcore/Params.cpp
index a6107e62b..916adf6ca 100644
--- a/libethcore/Params.cpp
+++ b/libethcore/Params.cpp
@@ -20,6 +20,7 @@
  */
 
 #include "Params.h"
+#include "Common.h"
 
 using namespace std;
 namespace dev
@@ -35,7 +36,7 @@ u256 const c_minGasLimit = 125000;
 u256 const c_gasLimitBoundDivisor = 1024;
 u256 const c_minimumDifficulty = 131072;
 u256 const c_difficultyBoundDivisor = 2048;
-u256 const c_durationLimit = 8;
+u256 const c_durationLimit = c_network == Network::Olympic ? 8 : 12;
 //--- END: AUTOGENERATED FROM /feeStructure.json
 
 }
diff --git a/libethereum/BlockQueue.cpp b/libethereum/BlockQueue.cpp
index 013d8a000..360bf915e 100644
--- a/libethereum/BlockQueue.cpp
+++ b/libethereum/BlockQueue.cpp
@@ -81,7 +81,7 @@ void BlockQueue::verifierBody()
 				res.first.populate(res.second, CheckEverything, work.first);
 				res.first.verifyInternals(&res.second);
 			}
-			catch (InvalidNonce&)
+			catch (InvalidBlockNonce&)
 			{
 				badBlock(res.second, "Invalid block nonce");
 				cwarn << "  Nonce:" << res.first.nonce.hex();
diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp
index b737f53c9..46fbbdfb1 100644
--- a/libethereum/Client.cpp
+++ b/libethereum/Client.cpp
@@ -665,7 +665,7 @@ void Client::doWork()
 		syncBlockQueue();
 
 	t = true;
-	if (m_syncTransactionQueue.compare_exchange_strong(t, false) && !m_remoteWorking)
+	if (m_syncTransactionQueue.compare_exchange_strong(t, false) && !m_remoteWorking && !isSyncing())
 		syncTransactionQueue();
 
 	tick();
diff --git a/libethereum/State.cpp b/libethereum/State.cpp
index f84ee819f..92c84c9b3 100644
--- a/libethereum/State.cpp
+++ b/libethereum/State.cpp
@@ -46,7 +46,7 @@ using namespace dev::eth;
 #define ctrace clog(StateTrace)
 #define ETH_TIMED_ENACTMENTS 0
 
-static const u256 c_blockReward = 1500 * finney;
+static const u256 c_blockReward = c_network == Network::Olympic ? (1500 * finney) : (5 * ether);
 
 const char* StateSafeExceptions::name() { return EthViolet "⚙" EthBlue " ℹ"; }
 const char* StateDetail::name() { return EthViolet "⚙" EthWhite " ◌"; }
diff --git a/libp2p/RLPxHandshake.cpp b/libp2p/RLPxHandshake.cpp
index d7c2e5e3b..b8faf0e3e 100644
--- a/libp2p/RLPxHandshake.cpp
+++ b/libp2p/RLPxHandshake.cpp
@@ -184,7 +184,7 @@ void RLPXHandshake::transition(boost::system::error_code _ech)
 		// old packet format
 		// 5 arguments, HelloPacket
 		RLPStream s;
-		s.append((unsigned)0).appendList(5)
+		s.append((unsigned)HelloPacket).appendList(5)
 		<< dev::p2p::c_protocolVersion
 		<< m_host->m_clientVersion
 		<< m_host->caps()
@@ -205,15 +205,16 @@ void RLPXHandshake::transition(boost::system::error_code _ech)
 		m_nextState = StartSession;
 		
 		// read frame header
-		m_handshakeInBuffer.resize(h256::size);
-		ba::async_read(m_socket->ref(), boost::asio::buffer(m_handshakeInBuffer, h256::size), [this, self](boost::system::error_code ec, std::size_t)
+		unsigned const handshakeSize = 32;
+		m_handshakeInBuffer.resize(handshakeSize);
+		ba::async_read(m_socket->ref(), boost::asio::buffer(m_handshakeInBuffer, handshakeSize), [this, self](boost::system::error_code ec, std::size_t)
 		{
 			if (ec)
 				transition(ec);
 			else
 			{
 				/// authenticate and decrypt header
-				if (!m_io->authAndDecryptHeader(bytesRef(m_handshakeInBuffer.data(), h256::size)))
+				if (!m_io->authAndDecryptHeader(bytesRef(m_handshakeInBuffer.data(), handshakeSize)))
 				{
 					m_nextState = Error;
 					transition();
@@ -235,7 +236,7 @@ void RLPXHandshake::transition(boost::system::error_code _ech)
 				}
 				
 				/// rlp of header has protocol-type, sequence-id[, total-packet-size]
-				bytes headerRLP(header.size() - 3 - h128::size);
+				bytes headerRLP(header.size() - 3 - h128::size);	// this is always 32 - 3 - 16 = 13. wtf?
 				bytesConstRef(&header).cropped(3).copyTo(&headerRLP);
 				
 				/// read padded frame and mac
@@ -255,8 +256,8 @@ void RLPXHandshake::transition(boost::system::error_code _ech)
 							return;
 						}
 						
-						PacketType packetType = (PacketType)(frame[0] == 0x80 ? 0x0 : frame[0]);
-						if (packetType != 0)
+						PacketType packetType = frame[0] == 0x80 ? HelloPacket : (PacketType)frame[0];
+						if (packetType != HelloPacket)
 						{
 							clog(NetTriviaSummary) << (m_originated ? "p2p.connect.egress" : "p2p.connect.ingress") << "hello frame: invalid packet type";
 							m_nextState = Error;