Skip to content

Commit 2f2cd4b

Browse files
author
Mikhail Tagirov
authored
Miner actor precommit sector v2 (#482)
Signed-off-by: Mikhail Tagirov <[email protected]>
1 parent ea715ad commit 2f2cd4b

File tree

15 files changed

+366
-66
lines changed

15 files changed

+366
-66
lines changed

core/const.cpp

Lines changed: 40 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@
1616

1717
namespace fc {
1818
using primitives::sector::RegisteredSealProof;
19-
using vm::actor::builtin::types::miner::kPreCommitChallengeDelay;
20-
using vm::actor::builtin::types::miner::kSupportedProofs;
21-
using vm::actor::builtin::types::storage_power::kConsensusMinerMinPower;
22-
using vm::actor::builtin::types::verified_registry::kMinVerifiedDealSize;
19+
using namespace vm::actor::builtin::types;
2320

2421
// Initialize parameters with mainnet values
2522
DEFINE(kEpochDurationSeconds){30};
@@ -58,6 +55,7 @@ namespace fc::vm::actor::builtin::types::market {
5855
namespace fc::vm::actor::builtin::types::miner {
5956
DEFINE(kWPoStProvingPeriod) = kEpochsInDay;
6057
DEFINE(kWPoStChallengeWindow) = 30 * 60 / kEpochDurationSeconds;
58+
DEFINE(kMaxPreCommitRandomnessLookback) = kEpochsInDay + kChainFinality;
6159
DEFINE(kPreCommitChallengeDelay){150};
6260
DEFINE(kFaultMaxAge){kWPoStProvingPeriod * 14};
6361
DEFINE(kMinSectorExpiration) = 180 * kEpochsInDay;
@@ -111,31 +109,28 @@ namespace fc {
111109
kBreezeGasTampingDuration = 0;
112110

113111
// Update actor constants
114-
vm::actor::builtin::types::market::kDealUpdatesInterval =
115-
static_cast<EpochDuration>(kEpochsInDay);
116-
117-
vm::actor::builtin::types::miner::kWPoStProvingPeriod = kEpochsInDay;
118-
vm::actor::builtin::types::miner::kWPoStChallengeWindow =
119-
30 * 60 / kEpochDurationSeconds;
120-
vm::actor::builtin::types::miner::kFaultMaxAge =
121-
vm::actor::builtin::types::miner::kWPoStProvingPeriod * 14;
122-
vm::actor::builtin::types::miner::kMinSectorExpiration = 180 * kEpochsInDay;
123-
vm::actor::builtin::types::miner::kMaxSectorExpirationExtension =
124-
540 * kEpochsInDay;
125-
vm::actor::builtin::types::miner::kMaxProveCommitDuration =
126-
kEpochsInDay + kPreCommitChallengeDelay;
127-
kSupportedProofs = {
112+
market::kDealUpdatesInterval = static_cast<EpochDuration>(kEpochsInDay);
113+
114+
miner::kWPoStProvingPeriod = kEpochsInDay;
115+
miner::kWPoStChallengeWindow = 30 * 60 / kEpochDurationSeconds;
116+
miner::kMaxPreCommitRandomnessLookback =
117+
kEpochsInDay + miner::kChainFinality;
118+
miner::kFaultMaxAge = miner::kWPoStProvingPeriod * 14;
119+
miner::kMinSectorExpiration = 180 * kEpochsInDay;
120+
miner::kMaxSectorExpirationExtension = 540 * kEpochsInDay;
121+
miner::kMaxProveCommitDuration =
122+
kEpochsInDay + miner::kPreCommitChallengeDelay;
123+
miner::kSupportedProofs = {
128124
RegisteredSealProof::kStackedDrg2KiBV1,
129125
RegisteredSealProof::kStackedDrg8MiBV1,
130126
};
131127

132-
vm::actor::builtin::types::payment_channel::kSettleDelay =
133-
kEpochsInHour * 12;
128+
payment_channel::kSettleDelay = kEpochsInHour * 12;
134129

135-
kConsensusMinerMinPower = 2048;
130+
storage_power::kConsensusMinerMinPower = 2048;
136131

137-
kMinVerifiedDealSize = 256;
138-
kPreCommitChallengeDelay = 10;
132+
verified_registry::kMinVerifiedDealSize = 256;
133+
miner::kPreCommitChallengeDelay = 10;
139134
}
140135

141136
void setParamsNoUpgrades() {
@@ -166,27 +161,24 @@ namespace fc {
166161
kBreezeGasTampingDuration = 0;
167162

168163
// Update actor constants
169-
vm::actor::builtin::types::market::kDealUpdatesInterval =
170-
static_cast<EpochDuration>(kEpochsInDay);
171-
172-
vm::actor::builtin::types::miner::kWPoStProvingPeriod = kEpochsInDay;
173-
vm::actor::builtin::types::miner::kWPoStChallengeWindow =
174-
30 * 60 / kEpochDurationSeconds;
175-
vm::actor::builtin::types::miner::kFaultMaxAge =
176-
vm::actor::builtin::types::miner::kWPoStProvingPeriod * 14;
177-
vm::actor::builtin::types::miner::kMinSectorExpiration = 180 * kEpochsInDay;
178-
vm::actor::builtin::types::miner::kMaxSectorExpirationExtension =
179-
540 * kEpochsInDay;
180-
vm::actor::builtin::types::miner::kMaxProveCommitDuration =
181-
kEpochsInDay + kPreCommitChallengeDelay;
182-
kSupportedProofs = {RegisteredSealProof::kStackedDrg2KiBV1};
183-
184-
vm::actor::builtin::types::payment_channel::kSettleDelay =
185-
kEpochsInHour * 12;
186-
187-
kConsensusMinerMinPower = 2048;
188-
189-
kMinVerifiedDealSize = 256;
164+
market::kDealUpdatesInterval = static_cast<EpochDuration>(kEpochsInDay);
165+
166+
miner::kWPoStProvingPeriod = kEpochsInDay;
167+
miner::kWPoStChallengeWindow = 30 * 60 / kEpochDurationSeconds;
168+
miner::kMaxPreCommitRandomnessLookback =
169+
kEpochsInDay + miner::kChainFinality;
170+
miner::kFaultMaxAge = miner::kWPoStProvingPeriod * 14;
171+
miner::kMinSectorExpiration = 180 * kEpochsInDay;
172+
miner::kMaxSectorExpirationExtension = 540 * kEpochsInDay;
173+
miner::kMaxProveCommitDuration =
174+
kEpochsInDay + miner::kPreCommitChallengeDelay;
175+
miner::kSupportedProofs = {RegisteredSealProof::kStackedDrg2KiBV1};
176+
177+
payment_channel::kSettleDelay = kEpochsInHour * 12;
178+
179+
storage_power::kConsensusMinerMinPower = 2048;
180+
181+
verified_registry::kMinVerifiedDealSize = 256;
190182
}
191183

192184
void setParamsInteropnet() {
@@ -211,13 +203,13 @@ namespace fc {
211203
kBreezeGasTampingDuration = 0;
212204

213205
// Update actor constants
214-
kSupportedProofs = {
206+
miner::kSupportedProofs = {
215207
RegisteredSealProof::kStackedDrg2KiBV1,
216208
RegisteredSealProof::kStackedDrg8MiBV1,
217209
RegisteredSealProof::kStackedDrg512MiBV1,
218210
};
219-
kConsensusMinerMinPower = 2048;
220-
kMinVerifiedDealSize = 256;
221-
kPreCommitChallengeDelay = 10;
211+
storage_power::kConsensusMinerMinPower = 2048;
212+
verified_registry::kMinVerifiedDealSize = 256;
213+
miner::kPreCommitChallengeDelay = 10;
222214
}
223215
} // namespace fc

core/vm/actor/builtin/types/miner/monies.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ namespace fc::vm::actor::builtin::types::miner {
9393
const StoragePower &sector_power) const = 0;
9494

9595
virtual outcome::result<TokenAmount> repayDebtsOrAbort(
96-
Runtime &runtime, MinerActorStatePtr miner_state) const = 0;
96+
Runtime &runtime, MinerActorStatePtr &miner_state) const = 0;
9797

9898
virtual outcome::result<TokenAmount> consensusFaultPenalty(
9999
const TokenAmount &this_epoch_reward) const = 0;

core/vm/actor/builtin/types/miner/policy.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ namespace fc::vm::actor::builtin::types::miner {
6060
.mh_type = HashType::poseidon_bls12_381_a1_fc1,
6161
.mh_length = kCommitmentBytesLen};
6262

63+
// Maximum delay between challenge and pre-commitment.
64+
// This prevents a miner sealing sectors far in advance of committing them to
65+
// the chain, thus committing to a particular chain.
66+
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
67+
extern EpochDuration kMaxPreCommitRandomnessLookback;
68+
6369
// Number of epochs between publishing the precommit and when the challenge
6470
// for interactive PoRep is drawn used to ensure it is not predictable by
6571
// miner

core/vm/actor/builtin/types/miner/v0/monies.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ namespace fc::vm::actor::builtin::v0::miner {
141141
}
142142

143143
outcome::result<TokenAmount> Monies::repayDebtsOrAbort(
144-
Runtime &runtime, MinerActorStatePtr miner_state) const {
144+
Runtime &runtime, MinerActorStatePtr &miner_state) const {
145145
return TokenAmount{};
146146
}
147147

core/vm/actor/builtin/types/miner/v0/monies.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ namespace fc::vm::actor::builtin::v0::miner {
104104
const StoragePower &sector_power) const override;
105105

106106
outcome::result<TokenAmount> repayDebtsOrAbort(
107-
Runtime &runtime, MinerActorStatePtr miner_state) const override;
107+
Runtime &runtime, MinerActorStatePtr &miner_state) const override;
108108

109109
outcome::result<TokenAmount> consensusFaultPenalty(
110110
const TokenAmount &this_epoch_reward) const override;

core/vm/actor/builtin/types/miner/v2/monies.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,12 @@ namespace fc::vm::actor::builtin::v2::miner {
126126
}
127127

128128
outcome::result<TokenAmount> Monies::repayDebtsOrAbort(
129-
Runtime &runtime, MinerActorStatePtr miner_state) const {
129+
Runtime &runtime, MinerActorStatePtr &miner_state) const {
130130
OUTCOME_TRY(curr_balance, runtime.getCurrentBalance());
131-
return miner_state->repayDebts(curr_balance);
131+
REQUIRE_NO_ERROR_A(to_burn,
132+
miner_state->repayDebts(curr_balance),
133+
VMExitCode::kErrIllegalState);
134+
return std::move(to_burn);
132135
}
133136

134137
outcome::result<TokenAmount> Monies::consensusFaultPenalty(

core/vm/actor/builtin/types/miner/v2/monies.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ namespace fc::vm::actor::builtin::v2::miner {
7676
const TokenAmount &network_circulation_supply_smoothed) const override;
7777

7878
outcome::result<TokenAmount> repayDebtsOrAbort(
79-
Runtime &runtime, MinerActorStatePtr miner_state) const override;
79+
Runtime &runtime, MinerActorStatePtr &miner_state) const override;
8080

8181
outcome::result<TokenAmount> consensusFaultPenalty(
8282
const TokenAmount &this_epoch_reward) const override;

core/vm/actor/builtin/v0/miner/miner_actor.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,10 @@ namespace fc::vm::actor::builtin::v0::miner {
285285
ACTOR_METHOD_IMPL(PreCommitSector) {
286286
const auto current_epoch = runtime.getCurrentEpoch();
287287

288-
const auto search =
289-
kPreCommitSealProofTypesV0.find(params.registered_proof);
290-
OUTCOME_TRY(
291-
runtime.validateArgument(search != kPreCommitSealProofTypesV0.end()));
288+
const auto utils = Toolchain::createMinerUtils(runtime);
289+
290+
OUTCOME_TRY(utils->canPreCommitSealProof(params.registered_proof,
291+
runtime.getNetworkVersion()));
292292

293293
OUTCOME_TRY(runtime.validateArgument(params.sector <= kMaxSectorNumber));
294294

@@ -317,8 +317,6 @@ namespace fc::vm::actor::builtin::v0::miner {
317317
OUTCOME_TRY(
318318
runtime.validateArgument(params.replace_sector <= kMaxSectorNumber));
319319

320-
const auto utils = Toolchain::createMinerUtils(runtime);
321-
322320
OUTCOME_TRY(reward, utils->requestCurrentEpochBlockReward());
323321
OUTCOME_TRY(total_power, utils->requestCurrentTotalPower());
324322
OUTCOME_TRY(deal_weight,

core/vm/actor/builtin/v0/miner/miner_actor.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ namespace fc::vm::actor::builtin::v0::miner {
130130

131131
struct PreCommitSector : ActorMethodBase<6> {
132132
using Params = SectorPreCommitInfo;
133+
133134
ACTOR_METHOD_DECL();
134135
};
135136

0 commit comments

Comments
 (0)