Skip to content

Commit c87d495

Browse files
Feature/runtime (#65)
Signed-off-by: Alexey-N-Chernyshov <[email protected]>
1 parent 38aa0db commit c87d495

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1395
-202
lines changed

core/primitives/address/address.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ namespace fc::primitives::address {
5353
&& lhs.data == rhs.data;
5454
}
5555

56+
bool operator!=(const Address &lhs, const Address &rhs) {
57+
return !(lhs == rhs);
58+
}
59+
5660
bool operator<(const Address &lhs, const Address &rhs) {
5761
return lhs.network < rhs.network
5862
|| (lhs.network == rhs.network

core/primitives/address/address.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ namespace fc::primitives::address {
7777
*/
7878
bool operator==(const Address &lhs, const Address &rhs);
7979

80+
/**
81+
* @brief Addresses not equality operator
82+
*/
83+
bool operator!=(const Address &lhs, const Address &rhs);
84+
8085
/**
8186
* @brief Addresses "less than" operator
8287
*/

core/primitives/big_int.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ namespace fc::primitives {
2121
using cpp_int::cpp_int;
2222
};
2323

24+
static inline BigInt operator*(const BigInt &lhs, const BigInt &rhs) {
25+
return static_cast<cpp_int>(lhs) * static_cast<cpp_int>(rhs);
26+
}
27+
28+
static inline BigInt operator*(const unsigned long &lhs, const BigInt &rhs) {
29+
return static_cast<cpp_int>(lhs) * static_cast<cpp_int>(rhs);
30+
}
31+
2432
static inline BigInt operator+(const BigInt &lhs, const BigInt &rhs) {
2533
return static_cast<cpp_int>(lhs) + static_cast<cpp_int>(rhs);
2634
}

core/vm/CMakeLists.txt

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

66
add_subdirectory(actor)
77
add_subdirectory(exit_code)
8+
add_subdirectory(indices)
9+
add_subdirectory(runtime)
810
add_subdirectory(state)
911
add_subdirectory(message)

core/vm/actor/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ add_library(actor
88
actor.cpp
99
init_actor.cpp
1010
cron_actor.cpp
11+
impl/invoker_impl.cpp
1112
storage_power_actor.cpp
12-
invoker.cpp
1313
)
14-
1514
target_link_libraries(actor
1615
address
1716
cid

core/vm/actor/actor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <libp2p/crypto/sha/sha256.hpp>
1212

1313
namespace fc::vm::actor {
14+
1415
bool operator==(const Actor &lhs, const Actor &rhs) {
1516
return lhs.code == rhs.code && lhs.head == rhs.head
1617
&& lhs.nonce == rhs.nonce && lhs.balance == rhs.balance;

core/vm/actor/actor.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ namespace fc::vm::actor {
3232
inline bool operator==(const MethodNumber &other) const {
3333
return method_number == other.method_number;
3434
}
35+
36+
inline bool operator<(const MethodNumber &other) const {
37+
return method_number < other.method_number;
38+
}
3539
};
3640

3741
template <class Stream,

core/vm/actor/actor_method.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@
77
#define CPP_FILECOIN_CORE_VM_ACTOR_ACTOR_METHOD_HPP
88

99
#include "codec/cbor/cbor.hpp"
10-
#include "common/buffer.hpp"
1110
#include "common/outcome.hpp"
1211
#include "vm/actor/actor.hpp"
1312
#include "vm/exit_code/exit_code.hpp"
14-
#include "vm/vm_context.hpp"
13+
#include "vm/runtime/runtime.hpp"
1514

1615
namespace fc::vm::actor {
17-
using common::Buffer;
16+
using runtime::InvocationOutput;
17+
using runtime::Runtime;
1818

1919
/// Actor method signature
20-
using ActorMethod = std::function<outcome::result<Buffer>(
21-
const Actor &, VMContext &, gsl::span<const uint8_t>)>;
20+
using ActorMethod = std::function<outcome::result<InvocationOutput>(
21+
const Actor &, Runtime &, const MethodParams &)>;
2222

2323
/// Actor methods exported by number
24-
using ActorExports = std::map<uint64_t, ActorMethod>;
24+
using ActorExports = std::map<MethodNumber, ActorMethod>;
2525

2626
constexpr VMExitCode DECODE_ACTOR_PARAMS_ERROR{1};
2727

core/vm/actor/cron_actor.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,29 @@
66
#include "vm/actor/cron_actor.hpp"
77

88
namespace fc::vm::actor {
9+
10+
using vm::actor::MethodNumber;
11+
using vm::runtime::InvocationOutput;
12+
using vm::runtime::Runtime;
13+
14+
constexpr MethodNumber kEpochTickMethodNumber{2};
15+
916
std::vector<CronTableEntry> CronActor::entries = {
1017
{kStoragePowerAddress, SpaMethods::CHECK_PROOF_SUBMISSIONS}};
1118

12-
outcome::result<Buffer> CronActor::epochTick(
13-
const Actor &actor,
14-
vm::VMContext &vmctx,
15-
gsl::span<const uint8_t> params) {
16-
if (!(vmctx.message().from == kCronAddress)) {
19+
outcome::result<InvocationOutput> CronActor::epochTick(
20+
const Actor &actor, Runtime &runtime, const MethodParams &params) {
21+
if ((runtime.getMessage()->from != kCronAddress)) {
1722
return WRONG_CALL;
1823
}
1924

2025
for (const auto &entry : entries) {
21-
OUTCOME_TRY(vmctx.send(entry.to_addr, entry.method_num, BigInt(0), {}));
26+
OUTCOME_TRY(runtime.send(entry.to_addr, entry.method_num, {}, BigInt(0)));
2227
}
2328
return outcome::success();
2429
}
2530

2631
ActorExports CronActor::exports = {
27-
{2, ActorMethod(CronActor::epochTick)},
32+
{kEpochTickMethodNumber, ActorMethod(CronActor::epochTick)},
2833
};
2934
} // namespace fc::vm::actor

core/vm/actor/cron_actor.hpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@
1111

1212
namespace fc::vm::actor {
1313

14+
using runtime::InvocationOutput;
15+
using runtime::Runtime;
16+
1417
struct CronTableEntry {
1518
Address to_addr;
16-
uint64_t method_num{};
19+
MethodNumber method_num{};
1720
};
1821

1922
struct CronActor {
@@ -28,13 +31,12 @@ namespace fc::vm::actor {
2831
/**
2932
* @brief EpochTick executes built-in periodic actions, run at every Epoch.
3033
* @param actor from Lotus(doesn't use)
31-
* @param vmctx is virtual machine context
34+
* @param runtime is virtual machine context
3235
* @param params from Lotus(doesn't use)
3336
* @return success or error
3437
*/
35-
static outcome::result<Buffer> epochTick(const Actor &actor,
36-
VMContext &vmctx,
37-
gsl::span<const uint8_t> params);
38+
static outcome::result<InvocationOutput> epochTick(
39+
const Actor &actor, Runtime &runtime, const MethodParams &params);
3840

3941
static ActorExports exports;
4042
};

0 commit comments

Comments
 (0)