Skip to content

Commit 5874a36

Browse files
authored
Verbose VMExitCode (#81)
Signed-off-by: turuslan <[email protected]>
1 parent 265a1e3 commit 5874a36

18 files changed

+119
-49
lines changed

core/vm/actor/account_actor.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55

66
#include "vm/actor/account_actor.hpp"
77

8+
#include "vm/exit_code/exit_code.hpp"
9+
810
namespace fc::vm::actor {
911
outcome::result<Actor> AccountActor::create(
1012
const std::shared_ptr<StateTree> &state_tree, const Address &address) {
1113
if (!address.isKeyType()) {
12-
return CREATE_WRONG_ADDRESS_TYPE;
14+
return VMExitCode::ACCOUNT_ACTOR_CREATE_WRONG_ADDRESS_TYPE;
1315
}
1416
Actor actor{kAccountCodeCid, ActorSubstateCID{kEmptyObjectCid}, 0, 0};
1517
if (address.getProtocol() == Protocol::BLS) {
@@ -28,11 +30,11 @@ namespace fc::vm::actor {
2830
}
2931
auto maybe_actor = state_tree->get(address);
3032
if (!maybe_actor) {
31-
return RESOLVE_NOT_FOUND;
33+
return VMExitCode::ACCOUNT_ACTOR_RESOLVE_NOT_FOUND;
3234
}
3335
auto actor = maybe_actor.value();
3436
if (actor.code != kAccountCodeCid) {
35-
return RESOLVE_NOT_ACCOUNT_ACTOR;
37+
return VMExitCode::ACCOUNT_ACTOR_RESOLVE_NOT_ACCOUNT_ACTOR;
3638
}
3739
OUTCOME_TRY(account_actor_state,
3840
state_tree->getStore()->getCbor<AccountActorState>(actor.head));

core/vm/actor/account_actor.hpp

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

99
#include "primitives/address/address_codec.hpp"
10-
#include "vm/exit_code/exit_code.hpp"
1110
#include "vm/state/state_tree.hpp"
1211

1312
namespace fc::vm::actor {
@@ -36,10 +35,6 @@ namespace fc::vm::actor {
3635

3736
/// Account actors represent actors without code
3837
struct AccountActor {
39-
static constexpr VMExitCode CREATE_WRONG_ADDRESS_TYPE{1};
40-
static constexpr VMExitCode RESOLVE_NOT_FOUND{1};
41-
static constexpr VMExitCode RESOLVE_NOT_ACCOUNT_ACTOR{1};
42-
4338
/// Create account actor from BLS or Secp256k1 address
4439
static outcome::result<Actor> create(
4540
const std::shared_ptr<StateTree> &state_tree, const Address &address);

core/vm/actor/actor_method.hpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,22 @@ namespace fc::vm::actor {
2626
/// Reserved method number for constructor
2727
constexpr MethodNumber kConstructorMethodNumber{1};
2828

29-
constexpr VMExitCode DECODE_ACTOR_PARAMS_ERROR{1};
30-
3129
/// Decode actor params, raises appropriate error
3230
template <typename T>
3331
outcome::result<T> decodeActorParams(gsl::span<const uint8_t> params_bytes) {
3432
auto maybe_params = codec::cbor::decode<T>(params_bytes);
3533
if (!maybe_params) {
36-
return DECODE_ACTOR_PARAMS_ERROR;
34+
return VMExitCode::DECODE_ACTOR_PARAMS_ERROR;
3735
}
3836
return maybe_params;
3937
}
4038

41-
constexpr VMExitCode ENCODE_ACTOR_PARAMS_ERROR{1};
42-
4339
/// Encode actor params, raises appropriate error
4440
template <typename T>
4541
outcome::result<std::vector<uint8_t>> encodeActorParams(const T &params) {
4642
auto maybe_bytes = codec::cbor::encode(params);
4743
if (!maybe_bytes) {
48-
return ENCODE_ACTOR_PARAMS_ERROR;
44+
return VMExitCode::ENCODE_ACTOR_PARAMS_ERROR;
4945
}
5046
return maybe_bytes;
5147
}

core/vm/actor/cron_actor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace fc::vm::actor::cron_actor {
1717
Runtime &runtime,
1818
const MethodParams &params) {
1919
if ((runtime.getMessage().get().from != kCronAddress)) {
20-
return cron_actor::WRONG_CALL;
20+
return VMExitCode::CRON_ACTOR_WRONG_CALL;
2121
}
2222

2323
for (const auto &entry : entries) {

core/vm/actor/cron_actor.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ namespace fc::vm::actor::cron_actor {
1616
};
1717

1818
constexpr MethodNumber kEpochTickMethodNumber{2};
19-
constexpr VMExitCode WRONG_CALL{1};
2019

2120
/**
2221
* @brief EpochTick executes built-in periodic actions, run at every Epoch.

core/vm/actor/impl/invoker_impl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ namespace fc::vm::actor {
2323
MethodNumber method,
2424
const MethodParams &params) {
2525
if (actor.code == actor::kAccountCodeCid) {
26-
return CANT_INVOKE_ACCOUNT_ACTOR;
26+
return VMExitCode::INVOKER_CANT_INVOKE_ACCOUNT_ACTOR;
2727
}
2828
auto maybe_builtin_actor = builtin_.find(actor.code);
2929
if (maybe_builtin_actor == builtin_.end()) {
30-
return NO_CODE_OR_METHOD;
30+
return VMExitCode::INVOKER_NO_CODE_OR_METHOD;
3131
}
3232
auto builtin_actor = maybe_builtin_actor->second;
3333
auto maybe_builtin_method = builtin_actor.find(method);
3434
if (maybe_builtin_method == builtin_actor.end()) {
35-
return NO_CODE_OR_METHOD;
35+
return VMExitCode::INVOKER_NO_CODE_OR_METHOD;
3636
}
3737
return maybe_builtin_method->second(actor, runtime, params);
3838
}

core/vm/actor/impl/invoker_impl.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ namespace fc::vm::actor {
1717
/// Finds and loads actor code, invokes actor methods
1818
class InvokerImpl : public Invoker {
1919
public:
20-
static constexpr VMExitCode CANT_INVOKE_ACCOUNT_ACTOR{254};
21-
static constexpr VMExitCode NO_CODE_OR_METHOD{255};
22-
2320
InvokerImpl();
2421
~InvokerImpl() override = default;
2522
outcome::result<InvocationOutput> invoke(

core/vm/actor/init_actor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ namespace fc::vm::actor::init_actor {
2626
const MethodParams &params) {
2727
OUTCOME_TRY(exec_params, decodeActorParams<ExecParams>(params));
2828
if (!isBuiltinActor(exec_params.code)) {
29-
return init_actor::NOT_BUILTIN_ACTOR;
29+
return VMExitCode::INIT_ACTOR_NOT_BUILTIN_ACTOR;
3030
}
3131
if (isSingletonActor(exec_params.code)) {
32-
return init_actor::SINGLETON_ACTOR;
32+
return VMExitCode::INIT_ACTOR_SINGLETON_ACTOR;
3333
}
3434
OUTCOME_TRY(runtime.chargeGas(runtime::kInitActorExecCost));
3535
auto &message = runtime.getMessage().get();

core/vm/actor/init_actor.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ namespace fc::vm::actor::init_actor {
3838
}
3939

4040
constexpr MethodNumber kExecMethodNumber{2};
41-
constexpr VMExitCode NOT_BUILTIN_ACTOR{1};
42-
constexpr VMExitCode SINGLETON_ACTOR{1};
4341

4442
struct ExecParams {
4543
CodeId code;

core/vm/actor/storage_power_actor.cpp

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

88
#include "power/impl/power_table_impl.hpp"
9+
#include "vm/exit_code/exit_code.hpp"
910
#include "vm/indices/indices.hpp"
1011

1112
namespace fc::vm::actor {
@@ -21,7 +22,9 @@ namespace fc::vm::actor {
2122
const crypto::randomness::Randomness &randomness) {
2223
std::vector<primitives::address::Address> selected_miners;
2324

24-
if (power_table_->getSize() < challenge_count) return OUT_OF_BOUND;
25+
if (power_table_->getSize() < challenge_count) {
26+
return VMExitCode::STORAGE_POWER_ACTOR_OUT_OF_BOUND;
27+
}
2528

2629
OUTCOME_TRY(all_miners, power_table_->getMiners());
2730

@@ -181,7 +184,9 @@ namespace fc::vm::actor {
181184
outcome::result<void> StoragePowerActor::addMiner(
182185
const primitives::address::Address &miner_addr) {
183186
auto check = power_table_->getMinerPower(miner_addr);
184-
if (!check.has_error()) return ALREADY_EXISTS;
187+
if (!check.has_error()) {
188+
return VMExitCode::STORAGE_POWER_ACTOR_ALREADY_EXISTS;
189+
}
185190

186191
OUTCOME_TRY(power_table_->setMinerPower(miner_addr, 0));
187192
OUTCOME_TRY(nominal_power_->setMinerPower(miner_addr, 0));

0 commit comments

Comments
 (0)