Skip to content

Commit

Permalink
Feat: Updating classes to new design. Stripping runtime mentions
Browse files Browse the repository at this point in the history
  • Loading branch information
henriqueaklein committed Feb 29, 2024
1 parent 1b1f076 commit 900e0e6
Show file tree
Hide file tree
Showing 22 changed files with 232 additions and 21 deletions.
4 changes: 4 additions & 0 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ add_executable (sgns_demo
dummy_sync_protocol_client
production_synchronizer
block_validator
sr25519_provider
epoch_storage
authority_manager
proposer
p2p::p2p_basic_host
p2p::p2p_default_network
p2p::p2p_peer_repository
Expand Down
63 changes: 63 additions & 0 deletions app/integration/AuthorityUpdateObserverFactory.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* @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<sgns::application::AppStateManager>( result.value() );

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
32 changes: 32 additions & 0 deletions app/integration/EpochStorageFactory.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* @file EpochStorageFactory.hpp
* @brief
* @date 2024-02-29
* @author Henrique A. Klein ([email protected])
*/
#ifndef _EPOCH_STORAGE_HPP_
#define _EPOCH_STORAGE_HPP_
#include "verification/production/impl/epoch_storage_impl.hpp"
#include "integration/CComponentFactory.hpp"
#include "storage/buffer_map_types.hpp"

class EpochStorageFactory
{
public:
static std::shared_ptr<sgns::verification::EpochStorage> create()
{
auto component_factory = SINGLETONINSTANCE( CComponentFactory );

auto result = component_factory->GetComponent( "BufferStorage", boost::make_optional(std::string("rocksdb")));

if ( !result )
{
throw std::runtime_error( "Initialize BufferStorage first" );
}
auto buffer_storage = std::dynamic_pointer_cast<sgns::storage::BufferStorage>( result.value() );

return std::make_shared<sgns::verification::EpochStorageImpl>( buffer_storage );
}
};

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

#include "authorship/impl/proposer_impl.hpp"
#include "integration/CComponentFactory.hpp"
#include "transaction_pool/transaction_pool.hpp"

class ProposerFactory
{
public:
static std::shared_ptr<sgns::authorship::Proposer> create()
{
//TODO - Removed runtime::BlockBuilder because of binaryen dependecy
auto component_factory = SINGLETONINSTANCE( CComponentFactory );

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

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

return std::make_shared<sgns::authorship::ProposerImpl>( block_builder_factory, transaction_pool);
}
};

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

#include "crypto/sr25519/sr25519_provider_impl.hpp"
#include "crypto/random_generator/boost_generator.hpp"

class SR25519ProviderFactory
{
public:
static std::shared_ptr<sgns::crypto::SR25519Provider> create()
{
return std::make_shared<sgns::crypto::SR25519ProviderImpl>(std::make_shared<sgns::crypto::BoostRandomGenerator>());
}
};

#endif

10 changes: 9 additions & 1 deletion src/application/impl/validating_node_application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
#include "integration/ProductionSynchronizerFactory.hpp"
#include "integration/OwnPeerInfoFactory.hpp"
#include "integration/BlockValidatorFactory.hpp"
#include "integration/SR25519ProviderFactory.hpp"
#include "integration/EpochStorageFactory.hpp"
#include "integration/AuthorityUpdateObserverFactory.hpp"
#include "integration/ProposerFactory.hpp"

#include "storage/trie/supergenius_trie/supergenius_trie_factory_impl.hpp"
#include "storage/trie/serialization/supergenius_codec.hpp"
Expand Down Expand Up @@ -72,13 +76,17 @@ namespace sgns::application
component_factory->Register( BlockStorageFactory::create(), "BlockStorage", boost::none );
component_factory->Register( ExtrinsicGossiperFactory::create(), "ExtrinsicGossiper", boost::none );
component_factory->Register( PoolModeratorFactory::create(), "PoolModerator", boost::none );
component_factory->Register( ProposerFactory::create(), "Proposer", boost::none );
component_factory->Register( TranscationPoolFactory::create(), "TransactionPool", boost::none );
component_factory->Register( AuthorApiFactory::create(), "AuthorApi", boost::none );
component_factory->Register( ExtrinsicObserverFactory::create(), "ExtrinsicObserver", boost::none );
component_factory->Register( BlockTreeFactory::create(), "BlockTree", boost::none );
component_factory->Register( ProductionConfigurationFactory::create(), "ProductionConfiguration", boost::none );
component_factory->Register( AuthorityUpdateObserverFactory::create(), "AuthorityUpdateObserver", boost::none );
component_factory->Register( EpochStorageFactory::create(), "EpochStorage", boost::none );
component_factory->Register( SR25519ProviderFactory::create(), "SR25519Provider", boost::none );
component_factory->Register( BlockValidatorFactory::create(), "BlockValidator", boost::none );
component_factory->Register( OwnPeerInfoFactory::create(app_config->p2p_port()), "OwnPeerInfo", boost::none );
component_factory->Register( ProductionConfigurationFactory::create(), "ProductionConfiguration", boost::none );
component_factory->Register( ProductionSynchronizerFactory::create(), "ProductionSynchronizer", boost::none );
component_factory->Register( BlockExecutorFactory::create(), "BlockExecutor", boost::none );
component_factory->Register( ProductionFactory::create(*io_context_), "Production", boost::none );
Expand Down
18 changes: 11 additions & 7 deletions src/authorship/impl/proposer_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ namespace sgns::authorship {

ProposerImpl::ProposerImpl(
std::shared_ptr<BlockBuilderFactory> block_builder_factory,
std::shared_ptr<transaction_pool::TransactionPool> transaction_pool,
std::shared_ptr<runtime::BlockBuilder> r_block_builder)
std::shared_ptr<transaction_pool::TransactionPool> transaction_pool/*,
std::shared_ptr<runtime::BlockBuilder> r_block_builder*/)
: block_builder_factory_{std::move(block_builder_factory)},
transaction_pool_{std::move(transaction_pool)},
r_block_builder_{std::move(r_block_builder)} {
transaction_pool_{std::move(transaction_pool)}/*,
r_block_builder_{std::move(r_block_builder)}*/ {
BOOST_ASSERT(block_builder_factory_);
BOOST_ASSERT(transaction_pool_);
BOOST_ASSERT(r_block_builder_);
//BOOST_ASSERT(r_block_builder_);
}

outcome::result<primitives::Block> ProposerImpl::propose(
Expand All @@ -23,22 +23,25 @@ namespace sgns::authorship {
block_builder),
block_builder_factory_->create(parent_block_id, inherent_digest));

auto inherent_xts_res =

//TODO - Removed binaryen stuff (inherent_extrinsics). Replace with something else
/**auto inherent_xts_res =
r_block_builder_->inherent_extrinsics(inherent_data);
if (! inherent_xts_res) {
logger_->error("BlockBuilder->inherent_extrinsics failed with error: {}",
inherent_xts_res.error().message());
return inherent_xts_res.error();
}
auto inherent_xts = inherent_xts_res.value();
*/

auto log_push_error = [this](const primitives::Extrinsic &xt,
std::string_view message) {
logger_->warn("Extrinsic {} was not added to the block. Reason: {}",
xt.data.toHex(),
message);
};

/*
for (const auto &xt : inherent_xts) {
logger_->debug("Adding inherent extrinsic: {}", xt.data.toHex());
auto inserted_res = block_builder->pushExtrinsic(xt);
Expand All @@ -47,6 +50,7 @@ namespace sgns::authorship {
return inserted_res.error();
}
}
*/

const auto &ready_txs = transaction_pool_->getReadyTransactions();

Expand Down
10 changes: 7 additions & 3 deletions src/authorship/impl/proposer_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,22 @@ namespace sgns::authorship {

ProposerImpl(
std::shared_ptr<BlockBuilderFactory> block_builder_factory,
std::shared_ptr<transaction_pool::TransactionPool> transaction_pool,
std::shared_ptr<runtime::BlockBuilder> r_block_builder);
std::shared_ptr<transaction_pool::TransactionPool> transaction_pool);

outcome::result<primitives::Block> propose(
const primitives::BlockId &parent_block_id,
const primitives::InherentData &inherent_data,
const primitives::Digest &inherent_digest) override;

std::string GetName() override
{
return "ProposerImpl";
}

private:
std::shared_ptr<BlockBuilderFactory> block_builder_factory_;
std::shared_ptr<transaction_pool::TransactionPool> transaction_pool_;
std::shared_ptr<runtime::BlockBuilder> r_block_builder_;
//std::shared_ptr<runtime::BlockBuilder> r_block_builder_;
base::Logger logger_ = base::createLogger("Proposer");
};

Expand Down
3 changes: 2 additions & 1 deletion src/authorship/proposer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
#include "primitives/block_id.hpp"
#include "primitives/digest.hpp"
#include "primitives/inherent_data.hpp"
#include "integration/IComponent.hpp"

namespace sgns::authorship {

/**
* Create block to further proposal for verification
*/
class Proposer {
class Proposer : public IComponent {
public:
virtual ~Proposer() = default;

Expand Down
4 changes: 4 additions & 0 deletions src/crypto/sr25519/sr25519_provider_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ namespace sgns::crypto {
const SR25519Signature &signature,
gsl::span<const uint8_t> message,
const SR25519PublicKey &public_key) const override;
std::string GetName() override
{
return "SR25519ProviderImpl";
}

private:
std::shared_ptr<CSPRNG> generator_;
Expand Down
3 changes: 2 additions & 1 deletion src/verification/authority/authority_update_observer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
#include <outcome/outcome.hpp>

#include "primitives/digest.hpp"
#include "integration/IComponent.hpp"

namespace sgns::authority {
class AuthorityUpdateObserver {
class AuthorityUpdateObserver : public IComponent {
public:
virtual ~AuthorityUpdateObserver() = default;

Expand Down
5 changes: 5 additions & 0 deletions src/verification/authority/impl/authority_manager_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ namespace sgns::authority {

outcome::result<void> onFinalize(
const primitives::BlockInfo &block) override;

std::string GetName() override
{
return "AuthorityManagerImpl";
}

private:
base::Logger log_;
Expand Down
3 changes: 2 additions & 1 deletion src/verification/production/epoch_storage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@

#include "verification/production/common.hpp"
#include "verification/production/types/next_epoch_descriptor.hpp"
#include "integration/IComponent.hpp"

namespace sgns::verification {
/**
* Allows to store epochs
*/
struct EpochStorage {
struct EpochStorage : public IComponent {
virtual ~EpochStorage() = default;

/**
Expand Down
4 changes: 4 additions & 0 deletions src/verification/production/impl/epoch_storage_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ namespace sgns::verification {
outcome::result<NextEpochDescriptor> getEpochDescriptor(
EpochIndex epoch_number) const override;

std::string GetName() override
{
return "EpochStorageImpl";
}
private:
std::shared_ptr<storage::BufferStorage> storage_;
};
Expand Down
3 changes: 2 additions & 1 deletion src/verification/validation/block_validator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
#include <outcome/outcome.hpp>
#include "verification/production/types/epoch.hpp"
#include "primitives/block.hpp"
#include "integration/IComponent.hpp"

namespace sgns::verification {
/**
* Validator of the blocks
*/
class BlockValidator {
class BlockValidator : public IComponent {
public:
virtual ~BlockValidator() = default;

Expand Down
Loading

0 comments on commit 900e0e6

Please sign in to comment.