Skip to content

Commit 9122b2e

Browse files
committed
Merge branch 'dev3' into mainnet
2 parents e9dcc29 + d881d9f commit 9122b2e

File tree

111 files changed

+11135
-11964
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+11135
-11964
lines changed

CMakeLists.txt

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
11
cmake_minimum_required(VERSION 3.1)
22

33
set(VERSION_MAJOR 10)
4-
set(VERSION_MINOR 1)
4+
set(VERSION_MINOR 2)
55
set(VERSION_REVISION 0)
66
set(GIT_COMMIT_HASH "unknown")
77

8-
set(GRIMM_SUFFIX_LOWER_CASE "mainnet")
9-
set(GRIMM_SUFFIX_UPPER_CASE "Mainnet")
10-
set(GRIMM_TARGET_SUFFIX "-${GRIMM_SUFFIX_LOWER_CASE}")
11-
set(GRIMM_DISPLAY_SUFFIX " ${GRIMM_SUFFIX_UPPER_CASE}")
8+
# uncoment next line for testnet
9+
set(GRIMM_TESTNET TRUE)
10+
11+
if(GRIMM_TESTNET)
12+
add_definitions(-DGRIMM_TESTNET)
13+
set(GRIMM_SUFFIX_LOWER_CASE "testnet")
14+
set(GRIMM_SUFFIX_UPPER_CASE "Testnet")
15+
set(GRIMM_TARGET_SUFFIX "-${GRIMM_SUFFIX_LOWER_CASE}")
16+
set(GRIMM_DISPLAY_SUFFIX " ${GRIMM_SUFFIX_UPPER_CASE}")
17+
else()
18+
set(GRIMM_SUFFIX_LOWER_CASE "mainnet")
19+
set(GRIMM_SUFFIX_UPPER_CASE "Mainnet")
20+
set(GRIMM_TARGET_SUFFIX "-${GRIMM_SUFFIX_LOWER_CASE}")
21+
set(GRIMM_DISPLAY_SUFFIX " ${GRIMM_SUFFIX_UPPER_CASE}")
22+
23+
endif()
24+
25+
1226

1327
if (GRIMM_SIGN_PACKAGE AND WIN32)
1428
# add_custom_target(signing ALL DEPENDS grimm-wallet-ui COMMENT "Signing Package...")
@@ -110,11 +124,6 @@ if (GRIMM_CPU_ARCH MATCHES "avx")
110124
set(GRIMM_USE_AVX TRUE)
111125
endif()
112126

113-
if(GRIMM_USE_GPU)
114-
add_definitions(-DGRIMM_USE_GPU)
115-
set(GRIMM_USE_AVX TRUE)
116-
endif()
117-
118127
if(GRIMM_USE_AVX)
119128
add_definitions(-DGRIMM_USE_AVX)
120129
endif()
@@ -144,28 +153,6 @@ if(SHOW_CODE_LOCATION)
144153
add_definitions(-DSHOW_CODE_LOCATION=1)
145154
endif()
146155

147-
# uncoment next line for testnet
148-
#set(GRIMM_TESTNET TRUE)
149-
# uncoment next line for mainnet
150-
#set(GRIMM_MAINNET TRUE)
151-
152-
if(GRIMM_TESTNET)
153-
add_definitions(-DGRIMM_TESTNET)
154-
set(GRIMM_SUFFIX_LOWER_CASE "testnet")
155-
set(GRIMM_SUFFIX_UPPER_CASE "Testnet")
156-
set(GRIMM_TARGET_SUFFIX "-${GRIMM_SUFFIX_LOWER_CASE}")
157-
set(GRIMM_DISPLAY_SUFFIX " ${GRIMM_SUFFIX_UPPER_CASE}")
158-
elseif(GRIMM_MAINNET)
159-
add_definitions(-DGRIMM_MAINNET)
160-
set(GRIMM_SUFFIX_LOWER_CASE "")
161-
set(GRIMM_SUFFIX_UPPER_CASE "")
162-
set(GRIMM_TARGET_SUFFIX "")
163-
set(GRIMM_DISPLAY_SUFFIX "")
164-
endif()
165-
166-
167-
168-
169156

170157
if(MSVC)
171158
if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
- [Website grimmw.com](https://grimmw.com)
55
### Current status
66

7-
#### Mainnet online. First block "timestamp":1564997815 Aug. 5th, 2019 @ 9:36am (UTC)
7+
#### Mainnet online. First block "timestamp":1564997815 Aug. 5th, 2019 @ 9:36am (UTC) [mainnet branch](https://github.com/freenetcoder/grimm/tree/mainnet)
8+
9+
#### Testnet online [testnet branch](https://github.com/freenetcoder/grimm/tree/testnet)
810

911

1012

@@ -24,6 +26,10 @@ We designed Grimm so that it doesn’t depend on any one person. We don’t cont
2426

2527
[English](https://t.me/grimmw) | [Русский](https://t.me/grimmwru)
2628

29+
### DISCORD
30+
31+
[invite link](https://discord.gg/XKgPPW2)
32+
2733
### EITHER HELP US, OR GET OUT OF OUR WAY
2834

2935
[twitter](https://twitter.com/grimmwcom) | [medium](https://medium.com/grimmwcom) | [bitcointalk](https://bitcointalk.org)
@@ -64,7 +70,7 @@ Add .../qt511/5.11.1/msvc2017_64/bin and .../boost_1_68_0/lib64-msvc-14.1 to the
6470
- Go to CMake -> Cache -> Open Cache Folder -> grimm (you'll find binaries in grimm/..., wallet/..., ui/..., explorer/... subfolders).
6571

6672
### Linux
67-
### Ubuntu 14.04
73+
### Ubuntu 18.04
6874
- Install gcc7 boost ssl packages.
6975
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
7076
sudo apt update

android/node_model.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,6 @@ std::vector<std::string> NodeModel::getLocalNodePeers()
132132
return getDefaultPeers();
133133
}
134134

135-
#ifdef GRIMM_USE_GPU
136-
std::unique_ptr<IExternalPOW> NodeModel::getStratumServer()
137-
{
138-
return nullptr;
139-
}
140-
#endif // GRIMM_USE_GPU
141-
142135
void NodeModel::onNodeThreadFinished()
143136
{
144137
JNIEnv* env = Android_JNI_getEnv();

android/node_model.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,7 @@ class NodeModel
4848
std::string getLocalNodeStorage() override;
4949
std::string getTempDir() override;
5050
std::vector<std::string> getLocalNodePeers() override;
51-
#ifdef GRIMM_USE_GPU
52-
std::unique_ptr<grimm::IExternalPOW> getStratumServer() override;
53-
#endif // GRIMM_USE_GPU
54-
51+
5552
void onNodeThreadFinished() override;
5653

5754
private:

core/block_crypt.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -989,8 +989,22 @@ namespace grimm
989989
}
990990
}
991991

992+
bool Rules::IsForkHeightsConsistent() const
993+
{
994+
if (pForks[0].m_Height != Rules::HeightGenesis - 1)
995+
return false;
996+
997+
for (size_t i = 1; i < _countof(pForks); i++)
998+
if (pForks[i].m_Height < pForks[i - 1].m_Height)
999+
return false;
1000+
1001+
return true;
1002+
}
1003+
9921004
void Rules::UpdateChecksum()
9931005
{
1006+
if (!IsForkHeightsConsistent())
1007+
throw std::runtime_error("Inconsistent Forks");
9941008
// all parameters, including const (in case they'll be hardcoded to different values in later versions)
9951009
ECC::Oracle oracle;
9961010
oracle
@@ -1021,7 +1035,7 @@ namespace grimm
10211035
<< (uint32_t) Block::PoW::N
10221036
<< (uint32_t) Block::PoW::NonceType::nBits
10231037
<< uint32_t(16) // increment this whenever we change something in the protocol
1024-
#ifndef GRIMM_TESTNET
1038+
#ifndef GRIMM_TESTNET1
10251039
<< "masternet"
10261040
#endif
10271041
// out
@@ -1034,6 +1048,14 @@ namespace grimm
10341048
<< DA.Damp.N
10351049
// out
10361050
>> pForks[1].m_Hash;
1051+
1052+
oracle
1053+
<< "fork2"
1054+
<< pForks[2].m_Height
1055+
// TBD
1056+
// ...
1057+
// out
1058+
>> pForks[2].m_Hash;
10371059
}
10381060

10391061
const HeightHash* Rules::FindFork(const Merkle::Hash& hv) const

core/block_crypt.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,15 @@ namespace grimm
148148
static void get_Emission(AmountBig::Type&, const HeightRange&);
149149
static void get_Emission(AmountBig::Type&, const HeightRange&, Amount base);
150150

151-
HeightHash pForks[2];
151+
HeightHash pForks[3];
152152

153153
const HeightHash& get_LastFork() const;
154154
const HeightHash* FindFork(const Merkle::Hash&) const;
155155
std::string get_SignatureStr() const;
156156

157157
private:
158158
Amount get_EmissionEx(Height, Height& hEnd, Amount base) const;
159+
bool IsForkHeightsConsistent() const;
159160
};
160161

161162
class SwitchCommitment

core/proto.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -759,9 +759,14 @@ void NodeConnection::OnLoginInternal(Height hScheme, Login&& msg)
759759
}
760760
}
761761

762-
Height hMinScheme = get_MinPeerFork();
763-
if (hScheme < hMinScheme)
764-
ThrowUnexpected("Legacy", NodeProcessingException::Type::Incompatible);
762+
if (hScheme < MaxHeight)
763+
{
764+
LOG_WARNING() << "Peer " << m_Connection->peer_address() << " incompatible with fork " << (hScheme + 1);
765+
766+
Height hMinScheme = get_MinPeerFork();
767+
if (hScheme < hMinScheme)
768+
ThrowUnexpected("Legacy", NodeProcessingException::Type::Incompatible);
769+
}
765770

766771
OnLogin(std::move(msg));
767772
}

explorer/adapter.cpp

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ class Adapter : public Node::IObserver, public IAdapter {
116116

117117
private:
118118
void init_helper_fragments() {
119-
static const char* s = "[,]";
120-
io::SharedBuffer buf(s, 3);
119+
static const char* s = "[,]\"";
120+
io::SharedBuffer buf(s, 4);
121121
_leftBrace = buf;
122122
_leftBrace.size = 1;
123123
_comma = buf;
@@ -126,6 +126,9 @@ class Adapter : public Node::IObserver, public IAdapter {
126126
_rightBrace = buf;
127127
_rightBrace.size = 1;
128128
_rightBrace.data += 2;
129+
_quote = buf;
130+
_quote.size = 1;
131+
_quote.data += 3;
129132
}
130133

131134
/// Returns body for /status request
@@ -174,7 +177,8 @@ class Adapter : public Node::IObserver, public IAdapter {
174177
{ "height", _cache.currentHeight },
175178
{ "low_horizon", _nodeBackend.m_Extra.m_LoHorizon },
176179
{ "hash", hash_to_hex(buf, cursor.m_ID.m_Hash) },
177-
{ "chainwork", uint256_to_hex(buf, cursor.m_Full.m_ChainWork) }
180+
{ "chainwork", uint256_to_hex(buf, cursor.m_Full.m_ChainWork) },
181+
{ "peers_count", _node.get_AcessiblePeerCount() }
178182
}
179183
)) {
180184
return false;
@@ -389,14 +393,42 @@ class Adapter : public Node::IObserver, public IAdapter {
389393
return true;
390394
}
391395

396+
bool get_peers(io::SerializedMsg& out) override
397+
{
398+
auto& peers = _node.get_AcessiblePeerAddrs();
399+
400+
out.push_back(_leftBrace);
401+
402+
for (auto& peer : peers)
403+
{
404+
auto addr = peer.get_ParentObj().m_Addr.m_Value.str();
405+
406+
{
407+
out.push_back(_quote);
408+
out.push_back({ addr.data(), addr.size() });
409+
out.push_back(_quote);
410+
}
411+
412+
out.push_back(_comma);
413+
}
414+
415+
// remove last comma
416+
if (!peers.empty())
417+
out.pop_back();
418+
419+
out.push_back(_rightBrace);
420+
421+
return true;
422+
}
423+
392424
HttpMsgCreator _packer;
393425

394426
// node db interface
395427
Node& _node;
396428
NodeProcessor& _nodeBackend;
397429

398430
// helper fragments
399-
io::SharedBuffer _leftBrace, _comma, _rightBrace;
431+
io::SharedBuffer _leftBrace, _comma, _rightBrace, _quote;
400432

401433
// If true then status boby needs to be refreshed
402434
bool _statusDirty;
@@ -418,4 +450,3 @@ IAdapter::Ptr create_adapter(Node& node) {
418450
}
419451

420452
}} //namespaces
421-

explorer/adapter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ struct IAdapter {
3737
virtual bool get_block_by_kernel(io::SerializedMsg& out, const ByteBuffer& key) = 0;
3838

3939
virtual bool get_blocks(io::SerializedMsg& out, uint64_t startHeight, uint64_t n) = 0;
40+
41+
virtual bool get_peers(io::SerializedMsg& out) = 0;
4042
};
4143

4244
IAdapter::Ptr create_adapter(Node& node);

explorer/server.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static const unsigned SERVER_RESTART_INTERVAL = 1000;
3131
static const unsigned ACL_REFRESH_INTERVAL = 5555;
3232

3333
enum Dirs {
34-
DIR_STATUS, DIR_BLOCK, DIR_BLOCKS
34+
DIR_STATUS, DIR_BLOCK, DIR_BLOCKS, DIR_PEERS
3535
// etc
3636
};
3737

@@ -112,7 +112,7 @@ bool Server::on_request(uint64_t id, const HttpMsgReader::Message& msg) {
112112
const std::string& path = msg.msg->get_path();
113113

114114
static const std::map<std::string_view, int> dirs {
115-
{ "status", DIR_STATUS }, { "block", DIR_BLOCK }, { "blocks", DIR_BLOCKS }
115+
{ "status", DIR_STATUS }, { "block", DIR_BLOCK }, { "blocks", DIR_BLOCKS }, { "peers", DIR_PEERS}
116116
};
117117

118118
const HttpConnection::Ptr& conn = it->second;
@@ -130,6 +130,9 @@ bool Server::on_request(uint64_t id, const HttpMsgReader::Message& msg) {
130130
case DIR_BLOCKS:
131131
func = &Server::send_blocks;
132132
break;
133+
case DIR_PEERS:
134+
func = &Server::send_peers;
135+
break;
133136
default:
134137
break;
135138
}
@@ -182,7 +185,7 @@ bool Server::send_block(const HttpConnection::Ptr &conn) {
182185
return send(conn, 500, "Internal error #2");
183186
}
184187
}
185-
else
188+
else
186189
{
187190
auto height = _currentUrl.get_int_arg("height", 0);
188191
if (!_backend.get_block(_body, height)) {
@@ -205,6 +208,13 @@ bool Server::send_blocks(const HttpConnection::Ptr& conn) {
205208
return send(conn, 200, "OK");
206209
}
207210

211+
bool Server::send_peers(const HttpConnection::Ptr& conn) {
212+
if (!_backend.get_peers(_body)) {
213+
return send(conn, 500, "Internal error #3");
214+
}
215+
return send(conn, 200, "OK");
216+
}
217+
208218
bool Server::send(const HttpConnection::Ptr& conn, int code, const char* message) {
209219
assert(conn);
210220

0 commit comments

Comments
 (0)