Skip to content

Commit

Permalink
Sync test: added merge mining
Browse files Browse the repository at this point in the history
  • Loading branch information
SChernykh committed Nov 17, 2023
1 parent d1fee33 commit 5aff5f5
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 19 deletions.
44 changes: 36 additions & 8 deletions .github/workflows/test-sync.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
name: Sync test

on: workflow_dispatch
on:
push:
paths-ignore:
- 'docker-compose/**'
- 'docs/**'
- 'README.md'

pull_request:

jobs:
sync-test-ubuntu-tsan:
Expand Down Expand Up @@ -57,7 +64,10 @@ jobs:
python ../tests/src/stratum_dummy.py 1 &
python ../tests/src/stratum_dummy.py 2 &
python ../tests/src/stratum_dummy.py 3 &
TSAN_OPTIONS="suppressions=../tests/src/tsan_sup.txt halt_on_error=1" ./p2pool --host xmrnode.facspro.net --rpc-port 18089 --zmq-port 18084 --host xmr2.rs.me --wallet 44MnN1f3Eto8DZYUWuE5XZNUtE3vcRzt2j6PzqWpPau34e6Cf4fAxt6X2MBmrm6F9YMEiMNjN6W4Shn4pLcfNAja621jwyg --mini --out-peers 200 --data-api data --local-api --loglevel 6
python ../tests/src/mm_server.py 8000 id0 data0 &
python ../tests/src/mm_server.py 8001 id1 data1 &
python ../tests/src/mm_server.py 8002 id2 data2 &
TSAN_OPTIONS="suppressions=../tests/src/tsan_sup.txt halt_on_error=1" ./p2pool --host xmrnode.facspro.net --rpc-port 18089 --zmq-port 18084 --host xmr2.rs.me --wallet 44MnN1f3Eto8DZYUWuE5XZNUtE3vcRzt2j6PzqWpPau34e6Cf4fAxt6X2MBmrm6F9YMEiMNjN6W4Shn4pLcfNAja621jwyg --mini --out-peers 200 --data-api data --local-api --merge-mine 127.0.0.1:8000 test0 --merge-mine 127.0.0.1:8001 test1 --merge-mine 127.0.0.1:8002 test2 --loglevel 6
- name: Check p2pool.log
run: |
Expand Down Expand Up @@ -142,7 +152,10 @@ jobs:
python ../tests/src/stratum_dummy.py 1 &
python ../tests/src/stratum_dummy.py 2 &
python ../tests/src/stratum_dummy.py 3 &
MSAN_OPTIONS="halt_on_error=1" ./p2pool --host xmrnode.facspro.net --rpc-port 18089 --zmq-port 18084 --host xmr2.rs.me --wallet 44MnN1f3Eto8DZYUWuE5XZNUtE3vcRzt2j6PzqWpPau34e6Cf4fAxt6X2MBmrm6F9YMEiMNjN6W4Shn4pLcfNAja621jwyg --mini --out-peers 200 --data-api data --local-api --loglevel 6
python ../tests/src/mm_server.py 8000 id0 data0 &
python ../tests/src/mm_server.py 8001 id1 data1 &
python ../tests/src/mm_server.py 8002 id2 data2 &
MSAN_OPTIONS="halt_on_error=1" ./p2pool --host xmrnode.facspro.net --rpc-port 18089 --zmq-port 18084 --host xmr2.rs.me --wallet 44MnN1f3Eto8DZYUWuE5XZNUtE3vcRzt2j6PzqWpPau34e6Cf4fAxt6X2MBmrm6F9YMEiMNjN6W4Shn4pLcfNAja621jwyg --mini --out-peers 200 --data-api data --local-api --merge-mine 127.0.0.1:8000 test0 --merge-mine 127.0.0.1:8001 test1 --merge-mine 127.0.0.1:8002 test2 --loglevel 6
- name: Check p2pool.log
run: |
Expand Down Expand Up @@ -188,7 +201,10 @@ jobs:
python ../tests/src/stratum_dummy.py 1 &
python ../tests/src/stratum_dummy.py 2 &
python ../tests/src/stratum_dummy.py 3 &
UBSAN_OPTIONS="suppressions=../tests/src/ubsan_sup.txt halt_on_error=1" ./p2pool --host xmrnode.facspro.net --rpc-port 18089 --zmq-port 18084 --host xmr2.rs.me --wallet 44MnN1f3Eto8DZYUWuE5XZNUtE3vcRzt2j6PzqWpPau34e6Cf4fAxt6X2MBmrm6F9YMEiMNjN6W4Shn4pLcfNAja621jwyg --mini --out-peers 200 --data-api data --local-api --loglevel 6
python ../tests/src/mm_server.py 8000 id0 data0 &
python ../tests/src/mm_server.py 8001 id1 data1 &
python ../tests/src/mm_server.py 8002 id2 data2 &
UBSAN_OPTIONS="suppressions=../tests/src/ubsan_sup.txt halt_on_error=1" ./p2pool --host xmrnode.facspro.net --rpc-port 18089 --zmq-port 18084 --host xmr2.rs.me --wallet 44MnN1f3Eto8DZYUWuE5XZNUtE3vcRzt2j6PzqWpPau34e6Cf4fAxt6X2MBmrm6F9YMEiMNjN6W4Shn4pLcfNAja621jwyg --mini --out-peers 200 --data-api data --local-api --merge-mine 127.0.0.1:8000 test0 --merge-mine 127.0.0.1:8001 test1 --merge-mine 127.0.0.1:8002 test2 --loglevel 6
- name: Check p2pool.log
run: |
Expand Down Expand Up @@ -234,7 +250,10 @@ jobs:
python ../tests/src/stratum_dummy.py 1 &
python ../tests/src/stratum_dummy.py 2 &
python ../tests/src/stratum_dummy.py 3 &
ASAN_OPTIONS="detect_stack_use_after_return=1 atexit=1" ./p2pool --host xmrnode.facspro.net --rpc-port 18089 --zmq-port 18084 --host xmr2.rs.me --wallet 44MnN1f3Eto8DZYUWuE5XZNUtE3vcRzt2j6PzqWpPau34e6Cf4fAxt6X2MBmrm6F9YMEiMNjN6W4Shn4pLcfNAja621jwyg --mini --out-peers 200 --data-api data --local-api --loglevel 6
python ../tests/src/mm_server.py 8000 id0 data0 &
python ../tests/src/mm_server.py 8001 id1 data1 &
python ../tests/src/mm_server.py 8002 id2 data2 &
ASAN_OPTIONS="detect_stack_use_after_return=1 atexit=1" ./p2pool --host xmrnode.facspro.net --rpc-port 18089 --zmq-port 18084 --host xmr2.rs.me --wallet 44MnN1f3Eto8DZYUWuE5XZNUtE3vcRzt2j6PzqWpPau34e6Cf4fAxt6X2MBmrm6F9YMEiMNjN6W4Shn4pLcfNAja621jwyg --mini --out-peers 200 --data-api data --local-api --merge-mine 127.0.0.1:8000 test0 --merge-mine 127.0.0.1:8001 test1 --merge-mine 127.0.0.1:8002 test2 --loglevel 6
- name: Check p2pool.log
run: |
Expand Down Expand Up @@ -302,7 +321,10 @@ jobs:
python3 ../tests/src/stratum_dummy.py 1 &
python3 ../tests/src/stratum_dummy.py 2 &
python3 ../tests/src/stratum_dummy.py 3 &
./p2pool --host xmrnode.facspro.net --rpc-port 18089 --zmq-port 18084 --host xmr2.rs.me --wallet 44MnN1f3Eto8DZYUWuE5XZNUtE3vcRzt2j6PzqWpPau34e6Cf4fAxt6X2MBmrm6F9YMEiMNjN6W4Shn4pLcfNAja621jwyg --mini --out-peers 200 --data-api data --local-api --loglevel 6
python3 ../tests/src/mm_server.py 8000 id0 data0 &
python3 ../tests/src/mm_server.py 8001 id1 data1 &
python3 ../tests/src/mm_server.py 8002 id2 data2 &
./p2pool --host xmrnode.facspro.net --rpc-port 18089 --zmq-port 18084 --host xmr2.rs.me --wallet 44MnN1f3Eto8DZYUWuE5XZNUtE3vcRzt2j6PzqWpPau34e6Cf4fAxt6X2MBmrm6F9YMEiMNjN6W4Shn4pLcfNAja621jwyg --mini --out-peers 200 --data-api data --local-api --merge-mine 127.0.0.1:8000 test0 --merge-mine 127.0.0.1:8001 test1 --merge-mine 127.0.0.1:8002 test2 --loglevel 6
- name: Check p2pool.log
run: |
Expand Down Expand Up @@ -347,7 +369,10 @@ jobs:
start python ../../tests/src/stratum_dummy.py 1
start python ../../tests/src/stratum_dummy.py 2
start python ../../tests/src/stratum_dummy.py 3
p2pool.exe --host xmrnode.facspro.net --rpc-port 18089 --zmq-port 18084 --host xmr2.rs.me --wallet 44MnN1f3Eto8DZYUWuE5XZNUtE3vcRzt2j6PzqWpPau34e6Cf4fAxt6X2MBmrm6F9YMEiMNjN6W4Shn4pLcfNAja621jwyg --mini --out-peers 200 --data-api data --local-api --loglevel 6
start python ../../tests/src/mm_server.py 8000 id0 data0 &
start python ../../tests/src/mm_server.py 8001 id1 data1 &
start python ../../tests/src/mm_server.py 8002 id2 data2 &
p2pool.exe --host xmrnode.facspro.net --rpc-port 18089 --zmq-port 18084 --host xmr2.rs.me --wallet 44MnN1f3Eto8DZYUWuE5XZNUtE3vcRzt2j6PzqWpPau34e6Cf4fAxt6X2MBmrm6F9YMEiMNjN6W4Shn4pLcfNAja621jwyg --mini --out-peers 200 --data-api data --local-api --merge-mine 127.0.0.1:8000 test0 --merge-mine 127.0.0.1:8001 test1 --merge-mine 127.0.0.1:8002 test2 --loglevel 6
- name: Check p2pool.log
run: |
Expand Down Expand Up @@ -390,7 +415,10 @@ jobs:
Start-Process python -ArgumentList "../../tests/src/stratum_dummy.py 1"
Start-Process python -ArgumentList "../../tests/src/stratum_dummy.py 2"
Start-Process python -ArgumentList "../../tests/src/stratum_dummy.py 3"
./p2pool.exe --host xmrnode.facspro.net --rpc-port 18089 --zmq-port 18084 --host xmr2.rs.me --wallet 44MnN1f3Eto8DZYUWuE5XZNUtE3vcRzt2j6PzqWpPau34e6Cf4fAxt6X2MBmrm6F9YMEiMNjN6W4Shn4pLcfNAja621jwyg --mini --out-peers 200 --data-api data --local-api --loglevel 6
Start-Process python -ArgumentList "../../tests/src/mm_server.py 8000 id0 data0"
Start-Process python -ArgumentList "../../tests/src/mm_server.py 8001 id1 data1"
Start-Process python -ArgumentList "../../tests/src/mm_server.py 8002 id2 data2"
./p2pool.exe --host xmrnode.facspro.net --rpc-port 18089 --zmq-port 18084 --host xmr2.rs.me --wallet 44MnN1f3Eto8DZYUWuE5XZNUtE3vcRzt2j6PzqWpPau34e6Cf4fAxt6X2MBmrm6F9YMEiMNjN6W4Shn4pLcfNAja621jwyg --mini --out-peers 200 --data-api data --local-api --merge-mine 127.0.0.1:8000 test0 --merge-mine 127.0.0.1:8001 test1 --merge-mine 127.0.0.1:8002 test2 --loglevel 6
- name: Check p2pool.log
run: |
Expand Down
24 changes: 19 additions & 5 deletions src/merge_mining_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ MergeMiningClient::MergeMiningClient(p2pool* pool, const std::string& host, cons
, m_loopThread{}
, m_timer{}
, m_getJobRunning(false)
#ifdef DEV_TEST_SYNC
, m_getJobCounter(0)
#endif
, m_shutdownAsync{}
{
const size_t k = host.find_last_of(':');
Expand Down Expand Up @@ -110,16 +113,19 @@ void MergeMiningClient::merge_mining_get_chain_id()
m_ping = ping;
}

LOGINFO(1, m_host << ':' << m_port << " uses chain_id " << log::LightCyan() << m_chainID);
LOGINFO(1, m_host << ':' << m_port << " ping is " << m_ping << " ms");

// Chain ID received successfully, we can start polling for new mining jobs now
const int err = uv_timer_start(&m_timer, on_timer, 0, 500);
if (err) {
LOGERR(1, "failed to start timer, error " << uv_err_name(err));
}
}
},
[](const char* data, size_t size, double) {
[this](const char* data, size_t size, double) {
if (size > 0) {
LOGERR(1, "couldn't get merge mining id, error " << log::const_buf(data, size));
LOGERR(1, "couldn't get merge mining id from " << m_host << ':' << m_port << ", error " << log::const_buf(data, size));
}
}, &m_loop);
}
Expand Down Expand Up @@ -160,6 +166,14 @@ bool MergeMiningClient::parse_merge_mining_get_chain_id(const char* data, size_t

void MergeMiningClient::merge_mining_get_job(uint64_t height, const hash& prev_id, const std::string& wallet, const hash& aux_hash)
{
#ifdef DEV_TEST_SYNC
if (++m_getJobCounter > 100) {
LOGINFO(0, log::LightGreen() << "[DEV] Synchronization finished successfully, stopping P2Pool now");
m_pool->stop();
return;
}
#endif

if (m_getJobRunning) {
return;
}
Expand All @@ -182,7 +196,7 @@ void MergeMiningClient::merge_mining_get_job(uint64_t height, const hash& prev_i
},
[this](const char* data, size_t size, double) {
if (size > 0) {
LOGERR(1, "couldn't get merge mining job, error " << log::const_buf(data, size));
LOGERR(1, "couldn't get merge mining job from " << m_host << ':' << m_port << ", error " << log::const_buf(data, size));
}
m_getJobRunning = false;
}, &m_loop);
Expand Down Expand Up @@ -268,9 +282,9 @@ void MergeMiningClient::merge_mining_submit_solution(const std::vector<uint8_t>&
[this](const char* data, size_t size, double) {
parse_merge_mining_submit_solution(data, size);
},
[](const char* data, size_t size, double) {
[this](const char* data, size_t size, double) {
if (size > 0) {
LOGERR(1, "couldn't submit merge mining solution, error " << log::const_buf(data, size));
LOGERR(1, "couldn't submit merge mining solution to " << m_host << ':' << m_port << ", error " << log::const_buf(data, size));
}
}, &m_loop);
}
Expand Down
4 changes: 4 additions & 0 deletions src/merge_mining_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ class MergeMiningClient

bool m_getJobRunning;

#ifdef DEV_TEST_SYNC
uint32_t m_getJobCounter;
#endif

uv_async_t m_shutdownAsync;

static void on_shutdown(uv_async_t* async)
Expand Down
6 changes: 4 additions & 2 deletions src/p2pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,13 +346,15 @@ void p2pool::handle_miner_data(MinerData& data)
data.aux_chains.reserve(m_mergeMiningClients.size());

std::vector<hash> tmp;
tmp.reserve(m_mergeMiningClients.size());
tmp.reserve(m_mergeMiningClients.size() + 1);

for (const MergeMiningClient* c : m_mergeMiningClients) {
data.aux_chains.emplace_back(c->aux_id(), c->aux_data(), c->aux_diff());
tmp.emplace_back(c->aux_data());
tmp.emplace_back(c->aux_id());
}

tmp.emplace_back(m_sideChain->consensus_hash());

if (!find_aux_nonce(tmp, data.aux_nonce)) {
LOGERR(1, "Failed to find the aux nonce for merge mining. Merge mining will be off this round.");
data.aux_chains.clear();
Expand Down
30 changes: 26 additions & 4 deletions tests/src/mm_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
import socketserver
import json

chain_id = ''
aux_blob = ''
aux_diff = 1000
aux_hash = ''

counter = 0

class Server(http.server.BaseHTTPRequestHandler):
def do_POST(self):
length = int(self.headers['content-length'])
Expand All @@ -16,15 +23,30 @@ def do_POST(self):
response = {'jsonrpc':'2.0','id':'0'}

if request['method'] == 'merge_mining_get_chain_id':
response['result'] = {'chain_id':'0f28c4960d96647e77e7ab6d13b85bd16c7ca56f45df802cdc763a5e5c0c7863'}
response['result'] = {'chain_id':chain_id}
elif request['method'] == 'merge_mining_get_job':
response['result'] = {'aux_blob':'4c6f72656d20697073756d','aux_diff':123456,'aux_hash':'f6952d6eef555ddd87aca66e56b91530222d6e318414816f3ba7cf5bf694bf0f'}
global counter
counter += 1
s = aux_blob + '_' + str(counter // 10)
aux_hash = hashlib.sha256(s.encode('utf-8')).hexdigest()
if aux_hash != request['params']['aux_hash']:
response['result'] = {'aux_blob':s.encode('utf-8').hex(),'aux_diff':aux_diff,'aux_hash':aux_hash}
else:
response['result'] = {}
elif request['method'] == 'merge_mining_submit_solution':
response['result'] = {'status':'accepted'}

response = json.dumps(response);
print(response)
self.wfile.write(response.encode('utf-8'))

httpd = socketserver.TCPServer(('', 8000), Server)
httpd.serve_forever()
if __name__ == "__main__":
from sys import argv
import hashlib

port = int(argv[1])
chain_id = hashlib.sha256(argv[2].encode('utf-8')).hexdigest()
aux_blob = argv[3];

httpd = socketserver.TCPServer(('', port), Server)
httpd.serve_forever()

0 comments on commit 5aff5f5

Please sign in to comment.