Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update API/serialization time constraints #1139

Merged
merged 34 commits into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
bbeafe9
GH-1062 Remove deadline from trace_api_plugin
heifner May 2, 2023
4692fd8
GH-1062 Remove unused struct
heifner May 2, 2023
2eb261c
GH-1062 Enforce http_max_response_time on main thread only and always…
heifner May 2, 2023
6c831db
GH-1062 Use maximum() instead of 365 days for max
heifner May 2, 2023
8cb572c
GH-1062 Add 1000 limit
heifner May 2, 2023
da28bc9
Merge remote-tracking branch 'origin/main' into GH-1062-time-limits
heifner May 4, 2023
9bcbb44
GH-1062 Add move constructor for variant_object to mutable_variant_ob…
heifner May 5, 2023
4e176a1
GH-1062 Change default abi_serializer yield function to enforce max_s…
heifner May 5, 2023
086f1fb
GH-1062 Add a safe_add that does not overflow.
heifner May 5, 2023
0e8739e
GH-1062 Remove deadline since we no longer want to interrupt json cre…
heifner May 5, 2023
cb1b52d
GH-1062 Remove deadline since we no longer want to interrupt json cre…
heifner May 5, 2023
d480a26
GH-1062 mutable_variant_object constructor for variant_object now exp…
heifner May 5, 2023
7e2bd04
GH-1062 Enforce processing on the main thread to http-max-response-ti…
heifner May 5, 2023
a7c5d3c
GH-1062 Avoid unneeded copies
heifner May 6, 2023
0966651
GH-1062 Fix issue with variant internal variant_object being shared
heifner May 8, 2023
05ff752
GH-1062 Need to copy yield function since it is a const&
heifner May 8, 2023
0ef8b09
GH-1062 Only reset deadline when explicitly asked to do so.
heifner May 8, 2023
0eec87e
GH-1062 small optimization
heifner May 8, 2023
1d33a68
GH-1062 Add variant_object to the exclude list of universal reference…
heifner May 10, 2023
724be07
GH-1062 Also guard against underflow
heifner May 10, 2023
6096c0b
GH-1062 Refactor abi_serializer to accept a max_action_data_serializa…
heifner May 10, 2023
e666cd0
GH-1062 Revert unneeded changes to yield call
heifner May 10, 2023
99f9320
GH-1062 Use new fc time_point::safe_add
heifner May 10, 2023
c7bf139
GH-1062 Refactor start_action_serialization into constructor of context
heifner May 12, 2023
af766dc
GH-1062 Simplify recursion_depth lambda
heifner May 12, 2023
07d5a74
GH-1062 assert on exclusive ownership of variant_object
heifner May 13, 2023
079c650
Merge remote-tracking branch 'origin/main' into GH-1062-time-limits
heifner May 15, 2023
8ade327
GH-1062 Fix merge issues
heifner May 15, 2023
6d0a06b
GH-1062 Add back check for correct table
heifner May 15, 2023
87e598a
GH-1062 Simplify deadline calculation.
heifner May 15, 2023
3dc1841
GH-1062 Make get_activated_protocol_features atomic
heifner May 15, 2023
2df7459
GH-1062 Update test to reflect get_activate_protocol_features ignored…
heifner May 15, 2023
bd896c7
GH-1062 Change default http-max-response-time-ms from 30 to 15
heifner May 15, 2023
0465384
GH-1062 If time_limit_ms not specified use http-max-response-time-ms …
heifner May 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 27 additions & 20 deletions libraries/chain/abi_serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <fc/io/raw.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <fc/io/varint.hpp>
#include <fc/time.hpp>

namespace eosio { namespace chain {

Expand All @@ -23,11 +24,11 @@ namespace eosio { namespace chain {

template <typename T>
inline fc::variant variant_from_stream(fc::datastream<const char*>& stream, const abi_serializer::yield_function_t& yield) {
fc::yield_function_t y = [&yield](){ yield(0); }; // create yield function matching fc::variant requirements, 0 for recursive depth
T temp;
fc::raw::unpack( stream, temp );
y();
return fc::variant( temp, y );
yield(0);
// create yield function matching fc::variant requirements, 0 for recursive depth
return fc::variant( temp, [yield](){ yield(0); } );
}

template <typename T>
Expand Down Expand Up @@ -129,7 +130,7 @@ namespace eosio { namespace chain {
}

void abi_serializer::set_abi(abi_def abi, const yield_function_t& yield) {
impl::abi_traverse_context ctx(yield);
impl::abi_traverse_context ctx(yield, fc::microseconds{});

EOS_ASSERT(starts_with(abi.version, "eosio::abi/1."), unsupported_abi_version_exception, "ABI has an unsupported version");

Expand Down Expand Up @@ -235,7 +236,7 @@ namespace eosio { namespace chain {
}

bool abi_serializer::is_type(const std::string_view& type, const yield_function_t& yield)const {
impl::abi_traverse_context ctx(yield);
impl::abi_traverse_context ctx(yield, fc::microseconds{});
return _is_type(type, ctx);
}

Expand Down Expand Up @@ -464,23 +465,27 @@ namespace eosio { namespace chain {
}

fc::variant abi_serializer::binary_to_variant( const std::string_view& type, const bytes& binary, const yield_function_t& yield, bool short_path )const {
impl::binary_to_variant_context ctx(*this, yield, type);
impl::binary_to_variant_context ctx(*this, yield, fc::microseconds{}, type);
ctx.short_path = short_path;
return _binary_to_variant(type, binary, ctx);
}

fc::variant abi_serializer::binary_to_variant( const std::string_view& type, const bytes& binary, const fc::microseconds& max_serialization_time, bool short_path )const {
return binary_to_variant( type, binary, create_yield_function(max_serialization_time), short_path );
fc::variant abi_serializer::binary_to_variant( const std::string_view& type, const bytes& binary, const fc::microseconds& max_action_data_serialization_time, bool short_path )const {
impl::binary_to_variant_context ctx(*this, create_depth_yield_function(), max_action_data_serialization_time, type);
ctx.short_path = short_path;
return _binary_to_variant(type, binary, ctx);
}

fc::variant abi_serializer::binary_to_variant( const std::string_view& type, fc::datastream<const char*>& binary, const yield_function_t& yield, bool short_path )const {
impl::binary_to_variant_context ctx(*this, yield, type);
impl::binary_to_variant_context ctx(*this, yield, fc::microseconds{}, type);
ctx.short_path = short_path;
return _binary_to_variant(type, binary, ctx);
}

fc::variant abi_serializer::binary_to_variant( const std::string_view& type, fc::datastream<const char*>& binary, const fc::microseconds& max_serialization_time, bool short_path )const {
return binary_to_variant( type, binary, create_yield_function(max_serialization_time), short_path );
fc::variant abi_serializer::binary_to_variant( const std::string_view& type, fc::datastream<const char*>& binary, const fc::microseconds& max_action_data_serialization_time, bool short_path )const {
impl::binary_to_variant_context ctx(*this, create_depth_yield_function(), max_action_data_serialization_time, type);
ctx.short_path = short_path;
return _binary_to_variant(type, binary, ctx);
}

void abi_serializer::_variant_to_binary( const std::string_view& type, const fc::variant& var, fc::datastream<char *>& ds, impl::variant_to_binary_context& ctx )const
Expand Down Expand Up @@ -603,23 +608,27 @@ namespace eosio { namespace chain {
} FC_CAPTURE_AND_RETHROW() }

bytes abi_serializer::variant_to_binary( const std::string_view& type, const fc::variant& var, const yield_function_t& yield, bool short_path )const {
impl::variant_to_binary_context ctx(*this, yield, type);
impl::variant_to_binary_context ctx(*this, yield, fc::microseconds{}, type);
ctx.short_path = short_path;
return _variant_to_binary(type, var, ctx);
}

bytes abi_serializer::variant_to_binary( const std::string_view& type, const fc::variant& var, const fc::microseconds& max_serialization_time, bool short_path ) const {
return variant_to_binary( type, var, create_yield_function(max_serialization_time), short_path );
bytes abi_serializer::variant_to_binary( const std::string_view& type, const fc::variant& var, const fc::microseconds& max_action_data_serialization_time, bool short_path ) const {
impl::variant_to_binary_context ctx(*this, create_depth_yield_function(), max_action_data_serialization_time, type);
ctx.short_path = short_path;
return _variant_to_binary(type, var, ctx);
}

void abi_serializer::variant_to_binary( const std::string_view& type, const fc::variant& var, fc::datastream<char*>& ds, const yield_function_t& yield, bool short_path )const {
impl::variant_to_binary_context ctx(*this, yield, type);
impl::variant_to_binary_context ctx(*this, yield, fc::microseconds{}, type);
ctx.short_path = short_path;
_variant_to_binary(type, var, ds, ctx);
}

void abi_serializer::variant_to_binary( const std::string_view& type, const fc::variant& var, fc::datastream<char*>& ds, const fc::microseconds& max_serialization_time, bool short_path ) const {
variant_to_binary( type, var, create_yield_function(max_serialization_time), short_path );
void abi_serializer::variant_to_binary( const std::string_view& type, const fc::variant& var, fc::datastream<char*>& ds, const fc::microseconds& max_action_data_serialization_time, bool short_path ) const {
impl::variant_to_binary_context ctx(*this, create_depth_yield_function(), max_action_data_serialization_time, type);
ctx.short_path = short_path;
_variant_to_binary(type, var, ds, ctx);
}

type_name abi_serializer::get_action_type(name action)const {
Expand Down Expand Up @@ -650,9 +659,7 @@ namespace eosio { namespace chain {
namespace impl {

fc::scoped_exit<std::function<void()>> abi_traverse_context::enter_scope() {
std::function<void()> callback = [old_recursion_depth=recursion_depth, this](){
recursion_depth = old_recursion_depth;
};
std::function<void()> callback = [this](){ --recursion_depth; };

++recursion_depth;
yield( recursion_depth );
Expand Down
Loading