Skip to content

Commit

Permalink
Merge pull request #235 from graft-project/rta-mining-rc
Browse files Browse the repository at this point in the history
rta-mining release (1.0.0)
  • Loading branch information
mbg033 authored Mar 14, 2019
2 parents fc7a723 + 86190da commit 0fe88aa
Show file tree
Hide file tree
Showing 50 changed files with 1,504 additions and 671 deletions.
41 changes: 40 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,40 @@
cmake_minimum_required(VERSION 3.10)

if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo)
endif(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)

if(CMAKE_BUILD_TYPE MATCHES RelWithDebInfo)
message("==> The configuration is ${CMAKE_BUILD_TYPE}. Debug info will be extracted into separate files.")

function (add_executable _name)
_add_executable(${ARGV})

if (TARGET ${_name})
add_custom_command(TARGET ${_name} POST_BUILD
COMMAND echo "$<TARGET_FILE_NAME:${_name}>: extracting debug info"
COMMAND ${CMAKE_COMMAND} -E chdir $<TARGET_FILE_DIR:${_name}> objcopy --only-keep-debug "$<TARGET_FILE_NAME:${_name}>" "$<TARGET_FILE_NAME:${_name}>.debug"
COMMAND ${CMAKE_COMMAND} -E chdir $<TARGET_FILE_DIR:${_name}> strip --strip-debug --strip-unneeded "$<TARGET_FILE_NAME:${_name}>"
COMMAND ${CMAKE_COMMAND} -E chdir $<TARGET_FILE_DIR:${_name}> objcopy --add-gnu-debuglink="$<TARGET_FILE_NAME:${_name}>.debug" "$<TARGET_FILE_NAME:${_name}>"
)
endif()
endfunction()

function (add_library _name _type)
_add_library(${ARGV})

if (TARGET ${_name} AND ${_type} STREQUAL SHARED)
add_custom_command(TARGET ${_name} POST_BUILD
COMMAND echo "$<TARGET_FILE_NAME:${_name}>: extracting debug info"
COMMAND ${CMAKE_COMMAND} -E chdir $<TARGET_FILE_DIR:${_name}> objcopy --only-keep-debug "$<TARGET_FILE_NAME:${_name}>" "$<TARGET_FILE_NAME:${_name}>.debug"
COMMAND ${CMAKE_COMMAND} -E chdir $<TARGET_FILE_DIR:${_name}> strip --strip-debug --strip-unneeded "$<TARGET_FILE_NAME:${_name}>"
COMMAND ${CMAKE_COMMAND} -E chdir $<TARGET_FILE_DIR:${_name}> objcopy --add-gnu-debuglink="$<TARGET_FILE_NAME:${_name}>.debug" "$<TARGET_FILE_NAME:${_name}>"
)
endif()
endfunction()

endif(CMAKE_BUILD_TYPE MATCHES RelWithDebInfo)

project(graft_server)

option(OPT_BUILD_TESTS "Build tests." OFF)
Expand Down Expand Up @@ -190,7 +225,7 @@ endif()

set_target_properties(graft PROPERTIES LINK_FLAGS "-Wl,-E -rdynamic")

add_dependencies(graft libr3 cryptonode graftlet_lib)
add_dependencies(graft version libr3 cryptonode graftlet_lib)

### requests_common library
add_library(requests_common STATIC
Expand Down Expand Up @@ -245,7 +280,9 @@ add_library(supernode_common STATIC
${PROJECT_SOURCE_DIR}/src/supernode/requests/sale_status.cpp
${PROJECT_SOURCE_DIR}/src/supernode/requests/send_raw_tx.cpp
${PROJECT_SOURCE_DIR}/src/supernode/requests/send_supernode_announce.cpp
${PROJECT_SOURCE_DIR}/src/supernode/requests/send_supernode_stakes.cpp
${PROJECT_SOURCE_DIR}/src/supernode/requests/send_transfer.cpp
${PROJECT_SOURCE_DIR}/src/supernode/requests/blockchain_based_list.cpp
${PROJECT_SOURCE_DIR}/src/rta/DaemonRpcClient.cpp
${PROJECT_SOURCE_DIR}/src/rta/fullsupernodelist.cpp
${PROJECT_SOURCE_DIR}/src/rta/supernode.cpp
Expand Down Expand Up @@ -286,6 +323,8 @@ add_executable(supernode
${PROJECT_SOURCE_DIR}/src/supernode/main.cpp
)

set_target_properties(supernode PROPERTIES LINK_FLAGS "-Wl,-E")

target_include_directories(supernode PRIVATE
${GRAFT_INCLUDE_DIRS}
)
Expand Down
6 changes: 4 additions & 2 deletions data/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ lru-timeout-ms=60000
data-dir=
stake-wallet-name=stake-wallet
testnet=true
stake-wallet-refresh-interval-ms=50000
stake-wallet-refresh-interval-ms=90000
stake-wallet-refresh-interval-random-factor=0
wallet-public-address=

[ipfilter]
;; path to ipfilter rules file
Expand All @@ -55,4 +57,4 @@ walletnode=http://127.0.0.1:28694
[graftlets]
;;dirs parameter, a list of directories to search graftlets separated by colons. If a directory is set relative it will be interpreted both relative to the current directory and relative to the executable location. By default, 'graftlets' directory will be used relative to the executable location.
;;e.g. dirs=/var/opt/graftlets:graftlets
dirs=graftlets:/var/opt
dirs=graftlets:graftlets/supernode:/var/opt
10 changes: 9 additions & 1 deletion graftlets/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ include_directories(
${PROJECT_SOURCE_DIR}/../modules/libr3/include
)


add_library(graftlet_walletAddress SHARED
WalletAddress.cpp
)
set_target_properties(graftlet_walletAddress PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/supernode
)

if (OPT_BUILD_TESTS)
message("==> Test graftlets included")

Expand All @@ -35,5 +43,5 @@ if (OPT_BUILD_TESTS)
add_library(graftlet_plugin1 SHARED
TestGraftlet1.cpp
)
endif()

endif()
2 changes: 1 addition & 1 deletion graftlets/TestGraftlet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class TestGraftlet: public IGraftlet
return graft::Status::Ok;
}

virtual void initOnce()
virtual void initOnce(const graft::CommonOpts& opts) override
{
// REGISTER_ACTION(TestGraftlet, testUndefined);
REGISTER_ACTION(TestGraftlet, testInt1);
Expand Down
2 changes: 1 addition & 1 deletion graftlets/TestGraftlet1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class TestGraftlet1: public IGraftlet
return graft::Status::Ok;
}

virtual void initOnce()
virtual void initOnce(const graft::CommonOpts& opts) override
{
// REGISTER_ACTION(TestGraftlet1, testUndefined);
REGISTER_ACTION(TestGraftlet1, testInt1);
Expand Down
116 changes: 116 additions & 0 deletions graftlets/WalletAddress.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// Copyright (c) 2018, The Graft Project
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors may be
// used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#define __GRAFTLET__
#include "lib/graft/GraftletRegistry.h"
#include "lib/graft/IGraftlet.h"

#include "WalletAddress.h"
#include "supernode/requestdefines.h"
#include "rta/supernode.h"
#include "lib/graft/graft_exception.h"
#include "cryptonote_basic/cryptonote_basic_impl.h"
#include "cryptonote_protocol/blobdatatype.h"
#include "file_io_utils.h"

#include<cassert>

#undef MONERO_DEFAULT_LOG_CATEGORY
#define MONERO_DEFAULT_LOG_CATEGORY "graftlet.WalletAddress"

class WalletAddress: public IGraftlet
{
public:
WalletAddress(const char* name) : IGraftlet(name) { }

virtual void initOnce(const graft::CommonOpts& /*opts*/) override
{
REGISTER_ENDPOINT("/dapi/v2.0/cryptonode/getwalletaddress", METHOD_GET | METHOD_POST, WalletAddress, getWalletAddressHandler);
}
private:
graft::Status getWalletAddressHandler(const graft::Router::vars_t& vars, const graft::Input& input, graft::Context& ctx, graft::Output& output);

};

GRAFTLET_EXPORTS_BEGIN("walletAddress", GRAFTLET_MKVER(1,1));
GRAFTLET_PLUGIN(WalletAddress, IGraftlet, "walletAddressGL");
GRAFTLET_EXPORTS_END

GRAFTLET_PLUGIN_DEFAULT_CHECK_FW_VERSION(GRAFTLET_MKVER(0,3))

graft::Status WalletAddress::getWalletAddressHandler(const graft::Router::vars_t& vars, const graft::Input& input, graft::Context& ctx,
graft::Output& output)
{
LOG_PRINT_L2(__FUNCTION__);

if (ctx.local.getLastStatus() != graft::Status::None) {
graft::supernode::request::GetWalletAddressErrorResponse err;
err.error = string("internal error: wrong status: " + to_string((int)ctx.local.getLastStatus()));
return graft::Status::Error;
}

graft::SupernodePtr supernode = ctx.global.get(CONTEXT_KEY_SUPERNODE, graft::SupernodePtr());
if (!supernode) {
graft::supernode::request::GetWalletAddressErrorResponse err;
err.error = string("supernode was not setup correctly");
return graft::Status::Error;
}

graft::supernode::request::GetWalletAddressResponse response;
response.testnet = supernode->testnet();
response.id_key = supernode->idKeyAsString();
response.wallet_public_address = supernode->walletAddress();

crypto::signature sign;
std::string data = supernode->walletAddress() + ":" + supernode->idKeyAsString();
supernode->signMessage(data, sign);
response.signature = epee::string_tools::pod_to_hex(sign);
output.load(response);
return graft::Status::Ok;
}

namespace
{

struct Informer
{
Informer()
{
LOG_PRINT_L2("graftlet " << getGraftletName() << " loading");
}
~Informer()
{
LOG_PRINT_L2("graftlet " << getGraftletName() << " unloading");
}
};

Informer informer;

} //namespace


48 changes: 48 additions & 0 deletions graftlets/WalletAddress.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (c) 2018, The Graft Project
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors may be
// used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#pragma once

#include "lib/graft/router.h"
#include "lib/graft/jsonrpc.h"

namespace graft::supernode::request {

GRAFT_DEFINE_IO_STRUCT_INITED(GetWalletAddressResponse,
(bool, testnet, false),
(std::string, wallet_public_address, ""),
(std::string, id_key, ""),
(std::string, signature, "") //signature of wallet_public_address + ":" + id_key
);

GRAFT_DEFINE_IO_STRUCT_INITED(GetWalletAddressErrorResponse,
(bool, testnet, false),
(std::string, error, "The wallet public address is not set")
);
} //namespace graft::supernode::request

6 changes: 5 additions & 1 deletion include/lib/graft/GraftletLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ class GraftletLoader
using Version = int;
using GraftletExceptionList = std::vector< std::pair< DllName, std::vector< std::pair<Version, Version> >>>;

GraftletLoader(const graft::CommonOpts& opts) : m_opts(opts) { }

static Version getFwVersion() { return m_fwVersion; }
static void setFwVersion(Version fwVersion) { m_fwVersion = fwVersion; }

Expand Down Expand Up @@ -188,7 +190,7 @@ class GraftletLoader
GraftletRegistry* gr = it1->second;
std::shared_ptr<BaseT> concreteGraftlet = gr->resolveGraftlet<BaseT>();
if(!concreteGraftlet.get()) throw std::runtime_error("Cannot resolve dll name:" + dllName + " type:" + typeid(BaseT).name());
concreteGraftlet->init();
concreteGraftlet->init(m_opts);
ClsName name = concreteGraftlet->getClsName();
std::any any(concreteGraftlet);

Expand Down Expand Up @@ -258,6 +260,8 @@ class GraftletLoader
static Version m_fwVersion;
static ExceptionMap m_exceptionMap;

const graft::CommonOpts& m_opts;

//we can use functions in a dll until we release object of boost::dll::shared_library
//dll name -> (lib, version, path)
std::map<DllName, std::tuple<boost::dll::shared_library, Version, DllPath, Dependencies>> m_name2lib;
Expand Down
7 changes: 4 additions & 3 deletions include/lib/graft/IGraftlet.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <cassert>
#include <misc_log_ex.h>
#include "lib/graft/router.h"
#include "lib/graft/serveropts.h"

#define REGISTER_ACTION(T, f) \
register_handler_memf(#f, this, &T::f)
Expand All @@ -33,11 +34,11 @@ class IGraftlet
IGraftlet(const IGraftlet&) = delete;
IGraftlet& operator = (const IGraftlet&) = delete;

void init()
void init(const graft::CommonOpts& opts)
{
if(m_inited) return;
m_inited = true;
initOnce();
initOnce(opts);
}

const ClsName& getClsName() const { return m_clsName; }
Expand Down Expand Up @@ -130,7 +131,7 @@ class IGraftlet
}
protected:
IGraftlet(const ClsName& name = ClsName() ) : m_clsName(name) { }
virtual void initOnce() = 0;
virtual void initOnce(const graft::CommonOpts& opts) = 0;
private:
using TypeIndex2any = std::map<std::type_index, std::tuple<std::any, EndpointPath, Methods> >;
using Map = std::map<FuncName, TypeIndex2any>;
Expand Down
3 changes: 1 addition & 2 deletions include/lib/graft/common/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ std::string base64_encode(const std::string &data);
template <typename T>
T random_number(T startRange, T endRange)
{
std::random_device rd;
std::mt19937 mt(rd());
static std::mt19937 mt(std::random_device{}());
std::uniform_int_distribution<T> dist(startRange, endRange);
return dist(mt);
}
Expand Down
5 changes: 3 additions & 2 deletions include/lib/graft/handler_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ class HandlerAPI
public:
virtual void sendUpstreamBlocking(Output& output, Input& input, std::string& err) = 0;
virtual bool addPeriodicTask(const Router::Handler& h_worker,
std::chrono::milliseconds interval_ms,
std::chrono::milliseconds initial_interval_ms = std::chrono::milliseconds::max()) = 0;
std::chrono::milliseconds interval_ms,
std::chrono::milliseconds initial_interval_ms = std::chrono::milliseconds::max(),
double random_factor = 0) = 0;
virtual request::system_info::Counter& runtimeSysInfo() = 0;
virtual const ConfigOpts& configOpts() const = 0;
};
Expand Down
10 changes: 10 additions & 0 deletions include/lib/graft/serveropts.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@

namespace graft {

struct CommonOpts
{
// testnet flag
bool testnet;
// data directory - base directory where supernode stake wallet and other supernodes wallets are located
std::string data_dir;
std::string wallet_public_address;
};

struct IPFilterOpts
{
int requests_per_sec = 0;
Expand All @@ -30,6 +39,7 @@ struct ConfigOpts
std::vector<std::string> graftlet_dirs;
int lru_timeout_ms;
IPFilterOpts ipfilter;
CommonOpts common;

void check_asserts() const
{
Expand Down
Loading

0 comments on commit 0fe88aa

Please sign in to comment.