Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions contrib/linearize/example-linearize.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ max_height=313000
# bootstrap.dat input/output settings (linearize-data)

# mainnet
netmagic=f9beb4d9
genesis=000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f
netmagic=43524f57
genesis=0b2c703dc93bb63a36c4e33b85be4855ddbca2ac951a7a0a29b8de0408200a3c
input=/home/example/.raven/blocks

# testnet
Expand Down
31 changes: 9 additions & 22 deletions contrib/linearize/linearize-data.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import re
import os
import os.path
import subprocess
import sys
import hashlib
import datetime
import time
from collections import namedtuple
Expand Down Expand Up @@ -49,23 +49,11 @@ def wordreverse(in_buf):
out_words.reverse()
return b''.join(out_words)

def calc_hdr_hash(blk_hdr):
hash1 = hashlib.sha256()
hash1.update(blk_hdr)
hash1_o = hash1.digest()

hash2 = hashlib.sha256()
hash2.update(hash1_o)
hash2_o = hash2.digest()

return hash2_o

def calc_hash_str(blk_hdr):
hash = calc_hdr_hash(blk_hdr)
hash = bufreverse(hash)
hash = wordreverse(hash)
hash_str = hexlify(hash).decode('utf-8')
return hash_str
x16r_hash_cmd = os.path.dirname(os.path.realpath(__file__)) + "/../../src/test/test_raven_hash"
cmd = [x16r_hash_cmd, hexlify(blk_hdr).decode('utf-8'), "2"]
blk_hash = subprocess.run(cmd, stdout=subprocess.PIPE, check=True).stdout.decode('ascii')
return blk_hash

def get_blk_dt(blk_hdr):
members = struct.unpack("<I", blk_hdr[68:68+4])
Expand Down Expand Up @@ -216,7 +204,7 @@ def run(self):

inMagic = inhdr[:4]
if (inMagic != self.settings['netmagic']):
print("Invalid magic: " + hexlify(inMagic).decode('utf-8'))
print("Invalid magic: " + hexlify(inMagic).decode('utf-8') + " (" + str(inMagic) + ")")
return
inLenLE = inhdr[4:]
su = struct.unpack("<I", inLenLE)
Expand All @@ -228,8 +216,7 @@ def run(self):
if not self.hash_str in blkmap:
# Because blocks can be written to files out-of-order as of 0.10, the script
# may encounter blocks it doesn't know about. Treat as debug output.
if settings['debug_output'] == 'true':
print("Skipping unknown block " + self.hash_str)
print("Skipping unknown block " + self.hash_str)
self.inF.seek(inLen, os.SEEK_CUR)
continue

Expand Down Expand Up @@ -284,9 +271,9 @@ def run(self):
settings['rev_hash_bytes'] = settings['rev_hash_bytes'].lower()

if 'netmagic' not in settings:
settings['netmagic'] = 'f9beb4d9'
settings['netmagic'] = '43524f57'
if 'genesis' not in settings:
settings['genesis'] = '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f'
settings['genesis'] = '0b2c703dc93bb63a36c4e33b85be4855ddbca2ac951a7a0a29b8de0408200a3c'
if 'input' not in settings:
settings['input'] = 'input'
if 'hashlist' not in settings:
Expand Down
72 changes: 72 additions & 0 deletions src/rpc/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "utilstrencodings.h"
#include "mining.h"

#include <mutex>
#include <univalue.h>

#include <boost/bind.hpp>
Expand All @@ -39,6 +40,37 @@ static RPCTimerInterface* timerInterface = nullptr;
/* Map of name to timer. */
static std::map<std::string, std::unique_ptr<RPCTimerBase> > deadlineTimers;

struct RPCCommandExecutionInfo
{
std::string method;
int64_t start;
};

struct RPCServerInfo
{
std::mutex mtx;
std::list<RPCCommandExecutionInfo> active_commands GUARDED_BY(mtx);
};

static RPCServerInfo g_rpc_server_info;

struct RPCCommandExecution
{
std::list<RPCCommandExecutionInfo>::iterator it;
explicit RPCCommandExecution(const std::string& method)
{
g_rpc_server_info.mtx.lock();
it = g_rpc_server_info.active_commands.insert(g_rpc_server_info.active_commands.end(), {method, GetTimeMicros()});
g_rpc_server_info.mtx.unlock();
}
~RPCCommandExecution()
{
g_rpc_server_info.mtx.lock();
g_rpc_server_info.active_commands.erase(it);
g_rpc_server_info.mtx.unlock();
}
};

static struct CRPCSignals
{
boost::signals2::signal<void ()> Started;
Expand Down Expand Up @@ -263,13 +295,52 @@ UniValue uptime(const JSONRPCRequest& jsonRequest)
return GetTime() - GetStartupTime();
}

UniValue getrpcinfo(const JSONRPCRequest& jsonRequest)
{

if (jsonRequest.fHelp || jsonRequest.params.size() > 0)
throw std::runtime_error(
"getrpcinfo\n"
"Returns details of the RPC server.\n"
"\nResult:\n"
"{\n"
" \"active_commands\" (array) All active commands\n"
" [\n"
" { (object) Information about an active command\n"
" \"method\" (string) The name of the RPC command \n"
" \"duration\" (numeric) The running time in microseconds\n"
" },...\n"
" ],\n"
"}\n"
+ HelpExampleCli("getrpcinfo", "")
+ HelpExampleRpc("getrpcinfo", "")
);

g_rpc_server_info.mtx.lock();
UniValue active_commands(UniValue::VARR);
for (const RPCCommandExecutionInfo& info : g_rpc_server_info.active_commands) {
UniValue entry(UniValue::VOBJ);
entry.pushKV("method", info.method);
entry.pushKV("duration", GetTimeMicros() - info.start);
active_commands.push_back(entry);
}

UniValue result(UniValue::VOBJ);
result.pushKV("active_commands", active_commands);
g_rpc_server_info.mtx.unlock();

return result;
}


/**
* Call Table
*/
static const CRPCCommand vRPCCommands[] =
{ // category name actor (function) argNames
// --------------------- ------------------------ ----------------------- ----------
/* Overall control/query calls */
{ "control", "getrpcinfo", &getrpcinfo, {} },
{ "control", "help", &help, {"command"} },
{ "control", "stop", &stop, {} },
{ "control", "uptime", &uptime, {} },
Expand Down Expand Up @@ -496,6 +567,7 @@ UniValue CRPCTable::execute(const JSONRPCRequest &request) const

try
{
RPCCommandExecution execution(request.strMethod);
// Execute, convert arguments to array if necessary
if (request.params.isObject()) {
return pcmd->actor(transformNamedArguments(request, pcmd->argNames));
Expand Down
10 changes: 5 additions & 5 deletions src/test/script_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1502,9 +1502,9 @@ BOOST_FIXTURE_TEST_SUITE(script_tests, BasicTestingSetup)

BOOST_AUTO_TEST_CASE(script_FindAndDelete_test)
{
BOOST_TEST_MESSAGE("Running script FindAndDelete Test");
BOOST_TEST_MESSAGE("Running script find_and_delete Test");

// Exercise the FindAndDelete functionality
// Exercise the find_and_delete functionality
CScript s;
CScript d;
CScript expect;
Expand Down Expand Up @@ -1541,7 +1541,7 @@ BOOST_FIXTURE_TEST_SUITE(script_tests, BasicTestingSetup)

s = ScriptFromHex("0302ff030302ff03");
d = ScriptFromHex("02");
expect = s; // FindAndDelete matches entire opcodes
expect = s; // find_and_delete matches entire opcodes
BOOST_CHECK_EQUAL(s.FindAndDelete(d), 0);
BOOST_CHECK(s == expect);

Expand Down Expand Up @@ -1586,13 +1586,13 @@ BOOST_FIXTURE_TEST_SUITE(script_tests, BasicTestingSetup)

s = CScript() << OP_0 << OP_0 << OP_1 << OP_1;
d = CScript() << OP_0 << OP_1;
expect = CScript() << OP_0 << OP_1; // FindAndDelete is single-pass
expect = CScript() << OP_0 << OP_1; // find_and_delete is single-pass
BOOST_CHECK_EQUAL(s.FindAndDelete(d), 1);
BOOST_CHECK(s == expect);

s = CScript() << OP_0 << OP_0 << OP_1 << OP_0 << OP_1 << OP_1;
d = CScript() << OP_0 << OP_1;
expect = CScript() << OP_0 << OP_1; // FindAndDelete is single-pass
expect = CScript() << OP_0 << OP_1; // find_and_delete is single-pass
BOOST_CHECK_EQUAL(s.FindAndDelete(d), 2);
BOOST_CHECK(s == expect);

Expand Down
4 changes: 2 additions & 2 deletions src/test/sighash_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

extern UniValue read_json(const std::string &jsondata);

// Old script.cpp SignatureHash function
// Old script.cpp signature_hash function
uint256 static SignatureHashOld(CScript scriptCode, const CTransaction &txTo, unsigned int nIn, int nHashType)
{
static const uint256 one(uint256S("0000000000000000000000000000000000000000000000000000000000000001"));
Expand Down Expand Up @@ -168,7 +168,7 @@ BOOST_FIXTURE_TEST_SUITE(sighash_tests, BasicTestingSetup)
#endif
}

// Goal: check that SignatureHash generates correct hash
// Goal: check that signature_hash generates correct hash
BOOST_AUTO_TEST_CASE(sighash_from_data_test)
{
BOOST_TEST_MESSAGE("Running SigHas From Data Test");
Expand Down
4 changes: 2 additions & 2 deletions src/test/sigopcount_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ BOOST_FIXTURE_TEST_SUITE(sigopcount_tests, BasicTestingSetup)

BOOST_AUTO_TEST_CASE(GetSigOpCount_test)
{
BOOST_TEST_MESSAGE("Running GetSigOpCount Test");
BOOST_TEST_MESSAGE("Running get_sig_op_count Test");

// Test CScript::GetSigOpCount()
// Test CScript::get_sig_op_count()
CScript s1;
BOOST_CHECK_EQUAL(s1.GetSigOpCount(false), 0U);
BOOST_CHECK_EQUAL(s1.GetSigOpCount(true), 0U);
Expand Down
11 changes: 8 additions & 3 deletions test/functional/combine_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
# Copyright (c) 2017-2019 The Raven Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Combine logs from multiple raven nodes as well as the test_framework log.

"""
Combine logs from multiple raven nodes as well as the test_framework log.

This streams the combined log output to stdout. Use combine_logs.py > outputfile
to write to an outputfile."""
to write to an outputfile.
"""

import argparse
from collections import (defaultdict, namedtuple)
from collections import defaultdict, namedtuple
import heapq
import itertools
import os
Expand Down Expand Up @@ -89,6 +92,8 @@ def get_log_events(source, logfile):
except FileNotFoundError:
print("File %s could not be opened. Continuing without it." % logfile, file=sys.stderr)


# noinspection PyProtectedMember
def print_logs(log_events, color=False, html=False):
"""Renders the iterator of log events into text or html."""
if not html:
Expand Down
4 changes: 3 additions & 1 deletion test/functional/create_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
# Copyright (c) 2017-2019 The Raven Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Create a blockchain cache.

"""
Create a blockchain cache.

Creating a cache of the blockchain speeds up test execution when running
multiple functional tests. This helper script is executed by test_runner when multiple
Expand Down
Loading