Skip to content

Commit

Permalink
Auth sample disqualifications added.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderSuprunenko committed May 23, 2019
1 parent 0e5619a commit 30f6534
Show file tree
Hide file tree
Showing 7 changed files with 894 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ add_library(supernode_common STATIC
${PROJECT_SOURCE_DIR}/src/supernode/requestdefines.cpp
${PROJECT_SOURCE_DIR}/src/supernode/requests.cpp
${PROJECT_SOURCE_DIR}/src/supernode/requests/authorize_rta_tx.cpp
${PROJECT_SOURCE_DIR}/src/supernode/requests/auth_sample_disqualificator.cpp
${PROJECT_SOURCE_DIR}/src/supernode/requests/debug.cpp
${PROJECT_SOURCE_DIR}/src/supernode/requests/forward.cpp
${PROJECT_SOURCE_DIR}/src/supernode/requests/get_info.cpp
Expand Down Expand Up @@ -418,6 +419,7 @@ if (OPT_BUILD_TESTS)
${PROJECT_SOURCE_DIR}/test/rta_classes_test.cpp
${PROJECT_SOURCE_DIR}/test/sys_info.cpp
${PROJECT_SOURCE_DIR}/test/strand_test.cpp
${PROJECT_SOURCE_DIR}/test/disqualification_test.cpp
${PROJECT_SOURCE_DIR}/test/serialize_test.cpp
${PROJECT_SOURCE_DIR}/test/main.cpp
)
Expand Down
59 changes: 59 additions & 0 deletions include/supernode/requests/auth_sample_disqualificator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// 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/inout.h"
#include "lib/graft/context.h"

#include <utils/cryptmsg.h>

#include <vector>

namespace graft::supernode::request
{

//The class is used for tests
class AuthSDisqualificator
{
public:
//supernodes ids
using Ids = std::vector<crypto::public_key>;

//it should be called as earlier as possible, at the request when payment_id is known, to be prepared to respond to votes of disqualification requests while we are not ready yet to do disqualifications
// returns Ok
static graft::Status initDisqualify(graft::Context& ctx, const std::string& payment_id);

//it should be called on payment timeout, when we know whom to disqualify
//block_height is required to generate correct auth sample
//ids - supernodes to be disqualified, they should be from the auth sample
//it fills output with multicast request and returns Forward. call it even if ids empty, it will clear the context and return Ok
static graft::Status startDisqualify(graft::Context& ctx, const std::string& payment_id, uint64_t block_height, const Ids& ids, graft::Output& output);
};

} //namespace graft::supernode::request
29 changes: 25 additions & 4 deletions include/supernode/requests/disqualificator.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

#pragma once

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

#include <utils/cryptmsg.h>

Expand All @@ -44,25 +44,44 @@ class BBLDisqualificatorBase
public:
using GetSupernodeKeys = std::function<void (crypto::public_key& pub, crypto::secret_key& sec)>;
using GetBBQSandQCL = std::function<void (uint64_t& block_height, crypto::hash& block_hash, std::vector<crypto::public_key>& bbqs, std::vector<crypto::public_key>& qcl)>;
using GetAuthSample = std::function<void (uint64_t& block_height, const std::string& payment_id, crypto::hash& block_hash, std::vector<crypto::public_key>& auths)>;
using CollectTxs = std::function<void (void* ptxs)>;
using AddPeriodic = std::function<bool (const graft::Router::Handler& h_worker, std::chrono::milliseconds interval_ms, std::chrono::milliseconds initial_interval_ms, double random_factor)>;

static std::unique_ptr<BBLDisqualificatorBase> createTestBBLDisqualificator(
GetSupernodeKeys fnGetSupernodeKeys,
GetBBQSandQCL fnGetBBQSandQCL,
CollectTxs fnCollectTxs
);

static std::unique_ptr<BBLDisqualificatorBase> createTestAuthSDisqualificator(
GetSupernodeKeys fnGetSupernodeKeys,
GetAuthSample fnGetAuthSample,
CollectTxs fnCollectTxs,
std::chrono::milliseconds addPeriodic_interval_ms
);

static void waitForTestAuthSDisqualificator();

struct command
{
std::string uri; //process if empty
// uri.empty()
// if uri.empty()
uint64 block_height;
crypto::hash block_hash;
// !uri.empty()
// if !uri.empty()
std::string body;
// if !payment_id.empty() it is command for auth sample
std::string payment_id;
std::vector<crypto::public_key> ids; //ids to disqualify, startDisqualify if not empty, initDisqualify otherwise

command() = default;
//for bbl disqualification
command(uint64 block_height, const crypto::hash& block_hash) : block_height(block_height), block_hash(block_hash) { }
//for auth sample disqualification
command(const std::string& payment_id, const std::vector<crypto::public_key>& ids, uint64 block_height, const crypto::hash& block_hash)
: payment_id(payment_id), ids(ids), block_height(block_height), block_hash(block_hash) { }
//
command(const std::string& uri, const std::string& body) : uri(uri), body(body) { }
};

Expand All @@ -77,8 +96,10 @@ class BBLDisqualificatorBase
protected:
GetSupernodeKeys fnGetSupernodeKeys;
GetBBQSandQCL fnGetBBQSandQCL;
GetAuthSample fnGetAuthSample;
CollectTxs fnCollectTxs;
AddPeriodic fnAddPeriodic;
std::chrono::milliseconds addPeriodic_interval_ms;
};


} //namespace graft::supernode::request
3 changes: 3 additions & 0 deletions src/supernode/requests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ namespace graft::request::system_info { void register_request(Router& router); }

namespace graft::supernode::request {

void registerAuthSDisqualificatorRequest(graft::Router &router);

void registerRTARequests(graft::Router &router)
{
registerSaleRequest(router);
Expand All @@ -37,6 +39,7 @@ void registerRTARequests(graft::Router &router)
registerSendSupernodeAnnounceRequest(router);
registerSendSupernodeStakesRequest(router);
registerBlockchainBasedListRequest(router);
registerAuthSDisqualificatorRequest(router);
}

void registerWalletApiRequests(graft::Router &router)
Expand Down
Loading

0 comments on commit 30f6534

Please sign in to comment.