Skip to content

Commit c6feeae

Browse files
refactor ChainEpoch (#76)
Signed-off-by: Alexey-N-Chernyshov <[email protected]>
1 parent 92826fe commit c6feeae

22 files changed

+57
-33
lines changed

core/clock/chain_epoch_clock.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@
77
#define CPP_FILECOIN_CORE_CLOCK_CHAIN_EPOCH_CLOCK_HPP
88

99
#include "clock/time.hpp"
10-
11-
#include "libp2p/multi/uvarint.hpp"
10+
#include "primitives/chain_epoch.hpp"
1211

1312
namespace fc::clock {
1413
enum class EpochAtTimeError { BEFORE_GENESIS = 1 };
1514

16-
using ChainEpoch = libp2p::multi::UVarint;
15+
using primitives::ChainEpoch;
1716

1817
/**
1918
* Converts UTC time to epoch number

core/crypto/bls/impl/bls_provider_impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include <gsl/gsl_util>
99

10-
namespace fc::crypto::bls::impl {
10+
namespace fc::crypto::bls {
1111
outcome::result<KeyPair> BlsProviderImpl::generateKeyPair() const {
1212
KeyPair key_pair{};
1313
PrivateKeyGenerateResponse *private_key_response = private_key_generate();

core/crypto/bls/impl/bls_provider_impl.hpp

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

99
#include "crypto/bls/bls_provider.hpp"
1010

11-
namespace fc::crypto::bls::impl {
11+
namespace fc::crypto::bls {
1212
class BlsProviderImpl : public BlsProvider {
1313
public:
1414
outcome::result<KeyPair> generateKeyPair() const override;
@@ -32,6 +32,6 @@ namespace fc::crypto::bls::impl {
3232
static outcome::result<Digest> generateHash(
3333
gsl::span<const uint8_t> message);
3434
};
35-
} // namespace fc::crypto::bls::impl
35+
} // namespace fc::crypto::bls
3636

3737
#endif

core/crypto/randomness/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
add_library(randomness_provider
5-
impl/randomness_provider.cpp
5+
impl/randomness_provider_imp.cpp
66
)
77
target_link_libraries(randomness_provider
88
Boost::boost

core/crypto/randomness/impl/randomness_provider.cpp renamed to core/crypto/randomness/impl/randomness_provider_imp.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
#include "crypto/randomness/impl/randomness_provider.hpp"
6+
#include "crypto/randomness/impl/randomness_provider_imp.hpp"
77

88
#include <libp2p/crypto/sha/sha256.hpp>
99
#include "common/le_encoder.hpp"
@@ -12,23 +12,23 @@ namespace fc::crypto::randomness {
1212

1313
Randomness RandomnessProviderImpl::deriveRandomness(DomainSeparationTag tag,
1414
Serialization s) {
15-
return deriveRandomness(tag, std::move(s), static_cast<size_t>(-1));
15+
return deriveRandomness(tag, std::move(s), ChainEpoch(-1));
1616
}
1717

1818
Randomness RandomnessProviderImpl::deriveRandomness(DomainSeparationTag tag,
1919
Serialization s,
20-
ChainEpoch index) {
20+
const ChainEpoch &index) {
2121
return deriveRandomnessInternal(tag, std::move(s), index);
2222
}
2323

2424
Randomness RandomnessProviderImpl::deriveRandomnessInternal(
25-
DomainSeparationTag tag, Serialization s, ChainEpoch index) {
25+
DomainSeparationTag tag, Serialization s, const ChainEpoch &index) {
2626
common::Buffer value{};
2727
const size_t bytes_required =
2828
sizeof(DomainSeparationTag) + sizeof(ChainEpoch) + s.size();
2929
value.reserve(bytes_required);
3030
common::encodeInteger(static_cast<size_t>(tag), value);
31-
common::encodeInteger(static_cast<size_t>(index), value);
31+
common::encodeInteger(static_cast<size_t>(index.toUInt64()), value);
3232
value.put(s);
3333
auto hash = libp2p::crypto::sha256(value);
3434

core/crypto/randomness/impl/randomness_provider.hpp renamed to core/crypto/randomness/impl/randomness_provider_imp.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace fc::crypto::randomness {
1919

2020
Randomness deriveRandomness(DomainSeparationTag tag,
2121
Serialization s,
22-
ChainEpoch index) override;
22+
const ChainEpoch &index) override;
2323

2424
int randomInt(const Randomness &randomness,
2525
size_t nonce,
@@ -28,7 +28,7 @@ namespace fc::crypto::randomness {
2828
private:
2929
Randomness deriveRandomnessInternal(DomainSeparationTag tag,
3030
Serialization s,
31-
ChainEpoch index);
31+
const ChainEpoch &index);
3232
};
3333

3434
} // namespace fc::crypto::randomness

core/crypto/randomness/randomness_provider.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77
#define CPP_FILECOIN_CORE_CRYPTO_RANDOMNESS_RANDOMNESS_PROVIDER_HPP
88

99
#include "crypto/randomness/randomness_types.hpp"
10+
#include "primitives/chain_epoch.hpp"
1011

1112
namespace fc::crypto::randomness {
13+
14+
using primitives::ChainEpoch;
15+
1216
/**
1317
* @class RandomnessProvider provides 2 methods for drawing randomness value
1418
*/
@@ -34,7 +38,7 @@ namespace fc::crypto::randomness {
3438
*/
3539
virtual Randomness deriveRandomness(DomainSeparationTag tag,
3640
Serialization s,
37-
ChainEpoch index) = 0;
41+
const ChainEpoch &index) = 0;
3842

3943
/**
4044
* @brief get random int value

core/crypto/randomness/randomness_types.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "common/buffer.hpp"
1111

1212
namespace fc::crypto::randomness {
13+
1314
/// @brief randomness value type
1415
using Randomness = common::Hash256;
1516

@@ -23,8 +24,6 @@ namespace fc::crypto::randomness {
2324
PoStDST = 3
2425
};
2526

26-
/// @brief epoch index type represents a round of a blockchain protocol
27-
using ChainEpoch = size_t;
2827
} // namespace fc::crypto::randomness
2928

3029
#endif // CPP_FILECOIN_CORE_CRYPTO_RANDOMNESS_RANDOMNESS_HPP

core/primitives/chain_epoch.hpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Copyright Soramitsu Co., Ltd. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#ifndef CPP_FILECOIN_PRIMITIVES_CHAIN_EPOCH_HPP
7+
#define CPP_FILECOIN_PRIMITIVES_CHAIN_EPOCH_HPP
8+
9+
#include "libp2p/multi/uvarint.hpp"
10+
11+
namespace fc::primitives {
12+
13+
/**
14+
* @brief epoch index type represents a round of a blockchain protocol, which
15+
* acts as a proxy for time within the VM
16+
*/
17+
using ChainEpoch = libp2p::multi::UVarint;
18+
19+
} // namespace fc::primitives
20+
21+
#endif // CPP_FILECOIN_PRIMITIVES_CHAIN_EPOCH_HPP

core/storage/repository/impl/filesystem_repository.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "storage/keystore/impl/filesystem/filesystem_keystore.hpp"
1616
#include "storage/repository/repository_error.hpp"
1717

18-
using fc::crypto::bls::impl::BlsProviderImpl;
18+
using fc::crypto::bls::BlsProviderImpl;
1919
using fc::primitives::address::AddressVerifierImpl;
2020
using fc::storage::ipfs::LeveldbDatastore;
2121
using fc::storage::keystore::FileSystemKeyStore;

0 commit comments

Comments
 (0)