Skip to content

Commit 262a217

Browse files
author
Mikhail Tagirov
authored
Miner actor submit window post v3 (#469)
Signed-off-by: Mikhail Tagirov <[email protected]>
1 parent 02c2dad commit 262a217

File tree

2 files changed

+120
-1
lines changed

2 files changed

+120
-1
lines changed

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

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include "vm/toolchain/toolchain.hpp"
1212

1313
namespace fc::vm::actor::builtin::v3::miner {
14+
using crypto::randomness::DomainSeparationTag;
15+
using crypto::randomness::kRandomnessLength;
1416
using states::makeEmptyMinerState;
1517
using states::MinerActorStatePtr;
1618
using toolchain::Toolchain;
@@ -69,6 +71,118 @@ namespace fc::vm::actor::builtin::v3::miner {
6971
return outcome::success();
7072
}
7173

74+
ACTOR_METHOD_IMPL(SubmitWindowedPoSt) {
75+
const auto current_epoch = runtime.getCurrentEpoch();
76+
77+
OUTCOME_TRY(
78+
runtime.validateArgument(params.deadline < kWPoStPeriodDeadlines));
79+
80+
OUTCOME_TRY(runtime.validateArgument(params.chain_commit_rand.size()
81+
<= kRandomnessLength));
82+
83+
const auto utils = Toolchain::createMinerUtils(runtime);
84+
85+
OUTCOME_TRY(state, runtime.getActorState<MinerActorStatePtr>());
86+
87+
OUTCOME_TRY(miner_info, state->getInfo());
88+
89+
auto callers = miner_info->control;
90+
callers.emplace_back(miner_info->owner);
91+
callers.emplace_back(miner_info->worker);
92+
OUTCOME_TRY(runtime.validateImmediateCallerIs(callers));
93+
94+
OUTCOME_TRY(runtime.validateArgument(params.proofs.size() == 1));
95+
OUTCOME_TRY(
96+
runtime.validateArgument(params.proofs[0].registered_proof
97+
== miner_info->window_post_proof_type));
98+
OUTCOME_TRY(runtime.validateArgument(params.proofs[0].proof.size()
99+
<= kMaxPoStProofSize));
100+
101+
const auto submission_partition_limit = utils->loadPartitionsSectorsMax(
102+
miner_info->window_post_partition_sectors);
103+
OUTCOME_TRY(runtime.validateArgument(params.partitions.size()
104+
<= submission_partition_limit));
105+
106+
const auto deadline_info = state->deadlineInfo(current_epoch);
107+
108+
if (!deadline_info.isOpen()) {
109+
ABORT(VMExitCode::kErrIllegalState);
110+
}
111+
112+
OUTCOME_TRY(
113+
runtime.validateArgument(params.deadline == deadline_info.index));
114+
115+
OUTCOME_TRY(runtime.validateArgument(params.chain_commit_epoch
116+
>= deadline_info.challenge));
117+
118+
OUTCOME_TRY(
119+
runtime.validateArgument(params.chain_commit_epoch < current_epoch));
120+
121+
OUTCOME_TRY(
122+
randomness,
123+
runtime.getRandomnessFromTickets(DomainSeparationTag::PoStChainCommit,
124+
params.chain_commit_epoch,
125+
{}));
126+
OUTCOME_TRY(
127+
runtime.validateArgument(randomness == params.chain_commit_rand));
128+
129+
REQUIRE_NO_ERROR_A(
130+
sectors, state->sectors.loadSectors(), VMExitCode::kErrIllegalState);
131+
132+
REQUIRE_NO_ERROR_A(
133+
deadlines, state->deadlines.get(), VMExitCode::kErrIllegalState);
134+
135+
REQUIRE_NO_ERROR_A(deadline,
136+
deadlines.loadDeadline(params.deadline),
137+
VMExitCode::kErrIllegalState);
138+
139+
const auto fault_expiration = deadline_info.last() + kFaultMaxAge;
140+
REQUIRE_NO_ERROR_A(post_result,
141+
deadline->recordProvenSectors(runtime,
142+
sectors,
143+
miner_info->sector_size,
144+
deadline_info.quant(),
145+
fault_expiration,
146+
params.partitions),
147+
VMExitCode::kErrIllegalState);
148+
149+
const auto proven_sectors =
150+
post_result.sectors - post_result.ignored_sectors;
151+
OUTCOME_TRY(runtime.validateArgument(!proven_sectors.empty()));
152+
153+
if (post_result.recovered_power.isZero()) {
154+
REQUIRE_NO_ERROR(deadline->optimistic_post_submissions.append(
155+
{post_result.partitions, params.proofs}),
156+
VMExitCode::kErrIllegalState);
157+
} else {
158+
REQUIRE_NO_ERROR_A(sector_infos,
159+
sectors.loadForProof(post_result.sectors,
160+
post_result.ignored_sectors),
161+
VMExitCode::kErrIllegalState);
162+
163+
OUTCOME_TRY(utils->verifyWindowedPost(
164+
deadline_info.challenge, sector_infos, params.proofs));
165+
}
166+
167+
REQUIRE_NO_ERROR(deadlines.updateDeadline(params.deadline, deadline),
168+
VMExitCode::kErrIllegalState);
169+
170+
REQUIRE_NO_ERROR(state->deadlines.set(deadlines),
171+
VMExitCode::kErrIllegalState);
172+
173+
OUTCOME_TRY(runtime.commitState(state));
174+
175+
OUTCOME_TRY(utils->requestUpdatePower(post_result.power_delta));
176+
177+
OUTCOME_TRYA(state, runtime.getActorState<MinerActorStatePtr>());
178+
179+
OUTCOME_TRY(balance, runtime.getCurrentBalance());
180+
REQUIRE_NO_ERROR(state->checkBalanceInvariants(balance),
181+
VMExitCode::kErrIllegalState);
182+
183+
return outcome::success();
184+
}
185+
72186
ACTOR_METHOD_IMPL(DisputeWindowedPoSt) {
73187
// TODO (a.chernyshov) FIL-342 implement
74188
return VMExitCode::kNotImplemented;

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,13 @@ namespace fc::vm::actor::builtin::v3::miner {
3737
using ChangeWorkerAddress = v2::miner::ChangeWorkerAddress;
3838
using ChangePeerId = v2::miner::ChangePeerId;
3939

40+
struct SubmitWindowedPoSt : ActorMethodBase<5> {
41+
using Params = v2::miner::SubmitWindowedPoSt::Params;
42+
43+
ACTOR_METHOD_DECL();
44+
};
45+
4046
// TODO implement
41-
using SubmitWindowedPoSt = v2::miner::SubmitWindowedPoSt;
4247
using PreCommitSector = v2::miner::PreCommitSector;
4348
using ProveCommitSector = v2::miner::ProveCommitSector;
4449
using ExtendSectorExpiration = v2::miner::ExtendSectorExpiration;

0 commit comments

Comments
 (0)