Skip to content

Commit 6b40763

Browse files
author
Mikhail Tagirov
authored
Miner actor submit window post test (#472)
Signed-off-by: Mikhail Tagirov <[email protected]>
1 parent 399ec86 commit 6b40763

35 files changed

+1576
-421
lines changed

core/vm/actor/builtin/states/miner/miner_actor_state.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,9 @@ namespace fc::vm::actor::builtin::states {
496496

497497
OUTCOME_TRY(deadlines, makeEmptyDeadlines(runtime, kEmptyObjectCid));
498498
OUTCOME_TRY(state->deadlines.set(deadlines));
499+
500+
VestingFunds vesting_funds;
501+
OUTCOME_TRY(state->vesting_funds.set(vesting_funds));
499502
}
500503

501504
return state;

core/vm/actor/builtin/types/miner/miner_info.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,18 @@ namespace fc::vm::actor::builtin::types::miner {
1919
const std::vector<Multiaddress> &multiaddrs,
2020
const RegisteredSealProof &seal_proof_type,
2121
const RegisteredPoStProof &window_post_proof_type) {
22-
OUTCOME_TRY(sector_size, getSectorSize(seal_proof_type));
23-
OUTCOME_TRY(partition_sectors,
24-
getSealProofWindowPoStPartitionSectors(seal_proof_type));
22+
SectorSize sector_size = 0;
23+
size_t partition_sectors = 0;
24+
25+
if (version < ActorVersion::kVersion3) {
26+
OUTCOME_TRYA(sector_size, getSectorSize(seal_proof_type));
27+
OUTCOME_TRYA(partition_sectors,
28+
getSealProofWindowPoStPartitionSectors(seal_proof_type));
29+
} else {
30+
OUTCOME_TRYA(sector_size, getSectorSize(window_post_proof_type));
31+
OUTCOME_TRYA(partition_sectors,
32+
getWindowPoStPartitionSectors(window_post_proof_type));
33+
}
2534

2635
Universal<MinerInfo> miner_info{version};
2736

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ namespace fc::vm::actor::builtin::types::miner {
106106
&& consensus_fault_elapsed == other.consensus_fault_elapsed
107107
&& pending_owner_address == other.pending_owner_address;
108108
}
109+
110+
inline bool operator!=(const MinerInfo &other) const {
111+
return !(*this == other);
112+
}
109113
};
110114

111115
outcome::result<Universal<MinerInfo>> makeMinerInfo(

core/vm/actor/builtin/types/miner/v3/miner_info.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ namespace fc::vm::actor::builtin::v3::miner {
2222
multiaddrs,
2323
window_post_proof_type,
2424
sector_size,
25-
window_post_partition_sectors)
25+
window_post_partition_sectors,
26+
consensus_fault_elapsed,
27+
pending_owner_address)
2628

2729
} // namespace fc::vm::actor::builtin::v3::miner

core/vm/actor/builtin/utils/miner_actor_utils.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ namespace fc::vm::actor::builtin::utils {
5151

5252
inline uint64_t loadPartitionsSectorsMax(
5353
uint64_t partition_sector_count) const {
54+
if (partition_sector_count == 0) {
55+
return 0;
56+
}
5457
return std::min(
5558
types::miner::kAddressedSectorsMax / partition_sector_count,
5659
getAddressedPartitionsMax());

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "vm/actor/builtin/v2/miner/miner_actor_utils.hpp"
77

88
#include "vm/actor/builtin/v2/account/account_actor.hpp"
9+
#include "vm/actor/builtin/v2/reward/reward_actor.hpp"
910
#include "vm/actor/builtin/v2/storage_power/storage_power_actor.hpp"
1011

1112
namespace fc::vm::actor::builtin::v2::miner {
@@ -79,6 +80,37 @@ namespace fc::vm::actor::builtin::v2::miner {
7980
<= kMaxControlAddresses);
8081
}
8182

83+
outcome::result<EpochReward> MinerUtils::requestCurrentEpochBlockReward()
84+
const {
85+
REQUIRE_SUCCESS_A(
86+
reward,
87+
getRuntime().sendM<reward::ThisEpochReward>(kRewardAddress, {}, 0));
88+
return EpochReward{
89+
.this_epoch_reward = 0,
90+
.this_epoch_reward_smoothed = reward.this_epoch_reward_smoothed,
91+
.this_epoch_baseline_power = reward.this_epoch_baseline_power};
92+
}
93+
94+
outcome::result<TotalPower> MinerUtils::requestCurrentTotalPower() const {
95+
REQUIRE_SUCCESS_A(power,
96+
getRuntime().sendM<storage_power::CurrentTotalPower>(
97+
kStoragePowerAddress, {}, 0));
98+
return TotalPower{
99+
.raw_byte_power = power.raw_byte_power,
100+
.quality_adj_power = power.quality_adj_power,
101+
.pledge_collateral = power.pledge_collateral,
102+
.quality_adj_power_smoothed = power.quality_adj_power_smoothed};
103+
}
104+
105+
outcome::result<void> MinerUtils::notifyPledgeChanged(
106+
const TokenAmount &pledge_delta) const {
107+
if (pledge_delta != 0) {
108+
REQUIRE_SUCCESS(getRuntime().sendM<storage_power::UpdatePledgeTotal>(
109+
kStoragePowerAddress, pledge_delta, 0));
110+
}
111+
return outcome::success();
112+
}
113+
82114
outcome::result<Address> MinerUtils::getPubkeyAddressFromAccountActor(
83115
const Address &address) const {
84116
return getRuntime().sendM<account::PubkeyAddress>(address, {}, 0);

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ namespace fc::vm::actor::builtin::v2::miner {
1515
using primitives::sector::RegisteredSealProof;
1616
using runtime::Runtime;
1717
using types::miner::CronEventPayload;
18+
using types::miner::EpochReward;
1819
using types::miner::PowerPair;
20+
using types::miner::TotalPower;
1921
using version::NetworkVersion;
2022

2123
class MinerUtils : public v0::miner::MinerUtils {
@@ -44,6 +46,14 @@ namespace fc::vm::actor::builtin::v2::miner {
4446
outcome::result<void> checkControlAddresses(
4547
const std::vector<Address> &control_addresses) const override;
4648

49+
outcome::result<EpochReward> requestCurrentEpochBlockReward()
50+
const override;
51+
52+
outcome::result<TotalPower> requestCurrentTotalPower() const override;
53+
54+
outcome::result<void> notifyPledgeChanged(
55+
const TokenAmount &pledge_delta) const override;
56+
4757
protected:
4858
outcome::result<Address> getPubkeyAddressFromAccountActor(
4959
const Address &address) const override;

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "vm/actor/builtin/v3/miner/miner_actor_utils.hpp"
77

88
#include "vm/actor/builtin/v3/account/account_actor.hpp"
9+
#include "vm/actor/builtin/v3/reward/reward_actor.hpp"
910
#include "vm/actor/builtin/v3/storage_power/storage_power_actor.hpp"
1011

1112
namespace fc::vm::actor::builtin::v3::miner {
@@ -17,6 +18,37 @@ namespace fc::vm::actor::builtin::v3::miner {
1718
return outcome::success();
1819
}
1920

21+
outcome::result<EpochReward> MinerUtils::requestCurrentEpochBlockReward()
22+
const {
23+
REQUIRE_SUCCESS_A(
24+
reward,
25+
getRuntime().sendM<reward::ThisEpochReward>(kRewardAddress, {}, 0));
26+
return EpochReward{
27+
.this_epoch_reward = 0,
28+
.this_epoch_reward_smoothed = reward.this_epoch_reward_smoothed,
29+
.this_epoch_baseline_power = reward.this_epoch_baseline_power};
30+
}
31+
32+
outcome::result<TotalPower> MinerUtils::requestCurrentTotalPower() const {
33+
REQUIRE_SUCCESS_A(power,
34+
getRuntime().sendM<storage_power::CurrentTotalPower>(
35+
kStoragePowerAddress, {}, 0));
36+
return TotalPower{
37+
.raw_byte_power = power.raw_byte_power,
38+
.quality_adj_power = power.quality_adj_power,
39+
.pledge_collateral = power.pledge_collateral,
40+
.quality_adj_power_smoothed = power.quality_adj_power_smoothed};
41+
}
42+
43+
outcome::result<void> MinerUtils::notifyPledgeChanged(
44+
const TokenAmount &pledge_delta) const {
45+
if (pledge_delta != 0) {
46+
REQUIRE_SUCCESS(getRuntime().sendM<storage_power::UpdatePledgeTotal>(
47+
kStoragePowerAddress, pledge_delta, 0));
48+
}
49+
return outcome::success();
50+
}
51+
2052
outcome::result<Address> MinerUtils::getPubkeyAddressFromAccountActor(
2153
const Address &address) const {
2254
return getRuntime().sendM<account::PubkeyAddress>(address, {}, 0);

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ namespace fc::vm::actor::builtin::v3::miner {
1515
using primitives::sector::RegisteredSealProof;
1616
using runtime::Runtime;
1717
using types::miner::CronEventPayload;
18+
using types::miner::EpochReward;
1819
using types::miner::PowerPair;
20+
using types::miner::TotalPower;
1921
using version::NetworkVersion;
2022

2123
class MinerUtils : public v2::miner::MinerUtils {
@@ -26,6 +28,14 @@ namespace fc::vm::actor::builtin::v3::miner {
2628
RegisteredSealProof seal_proof_type,
2729
NetworkVersion network_version) const override;
2830

31+
outcome::result<EpochReward> requestCurrentEpochBlockReward()
32+
const override;
33+
34+
outcome::result<TotalPower> requestCurrentTotalPower() const override;
35+
36+
outcome::result<void> notifyPledgeChanged(
37+
const TokenAmount &pledge_delta) const override;
38+
2939
protected:
3040
outcome::result<Address> getPubkeyAddressFromAccountActor(
3141
const Address &address) const override;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Copyright Soramitsu Co., Ltd. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#pragma once
7+
8+
#include "vm/actor/builtin/v2/reward/reward_actor.hpp"
9+
10+
namespace fc::vm::actor::builtin::v3::reward {
11+
12+
// TODO (m.tagirov) implement v3
13+
using Constructor = v2::reward::Constructor;
14+
using AwardBlockReward = v2::reward::AwardBlockReward;
15+
using ThisEpochReward = v2::reward::ThisEpochReward;
16+
using UpdateNetworkKPI = v2::reward::UpdateNetworkKPI;
17+
18+
} // namespace fc::vm::actor::builtin::v3::reward

0 commit comments

Comments
 (0)