Skip to content

Commit 86234f0

Browse files
author
Mikhail Tagirov
authored
Miner actor submit window post v2 (#467)
Signed-off-by: Mikhail Tagirov <[email protected]>
1 parent ec6aa00 commit 86234f0

File tree

4 files changed

+131
-4
lines changed

4 files changed

+131
-4
lines changed

core/crypto/randomness/randomness_types.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ namespace fc::crypto::randomness {
1515
/// @brief randomness value type
1616
using Randomness = common::Hash256;
1717

18+
constexpr size_t kRandomnessLength = 32;
19+
1820
/// @brief domain separation tag enum
1921
enum class DomainSeparationTag : uint64_t {
2022
TicketProduction = 1,

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

Lines changed: 121 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,19 @@
66
#include "vm/actor/builtin/v2/miner/miner_actor.hpp"
77

88
#include "vm/actor/builtin/states/miner/miner_actor_state.hpp"
9-
#include "vm/actor/builtin/types/miner/policy.hpp"
10-
#include "vm/actor/builtin/v2/account/account_actor.hpp"
11-
#include "vm/actor/builtin/v2/storage_power/storage_power_actor.hpp"
9+
#include "vm/actor/builtin/types/miner/monies.hpp"
1210
#include "vm/toolchain/toolchain.hpp"
1311

1412
namespace fc::vm::actor::builtin::v2::miner {
13+
using crypto::randomness::DomainSeparationTag;
14+
using crypto::randomness::kRandomnessLength;
15+
using crypto::randomness::Randomness;
1516
using primitives::ChainEpoch;
1617
using primitives::RleBitset;
1718
using states::makeEmptyMinerState;
1819
using states::MinerActorStatePtr;
1920
using toolchain::Toolchain;
21+
using types::Universal;
2022
using namespace types::miner;
2123

2224
ACTOR_METHOD_IMPL(Construct) {
@@ -108,6 +110,122 @@ namespace fc::vm::actor::builtin::v2::miner {
108110
return outcome::success();
109111
}
110112

113+
ACTOR_METHOD_IMPL(SubmitWindowedPoSt) {
114+
const auto current_epoch = runtime.getCurrentEpoch();
115+
const auto network_version = runtime.getNetworkVersion();
116+
117+
OUTCOME_TRY(
118+
runtime.validateArgument(params.deadline < kWPoStPeriodDeadlines));
119+
120+
OUTCOME_TRY(runtime.validateArgument(params.chain_commit_rand.size()
121+
<= kRandomnessLength));
122+
123+
RleBitset partition_indexes;
124+
if (network_version >= NetworkVersion::kVersion7) {
125+
for (const auto &partition : params.partitions) {
126+
partition_indexes.insert(partition.index);
127+
}
128+
}
129+
130+
const auto utils = Toolchain::createMinerUtils(runtime);
131+
132+
OUTCOME_TRY(state, runtime.getActorState<MinerActorStatePtr>());
133+
134+
OUTCOME_TRY(miner_info, state->getInfo());
135+
136+
auto callers = miner_info->control;
137+
callers.emplace_back(miner_info->owner);
138+
callers.emplace_back(miner_info->worker);
139+
OUTCOME_TRY(runtime.validateImmediateCallerIs(callers));
140+
141+
OUTCOME_TRY(runtime.validateArgument(params.proofs.size() == 1));
142+
OUTCOME_TRY(
143+
runtime.validateArgument(params.proofs[0].registered_proof
144+
== miner_info->window_post_proof_type));
145+
146+
const auto submission_partition_limit = utils->loadPartitionsSectorsMax(
147+
miner_info->window_post_partition_sectors);
148+
OUTCOME_TRY(runtime.validateArgument(params.partitions.size()
149+
<= submission_partition_limit));
150+
151+
const auto deadline_info = state->deadlineInfo(current_epoch);
152+
153+
if (!deadline_info.isOpen()) {
154+
ABORT(VMExitCode::kErrIllegalState);
155+
}
156+
157+
OUTCOME_TRY(
158+
runtime.validateArgument(params.deadline == deadline_info.index));
159+
160+
OUTCOME_TRY(runtime.validateArgument(params.chain_commit_epoch
161+
>= deadline_info.challenge));
162+
163+
OUTCOME_TRY(
164+
runtime.validateArgument(params.chain_commit_epoch < current_epoch));
165+
166+
OUTCOME_TRY(
167+
randomness,
168+
runtime.getRandomnessFromTickets(DomainSeparationTag::PoStChainCommit,
169+
params.chain_commit_epoch,
170+
{}));
171+
OUTCOME_TRY(
172+
runtime.validateArgument(randomness == params.chain_commit_rand));
173+
174+
REQUIRE_NO_ERROR_A(
175+
sectors, state->sectors.loadSectors(), VMExitCode::kErrIllegalState);
176+
177+
REQUIRE_NO_ERROR_A(
178+
deadlines, state->deadlines.get(), VMExitCode::kErrIllegalState);
179+
180+
REQUIRE_NO_ERROR_A(deadline,
181+
deadlines.loadDeadline(params.deadline),
182+
VMExitCode::kErrIllegalState);
183+
184+
if (network_version >= NetworkVersion::kVersion7) {
185+
const auto already_proven =
186+
deadline->partitions_posted.intersect(partition_indexes);
187+
OUTCOME_TRY(runtime.validateArgument(already_proven.empty()));
188+
}
189+
190+
const auto fault_expiration = deadline_info.last() + kFaultMaxAge;
191+
REQUIRE_NO_ERROR_A(post_result,
192+
deadline->recordProvenSectors(runtime,
193+
sectors,
194+
miner_info->sector_size,
195+
deadline_info.quant(),
196+
fault_expiration,
197+
params.partitions),
198+
VMExitCode::kErrIllegalState);
199+
200+
REQUIRE_NO_ERROR_A(
201+
sector_infos,
202+
sectors.loadForProof(post_result.sectors, post_result.ignored_sectors),
203+
VMExitCode::kErrIllegalState);
204+
205+
OUTCOME_TRY(runtime.validateArgument(!sector_infos.empty()));
206+
207+
OUTCOME_TRY(utils->verifyWindowedPost(
208+
deadline_info.challenge, sector_infos, params.proofs));
209+
210+
REQUIRE_NO_ERROR(deadlines.updateDeadline(params.deadline, deadline),
211+
VMExitCode::kErrIllegalState);
212+
213+
REQUIRE_NO_ERROR(state->deadlines.set(deadlines),
214+
VMExitCode::kErrIllegalState);
215+
216+
OUTCOME_TRY(runtime.commitState(state));
217+
218+
OUTCOME_TRY(utils->requestUpdatePower(post_result.power_delta));
219+
220+
OUTCOME_TRYA(state, runtime.getActorState<MinerActorStatePtr>());
221+
222+
OUTCOME_TRY(balance, runtime.getCurrentBalance());
223+
REQUIRE_NO_ERROR(state->checkBalanceInvariants(balance),
224+
VMExitCode::kErrIllegalState);
225+
226+
return outcome::success();
227+
}
228+
111229
ACTOR_METHOD_IMPL(ApplyRewards) {
112230
// TODO (a.chernyshov) FIL-310 - implement
113231
return VMExitCode::kNotImplemented;

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,13 @@ namespace fc::vm::actor::builtin::v2::miner {
2626

2727
using ChangePeerId = v0::miner::ChangePeerId;
2828

29+
struct SubmitWindowedPoSt : ActorMethodBase<5> {
30+
using Params = v0::miner::SubmitWindowedPoSt::Params;
31+
32+
ACTOR_METHOD_DECL();
33+
};
34+
2935
// TODO implement
30-
using SubmitWindowedPoSt = v0::miner::SubmitWindowedPoSt;
3136
using PreCommitSector = v0::miner::PreCommitSector;
3237
using ProveCommitSector = v0::miner::ProveCommitSector;
3338
using ExtendSectorExpiration = v0::miner::ExtendSectorExpiration;

core/vm/actor/impl/invoker_impl.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ namespace fc::vm::actor {
8585
builtin::v2::miner::ChangePeerId::Number);
8686
ready_miner_actor_methods_v2.insert(
8787
builtin::v2::miner::ChangeWorkerAddress::Number);
88+
ready_miner_actor_methods_v2.insert(
89+
builtin::v2::miner::SubmitWindowedPoSt::Number);
8890
}
8991

9092
outcome::result<InvocationOutput> InvokerImpl::invoke(

0 commit comments

Comments
 (0)