|
6 | 6 | #include "vm/actor/builtin/v2/miner/miner_actor.hpp"
|
7 | 7 |
|
8 | 8 | #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" |
12 | 10 | #include "vm/toolchain/toolchain.hpp"
|
13 | 11 |
|
14 | 12 | namespace fc::vm::actor::builtin::v2::miner {
|
| 13 | + using crypto::randomness::DomainSeparationTag; |
| 14 | + using crypto::randomness::kRandomnessLength; |
| 15 | + using crypto::randomness::Randomness; |
15 | 16 | using primitives::ChainEpoch;
|
16 | 17 | using primitives::RleBitset;
|
17 | 18 | using states::makeEmptyMinerState;
|
18 | 19 | using states::MinerActorStatePtr;
|
19 | 20 | using toolchain::Toolchain;
|
| 21 | + using types::Universal; |
20 | 22 | using namespace types::miner;
|
21 | 23 |
|
22 | 24 | ACTOR_METHOD_IMPL(Construct) {
|
@@ -108,6 +110,122 @@ namespace fc::vm::actor::builtin::v2::miner {
|
108 | 110 | return outcome::success();
|
109 | 111 | }
|
110 | 112 |
|
| 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 | + |
111 | 229 | ACTOR_METHOD_IMPL(ApplyRewards) {
|
112 | 230 | // TODO (a.chernyshov) FIL-310 - implement
|
113 | 231 | return VMExitCode::kNotImplemented;
|
|
0 commit comments