Skip to content

Commit

Permalink
Merge branch 'dev_cleanup' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
henriqueaklein committed Mar 11, 2024
2 parents 10b6079 + 5441835 commit ba6fbd5
Show file tree
Hide file tree
Showing 134 changed files with 2,498 additions and 291 deletions.
28 changes: 28 additions & 0 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,34 @@ add_executable (sgns_demo
changes_tracker
trie_serializer
supergenius_trie_factory
block_tree
extrinsic_observer
author_api_service
transaction_pool
gossiper_broadcast
waitable_timer
production
remote_sync_protocol_client
dummy_sync_protocol_client
production_synchronizer
block_validator
sr25519_provider
epoch_storage
authority_manager
proposer
finality
environment
ed25519_provider
sgns_router
sync_protocol_observer
api_service
api_transport
api_jrpc_server
chain_api_service
state_api_service
system_api_service
author_api_service
api_author_requests
p2p::p2p_basic_host
p2p::p2p_default_network
p2p::p2p_peer_repository
Expand Down
27 changes: 27 additions & 0 deletions app/SuperGeniusDemoApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "SuperGeniusDemoApp.hpp"
#include "base/logger.hpp"
#include "integration/AppConfigurationFactory.hpp"
#include <libp2p/log/configurator.hpp>
#include <libp2p/log/logger.hpp>

SuperGeniusDemoApp::SuperGeniusDemoApp()
{
Expand All @@ -25,6 +27,31 @@ void SuperGeniusDemoApp::init( int argc, char **argv )
//cfg = std::shared_ptr<sgns::application::AppConfiguration>( std::move( AppConfigurationFactory::create( logger ) ) );
cfg = AppConfigurationFactory::create( logger );

const std::string logger_config( R"(
# ----------------
sinks:
- name: console
type: console
color: true
groups:
- name: SuperGeniusDemo
sink: console
level: info
children:
- name: libp2p
- name: Gossip
# ----------------
)" );
auto p2p_log_system = std::make_shared<soralog::LoggingSystem>( std::make_shared<soralog::ConfiguratorFromYAML>(
// Original LibP2P logging config
std::make_shared<libp2p::log::Configurator>(),
// Additional logging config for application
logger_config ) );
p2p_log_system->configure();

libp2p::log::setLoggingSystem( p2p_log_system );
libp2p::log::setLevelOfGroup( "SuperGeniusDemo", soralog::Level::DEBUG );

cfg->initialize_from_args( sgns::application::AppConfiguration::LoadScheme::kValidating, argc, argv );

validation_node = std::make_shared<sgns::application::ValidatingNodeApplication>( std::move( cfg ) );
Expand Down
118 changes: 118 additions & 0 deletions app/integration/ApiServiceFactory.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/**
* @file ApiServiceFactory.hpp
* @brief
* @date 2024-03-04
* @author Henrique A. Klein ([email protected])
*/
#ifndef _API_SERVICE_FACTORY_HPP_
#define _API_SERVICE_FACTORY_HPP_

#include "api/service/api_service.hpp"
#include "application/app_state_manager.hpp"
#include "api/transport/rpc_thread_pool.hpp"
#include "api/transport/listener.hpp"
#include "api/jrpc/jrpc_server.hpp"
#include "api/jrpc/jrpc_processor.hpp"
#include "subscription/subscriber.hpp"

class CComponnetFactory;
namespace sgns
{
class ApiServiceFactory
{
public:
std::shared_ptr<api::ApiService> create()
{
auto component_factory = SINGLETONINSTANCE( CComponentFactory );

auto result = component_factory->GetComponent( "AppStateManager", boost::none );
if ( !result )
{
throw std::runtime_error( "Initialize AppStateManager first" );
}
//auto app_state_manager = std::dynamic_pointer_cast<application::AppStateManager>( result.value() );
auto app_state_manager = AppStateManagerFactory::create();

result = component_factory->GetComponent( "RpcThreadPool", boost::none );
if ( !result )
{
throw std::runtime_error( "Initialize RpcThreadPool first" );
}
auto rpc_thread_pool = std::dynamic_pointer_cast<api::RpcThreadPool>( result.value() );

result = component_factory->GetComponent( "Listener", boost::make_optional( std::string( "http" ) ) );
if ( !result )
{
throw std::runtime_error( "Initialize Http Listener first" );
}
auto http_listener = std::dynamic_pointer_cast<api::Listener>( result.value() );

result = component_factory->GetComponent( "Listener", boost::make_optional( std::string( "ws" ) ) );
if ( !result )
{
throw std::runtime_error( "Initialize Ws Listener first" );
}
auto ws_listener = std::dynamic_pointer_cast<api::Listener>( result.value() );

std::vector<std::shared_ptr<api::Listener>> listeners{ std::move( http_listener ), std::move( ws_listener ) };

result = component_factory->GetComponent( "JRpcServer", boost::none );
if ( !result )
{
throw std::runtime_error( "Initialize JRpcServer first" );
}
auto jrpc_server = std::dynamic_pointer_cast<api::JRpcServer>( result.value() );

result = component_factory->GetComponent( "JRpcProcessor", boost::make_optional( std::string( "State" ) ) );
if ( !result )
{
throw std::runtime_error( "Initialize StateJRpcProcessor first" );
}
auto state_jrpc_proc = std::dynamic_pointer_cast<api::JRpcProcessor>( result.value() );

result = component_factory->GetComponent( "JRpcProcessor", boost::make_optional( std::string( "Author" ) ) );
if ( !result )
{
throw std::runtime_error( "Initialize AuthorJRpcProcessor first" );
}
auto author_jrpc_proc = std::dynamic_pointer_cast<api::JRpcProcessor>( result.value() );

result = component_factory->GetComponent( "JRpcProcessor", boost::make_optional( std::string( "Chain" ) ) );
if ( !result )
{
throw std::runtime_error( "Initialize ChainJRpcProcessor first" );
}
auto chain_jrpc_proc = std::dynamic_pointer_cast<api::JRpcProcessor>( result.value() );

result = component_factory->GetComponent( "JRpcProcessor", boost::make_optional( std::string( "System" ) ) );
if ( !result )
{
throw std::runtime_error( "Initialize SystemJRpcProcessor first" );
}
auto system_jrpc_proc = std::dynamic_pointer_cast<api::JRpcProcessor>( result.value() );

std::vector<std::shared_ptr<api::JRpcProcessor>> processors{
state_jrpc_proc, //
author_jrpc_proc, //
chain_jrpc_proc, //
system_jrpc_proc //
};

//TODO - Not sute about this. Maybe also should be a singleton of sorts
using SubscriptionEngineType =
subscription::SubscriptionEngine<base::Buffer, std::shared_ptr<api::Session>, base::Buffer, primitives::BlockHash>;
auto subscription_engine = std::make_shared<SubscriptionEngineType>();

return std::make_shared<api::ApiService>( //
app_state_manager, //
rpc_thread_pool, //
listeners, //
jrpc_server, //
processors, //
subscription_engine //
);
}
};
}

#endif
2 changes: 1 addition & 1 deletion app/integration/AppConfigurationFactory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class AppConfigurationFactory
public:
static std::shared_ptr<sgns::application::AppConfiguration> create( sgns::base::Logger logger )
{
return std::make_shared<sgns::application::AppConfigurationImpl>( std::move( logger ) );
return std::make_shared<sgns::application::AppConfigurationImpl>( logger );
}
};

Expand Down
52 changes: 52 additions & 0 deletions app/integration/AuthorApiFactory.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* @file AuthorApiFactory.hpp
* @brief
* @date 2024-02-26
* @author Henrique A. Klein ([email protected])
*/
#ifndef _AUTHOR_API_FACTORY_HPP_
#define _AUTHOR_API_FACTORY_HPP_

#include "api/service/author/impl/author_api_impl.hpp"
#include "integration/CComponentFactory.hpp"
#include "transaction_pool/transaction_pool.hpp"
#include "crypto/hasher.hpp"
#include "network/extrinsic_gossiper.hpp"

class AuthorApiFactory
{
public:
//TODO - Removed "validate_transaction from runtime::TaggedTransactionQueue". Need to replace it
static std::shared_ptr<sgns::api::AuthorApi> create()
{
auto component_factory = SINGLETONINSTANCE( CComponentFactory );
auto result = component_factory->GetComponent( "TransactionPool", boost::none );

if ( !result )
{
throw std::runtime_error( "Initialize TransactionPool first" );
}
auto trans_pool = std::dynamic_pointer_cast<sgns::transaction_pool::TransactionPool>( result.value() );

result = component_factory->GetComponent( "Hasher", boost::none );

if ( !result )
{
throw std::runtime_error( "Initialize Hasher first" );
}
auto hasher = std::dynamic_pointer_cast<sgns::crypto::Hasher>( result.value() );

result = component_factory->GetComponent( "ExtrinsicGossiper", boost::none );

if ( !result )
{
throw std::runtime_error( "Initialize ExtrinsicGossiper first" );
}
auto gossiper = std::dynamic_pointer_cast<sgns::network::ExtrinsicGossiper>( result.value() );

return std::make_shared<sgns::api::AuthorApiImpl>( trans_pool, hasher, gossiper );
}
};


#endif
66 changes: 66 additions & 0 deletions app/integration/AuthorityManagerFactory.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* @file AuthorityManagerFactory.hpp
* @brief
* @date 2024-03-04
* @author Henrique A. Klein ([email protected])
*/
#ifndef _AUTHORITY_MANAGER_FACTORY_HPP_
#define _AUTHORITY_MANAGER_FACTORY_HPP_

#include "verification/authority/impl/authority_manager_impl.hpp"
#include "application/app_state_manager.hpp"
#include "primitives/production_configuration.hpp"
#include "blockchain/block_tree.hpp"
#include "storage/buffer_map_types.hpp"

class CComponentFactory;
namespace sgns
{

class AuthorityManagerFactory
{
public:
std::shared_ptr<authority::AuthorityManager> create()
{
auto component_factory = SINGLETONINSTANCE( CComponentFactory );

auto result = component_factory->GetComponent( "AppStateManager", boost::none );
if ( !result )
{
throw std::runtime_error( "Initialize AppStateManager first" );
}
//auto app_state_manager = std::dynamic_pointer_cast<application::AppStateManager>( result.value() );
auto app_state_manager = AppStateManagerFactory::create();

result = component_factory->GetComponent( "ProductionConfiguration", boost::none );
if ( !result )
{
throw std::runtime_error( "Initialize ProductionConfiguration first" );
}
auto prod_configuration = std::dynamic_pointer_cast<primitives::ProductionConfiguration>( result.value() );

result = component_factory->GetComponent( "BlockTree", boost::none );
if ( !result )
{
throw std::runtime_error( "Initialize BlockTree first" );
}
auto block_tree = std::dynamic_pointer_cast<blockchain::BlockTree>( result.value() );

result = component_factory->GetComponent( "BufferStorage",boost::make_optional(std::string("rocksdb")));
if ( !result )
{
throw std::runtime_error( "Initialize BufferStorage first" );
}
auto buff_storage = std::dynamic_pointer_cast<storage::BufferStorage>( result.value() );

return std::make_shared<authority::AuthorityManagerImpl>( //
app_state_manager, //
prod_configuration, //
block_tree, //
buff_storage //
);
}
};
}

#endif
64 changes: 64 additions & 0 deletions app/integration/AuthorityUpdateObserverFactory.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* @file AuthorityUpdateObserverFactory.hpp
* @brief
* @date 2024-02-29
* @author Henrique A. Klein ([email protected])
*/
#ifndef _AUTHORITY_UPDATE_OBSERVER_FACTORY_HPP_
#define _AUTHORITY_UPDATE_OBSERVER_FACTORY_HPP_

#include "verification/authority/impl/authority_manager_impl.hpp"
#include "integration/CComponentFactory.hpp"
#include "application/app_state_manager.hpp"
#include "blockchain/block_tree.hpp"
#include "storage/buffer_map_types.hpp"

class AuthorityUpdateObserverFactory
{
public:
static std::shared_ptr<sgns::authority::AuthorityUpdateObserver> create()
{
auto component_factory = SINGLETONINSTANCE( CComponentFactory );
auto result = component_factory->GetComponent( "AppStateManager", boost::none );
if ( !result )
{
throw std::runtime_error( "Initialize AppStateManager first" );
}

//auto app_state_manager = std::dynamic_pointer_cast<application::AppStateManager>( result.value() );
auto app_state_manager = AppStateManagerFactory::create();

result = component_factory->GetComponent( "ProductionConfiguration", boost::none );
if ( !result )
{
throw std::runtime_error( "Initialize ProductionConfiguration first" );
}

auto prod_config = std::dynamic_pointer_cast<sgns::primitives::ProductionConfiguration>( result.value() );

result = component_factory->GetComponent( "BlockTree", boost::none );
if ( !result )
{
throw std::runtime_error( "Initialize BlockTree first" );
}

auto block_tree = std::dynamic_pointer_cast<sgns::blockchain::BlockTree>( result.value() );

result = component_factory->GetComponent( "BufferStorage", boost::make_optional(std::string("rocksdb")) );
if ( !result )
{
throw std::runtime_error( "Initialize BufferStorage first" );
}

auto buff_storage = std::dynamic_pointer_cast<sgns::storage::BufferStorage>( result.value() );

return std::make_shared<sgns::authority::AuthorityManagerImpl>( //
app_state_manager, //
prod_config, //
block_tree, //
buff_storage //
);
}
};

#endif
Loading

0 comments on commit ba6fbd5

Please sign in to comment.