66#ifndef CPP_FILECOIN_CORE_STORAGE_CHAIN_CHAIN_STORE_HPP
77#define CPP_FILECOIN_CORE_STORAGE_CHAIN_CHAIN_STORE_HPP
88
9- #include < map>
10-
11- #include " blockchain/block_validator.hpp"
12- #include " blockchain/weight_calculator.hpp"
13- #include " common/logger.hpp"
14- #include " common/outcome.hpp"
15- #include " crypto/randomness/randomness_types.hpp"
16- #include " primitives/cid/cid.hpp"
9+ #include " primitives/block/block.hpp"
1710#include " primitives/tipset/tipset.hpp"
18- #include " storage/chain/chain_data_store.hpp"
19- #include " storage/ipfs/impl/ipfs_block_service.hpp"
2011
2112namespace fc ::storage::blockchain {
2213
@@ -33,90 +24,36 @@ namespace fc::storage::blockchain {
3324 primitives::tipset::Tipset value;
3425 };
3526
36- /* *
37- * @struct MmCids is a struct for using in mmCache cache
38- */
39- struct MmCids {
40- std::vector<CID> bls;
41- std::vector<CID> secpk;
42- };
43-
44- enum class ChainStoreError : int { NO_MIN_TICKET_BLOCK = 1 };
45-
4627 /* *
4728 * @class ChainStore keeps track of blocks
4829 */
4930 class ChainStore {
5031 public:
51- using BlockValidator = ::fc::blockchain::block_validator::BlockValidator;
32+ using BlockHeader = primitives::block::BlockHeader;
33+ using ChainRandomnessProvider = crypto::randomness::ChainRandomnessProvider;
34+ using Randomness = crypto::randomness::Randomness;
5235 using Tipset = primitives::tipset::Tipset;
5336 using TipsetKey = primitives::tipset::TipsetKey;
54- using Randomness = crypto::randomness::Randomness;
55- using BlockHeader = primitives::block::BlockHeader;
56- using WeightCalculator = ::fc::blockchain::weight::WeightCalculator;
5737
58- /* @brief creates new ChainStore instance */
59- static outcome::result<std::shared_ptr<ChainStore>> create (
60- std::shared_ptr<ipfs::IpfsBlockService> block_service,
61- std::shared_ptr<ChainDataStore> data_store,
62- std::shared_ptr<BlockValidator> block_validator,
63- std::shared_ptr<WeightCalculator> weight_calculator);
64-
65- /* * @brief stores head tipset */
66- outcome::result<void > writeHead (const Tipset &tipset);
67-
68- /* * @brief loads data from block storage and initializes storage */
69- outcome::result<void > load ();
38+ virtual ~ChainStore () = default ;
7039
7140 /* *
7241 * @brief loads tipset from store
7342 * @param key tipset key
7443 */
75- outcome::result<Tipset> loadTipset (const TipsetKey &key);
76-
77- // TODO(yuraz): FIL-151 add notifications
78- // TODO(yuraz): FIL-151 implement items caching to avoid refetching them
44+ virtual outcome::result<Tipset> loadTipset (const TipsetKey &key) = 0;
7945
80- /* * @brief draws randomness */
81- outcome::result<Randomness> sampleRandomness (const std::vector<CID> &blks,
82- uint64_t round);
83-
84- /* * @brief finds block by its cid */
85- outcome::result<BlockHeader> getBlock (const CID &cid) const ;
46+ /* * @brief creates chain randomness provider */
47+ virtual std::shared_ptr<ChainRandomnessProvider>
48+ createRandomnessProvider () = 0 ;
8649
8750 /* * @brief adds block to store */
88- outcome::result<void > addBlock (const BlockHeader &block);
89-
90- private:
91- ChainStore (std::shared_ptr<ipfs::IpfsBlockService> block_service,
92- std::shared_ptr<ChainDataStore> data_store,
93- std::shared_ptr<BlockValidator> block_validator,
94- std::shared_ptr<WeightCalculator> weight_calculator);
95-
96- ChainStore (ChainStore &&other) = default ;
97-
98- outcome::result<void > takeHeaviestTipset (const Tipset &tipset);
99-
100- outcome::result<void > persistBlockHeaders (
101- const std::vector<std::reference_wrapper<const BlockHeader>>
102- &block_headers);
103-
104- outcome::result<Tipset> expandTipset (const BlockHeader &block_header);
51+ virtual outcome::result<void > addBlock (const BlockHeader &block) = 0;
10552
106- outcome::result<void > updateHeavierTipset (const Tipset &tipset);
107-
108- std::shared_ptr<ipfs::IpfsBlockService> block_service_;
109- std::shared_ptr<ChainDataStore> data_store_;
110- std::shared_ptr<BlockValidator> block_validator_;
111- std::shared_ptr<WeightCalculator> weight_calculator_;
112-
113- boost::optional<Tipset> heaviest_tipset_;
114- std::map<uint64_t , std::vector<CID>> tipsets_;
115-
116- common::Logger logger_;
53+ /* * @brief finds block by its cid */
54+ virtual outcome::result<BlockHeader> getBlock (const CID &cid) const = 0;
11755 };
118- } // namespace fc::storage::blockchain
11956
120- OUTCOME_HPP_DECLARE_ERROR ( fc::storage::blockchain, ChainStoreError);
57+ } // namespace fc::storage::blockchain
12158
12259#endif // CPP_FILECOIN_CORE_STORAGE_CHAIN_CHAIN_STORE_HPP
0 commit comments