Progress #237: Begin work on delayed_node_plugin
This commit is contained in:
parent
2244e467ed
commit
baf6bfc17b
4 changed files with 155 additions and 0 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
add_subdirectory( witness )
|
add_subdirectory( witness )
|
||||||
add_subdirectory( account_history )
|
add_subdirectory( account_history )
|
||||||
add_subdirectory( market_history )
|
add_subdirectory( market_history )
|
||||||
|
add_subdirectory( delayed_node )
|
||||||
|
|
|
||||||
21
libraries/plugins/delayed_node/CMakeLists.txt
Normal file
21
libraries/plugins/delayed_node/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
file(GLOB HEADERS "include/graphene/delayed_node/*.hpp")
|
||||||
|
|
||||||
|
add_library( graphene_delayed_node
|
||||||
|
delayed_node_plugin.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries( graphene_delayed_node graphene_chain graphene_app )
|
||||||
|
target_include_directories( graphene_delayed_node
|
||||||
|
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" )
|
||||||
|
|
||||||
|
if(MSVC)
|
||||||
|
set_source_files_properties( delayed_node_plugin.cpp PROPERTIES COMPILE_FLAGS "/bigobj" )
|
||||||
|
endif(MSVC)
|
||||||
|
|
||||||
|
install( TARGETS
|
||||||
|
graphene_delayed_node
|
||||||
|
|
||||||
|
RUNTIME DESTINATION bin
|
||||||
|
LIBRARY DESTINATION lib
|
||||||
|
ARCHIVE DESTINATION lib
|
||||||
|
)
|
||||||
89
libraries/plugins/delayed_node/delayed_node_plugin.cpp
Normal file
89
libraries/plugins/delayed_node/delayed_node_plugin.cpp
Normal file
|
|
@ -0,0 +1,89 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2015, Cryptonomex, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is provided for evaluation in private test networks only, until September 8, 2015. After this date, this license expires and
|
||||||
|
* the code may not be used, modified or distributed for any purpose. Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
* are permitted until September 8, 2015, provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. The code and/or derivative works are used only for private test networks consisting of no more than 10 P2P nodes.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <graphene/delayed_node/delayed_node_plugin.hpp>
|
||||||
|
#include <graphene/chain/database.hpp>
|
||||||
|
#include <graphene/app/api.hpp>
|
||||||
|
|
||||||
|
#include <fc/network/http/websocket.hpp>
|
||||||
|
#include <fc/rpc/websocket_api.hpp>
|
||||||
|
#include <fc/api.hpp>
|
||||||
|
|
||||||
|
namespace graphene { namespace delayed_node {
|
||||||
|
namespace bpo = boost::program_options;
|
||||||
|
|
||||||
|
namespace detail {
|
||||||
|
struct delayed_node_plugin_impl {
|
||||||
|
std::string remote_endpoint;
|
||||||
|
int delay_blocks;
|
||||||
|
std::shared_ptr<fc::rpc::websocket_api_connection> client_connection;
|
||||||
|
fc::api<graphene::app::database_api> database_api;
|
||||||
|
boost::signals2::scoped_connection client_connection_closed;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
delayed_node_plugin::delayed_node_plugin()
|
||||||
|
: my(new detail::delayed_node_plugin_impl)
|
||||||
|
{}
|
||||||
|
|
||||||
|
void delayed_node_plugin::plugin_set_program_options(bpo::options_description&, bpo::options_description& cfg)
|
||||||
|
{
|
||||||
|
cfg.add_options()
|
||||||
|
("trusted_node", boost::program_options::value<std::string>()->required(), "RPC endpoint of a trusted validating node")
|
||||||
|
("delay_block_count", boost::program_options::value<int>()->required(), "Number of blocks to delay before advancing chain state")
|
||||||
|
;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void delayed_node_plugin::connect()
|
||||||
|
{
|
||||||
|
fc::http::websocket_client client;
|
||||||
|
my->client_connection = std::make_shared<fc::rpc::websocket_api_connection>(*client.connect(my->remote_endpoint));
|
||||||
|
my->database_api = my->client_connection->get_remote_api<graphene::app::database_api>(0);
|
||||||
|
my->client_connection_closed = my->client_connection->closed.connect([this] {
|
||||||
|
connection_failed();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void delayed_node_plugin::plugin_initialize(const boost::program_options::variables_map& options)
|
||||||
|
{
|
||||||
|
my->remote_endpoint = options.at("trusted_node").as<std::string>();
|
||||||
|
my->delay_blocks = options.at("delay_block_count").as<int>();
|
||||||
|
|
||||||
|
try {
|
||||||
|
connect();
|
||||||
|
} catch (const fc::exception& e) {
|
||||||
|
elog("Error during connection: ${e}", ("e", e.to_detail_string()));
|
||||||
|
connection_failed();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void delayed_node_plugin::connection_failed()
|
||||||
|
{
|
||||||
|
elog("Connection to trusted node failed; retrying in 5 seconds...");
|
||||||
|
fc::usleep(fc::seconds(5));
|
||||||
|
|
||||||
|
try {
|
||||||
|
connect();
|
||||||
|
} catch (const fc::exception& e) {
|
||||||
|
elog("Error during connection: ${e}", ("e", e.to_detail_string()));
|
||||||
|
fc::async([this]{connection_failed();});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} }
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2015, Cryptonomex, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is provided for evaluation in private test networks only, until September 8, 2015. After this date, this license expires and
|
||||||
|
* the code may not be used, modified or distributed for any purpose. Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
* are permitted until September 8, 2015, provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. The code and/or derivative works are used only for private test networks consisting of no more than 10 P2P nodes.
|
||||||
|
*
|
||||||
|
* 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 <graphene/app/plugin.hpp>
|
||||||
|
|
||||||
|
namespace graphene { namespace delayed_node {
|
||||||
|
namespace detail { struct delayed_node_plugin_impl; }
|
||||||
|
|
||||||
|
class delayed_node_plugin : public graphene::app::plugin
|
||||||
|
{
|
||||||
|
std::unique_ptr<detail::delayed_node_plugin_impl> my;
|
||||||
|
public:
|
||||||
|
delayed_node_plugin();
|
||||||
|
virtual ~delayed_node_plugin(){}
|
||||||
|
|
||||||
|
std::string plugin_name()const override { return "delayed_node"; }
|
||||||
|
virtual void plugin_set_program_options(boost::program_options::options_description&,
|
||||||
|
boost::program_options::options_description& cfg) override;
|
||||||
|
virtual void plugin_initialize(const boost::program_options::variables_map& options) override;
|
||||||
|
virtual void plugin_startup() override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void connection_failed();
|
||||||
|
void connect();
|
||||||
|
};
|
||||||
|
|
||||||
|
} } //graphene::account_history
|
||||||
|
|
||||||
Loading…
Reference in a new issue