diff --git a/app/integration/ApiServiceFactory.hpp b/app/integration/ApiServiceFactory.hpp index 5147a423..bfcb543c 100644 --- a/app/integration/ApiServiceFactory.hpp +++ b/app/integration/ApiServiceFactory.hpp @@ -30,7 +30,8 @@ namespace sgns { throw std::runtime_error( "Initialize AppStateManager first" ); } - auto app_state_manager = std::dynamic_pointer_cast( result.value() ); + //auto app_state_manager = std::dynamic_pointer_cast( result.value() ); + auto app_state_manager = AppStateManagerFactory::create(); result = component_factory->GetComponent( "RpcThreadPool", boost::none ); if ( !result ) diff --git a/app/integration/AuthorityManagerFactory.hpp b/app/integration/AuthorityManagerFactory.hpp index 4a9ded18..fb1995fa 100644 --- a/app/integration/AuthorityManagerFactory.hpp +++ b/app/integration/AuthorityManagerFactory.hpp @@ -29,7 +29,8 @@ namespace sgns { throw std::runtime_error( "Initialize AppStateManager first" ); } - auto app_state_manager = std::dynamic_pointer_cast( result.value() ); + //auto app_state_manager = std::dynamic_pointer_cast( result.value() ); + auto app_state_manager = AppStateManagerFactory::create(); result = component_factory->GetComponent( "ProductionConfiguration", boost::none ); if ( !result ) diff --git a/app/integration/AuthorityUpdateObserverFactory.hpp b/app/integration/AuthorityUpdateObserverFactory.hpp index f9eedb28..37c9e5c4 100644 --- a/app/integration/AuthorityUpdateObserverFactory.hpp +++ b/app/integration/AuthorityUpdateObserverFactory.hpp @@ -25,7 +25,8 @@ class AuthorityUpdateObserverFactory throw std::runtime_error( "Initialize AppStateManager first" ); } - auto app_state_manager = std::dynamic_pointer_cast( result.value() ); + //auto app_state_manager = std::dynamic_pointer_cast( result.value() ); + auto app_state_manager = AppStateManagerFactory::create(); result = component_factory->GetComponent( "ProductionConfiguration", boost::none ); if ( !result ) diff --git a/app/integration/FinalityFactory.hpp b/app/integration/FinalityFactory.hpp index 6d933afa..d227bee6 100644 --- a/app/integration/FinalityFactory.hpp +++ b/app/integration/FinalityFactory.hpp @@ -32,7 +32,8 @@ namespace sgns { throw std::runtime_error( "Initialize AppStateManager first" ); } - auto app_state_manager = std::dynamic_pointer_cast( result.value() ); + //auto app_state_manager = std::dynamic_pointer_cast( result.value() ); + auto app_state_manager = AppStateManagerFactory::create(); result = component_factory->GetComponent( "Environment", boost::none ); diff --git a/app/integration/ListenerFactory.hpp b/app/integration/ListenerFactory.hpp index b76ac9cb..5cc313d3 100644 --- a/app/integration/ListenerFactory.hpp +++ b/app/integration/ListenerFactory.hpp @@ -9,6 +9,7 @@ #include "api/transport/impl/http/http_listener_impl.hpp" #include "api/transport/impl/ws/ws_listener_impl.hpp" +#include "integration/RpcContextFactory.hpp" class CComponentFactory; namespace sgns @@ -25,14 +26,17 @@ namespace sgns { throw std::runtime_error( "Initialize AppStateManager first" ); } - auto app_state_manager = std::dynamic_pointer_cast( result.value() ); + //auto app_state_manager = std::dynamic_pointer_cast( result.value() ); + auto app_state_manager = AppStateManagerFactory::create(); - result = component_factory->GetComponent( "RpcContext", boost::none ); + /*result = component_factory->GetComponent( "RpcContext", boost::none ); if ( !result ) { throw std::runtime_error( "Initialize RpcContext first" ); } auto rpc_context = std::dynamic_pointer_cast( result.value() ); + */ + auto rpc_context = RpcContextFactory{}.create(); api::Listener::Configuration listener_config; listener_config.endpoint = endpoint; diff --git a/app/integration/ProductionFactory.hpp b/app/integration/ProductionFactory.hpp index 3f5d582b..8c6b1463 100644 --- a/app/integration/ProductionFactory.hpp +++ b/app/integration/ProductionFactory.hpp @@ -37,7 +37,8 @@ class ProductionFactory { throw std::runtime_error( "Initialize AppStateManager first" ); } - auto app_st_manager = std::dynamic_pointer_cast( result.value() ); + //auto app_state_manager = std::dynamic_pointer_cast( result.value() ); + auto app_state_manager = AppStateManagerFactory::create(); result = component_factory->GetComponent( "ProductionLottery", boost::none ); if ( !result ) @@ -132,7 +133,7 @@ class ProductionFactory auto auth_updt_observer = std::dynamic_pointer_cast( result.value() ); return std::make_shared( // - app_st_manager, // + app_state_manager, // prod_lottery, // block_executor, // trie_storage, // diff --git a/app/integration/RpcThreadPoolFactory.hpp b/app/integration/RpcThreadPoolFactory.hpp index 0a13ad8f..42c5a633 100644 --- a/app/integration/RpcThreadPoolFactory.hpp +++ b/app/integration/RpcThreadPoolFactory.hpp @@ -9,6 +9,7 @@ #include "api/transport/rpc_thread_pool.hpp" #include "api/transport/rpc_io_context.hpp" +#include "integration/RpcContextFactory.hpp" class CComponentFactory; namespace sgns @@ -20,12 +21,14 @@ namespace sgns { auto component_factory = SINGLETONINSTANCE( CComponentFactory ); - auto result = component_factory->GetComponent("RpcContext", boost::none); + /*auto result = component_factory->GetComponent("RpcContext", boost::none); if (!result) { throw std::runtime_error("Initialize RpcContext first"); } auto rpc_context = std::dynamic_pointer_cast(result.value()); + */ + auto rpc_context = RpcContextFactory{}.create(); return std::make_shared(rpc_context, api::RpcThreadPool::Configuration{}); } diff --git a/src/application/impl/validating_node_application.cpp b/src/application/impl/validating_node_application.cpp index cfede50a..7b3182b6 100644 --- a/src/application/impl/validating_node_application.cpp +++ b/src/application/impl/validating_node_application.cpp @@ -72,10 +72,11 @@ namespace sgns::application production_execution_strategy_ = boost::filesystem::exists( app_config->rocksdb_path() ) ? Production::ExecutionStrategy::SYNC_FIRST : Production::ExecutionStrategy::GENESIS; - io_context_ = std::make_shared(); auto component_factory = SINGLETONINSTANCE( CComponentFactory ); + component_factory->Register( sgns::RpcContextFactory{}.create(), "RpcContext", boost::none ); - component_factory->Register( std::make_shared(), "AppStateManager", boost::none ); + io_context_ = std::make_shared(); + component_factory->Register( AppStateManagerFactory::create(), "AppStateManager", boost::none ); component_factory->Register( ConfigurationStorageFactory::create( app_config->genesis_path() ), "ConfigurationStorage", boost::none ); component_factory->Register( KeyStorageFactory::create( app_config->keystore_path() ), "KeyStorage", boost::none ); component_factory->Register( SystemClockFactory::create(), "SystemClock", boost::none ); @@ -92,7 +93,7 @@ namespace sgns::application component_factory->Register( TrieStorageBackendFactory::create(), "TrieStorageBackend", boost::none ); component_factory->Register( TrieSerializerFactory::create(), "TrieSerializer", boost::none ); component_factory->Register( TrieStorageFactory::create(), "TrieStorage", boost::none ); - component_factory->Register( BlockStorageFactory::create(), "BlockStorage", boost::none ); + component_factory->Register( sgns::BlockStorageFactory{}.create(), "BlockStorage", boost::none ); component_factory->Register( ExtrinsicGossiperFactory::create(), "ExtrinsicGossiper", boost::none ); component_factory->Register( ExtrinsicGossiperFactory::create(), "Gossiper", boost::none ); component_factory->Register( PoolModeratorFactory::create(), "PoolModerator", boost::none ); @@ -113,7 +114,7 @@ namespace sgns::application component_factory->Register( ExtrinsicGossiperFactory::create(), "ProductionGossiper", boost::none ); component_factory->Register( sgns::SR25519KeypairFactory{}.create(), "SR25519Keypair", boost::none ); component_factory->Register( ProductionFactory::create( *io_context_ ), "Production", boost::none ); - component_factory->Register( (component_factory->GetComponent( "Production", boost::none )).value(), "ProductionObserver", boost::none ); + component_factory->Register( ( component_factory->GetComponent( "Production", boost::none ) ).value(), "ProductionObserver", boost::none ); component_factory->Register( sgns::EnvironmentFactory{}.create(), "Environment", boost::none ); component_factory->Register( sgns::ED25519ProviderFactory{}.create(), "ED25519Provider", boost::none ); component_factory->Register( sgns::ED25519KeyPairFactory{}.create(), "ED25519Keypair", boost::none ); @@ -123,20 +124,24 @@ namespace sgns::application component_factory->Register( sgns::FinalityFactory{}.create( io_context_ ), "RoundObserver", boost::none ); component_factory->Register( sgns::SyncProtocolObserverFactory{}.create(), "SyncProtocolObserver", boost::none ); component_factory->Register( sgns::RouterFactory{}.create(), "Router", boost::none ); - component_factory->Register( sgns::RpcContextFactory{}.create(), "RpcContext", boost::none ); + component_factory->Register( sgns::RpcThreadPoolFactory{}.create(), "RpcThreadPool", boost::none ); component_factory->Register( sgns::ListenerFactory{}.create( "ws", app_config->rpc_ws_endpoint() ), "Listener", boost::make_optional( std::string( "ws" ) ) ); component_factory->Register( sgns::ListenerFactory{}.create( "http", app_config->rpc_http_endpoint() ), "Listener", boost::make_optional( std::string( "http" ) ) ); component_factory->Register( sgns::JRpcServerFactory{}.create(), "JRpcServer", boost::none ); - component_factory->Register( sgns::JRpcProcessorFactory{}.create("Author"), "JRpcProcessor", boost::make_optional( std::string( "Author" ) ) ); + component_factory->Register( sgns::JRpcProcessorFactory{}.create( "Author" ), "JRpcProcessor", + boost::make_optional( std::string( "Author" ) ) ); component_factory->Register( sgns::ChainApiFactory{}.create(), "ChainApi", boost::none ); - component_factory->Register( sgns::JRpcProcessorFactory{}.create("Chain"), "JRpcProcessor", boost::make_optional( std::string( "Chain" ) ) ); + component_factory->Register( sgns::JRpcProcessorFactory{}.create( "Chain" ), "JRpcProcessor", + boost::make_optional( std::string( "Chain" ) ) ); component_factory->Register( sgns::StateApiFactory{}.create(), "StateApi", boost::none ); - component_factory->Register( sgns::JRpcProcessorFactory{}.create("State"), "JRpcProcessor", boost::make_optional( std::string( "State" ) ) ); + component_factory->Register( sgns::JRpcProcessorFactory{}.create( "State" ), "JRpcProcessor", + boost::make_optional( std::string( "State" ) ) ); component_factory->Register( sgns::SystemApiFactory{}.create(), "SystemApi", boost::none ); - component_factory->Register( sgns::JRpcProcessorFactory{}.create("System"), "JRpcProcessor", boost::make_optional( std::string( "System" ) ) ); + component_factory->Register( sgns::JRpcProcessorFactory{}.create( "System" ), "JRpcProcessor", + boost::make_optional( std::string( "System" ) ) ); component_factory->Register( sgns::ApiServiceFactory{}.create(), "ApiService", boost::none ); auto result = component_factory->GetComponent( "AppStateManager", boost::none ); @@ -205,28 +210,29 @@ namespace sgns::application [this] { // execute listeners - io_context_->post( [this] { - //di::bind.to( [p2p_port{ app_config->p2p_port() }]( const auto &injector ) - // { return get_peer_info( injector, p2p_port ); } ), - //auto p2p_injector = libp2p::injector::makeHostInjector(); - //auto &key_marshaller = p2p_injector.template create(); - //libp2p::peer::PeerId peer_id = libp2p::peer::PeerId::fromPublicKey( key_marshaller.marshal( public_key ).value() ).value(); - //auto p2p_info = std::shared_ptr(); - //const network::OwnPeerInfo ¤t_peer_info(); - //libp2p::Host &host = p2p_injector.template create(); - //for ( const auto &ma : current_peer_info.addresses ) - //{ - // auto listen = host.listen( ma ); - // if ( !listen ) - // { - // logger_->error( "Cannot listen address {}. Error: {}", ma.getStringAddress(), listen.error().message() ); - // std::exit( 1 ); - // } - //} - //this->router_->init(); + auto component_factory = SINGLETONINSTANCE( CComponentFactory ); + auto result = component_factory->GetComponent( "OwnPeerInfo", boost::none ); + if ( !result ) + { + throw std::runtime_error( "OwnPeerInfo not registered " ); + } + auto current_peer_info = std::dynamic_pointer_cast( result.value() ); + + auto p2p_injector = libp2p::injector::makeHostInjector(); + auto &host = p2p_injector.template create(); + for ( const auto &ma : current_peer_info->addresses ) + { + auto listen = host.listen( ma ); + if ( !listen ) + { + logger_->error( "Cannot listen address {}. Error: {}", ma.getStringAddress(), listen.error().message() ); + std::exit( 1 ); + } + } + this->router_->init(); } ); return true; } );