Skip to content

Commit 13c170e

Browse files
author
Mikhail Tagirov
authored
Miner actor precommit sector v0 (#478)
Signed-off-by: Mikhail Tagirov <[email protected]>
1 parent c5612fc commit 13c170e

40 files changed

+976
-138
lines changed

core/blockchain/block_validator/impl/consensus_rules.hpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@
1515
#include "storage/ipfs/datastore.hpp"
1616

1717
namespace fc::blockchain::block_validator {
18-
class ConsensusRules {
19-
protected:
20-
using WeightCalculator = weight::WeightCalculator;
21-
using BlockHeader = primitives::block::BlockHeader;
22-
using PowerTable = power::PowerTable;
23-
using ChainEpoch = primitives::ChainEpoch;
24-
using Tipset = primitives::tipset::Tipset;
18+
using power::PowerTable;
19+
using primitives::ChainEpoch;
20+
using primitives::block::BlockHeader;
21+
using primitives::tipset::Tipset;
22+
using weight::WeightCalculator;
2523

24+
class ConsensusRules {
2625
public:
2726
/**
2827
* @brief Check miner params

core/blockchain/weight_calculator.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
#include "primitives/tipset/tipset.hpp"
1010

1111
namespace fc::blockchain::weight {
12+
using primitives::BigInt;
13+
using primitives::tipset::Tipset;
14+
1215
/**
1316
* @class WeightCalculator is an interface providing a method for calculating
1417
* tipset weight
1518
*/
1619
class WeightCalculator {
1720
public:
18-
using BigInt = primitives::BigInt;
19-
using Tipset = primitives::tipset::Tipset;
20-
2121
virtual ~WeightCalculator() = default;
2222

2323
virtual outcome::result<BigInt> calculateWeight(const Tipset &tipset) = 0;

core/codec/rle/rle_plus.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,18 @@ namespace fc::codec::rle {
4040
if (input.empty()) {
4141
return data;
4242
}
43+
if (input.size() > BYTES_MAX_SIZE) {
44+
return RLEPlusDecodeError::kMaxSizeExceed;
45+
}
46+
4347
RLEPlusDecodingStream decoder(input);
48+
4449
try {
4550
decoder >> data;
4651
} catch (errors::VersionMismatch &) {
4752
return RLEPlusDecodeError::kVersionMismatch;
4853
} catch (errors::UnpackBytesOverflow &) {
4954
return RLEPlusDecodeError::kUnpackOverflow;
50-
} catch (errors::MaxSizeExceed &) {
51-
return RLEPlusDecodeError::kMaxSizeExceed;
5255
}
5356
return data;
5457
}

core/codec/rle/rle_plus_config.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ namespace fc::codec::rle {
3737
const int BYTE_SLICE_VALUE = 0x80;
3838

3939
/**
40-
* @var Maximum object size to encode or decode
40+
* @var Maximum bytes size to encode or decode
4141
*/
42-
const int OBJECT_MAX_SIZE = 0x100000;
42+
constexpr ssize_t BYTES_MAX_SIZE = 32 << 10;
4343

4444
} // namespace fc::codec::rle

core/codec/rle/rle_plus_decoding_stream.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ namespace fc::codec::rle {
5555
}
5656
}
5757
}
58-
constexpr size_t max_size = OBJECT_MAX_SIZE / sizeof(T);
59-
if (output.size() > max_size) {
60-
throw errors::MaxSizeExceed();
61-
}
6258
return *this;
6359
}
6460

core/common/smoothing/alpha_beta_filter.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ namespace fc::common::smoothing {
4343
uint64_t start,
4444
const FilterEstimate &num,
4545
const FilterEstimate &den) {
46-
BigInt delta_t{BigInt{delta} << kPrecision128}; // Q.0 => Q.128
47-
BigInt t0{BigInt{start} << kPrecision128}; // Q.0 => Q.128
46+
const BigInt delta_t{BigInt{delta} << kPrecision128}; // Q.0 => Q.128
47+
const BigInt t0{BigInt{start} << kPrecision128}; // Q.0 => Q.128
4848
const auto &position1{num.position};
4949
const auto &position2{den.position};
5050
const auto &velocity1{num.velocity};
@@ -80,13 +80,13 @@ namespace fc::common::smoothing {
8080
return bigdiv(m1 + m2, squared_velocity2); // Q.256 / Q.128 => Q.128
8181
}
8282

83-
BigInt half_delta_t{delta_t >> 1}; // Q.128 / Q.0 => Q.128
83+
const BigInt half_delta_t{delta_t >> 1}; // Q.128 / Q.0 => Q.128
8484
BigInt x1m{velocity1 * (t0 + half_delta_t)}; // Q.128 * Q.128 => Q.256
8585
x1m >>= kPrecision128; // Q.256 => Q.128
8686
x1m += position1;
8787

88-
BigInt cumsumRatio{x1m * delta_t}; // Q.128 * Q.128 => Q.256
89-
cumsumRatio /= position2; // Q.256 / Q.128 => Q.128
88+
BigInt cumsumRatio{x1m * delta_t}; // Q.128 * Q.128 => Q.256
89+
cumsumRatio = bigdiv(cumsumRatio, position2); // Q.256 / Q.128 => Q.128
9090
return cumsumRatio;
9191
}
9292
} // namespace fc::common::smoothing

core/primitives/go/math.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace fc::primitives::go {
2424
}
2525

2626
inline auto bitlen(const BigInt &x) {
27-
return x ? msb(x < 0 ? -x : x) : 0;
27+
return x ? msb(x < 0 ? -x : x) + 1 : 0;
2828
}
2929

3030
} // namespace fc::primitives::go

core/primitives/sector/sector.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace fc::primitives::sector {
2929
case RegisteredSealProof::kUndefined:
3030
return RegisteredPoStProof::kUndefined;
3131
default:
32-
return Errors::kInvalidPoStProof;
32+
return Errors::kInvalidSealProof;
3333
}
3434
}
3535

@@ -54,7 +54,7 @@ namespace fc::primitives::sector {
5454
case RegisteredSealProof::kUndefined:
5555
return RegisteredPoStProof::kUndefined;
5656
default:
57-
return Errors::kInvalidPoStProof;
57+
return Errors::kInvalidSealProof;
5858
}
5959
}
6060

@@ -103,7 +103,7 @@ namespace fc::primitives::sector {
103103
case RegisteredSealProof::kUndefined:
104104
return 0;
105105
default:
106-
return Errors::kInvalidPoStProof;
106+
return Errors::kInvalidSealProof;
107107
}
108108
}
109109

@@ -180,9 +180,7 @@ namespace fc::primitives::sector {
180180
case RegisteredPoStProof::kStackedDRG64GiBWindowPoSt:
181181
return RegisteredSealProof::kStackedDrg64GiBV1;
182182
default:
183-
return ERROR_TEXT(
184-
"getPreferredSealProofTypeFromWindowPoStType: unrecognized "
185-
"window post type");
183+
return Errors::kInvalidPoStProof;
186184
}
187185
}
188186

@@ -198,9 +196,7 @@ namespace fc::primitives::sector {
198196
case RegisteredPoStProof::kStackedDRG64GiBWindowPoSt:
199197
return RegisteredSealProof::kStackedDrg64GiBV1_1;
200198
default:
201-
return ERROR_TEXT(
202-
"getPreferredSealProofTypeFromWindowPoStType: unrecognized "
203-
"window post type");
199+
return Errors::kInvalidPoStProof;
204200
}
205201
}
206202
} // namespace fc::primitives::sector

core/storage/amt/amt.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,11 +379,11 @@ namespace fc::storage::amt {
379379
if (bits() <= 3) {
380380
return 1;
381381
}
382-
return 1 << (bits() - 3);
382+
return uint64_t(1) << (bits() - 3);
383383
}
384384

385385
uint64_t Amt::maskAt(uint64_t height) const {
386-
return 1 << (bits() * height);
386+
return uint64_t(1) << (bits() * height);
387387
}
388388

389389
uint64_t Amt::maxAt(uint64_t height) const {

core/vm/actor/builtin/states/miner/miner_actor_state.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ namespace fc::vm::actor::builtin::states {
1717
outcome::result<void> MinerActorState::allocateSectorNumber(
1818
SectorNumber sector_num) {
1919
if (sector_num > kMaxSectorNumber) {
20-
return ERROR_TEXT("sector number out of range");
20+
return VMExitCode::kErrIllegalArgument;
2121
}
2222

2323
OUTCOME_TRY(allocated, this->allocated_sectors.get());
2424

2525
if (allocated.has(sector_num)) {
26-
return ERROR_TEXT("sector number has already been allocated");
26+
return VMExitCode::kErrIllegalArgument;
2727
}
2828

2929
allocated.insert(sector_num);
@@ -36,13 +36,13 @@ namespace fc::vm::actor::builtin::states {
3636
outcome::result<void> MinerActorState::maskSectorNumbers(
3737
const RleBitset &sector_nos) {
3838
if (sector_nos.empty()) {
39-
return ERROR_TEXT("invalid mask bitfield");
39+
return VMExitCode::kErrIllegalArgument;
4040
}
4141

4242
const auto &last_sector = *std::prev(sector_nos.end());
4343

4444
if (last_sector > kMaxSectorNumber) {
45-
return ERROR_TEXT("masked sector number exceeded max sector number");
45+
return VMExitCode::kErrIllegalArgument;
4646
}
4747

4848
OUTCOME_TRY(allocated, this->allocated_sectors.get());
@@ -187,15 +187,15 @@ namespace fc::vm::actor::builtin::states {
187187
OUTCOME_TRY(partition, deadline->partitions.get(partition_id));
188188

189189
if (!partition->sectors.has(sector)) {
190-
return ERROR_TEXT("sector is not a member of partition");
190+
return VMExitCode::kErrNotFound;
191191
}
192192

193193
if (partition->faults.has(sector)) {
194-
return ERROR_TEXT("sector of partition is faulty");
194+
return VMExitCode::kErrForbidden;
195195
}
196196

197197
if (partition->terminated.has(sector)) {
198-
return ERROR_TEXT("sector of partition is terminated");
198+
return VMExitCode::kErrNotFound;
199199
}
200200

201201
return outcome::success();

0 commit comments

Comments
 (0)