Skip to content

Commit 92826fe

Browse files
author
Yura Zarudniy
authored
Feature/tipsets (#72)
* start implementing tipset Signed-off-by: Yura Zarudniy <[email protected]> * implement feature Signed-off-by: Yura Zarudniy <[email protected]> * fix clang-tidy issues Signed-off-by: Yura Zarudniy <[email protected]> * use new libp2p version, correct encodeKey function Signed-off-by: Yura Zarudniy <[email protected]> * refactore CID::toString() Signed-off-by: Yura Zarudniy <[email protected]> * temporary fix for failing github Signed-off-by: Yura Zarudniy <[email protected]> * remove redundant decodeKey function Signed-off-by: Yura Zarudniy <[email protected]> * start adding tests Signed-off-by: Yura Zarudniy <[email protected]> * refactore tipsetkey Signed-off-by: Yura Zarudniy <[email protected]> * remove commented out code Signed-off-by: Yura Zarudniy <[email protected]> * fix blockheader, add tipset tests Signed-off-by: Yura Zarudniy <[email protected]> * fix review issues Signed-off-by: Yura Zarudniy <[email protected]> * fix problem Signed-off-by: Yura Zarudniy <[email protected]> * fix create tipset test Signed-off-by: Yura Zarudniy <[email protected]> * fix review issues, use new libp2p version, add tests for tipsetkey Signed-off-by: Yura Zarudniy <[email protected]> * fix review issues Signed-off-by: Yura Zarudniy <[email protected]> * fix comment Signed-off-by: Yura Zarudniy <[email protected]>
1 parent c87d495 commit 92826fe

File tree

25 files changed

+804
-24
lines changed

25 files changed

+804
-24
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
sudo apt-get install -y ninja-build
5050
fi
5151
52-
sudo python3 -m pip install --upgrade pip
52+
pip3 -V || sudo python3 -m pip install --upgrade pip
5353
sudo pip3 install scikit-build cmake requests gitpython gcovr pyyaml
5454
sudo curl https://sh.rustup.rs -sSf | sh -s -- -y
5555
- name: cmake

cmake/Hunter/config.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ hunter_config(
3030
)
3131

3232
hunter_config(libp2p
33-
URL https://github.com/soramitsu/libp2p/archive/40b257824d3c88c30e474267222955db0a5fccfc.zip
34-
SHA1 40e2713d976858d31637f123a54896d25a78661d
33+
URL https://github.com/soramitsu/libp2p/archive/cdc092fe74ef5d8eeedf42e3e949488ff5052cb4.zip
34+
SHA1 16605084e4f018ebdb09018e906a54aa1909c8e1
3535
CMAKE_ARGS TESTING=OFF
3636
)

core/codec/cbor/cbor_encode_stream.hpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,26 @@ namespace fc::codec::cbor {
5353

5454
/// Encodes elements into list
5555
template <typename T>
56-
CborEncodeStream &operator<<(const std::vector<T> &values) {
56+
CborEncodeStream &operator<<(const gsl::span<T> &values) {
5757
auto l = list();
5858
for (auto &value : values) {
5959
l << value;
6060
}
6161
return *this << l;
6262
}
6363

64+
/// Encodes vector into list
65+
template <typename T>
66+
CborEncodeStream &operator<<(const std::vector<T> &values) {
67+
return *this << gsl::make_span(values);
68+
}
69+
70+
/// Encodes array into list
71+
template <class T, size_t size>
72+
CborEncodeStream &operator<<(const std::array<T, size> &values) {
73+
return *this << gsl::make_span(values);
74+
}
75+
6476
/** Encodes bytes */
6577
CborEncodeStream &operator<<(const std::vector<uint8_t> &bytes);
6678
/** Encodes bytes */

core/primitives/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ add_subdirectory(address)
77
add_subdirectory(block)
88
add_subdirectory(cid)
99
add_subdirectory(ticket)
10+
add_subdirectory(tipset)

core/primitives/address/address.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ OUTCOME_CPP_DEFINE_CATEGORY(fc::primitives::address, AddressError, e) {
1818
case (AddressError::UNKNOWN_NETWORK):
1919
return "Failed to create address: network must either be MAINNET or "
2020
"TESTNET";
21-
default:
22-
return "Failed to create address: unknown error";
23-
};
21+
}
22+
return "Failed to create address: unknown error";
2423
}
2524

2625
namespace fc::primitives::address {

core/primitives/block/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ add_library(block INTERFACE)
77
target_link_libraries(block INTERFACE
88
address
99
cbor
10+
signature
1011
tickets
1112
)

core/primitives/block/block.hpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
#include "primitives/ticket/epost_ticket_codec.hpp"
99
#include "primitives/ticket/ticket.hpp"
1010
#include "primitives/ticket/ticket_codec.hpp"
11+
#include "crypto/signature/signature.hpp"
1112

1213
namespace fc::primitives::block {
1314
using primitives::BigInt;
1415
using primitives::address::Address;
1516
using primitives::ticket::EPostProof;
1617
using primitives::ticket::Ticket;
17-
18-
// TODO(turuslan): FIL-72 signature
18+
// TODO (yuraz) : FIL-142 replace by crypto::signature::Signature
1919
using Signature = std::vector<uint8_t>;
2020

2121
struct BlockHeader {
@@ -31,8 +31,21 @@ namespace fc::primitives::block {
3131
Signature bls_aggregate;
3232
uint64_t timestamp;
3333
boost::optional<Signature> block_sig;
34+
uint64_t fork_signaling;
3435
};
3536

37+
inline bool operator==(const BlockHeader &lhs, const BlockHeader &rhs) {
38+
return lhs.miner == rhs.miner && lhs.ticket == rhs.ticket
39+
&& lhs.epost_proof == rhs.epost_proof && lhs.parents == rhs.parents
40+
&& lhs.parent_weight == rhs.parent_weight && lhs.height == rhs.height
41+
&& lhs.parent_state_root == rhs.parent_state_root
42+
&& lhs.parent_message_receipts == rhs.parent_message_receipts
43+
&& lhs.messages == rhs.messages
44+
&& lhs.bls_aggregate == rhs.bls_aggregate
45+
&& lhs.timestamp == rhs.timestamp && lhs.block_sig == rhs.block_sig
46+
&& lhs.fork_signaling == rhs.fork_signaling;
47+
}
48+
3649
template <class Stream,
3750
typename = std::enable_if_t<
3851
std::remove_reference_t<Stream>::is_cbor_encoder_stream>>
@@ -42,7 +55,7 @@ namespace fc::primitives::block {
4255
<< block.height << block.parent_state_root
4356
<< block.parent_message_receipts << block.messages
4457
<< block.bls_aggregate << block.timestamp
45-
<< block.block_sig);
58+
<< block.block_sig << block.fork_signaling);
4659
}
4760

4861
template <class Stream,
@@ -53,7 +66,7 @@ namespace fc::primitives::block {
5366
>> block.parents >> block.parent_weight >> block.height
5467
>> block.parent_state_root >> block.parent_message_receipts
5568
>> block.messages >> block.bls_aggregate >> block.timestamp
56-
>> block.block_sig;
69+
>> block.block_sig >> block.fork_signaling;
5770
return s;
5871
}
5972
} // namespace fc::primitives::block

core/primitives/cid/cid.cpp

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

66
#include "primitives/cid/cid.hpp"
77

8+
#include <libp2p/multi/content_identifier_codec.hpp>
89
#include "crypto/blake2/blake2b160.hpp"
910

1011
namespace fc {
@@ -13,6 +14,15 @@ namespace fc {
1314
{}, {}, libp2p::multi::Multihash::create({}, {}).value()) {}
1415

1516
CID::CID(const ContentIdentifier &cid) : ContentIdentifier(cid) {}
17+
18+
outcome::result<std::string> CID::toString() const {
19+
return libp2p::multi::ContentIdentifierCodec::toString(*this);
20+
}
21+
22+
outcome::result<std::vector<uint8_t>> CID::toBytes() const {
23+
return libp2p::multi::ContentIdentifierCodec::encode(*this);
24+
}
25+
1626
} // namespace fc
1727

1828
namespace fc::common {

core/primitives/cid/cid.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ namespace fc {
2323
*/
2424
CID();
2525
CID(const ContentIdentifier &cid);
26+
/**
27+
* @brief string-encodes cid
28+
* @return encoded value or error
29+
*/
30+
outcome::result<std::string> toString() const;
31+
32+
/**
33+
* @brief encodes CID to bytes
34+
* @return byte-representation of CID
35+
*/
36+
outcome::result<std::vector<uint8_t>> toBytes() const;
2637
};
2738
} // namespace fc
2839

core/primitives/cid/cid_of_cbor.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_PRIMITIVES_CID_CID_OF_CBOR_HPP
7+
#define CPP_FILECOIN_CORE_PRIMITIVES_CID_CID_OF_CBOR_HPP
8+
9+
#include "primitives/cid/cid.hpp"
10+
#include "codec/cbor/cbor.hpp"
11+
12+
namespace fc::primitives::cid {
13+
14+
/**
15+
* @brief helper function to calculate cid of an object
16+
* @tparam T object type
17+
* @param value object instance reference
18+
* @return calculated cid or error
19+
*/
20+
template <class T>
21+
outcome::result<CID> getCidOfCbor(const T &value) {
22+
OUTCOME_TRY(bytes, fc::codec::cbor::encode(value));
23+
return common::getCidOf(bytes);
24+
}
25+
} // namespace fc::primitives::cid
26+
27+
#endif // CPP_FILECOIN_CORE_PRIMITIVES_CID_CID_OF_CBOR_HPP

0 commit comments

Comments
 (0)