mirror of
https://github.com/SChernykh/p2pool.git
synced 2024-12-22 19:39:22 +00:00
Sync test: submit fake shares to test stratum
This commit is contained in:
parent
229d7b052a
commit
929f908a86
2 changed files with 57 additions and 13 deletions
|
@ -973,14 +973,14 @@ void StratumServer::on_after_share_found(uv_work_t* req, int /*status*/)
|
|||
BACKGROUND_JOB_STOP(StratumServer::on_share_found);
|
||||
}
|
||||
|
||||
ON_SCOPE_LEAVE([share]()
|
||||
StratumServer* server = share->m_server;
|
||||
|
||||
ON_SCOPE_LEAVE([share, server]()
|
||||
{
|
||||
ASAN_POISON_MEMORY_REGION(share, sizeof(SubmittedShare));
|
||||
share->m_server->m_submittedSharesPool.push_back(share);
|
||||
server->m_submittedSharesPool.push_back(share);
|
||||
});
|
||||
|
||||
StratumServer* server = share->m_server;
|
||||
|
||||
const bool bad_share = (share->m_result == SubmittedShare::Result::LOW_DIFF) || (share->m_result == SubmittedShare::Result::INVALID_POW);
|
||||
|
||||
if ((client->m_resetCounter.load() == share->m_clientResetCounter) && (client->m_rpcId == share->m_rpcId)) {
|
||||
|
|
|
@ -1,37 +1,81 @@
|
|||
import socket
|
||||
import time
|
||||
import sys
|
||||
import json
|
||||
|
||||
f = open('stratum_dummy' + sys.argv[1] + '.log', 'wb');
|
||||
f = open('stratum_dummy' + sys.argv[1] + '.log', 'wb')
|
||||
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
sock.settimeout(1)
|
||||
sock.setblocking(True)
|
||||
|
||||
f.write(b'Connecting')
|
||||
time.sleep(5)
|
||||
|
||||
while sock.connect_ex(('127.0.0.1', 3333)) != 0:
|
||||
f.write(b'.\n')
|
||||
f.write(b'.')
|
||||
print('.')
|
||||
time.sleep(1)
|
||||
|
||||
diff = '';
|
||||
f.write(b'\n')
|
||||
|
||||
diff = ''
|
||||
|
||||
if (sys.argv[1] == '2'):
|
||||
diff = '+1000';
|
||||
diff = '+1000'
|
||||
if (sys.argv[1] == '3'):
|
||||
diff = '+10000000';
|
||||
diff = '+10000000'
|
||||
|
||||
request = '{"id":1,"method":"login","params":{"login":"x' + diff + '"}}\n'
|
||||
msg_id = 1
|
||||
|
||||
request = '{"id":' + str(msg_id) + ',"method":"login","params":{"login":"x' + diff + '"}}\n'
|
||||
msg_id += 1
|
||||
s = '-> ' + request
|
||||
print(s, end='')
|
||||
sock.sendall(request.encode('utf-8'))
|
||||
|
||||
f.write(s.encode('utf-8'))
|
||||
f.flush()
|
||||
|
||||
rpc_id = ''
|
||||
|
||||
while True:
|
||||
data = sock.recv(1024)
|
||||
if len(data) == 0:
|
||||
break;
|
||||
f.write(data)
|
||||
break
|
||||
|
||||
s = '<- ' + data.decode('utf-8')
|
||||
print(s, end='')
|
||||
|
||||
f.write(s.encode('utf-8'))
|
||||
f.flush()
|
||||
print(data.decode('utf-8'))
|
||||
|
||||
obj = json.loads(data)
|
||||
job_id = ''
|
||||
|
||||
if ('method' in obj) and ('params' in obj) and (obj['method'] == 'job'):
|
||||
job_id = obj['params']['job_id']
|
||||
target = obj['params']['target']
|
||||
elif ('result' in obj):
|
||||
if ('id' in obj['result']):
|
||||
rpc_id = obj['result']['id']
|
||||
job_id = obj['result']['job']['job_id']
|
||||
target = obj['result']['job']['target']
|
||||
|
||||
if (job_id != ''):
|
||||
if (msg_id < 4):
|
||||
result = ('f' if (msg_id == 2) else '0') * 64
|
||||
request = '{"id":' + str(msg_id) + ',"method":"submit","params":{"id":"' + rpc_id + '","job_id":"' + job_id + '","nonce":"ffffffff","result":"' + result + '"}}\n'
|
||||
else:
|
||||
request = '{"id":' + str(msg_id) + ',"method":"keepalived"}\n'
|
||||
|
||||
msg_id += 1
|
||||
s = '-> ' + request
|
||||
print(s, end='')
|
||||
sock.sendall(request.encode('utf-8'))
|
||||
|
||||
f.write(s.encode('utf-8'))
|
||||
f.flush()
|
||||
|
||||
sock.close()
|
||||
f.close()
|
||||
|
|
Loading…
Reference in a new issue