|
11 | 11 | #include "vm/toolchain/toolchain.hpp"
|
12 | 12 |
|
13 | 13 | namespace fc::vm::actor::builtin::v3::miner {
|
| 14 | + using crypto::randomness::DomainSeparationTag; |
| 15 | + using crypto::randomness::kRandomnessLength; |
14 | 16 | using states::makeEmptyMinerState;
|
15 | 17 | using states::MinerActorStatePtr;
|
16 | 18 | using toolchain::Toolchain;
|
@@ -69,6 +71,118 @@ namespace fc::vm::actor::builtin::v3::miner {
|
69 | 71 | return outcome::success();
|
70 | 72 | }
|
71 | 73 |
|
| 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 | + |
72 | 186 | ACTOR_METHOD_IMPL(DisputeWindowedPoSt) {
|
73 | 187 | // TODO (a.chernyshov) FIL-342 implement
|
74 | 188 | return VMExitCode::kNotImplemented;
|
|
0 commit comments