Skip to content

Commit 726eeef

Browse files
author
Yura Zarudniy
authored
Feature: chain store (#89)
* start implementing Signed-off-by: Yura Zarudniy <[email protected]> * rebased on master Signed-off-by: Yura Zarudniy <[email protected]> * continue implementing Signed-off-by: Yura Zarudniy <[email protected]> * update tinycbor Signed-off-by: Yura Zarudniy <[email protected]> * add CID to/from json Signed-off-by: Yura Zarudniy <[email protected]> * fix cid encode/decode Signed-off-by: Yura Zarudniy <[email protected]> * add draw randomness Signed-off-by: Yura Zarudniy <[email protected]> * update submodules, add chain_data_store, refactore datastore_key usage Signed-off-by: Yura Zarudniy <[email protected]> * temporary fix for cbor key encode Signed-off-by: Yura Zarudniy <[email protected]> * implement load functions Signed-off-by: Yura Zarudniy <[email protected]> * refactore datastore key, add cbor encode/decode Signed-off-by: Yura Zarudniy <[email protected]> * complete adding block, add comments, refactore Signed-off-by: Yura Zarudniy <[email protected]> * add some tests, fix mistakes Signed-off-by: Yura Zarudniy <[email protected]> * add datastore tests Signed-off-by: Yura Zarudniy <[email protected]> * add test for chain store Signed-off-by: Yura Zarudniy <[email protected]> * fix review issues Signed-off-by: Yura Zarudniy <[email protected]> * fix rebase issues Signed-off-by: Yura Zarudniy <[email protected]>
1 parent 2ed0bc1 commit 726eeef

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1658
-2
lines changed

core/blockchain/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,17 @@
44
#
55

66
add_subdirectory(message_pool)
7+
8+
add_library(block_validator
9+
impl/block_validator_impl.cpp
10+
)
11+
target_link_libraries(block_validator
12+
block
13+
)
14+
15+
add_library(weight_calculator
16+
impl/weight_calculator_impl.cpp
17+
)
18+
target_link_libraries(weight_calculator
19+
tipset
20+
)

core/blockchain/block_validator.hpp

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+
#ifndef CPP_FILECOIN_CORE_CHAIN_BLOCK_VALIDATOR_HPP
7+
#define CPP_FILECOIN_CORE_CHAIN_BLOCK_VALIDATOR_HPP
8+
9+
#include "primitives/block/block.hpp"
10+
11+
namespace fc::blockchain::block_validator {
12+
13+
/**
14+
* @class BlockValidator block validator interface
15+
*/
16+
class BlockValidator {
17+
public:
18+
using BlockHeader = primitives::block::BlockHeader;
19+
virtual ~BlockValidator() = default;
20+
21+
virtual outcome::result<void> validateBlock(
22+
const BlockHeader &block) const = 0;
23+
};
24+
25+
} // namespace fc::chain::block_validator
26+
27+
#endif // CPP_FILECOIN_CORE_CHAIN_BLOCK_VALIDATOR_HPP

core/blockchain/chain_manager.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Copyright Soramitsu Co., Ltd. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#ifndef CPP_FILECOIN_CORE_PRIMITIVES_CHAIN_CHAIN_MANAGER_HPP
7+
#define CPP_FILECOIN_CORE_PRIMITIVES_CHAIN_CHAIN_MANAGER_HPP
8+
9+
namespace fc::primitives::chain {
10+
class ChainManager {
11+
public:
12+
virtual ~ChainManager()= default;
13+
};
14+
}
15+
16+
#endif //CPP_FILECOIN_CORE_PRIMITIVES_CHAIN_CHAIN_MANAGER_HPP
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Copyright Soramitsu Co., Ltd. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#ifndef CPP_FILECOIN_CORE_PRIMITIVES_CHAIN_CHAIN_TIPS_MANAGER_HPP
7+
#define CPP_FILECOIN_CORE_PRIMITIVES_CHAIN_CHAIN_TIPS_MANAGER_HPP
8+
9+
#include "primitives/tipset/tipset.hpp"
10+
11+
namespace fc::primitives::chain {
12+
13+
class ChainTipsManager {
14+
virtual ~ChainTipsManager() = default;
15+
// Returns the ticket that is at round 'r' in the chain behind 'head'
16+
virtual outcome::result<std::reference_wrapper<const ticket::Ticket>>
17+
getTicketFromRound(const tipset::Tipset &tipset, uint64_t rount) const = 0;
18+
19+
// Returns the tipset that contains round r (Note: multiple rounds' worth of
20+
// tickets may exist within a single block due to losing tickets being added
21+
// to the eventually successfully generated block)
22+
virtual outcome::result<std::reference_wrapper<const tipset::Tipset>>
23+
getTipsetFromRound(const tipset::Tipset &tipset, uint64_t round) const = 0;
24+
25+
// GetBestTipset returns the best known tipset. If the 'best' tipset hasn't
26+
// changed, then this will return the previous best tipset.
27+
virtual outcome::result<std::reference_wrapper<const tipset::Tipset>>
28+
getBestTipset() const = 0;
29+
30+
// Adds the losing ticket to the chaintips manager so that blocks can be
31+
// mined on top of it
32+
virtual outcome::result<void> addLosingTicket(
33+
const tipset::Tipset &parent, const ticket::Ticket &ticket) = 0;
34+
35+
};
36+
} // namespace fc::primitives::chain
37+
38+
#endif // CPP_FILECOIN_CORE_PRIMITIVES_CHAIN_CHAIN_TIPS_MANAGER_HPP
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Copyright Soramitsu Co., Ltd. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include "blockchain/impl/block_validator_impl.hpp"
7+
8+
namespace fc::blockchain::block_validator {
9+
// TODO (yuraz): FIL-87 implement proper validation
10+
outcome::result<void> BlockValidatorImpl::validateBlock(
11+
const BlockHeader &block) const {
12+
return outcome::success();
13+
}
14+
15+
} // namespace fc::chain::block_validator
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Copyright Soramitsu Co., Ltd. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#ifndef CPP_FILECOIN_CORE_CHAIN_IMPL_BLOCK_VALIDATOR_IMPL_HPP
7+
#define CPP_FILECOIN_CORE_CHAIN_IMPL_BLOCK_VALIDATOR_IMPL_HPP
8+
9+
#include "blockchain/block_validator.hpp"
10+
11+
namespace fc::blockchain::block_validator {
12+
13+
class BlockValidatorImpl : public BlockValidator {
14+
public:
15+
~BlockValidatorImpl() override = default;
16+
17+
outcome::result<void> validateBlock(
18+
const BlockHeader &block) const override;
19+
};
20+
21+
} // namespace fc::chain::block_validator
22+
23+
#endif // CPP_FILECOIN_CORE_CHAIN_IMPL_BLOCK_VALIDATOR_IMPL_HPP
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Copyright Soramitsu Co., Ltd. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include "blockchain/impl/weight_calculator_impl.hpp"
7+
8+
namespace fc::blockchain::weight {
9+
using primitives::BigInt;
10+
11+
outcome::result<BigInt> WeightCalculatorImpl::calculateWeight(
12+
const Tipset &tipset) {
13+
// TODO(yuraz): FIL-155 implement weight calculator, this one is stub
14+
return 1;
15+
}
16+
17+
} // namespace fc::blockchain::weight
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Copyright Soramitsu Co., Ltd. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#ifndef CPP_FILECOIN_CORE_CHAIN_IMPL_WEIGHT_CALCULATOR_IMPL_HPP
7+
#define CPP_FILECOIN_CORE_CHAIN_IMPL_WEIGHT_CALCULATOR_IMPL_HPP
8+
9+
#include "blockchain/weight_calculator.hpp"
10+
11+
namespace fc::blockchain::weight {
12+
13+
// TODO(yuraz): FIL-155 implement weight calculator, this one is stub
14+
class WeightCalculatorImpl : public WeightCalculator {
15+
public:
16+
~WeightCalculatorImpl() override = default;
17+
18+
outcome::result<BigInt> calculateWeight(const Tipset &tipset) override;
19+
};
20+
21+
} // namespace fc::blockchain::weight
22+
23+
#endif // CPP_FILECOIN_CORE_CHAIN_IMPL_WEIGHT_CALCULATOR_IMPL_HPP

core/blockchain/weight_calculator.hpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Copyright Soramitsu Co., Ltd. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#ifndef CPP_FILECOIN_CORE_STORAGE_CHAIN_WEIGHTCALCULATOR_HPP
7+
#define CPP_FILECOIN_CORE_STORAGE_CHAIN_WEIGHTCALCULATOR_HPP
8+
9+
#include "primitives/big_int.hpp"
10+
#include "primitives/tipset/tipset.hpp"
11+
12+
namespace fc::blockchain::weight {
13+
/**
14+
* @class WeightCalculator is an interface providing a method for calculating
15+
* tipset weight
16+
*/
17+
class WeightCalculator {
18+
public:
19+
using BigInt = primitives::BigInt;
20+
using Tipset = primitives::tipset::Tipset;
21+
22+
virtual ~WeightCalculator() = default;
23+
24+
virtual outcome::result<BigInt> calculateWeight(const Tipset &tipset) = 0;
25+
};
26+
} // namespace fc::blockchain::weight
27+
28+
#endif // CPP_FILECOIN_CORE_STORAGE_CHAIN_WEIGHTCALCULATOR_HPP

core/primitives/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55

66
add_subdirectory(address)
77
add_subdirectory(block)
8+
add_subdirectory(chain)
89
add_subdirectory(chain_epoch)
910
add_subdirectory(cid)
11+
add_subdirectory(persistent_block)
1012
add_subdirectory(rle_bitset)
1113
add_subdirectory(ticket)
1214
add_subdirectory(tipset)

0 commit comments

Comments
 (0)