Skip to content

Commit 0280f3f

Browse files
authored
Miner actor related (#111)
Signed-off-by: turuslan <[email protected]>
1 parent 8421ed5 commit 0280f3f

Some content is hidden

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

55 files changed

+824
-212
lines changed

core/adt/balance_table_hamt.hpp

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

99
#include "common/outcome.hpp"
1010
#include "primitives/address/address.hpp"
11-
#include "primitives/big_int.hpp"
1211
#include "primitives/cid/cid.hpp"
12+
#include "primitives/types.hpp"
1313
#include "storage/hamt/hamt.hpp"
1414
#include "storage/ipfs/datastore.hpp"
1515

1616
namespace fc::adt {
1717

18-
using primitives::BigInt;
18+
using primitives::TokenAmount;
1919
using primitives::address::Address;
2020
using storage::hamt::Hamt;
2121
using storage::ipfs::IpfsDatastore;
22-
using TokenAmount = BigInt;
2322

2423
/**
2524
* Stores miner balances

core/codec/cbor/cbor_decode_stream.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ namespace fc::codec::cbor {
2626
typename T,
2727
typename = std::enable_if_t<std::is_integral_v<T> || std::is_enum_v<T>>>
2828
CborDecodeStream &operator>>(T &num) {
29+
if constexpr (std::is_enum_v<T>) {
30+
std::underlying_type_t<T> value;
31+
*this >> value;
32+
num = T{value};
33+
return *this;
34+
}
2935
if constexpr (std::is_same_v<T, bool>) {
3036
if (!cbor_value_is_boolean(&value_)) {
3137
outcome::raise(CborDecodeError::WRONG_TYPE);

core/codec/cbor/cbor_encode_stream.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
#include <cbor.h>
1515

16+
#include "common/enum.hpp"
17+
1618
namespace fc::codec::cbor {
1719
/** Encodes CBOR */
1820
class CborEncodeStream {
@@ -24,6 +26,9 @@ namespace fc::codec::cbor {
2426
typename T,
2527
typename = std::enable_if_t<std::is_integral_v<T> || std::is_enum_v<T>>>
2628
CborEncodeStream &operator<<(T num) {
29+
if constexpr (std::is_enum_v<T>) {
30+
return *this << common::to_int(num);
31+
}
2732
addCount(1);
2833
std::array<uint8_t, 9> buffer{0};
2934
CborEncoder encoder;

core/crypto/randomness/randomness_types.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ namespace fc::crypto::randomness {
2121
enum class DomainSeparationTag : size_t {
2222
TicketDrawingDST = 1,
2323
TicketProductionDST = 2,
24-
PoStDST = 3
24+
PoStDST = 3,
25+
SealRandomness = 4,
26+
InteractiveSealChallengeSeed = 5,
2527
};
2628

2729
} // namespace fc::crypto::randomness

core/primitives/address/address.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ namespace fc::primitives::address {
6262
return {network, BLSPublicKeyHash{public_key}};
6363
}
6464

65+
uint64_t Address::getId() const {
66+
return boost::get<uint64_t>(data);
67+
}
68+
6569
bool Address::verifySyntax(gsl::span<const uint8_t> seed_data) const {
6670
return visit_in_place(
6771
data,
@@ -86,8 +90,7 @@ namespace fc::primitives::address {
8690
}
8791

8892
bool operator==(const Address &lhs, const Address &rhs) {
89-
return lhs.network == rhs.network
90-
&& lhs.data == rhs.data;
93+
return lhs.network == rhs.network && lhs.data == rhs.data;
9194
}
9295

9396
bool operator!=(const Address &lhs, const Address &rhs) {

core/primitives/address/address.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ namespace fc::primitives::address {
8484
static Address makeBls(const BlsPublicKey &public_key,
8585
Network network = kDefaultNetwork);
8686

87+
uint64_t getId() const;
88+
8789
bool verifySyntax(gsl::span<const uint8_t> seed_data) const;
8890

8991
Network network;

core/primitives/chain_epoch/chain_epoch.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#ifndef CPP_FILECOIN_PRIMITIVES_CHAIN_EPOCH_HPP
77
#define CPP_FILECOIN_PRIMITIVES_CHAIN_EPOCH_HPP
88

9-
#include "primitives/big_int.hpp"
9+
#include <cstdint>
1010

1111
namespace fc::primitives {
1212

core/primitives/chain_epoch/chain_epoch_codec.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ namespace fc::primitives::chain_epoch {
1111

1212
using libp2p::multi::UVarint;
1313

14+
std::string uvarintKey(uint64_t value) {
15+
UVarint uvarint{value};
16+
auto encoded = uvarint.toBytes();
17+
return std::string(encoded.begin(), encoded.end());
18+
}
19+
1420
std::string encodeToByteString(const ChainEpoch &epoch) {
1521
// TODO (a.chernyshov) actor-specs uses Protobuf Varint encoding
16-
UVarint number(epoch);
17-
auto encoded = number.toBytes();
18-
return std::string(encoded.begin(), encoded.end());
22+
return uvarintKey(epoch);
1923
}
2024

2125
} // namespace fc::primitives::chain_epoch

core/primitives/chain_epoch/chain_epoch_codec.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66
#ifndef CPP_FILECOIN_PRIMITIVES_CHAIN_EPOCH_CODEC_HPP
77
#define CPP_FILECOIN_PRIMITIVES_CHAIN_EPOCH_CODEC_HPP
88

9+
#include <string>
10+
911
#include "primitives/chain_epoch/chain_epoch.hpp"
1012

1113
namespace fc::primitives::chain_epoch {
14+
std::string uvarintKey(uint64_t value);
1215

1316
std::string encodeToByteString(const ChainEpoch &epoch);
14-
}
17+
} // namespace fc::primitives::chain_epoch
1518

1619
#endif // CPP_FILECOIN_PRIMITIVES_CHAIN_EPOCH_CODEC_HPP

core/primitives/types.hpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Copyright Soramitsu Co., Ltd. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#ifndef CPP_FILECOIN_CORE_PRIMITIVES_TYPES_HPP
7+
#define CPP_FILECOIN_CORE_PRIMITIVES_TYPES_HPP
8+
9+
#include <cstdint>
10+
11+
#include "codec/cbor/streams_annotation.hpp"
12+
#include "primitives/big_int.hpp"
13+
#include "primitives/chain_epoch/chain_epoch.hpp"
14+
15+
namespace fc::primitives {
16+
using ActorId = uint64_t;
17+
18+
using TokenAmount = BigInt;
19+
20+
using SectorSize = uint64_t;
21+
22+
using SectorNumber = uint64_t;
23+
24+
using DealWeight = BigInt;
25+
26+
using DealId = uint64_t;
27+
28+
struct SectorStorageWeightDesc {
29+
SectorSize sector_size;
30+
EpochDuration duration;
31+
DealWeight deal_weight;
32+
};
33+
34+
CBOR_TUPLE(SectorStorageWeightDesc, sector_size, duration, deal_weight)
35+
} // namespace fc::primitives
36+
37+
#endif // CPP_FILECOIN_CORE_PRIMITIVES_TYPES_HPP

0 commit comments

Comments
 (0)