Skip to content

Commit e2d69bd

Browse files
IPFS block service refactor (#102)
1 parent 599716b commit e2d69bd

14 files changed

+103
-183
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Copyright Soramitsu Co., Ltd. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include <memory>
7+
8+
#include "blockchain/message_pool/message_storage.hpp"
9+
#include "storage/ipfs/datastore.hpp"
10+
#include "primitives/tipset/tipset.hpp"
11+
#include "primitives/block/block.hpp"
12+
#include "primitives/cid/cid.hpp"
13+
14+
namespace fc::blockchain::production {
15+
class BlockGenerator {
16+
using fc::blockchain::message_pool::MessageStorage;
17+
using fc::primitives::tipset::Tipset;
18+
using fc::storage::ipfs::IpfsDataStore;
19+
using primitives::block::BlockHeader;
20+
21+
public:
22+
BlockGenerator(std::shared_ptr<IpfsDataStore> data_store,
23+
std::shared_ptr<MessageStorage> messages_store);
24+
25+
26+
};
27+
} // namespace fc::blockchain::production

core/storage/ipfs/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ target_link_libraries(ipfs_datastore_leveldb
2424
)
2525

2626
add_library(ipfs_blockservice
27-
impl/blockservice_impl.cpp
27+
impl/ipfs_block_service.cpp
2828
)
2929
target_link_libraries(ipfs_blockservice
3030
buffer

core/storage/ipfs/blockservice.hpp

Lines changed: 0 additions & 70 deletions
This file was deleted.

core/storage/ipfs/impl/blockservice_impl.cpp

Lines changed: 0 additions & 66 deletions
This file was deleted.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Copyright Soramitsu Co., Ltd. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include "storage/ipfs/impl/ipfs_block_service.hpp"
7+
8+
namespace fc::storage::ipfs {
9+
IpfsBlockService::IpfsBlockService(std::shared_ptr<IpfsDatastore> data_store)
10+
: local_storage_{std::move(data_store)} {
11+
BOOST_ASSERT_MSG(local_storage_ != nullptr,
12+
"IPFS block service: invalid local storage");
13+
}
14+
15+
outcome::result<bool> IpfsBlockService::contains(const CID &key) const {
16+
return local_storage_->contains(key);
17+
}
18+
19+
outcome::result<void> IpfsBlockService::set(const CID &key, Value value) {
20+
auto result = local_storage_->set(key, std::move(value));
21+
if (result.has_error()) return result.error();
22+
return outcome::success();
23+
}
24+
25+
outcome::result<IpfsBlockService::Value> IpfsBlockService::get(
26+
const CID &key) const {
27+
OUTCOME_TRY(data, local_storage_->get(key));
28+
return std::move(data);
29+
}
30+
31+
outcome::result<void> IpfsBlockService::remove(const CID &key) {
32+
return local_storage_->remove(key);
33+
}
34+
} // namespace fc::storage::ipfs

core/storage/ipfs/impl/blockservice_impl.hpp renamed to core/storage/ipfs/impl/ipfs_block_service.hpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,24 @@
88

99
#include <memory>
1010

11-
#include "storage/ipfs/blockservice.hpp"
11+
#include "storage/ipfs/datastore.hpp"
1212

1313
namespace fc::storage::ipfs {
14-
class BlockServiceImpl : public BlockService {
14+
class IpfsBlockService : public IpfsDatastore {
1515
public:
1616
/**
17-
* @brief Construct block service
17+
* @brief Construct IPFS storage
1818
* @param data_store - IPFS storage implementation
1919
*/
20-
explicit BlockServiceImpl(std::shared_ptr<IpfsDatastore> data_store);
20+
explicit IpfsBlockService(std::shared_ptr<IpfsDatastore> data_store);
2121

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

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

26-
outcome::result<Block::Content> getBlockContent(
27-
const CID &cid) const override;
26+
outcome::result<Value> get(const CID &key) const override;
2827

29-
outcome::result<void> removeBlock(const CID &cid) override;
28+
outcome::result<void> remove(const CID &key) override;
3029

3130
private:
3231
std::shared_ptr<IpfsDatastore> local_storage_; /**< Local data storage */

core/storage/ipfs/block.hpp renamed to core/storage/ipfs/ipfs_block.hpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@ namespace fc::storage::ipfs {
1616
/**
1717
* @interface Piece of data, which is used with BlockService
1818
*/
19-
struct Block {
20-
using Content = common::Buffer; /**< Alias for content type */
21-
19+
struct IpfsBlock {
2220
/**
2321
* @brief Default destructor
2422
*/
25-
virtual ~Block() = default;
23+
virtual ~IpfsBlock() = default;
2624

2725
/**
2826
* @brief Get content identifier
@@ -34,7 +32,7 @@ namespace fc::storage::ipfs {
3432
* @brief Get block content
3533
* @return Block's raw data for store in the BlockService
3634
*/
37-
virtual const Content &getRawBytes() const = 0;
35+
virtual const common::Buffer &getRawBytes() const = 0;
3836
};
3937
} // namespace fc::storage::ipfs
4038

core/storage/ipfs/merkledag/impl/merkledag_service_impl.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,25 @@ using libp2p::multi::ContentIdentifierCodec;
1313

1414
namespace fc::storage::ipfs::merkledag {
1515
MerkleDagServiceImpl::MerkleDagServiceImpl(
16-
std::shared_ptr<BlockService> service)
16+
std::shared_ptr<IpfsDatastore> service)
1717
: block_service_{std::move(service)} {
1818
BOOST_ASSERT_MSG(block_service_ != nullptr,
1919
"MerkleDAG service: Block service not connected");
2020
}
2121

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

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

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

3737
outcome::result<size_t> MerkleDagServiceImpl::select(

core/storage/ipfs/merkledag/impl/merkledag_service_impl.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include <memory>
1010

11-
#include "storage/ipfs/blockservice.hpp"
11+
#include "storage/ipfs/datastore.hpp"
1212
#include "storage/ipfs/merkledag/impl/leaf_impl.hpp"
1313
#include "storage/ipfs/merkledag/merkledag_service.hpp"
1414

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

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

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

4343
private:
44-
std::shared_ptr<BlockService> block_service_;
44+
std::shared_ptr<IpfsDatastore> block_service_;
4545

4646
/**
4747
* @brief Fetch graph internal recursive implementation

core/storage/ipfs/merkledag/merkledag_service.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include <memory>
1010

1111
#include "common/outcome.hpp"
12-
#include "storage/ipfs/blockservice.hpp"
1312
#include "storage/ipfs/merkledag/leaf.hpp"
1413
#include "storage/ipfs/merkledag/node.hpp"
1514

0 commit comments

Comments
 (0)