Skip to content

IPFS block service refactor #102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions core/blockchain/production/block_generator.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright Soramitsu Co., Ltd. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

#include <memory>

#include "blockchain/message_pool/message_storage.hpp"
#include "storage/ipfs/datastore.hpp"
#include "primitives/tipset/tipset.hpp"
#include "primitives/block/block.hpp"
#include "primitives/cid/cid.hpp"

namespace fc::blockchain::production {
class BlockGenerator {
using fc::blockchain::message_pool::MessageStorage;
using fc::primitives::tipset::Tipset;
using fc::storage::ipfs::IpfsDataStore;
using primitives::block::BlockHeader;

public:
BlockGenerator(std::shared_ptr<IpfsDataStore> data_store,
std::shared_ptr<MessageStorage> messages_store);


};
} // namespace fc::blockchain::production
2 changes: 1 addition & 1 deletion core/storage/ipfs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ target_link_libraries(ipfs_datastore_leveldb
)

add_library(ipfs_blockservice
impl/blockservice_impl.cpp
impl/ipfs_block_service.cpp
)
target_link_libraries(ipfs_blockservice
buffer
Expand Down
70 changes: 0 additions & 70 deletions core/storage/ipfs/blockservice.hpp

This file was deleted.

66 changes: 0 additions & 66 deletions core/storage/ipfs/impl/blockservice_impl.cpp

This file was deleted.

34 changes: 34 additions & 0 deletions core/storage/ipfs/impl/ipfs_block_service.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Copyright Soramitsu Co., Ltd. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

#include "storage/ipfs/impl/ipfs_block_service.hpp"

namespace fc::storage::ipfs {
IpfsBlockService::IpfsBlockService(std::shared_ptr<IpfsDatastore> data_store)
: local_storage_{std::move(data_store)} {
BOOST_ASSERT_MSG(local_storage_ != nullptr,
"IPFS block service: invalid local storage");
}

outcome::result<bool> IpfsBlockService::contains(const CID &key) const {
return local_storage_->contains(key);
}

outcome::result<void> IpfsBlockService::set(const CID &key, Value value) {
auto result = local_storage_->set(key, std::move(value));
if (result.has_error()) return result.error();
return outcome::success();
}

outcome::result<IpfsBlockService::Value> IpfsBlockService::get(
const CID &key) const {
OUTCOME_TRY(data, local_storage_->get(key));
return std::move(data);
}

outcome::result<void> IpfsBlockService::remove(const CID &key) {
return local_storage_->remove(key);
}
} // namespace fc::storage::ipfs
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,24 @@

#include <memory>

#include "storage/ipfs/blockservice.hpp"
#include "storage/ipfs/datastore.hpp"

namespace fc::storage::ipfs {
class BlockServiceImpl : public BlockService {
class IpfsBlockService : public IpfsDatastore {
public:
/**
* @brief Construct block service
* @brief Construct IPFS storage
* @param data_store - IPFS storage implementation
*/
explicit BlockServiceImpl(std::shared_ptr<IpfsDatastore> data_store);
explicit IpfsBlockService(std::shared_ptr<IpfsDatastore> data_store);

outcome::result<void> addBlock(const Block &block) override;
outcome::result<bool> contains(const CID &key) const override;

outcome::result<bool> has(const CID &cid) const override;
outcome::result<void> set(const CID &key, Value value) override;

outcome::result<Block::Content> getBlockContent(
const CID &cid) const override;
outcome::result<Value> get(const CID &key) const override;

outcome::result<void> removeBlock(const CID &cid) override;
outcome::result<void> remove(const CID &key) override;

private:
std::shared_ptr<IpfsDatastore> local_storage_; /**< Local data storage */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ namespace fc::storage::ipfs {
/**
* @interface Piece of data, which is used with BlockService
*/
struct Block {
using Content = common::Buffer; /**< Alias for content type */

struct IpfsBlock {
/**
* @brief Default destructor
*/
virtual ~Block() = default;
virtual ~IpfsBlock() = default;

/**
* @brief Get content identifier
Expand All @@ -34,7 +32,7 @@ namespace fc::storage::ipfs {
* @brief Get block content
* @return Block's raw data for store in the BlockService
*/
virtual const Content &getRawBytes() const = 0;
virtual const common::Buffer &getRawBytes() const = 0;
};
} // namespace fc::storage::ipfs

Expand Down
8 changes: 4 additions & 4 deletions core/storage/ipfs/merkledag/impl/merkledag_service_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@ using libp2p::multi::ContentIdentifierCodec;

namespace fc::storage::ipfs::merkledag {
MerkleDagServiceImpl::MerkleDagServiceImpl(
std::shared_ptr<BlockService> service)
std::shared_ptr<IpfsDatastore> service)
: block_service_{std::move(service)} {
BOOST_ASSERT_MSG(block_service_ != nullptr,
"MerkleDAG service: Block service not connected");
}

outcome::result<void> MerkleDagServiceImpl::addNode(
std::shared_ptr<const Node> node) {
return block_service_->addBlock(*node);
return block_service_->set(node->getCID(), node->getRawBytes());
}

outcome::result<std::shared_ptr<Node>> MerkleDagServiceImpl::getNode(
const CID &cid) const {
OUTCOME_TRY(content, block_service_->getBlockContent(cid));
OUTCOME_TRY(content, block_service_->get(cid));
return NodeImpl::createFromRawBytes(content);
}

outcome::result<void> MerkleDagServiceImpl::removeNode(const CID &cid) {
return block_service_->removeBlock(cid);
return block_service_->remove(cid);
}

outcome::result<size_t> MerkleDagServiceImpl::select(
Expand Down
6 changes: 3 additions & 3 deletions core/storage/ipfs/merkledag/impl/merkledag_service_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <memory>

#include "storage/ipfs/blockservice.hpp"
#include "storage/ipfs/datastore.hpp"
#include "storage/ipfs/merkledag/impl/leaf_impl.hpp"
#include "storage/ipfs/merkledag/merkledag_service.hpp"

Expand All @@ -19,7 +19,7 @@ namespace fc::storage::ipfs::merkledag {
* @brief Construct service
* @param service - underlying block service
*/
explicit MerkleDagServiceImpl(std::shared_ptr<BlockService> service);
explicit MerkleDagServiceImpl(std::shared_ptr<IpfsDatastore> service);

outcome::result<void> addNode(std::shared_ptr<const Node> node) override;

Expand All @@ -41,7 +41,7 @@ namespace fc::storage::ipfs::merkledag {
const CID &cid, uint64_t depth) const override;

private:
std::shared_ptr<BlockService> block_service_;
std::shared_ptr<IpfsDatastore> block_service_;

/**
* @brief Fetch graph internal recursive implementation
Expand Down
1 change: 0 additions & 1 deletion core/storage/ipfs/merkledag/merkledag_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <memory>

#include "common/outcome.hpp"
#include "storage/ipfs/blockservice.hpp"
#include "storage/ipfs/merkledag/leaf.hpp"
#include "storage/ipfs/merkledag/node.hpp"

Expand Down
4 changes: 2 additions & 2 deletions core/storage/ipfs/merkledag/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@

#include "common/buffer.hpp"
#include "common/outcome.hpp"
#include "storage/ipfs/block.hpp"
#include "storage/ipfs/ipfs_block.hpp"
#include "storage/ipfs/merkledag/link.hpp"

namespace fc::storage::ipfs::merkledag {
/**
* @interface MerkleDAG service node
*/
class Node : public Block {
class Node : public IpfsBlock {
public:
/**
* @brief Total size of the data including the total sizes of references
Expand Down
2 changes: 1 addition & 1 deletion test/core/storage/ipfs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ target_link_libraries(in_memory_ipfs_datastore_test
)

addtest(ipfs_blockservice_test
blockservice_test.cpp
ipfs_block_service_test.cpp
)
target_link_libraries(ipfs_blockservice_test
ipfs_blockservice
Expand Down
Loading