Skip to content

Commit 8421ed5

Browse files
StoragePowerActor - 0-2 methods (#106)
Signed-off-by: Alexey-N-Chernyshov <[email protected]>
1 parent 726eeef commit 8421ed5

22 files changed

+911
-277
lines changed

core/adt/impl/balance_table_hamt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ using fc::primitives::address::encodeToByteString;
1212

1313
BalanceTableHamt::BalanceTableHamt(std::shared_ptr<IpfsDatastore> datastore,
1414
const CID &new_root)
15-
: root{new_root}, hamt_{datastore} {}
15+
: root{new_root}, hamt_{datastore, new_root} {}
1616

1717
fc::outcome::result<TokenAmount> BalanceTableHamt::get(
1818
const Address &key) const {

core/vm/actor/builtin/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ add_subdirectory(miner)
1010
add_subdirectory(multisig)
1111
add_subdirectory(payment_channel)
1212
add_subdirectory(reward)
13+
add_subdirectory(shared)
1314
add_subdirectory(storage_power)

core/vm/actor/builtin/cron/cron_actor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
*/
55

66
#include "vm/actor/builtin/cron/cron_actor.hpp"
7+
#include "vm/actor/builtin/storage_power/storage_power_actor_export.hpp"
78

89
namespace fc::vm::actor::builtin::cron {
910
/**
1011
* Entries is a set of actors (and corresponding methods) to call during
1112
* EpochTick
1213
*/
1314
std::vector<CronTableEntry> entries = {
14-
{kStoragePowerAddress,
15-
{storage_power::SpaMethods::CHECK_PROOF_SUBMISSIONS}}};
15+
{kStoragePowerAddress, {storage_power::kOnEpochTickEndMethodNumber}}};
1616

1717
outcome::result<InvocationOutput> epochTick(const Actor &actor,
1818
Runtime &runtime,

core/vm/actor/builtin/cron/cron_actor.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#define CPP_FILECOIN_CORE_VM_ACTOR_CRON_ACTOR_HPP
88

99
#include "vm/actor/actor_method.hpp"
10-
#include "vm/actor/builtin/storage_power/storage_power_actor_state.hpp"
1110

1211
namespace fc::vm::actor::builtin::cron {
1312

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,24 @@
66
#ifndef CPP_FILECOIN_CORE_VM_ACTOR_BUILTIN_MINER_MINER_ACTOR_HPP
77
#define CPP_FILECOIN_CORE_VM_ACTOR_BUILTIN_MINER_MINER_ACTOR_HPP
88

9-
#include "vm/actor/actor_method.hpp"
9+
#include "codec/cbor/streams_annotation.hpp"
10+
#include "primitives/address/address.hpp"
11+
#include "primitives/address/address_codec.hpp"
12+
#include "vm/actor/actor.hpp"
1013
#include "vm/actor/builtin/miner/types.hpp"
1114

1215
namespace fc::vm::actor::builtin::miner {
16+
17+
constexpr MethodNumber kGetControlAddresses{2};
1318
constexpr MethodNumber kSubmitElectionPoStMethodNumber{20};
19+
20+
struct GetControlAddressesReturn {
21+
Address owner;
22+
Address worker;
23+
};
24+
25+
CBOR_TUPLE(GetControlAddressesReturn, owner, worker);
26+
1427
} // namespace fc::vm::actor::builtin::miner
1528

1629
#endif // CPP_FILECOIN_CORE_VM_ACTOR_BUILTIN_MINER_MINER_ACTOR_HPP

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include "primitives/address/address_codec.hpp"
1212
#include "primitives/big_int.hpp"
13+
#include "primitives/chain_epoch/chain_epoch.hpp"
1314
#include "primitives/rle_bitset/rle_bitset.hpp"
1415
#include "proofs/proofs.hpp"
1516

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#
2+
# Copyright Soramitsu Co., Ltd. All Rights Reserved.
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
6+
add_library(builtin_shared
7+
shared.cpp
8+
)
9+
target_link_libraries(builtin_shared
10+
actor
11+
address
12+
runtime
13+
)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Copyright Soramitsu Co., Ltd. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include "vm/actor/builtin/shared/shared.hpp"
7+
#include "adt/balance_table_hamt.hpp"
8+
#include "codec/cbor/cbor.hpp"
9+
10+
namespace fc::vm::actor::builtin {
11+
12+
using adt::TokenAmount;
13+
using power::Address;
14+
using miner::kGetControlAddresses;
15+
using runtime::Runtime;
16+
using codec::cbor::decode;
17+
18+
fc::outcome::result<GetControlAddressesReturn> requestMinerControlAddress(
19+
Runtime &runtime, const Address &miner) {
20+
OUTCOME_TRY(result,
21+
runtime.send(miner, kGetControlAddresses, {}, TokenAmount{0}));
22+
OUTCOME_TRY(addresses, decode<GetControlAddressesReturn>(result.return_value.toVector()));
23+
return std::move(addresses);
24+
}
25+
26+
} // namespace fc::vm::actor::builtin
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Copyright Soramitsu Co., Ltd. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#ifndef CPP_FILECOIN_SHARED_HPP
7+
#define CPP_FILECOIN_SHARED_HPP
8+
9+
#include "primitives/address/address.hpp"
10+
#include "vm/actor/builtin/miner/miner_actor.hpp"
11+
#include "vm/runtime/runtime.hpp"
12+
13+
/**
14+
* Code shared by multiple built-in actors
15+
*/
16+
17+
namespace fc::vm::actor::builtin {
18+
19+
using miner::GetControlAddressesReturn;
20+
using runtime::Runtime;
21+
22+
/**
23+
* Get worker address
24+
* @param runtime
25+
* @param miner
26+
* @return
27+
*/
28+
fc::outcome::result<GetControlAddressesReturn> requestMinerControlAddress(
29+
Runtime &runtime, const Address &miner);
30+
} // namespace fc::vm::actor::builtin
31+
32+
#endif // CPP_FILECOIN_SHARED_HPP

core/vm/actor/builtin/storage_power/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55

66
add_library(storage_power_actor
77
storage_power_actor_state.cpp
8+
storage_power_actor_export.cpp
89
)
910
target_link_libraries(storage_power_actor
1011
actor
12+
builtin_shared
1113
chain_epoch_codec
1214
balance_table_hamt
1315
hamt

0 commit comments

Comments
 (0)