Skip to content

Commit

Permalink
Do not reset time cap on inner calls
Browse files Browse the repository at this point in the history
  • Loading branch information
achamayou committed Oct 13, 2023
1 parent f1ccfb9 commit c55063a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/apps/js_generic/js_generic_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ namespace ccfapp
// Call exported function
auto request = create_request_obj(endpoint, endpoint_ctx, ctx);

auto val = ctx.call(export_func, {request}, &endpoint_ctx.tx);
auto val = ctx.call_with_rt_options(export_func, {request}, &endpoint_ctx.tx);

if (JS_IsException(val))
{
Expand Down
28 changes: 18 additions & 10 deletions src/js/wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ namespace ccf::js
}
}

JSWrappedValue Context::call(
JSWrappedValue Context::call_with_rt_options(
const JSWrappedValue& f,
const std::vector<js::JSWrappedValue>& argv,
kv::Tx* tx)
Expand All @@ -148,24 +148,32 @@ namespace ccf::js
{
argvn.push_back(a.val);
}
if (tx != nullptr)
{
rt.set_runtime_options(tx);
}
rt.set_runtime_options(tx);
const auto curr_time = ccf::get_enclave_time();
interrupt_data.start_time = curr_time;
interrupt_data.max_execution_time = rt.get_max_exec_time();
interrupt_data.access = access;
JS_SetInterruptHandler(rt, js_custom_interrupt_handler, &interrupt_data);

const auto rv = W(JS_Call(
ctx, f, ccf::js::constants::Undefined, argv.size(), argvn.data()));
if (tx != nullptr)
rt.reset_runtime_options();

return rv;
}

JSWrappedValue Context::inner_call(
const JSWrappedValue& f,
const std::vector<js::JSWrappedValue>& argv)
{
std::vector<JSValue> argvn;
argvn.reserve(argv.size());
for (auto& a : argv)
{
rt.reset_runtime_options();
argvn.push_back(a.val);
}

return rv;
return W(JS_Call(
ctx, f, ccf::js::constants::Undefined, argv.size(), argvn.data()));
}

Runtime::Runtime()
Expand Down Expand Up @@ -400,7 +408,7 @@ namespace ccf::js
jsctx.new_array_buffer_copy(k.data(), k.size()),
obj};

auto val = jsctx.call(func, args, nullptr);
auto val = jsctx.inner_call(func, args);

if (JS_IsException(val))
{
Expand Down
6 changes: 5 additions & 1 deletion src/js/wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -518,11 +518,15 @@ namespace ccf::js
return W(JS_GetException(ctx));
}

JSWrappedValue call(
JSWrappedValue call_with_rt_options(
const JSWrappedValue& f,
const std::vector<js::JSWrappedValue>& argv,
kv::Tx* tx);

JSWrappedValue inner_call(
const JSWrappedValue& f,
const std::vector<js::JSWrappedValue>& argv);

JSWrappedValue parse_json(const nlohmann::json& j) const
{
const auto buf = j.dump();
Expand Down
8 changes: 4 additions & 4 deletions src/node/gov/handlers/proposals.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ namespace ccf::gov::endpoints
proposal_info.proposer_id.data(),
proposal_info.proposer_id.size())};

auto val = js_context.call(ballot_func, argv, &tx);
auto val = js_context.call_with_rt_options(ballot_func, argv, &tx);

if (!JS_IsException(val))
{
Expand Down Expand Up @@ -212,7 +212,7 @@ namespace ccf::gov::endpoints
}
argv.push_back(vs);

auto val = js_context.call(resolve_func, argv, &tx);
auto val = js_context.call_with_rt_options(resolve_func, argv, &tx);

if (JS_IsException(val))
{
Expand Down Expand Up @@ -290,7 +290,7 @@ namespace ccf::gov::endpoints
js_context.new_string_len(
proposal_id.c_str(), proposal_id.size())};

auto val = js_context.call(apply_func, argv, &tx);
auto val = js_context.call_with_rt_options(apply_func, argv, &tx);

if (JS_IsException(val))
{
Expand Down Expand Up @@ -448,7 +448,7 @@ namespace ccf::gov::endpoints
auto proposal_arg = context.new_string_len(
(const char*)proposal_body.data(), proposal_body.size());
auto validate_result =
context.call(validate_func, {proposal_arg}, &ctx.tx);
context.call_with_rt_options(validate_func, {proposal_arg}, &ctx.tx);

// Handle error cases of validation
{
Expand Down
8 changes: 4 additions & 4 deletions src/node/rpc/member_frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ namespace ccf
context.new_string_len(
pi_->proposer_id.data(), pi_->proposer_id.size())};

auto val = context.call(ballot_func, argv, &tx);
auto val = context.call_with_rt_options(ballot_func, argv, &tx);

if (!JS_IsException(val))
{
Expand Down Expand Up @@ -215,7 +215,7 @@ namespace ccf
}
argv.push_back(vs);

auto val = js_context.call(resolve_func, argv, &tx);
auto val = js_context.call_with_rt_options(resolve_func, argv, &tx);

std::optional<jsgov::Failure> failure = std::nullopt;
if (JS_IsException(val))
Expand Down Expand Up @@ -308,7 +308,7 @@ namespace ccf
apply_js_context.new_string_len(
proposal_id.c_str(), proposal_id.size())};

auto apply_val = apply_js_context.call(apply_func, apply_argv, &tx);
auto apply_val = apply_js_context.call_with_rt_options(apply_func, apply_argv, &tx);

if (JS_IsException(apply_val))
{
Expand Down Expand Up @@ -1163,7 +1163,7 @@ namespace ccf
auto body_len = proposal_body.size();

auto proposal = context.new_string_len(body, body_len);
auto val = context.call(validate_func, {proposal}, &ctx.tx);
auto val = context.call_with_rt_options(validate_func, {proposal}, &ctx.tx);

if (JS_IsException(val))
{
Expand Down

0 comments on commit c55063a

Please sign in to comment.